aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorJiang Liu <jiang.liu@huawei.com>2012-07-24 05:20:06 -0400
committerBjorn Helgaas <bhelgaas@google.com>2012-08-23 11:41:37 -0400
commit59875ae489609b2267548dc85160c5f0f0c6f9d4 (patch)
treeefadf88450c3d239806b0020c2b16b56c16f598d /drivers/pci
parent8c0d3a02c1309eb6112d2e7c8172e8ceb26ecfca (diff)
PCI/core: Use PCI Express Capability accessors
Use PCI Express Capability access functions to simplify core. Signed-off-by: Jiang Liu <jiang.liu@huawei.com> Signed-off-by: Yijing Wang <wangyijing@huawei.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/pci.c314
-rw-r--r--drivers/pci/probe.c17
-rw-r--r--drivers/pci/quirks.c9
3 files changed, 66 insertions, 274 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 28eb55b77ee9..fac08f508d09 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -254,38 +254,6 @@ 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 */
273static 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/**
289 * pci_find_ext_capability - Find an extended capability 257 * pci_find_ext_capability - Find an extended capability
290 * @dev: PCI device to query 258 * @dev: PCI device to query
291 * @cap: capability code 259 * @cap: capability code
@@ -854,21 +822,6 @@ EXPORT_SYMBOL(pci_choose_state);
854 822
855#define PCI_EXP_SAVE_REGS 7 823#define PCI_EXP_SAVE_REGS 7
856 824
857#define pcie_cap_has_devctl(type, flags) 1
858#define pcie_cap_has_lnkctl(type, flags) \
859 ((flags & PCI_EXP_FLAGS_VERS) > 1 || \
860 (type == PCI_EXP_TYPE_ROOT_PORT || \
861 type == PCI_EXP_TYPE_ENDPOINT || \
862 type == PCI_EXP_TYPE_LEG_END))
863#define pcie_cap_has_sltctl(type, flags) \
864 ((flags & PCI_EXP_FLAGS_VERS) > 1 || \
865 ((type == PCI_EXP_TYPE_ROOT_PORT) || \
866 (type == PCI_EXP_TYPE_DOWNSTREAM && \
867 (flags & PCI_EXP_FLAGS_SLOT))))
868#define pcie_cap_has_rtctl(type, flags) \
869 ((flags & PCI_EXP_FLAGS_VERS) > 1 || \
870 (type == PCI_EXP_TYPE_ROOT_PORT || \
871 type == PCI_EXP_TYPE_RC_EC))
872 825
873static struct pci_cap_saved_state *pci_find_saved_cap( 826static struct pci_cap_saved_state *pci_find_saved_cap(
874 struct pci_dev *pci_dev, char cap) 827 struct pci_dev *pci_dev, char cap)
@@ -885,13 +838,11 @@ static struct pci_cap_saved_state *pci_find_saved_cap(
885 838
886static int pci_save_pcie_state(struct pci_dev *dev) 839static int pci_save_pcie_state(struct pci_dev *dev)
887{ 840{
888 int type, pos, i = 0; 841 int i = 0;
889 struct pci_cap_saved_state *save_state; 842 struct pci_cap_saved_state *save_state;
890 u16 *cap; 843 u16 *cap;
891 u16 flags;
892 844
893 pos = pci_pcie_cap(dev); 845 if (!pci_is_pcie(dev))
894 if (!pos)
895 return 0; 846 return 0;
896 847
897 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); 848 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
@@ -899,62 +850,37 @@ static int pci_save_pcie_state(struct pci_dev *dev)
899 dev_err(&dev->dev, "buffer not found in %s\n", __func__); 850 dev_err(&dev->dev, "buffer not found in %s\n", __func__);
900 return -ENOMEM; 851 return -ENOMEM;
901 } 852 }
902 cap = (u16 *)&save_state->cap.data[0];
903
904 pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags);
905
906 type = pci_pcie_type(dev);
907 if (pcie_cap_has_devctl(type, flags))
908 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &cap[i++]);
909 if (pcie_cap_has_lnkctl(type, flags))
910 pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]);
911 if (pcie_cap_has_sltctl(type, flags))
912 pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]);
913 if (pcie_cap_has_rtctl(type, flags))
914 pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]);
915 853
916 pos = pci_pcie_cap2(dev); 854 cap = (u16 *)&save_state->cap.data[0];
917 if (!pos) 855 pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &cap[i++]);
918 return 0; 856 pcie_capability_read_word(dev, PCI_EXP_LNKCTL, &cap[i++]);
857 pcie_capability_read_word(dev, PCI_EXP_SLTCTL, &cap[i++]);
858 pcie_capability_read_word(dev, PCI_EXP_RTCTL, &cap[i++]);
859 pcie_capability_read_word(dev, PCI_EXP_DEVCTL2, &cap[i++]);
860 pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &cap[i++]);
861 pcie_capability_read_word(dev, PCI_EXP_SLTCTL2, &cap[i++]);
919 862
920 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &cap[i++]);
921 pci_read_config_word(dev, pos + PCI_EXP_LNKCTL2, &cap[i++]);
922 pci_read_config_word(dev, pos + PCI_EXP_SLTCTL2, &cap[i++]);
923 return 0; 863 return 0;
924} 864}
925 865
926static void pci_restore_pcie_state(struct pci_dev *dev) 866static void pci_restore_pcie_state(struct pci_dev *dev)
927{ 867{
928 int i = 0, pos, type; 868 int i = 0;
929 struct pci_cap_saved_state *save_state; 869 struct pci_cap_saved_state *save_state;
930 u16 *cap; 870 u16 *cap;
931 u16 flags;
932 871
933 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); 872 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
934 pos = pci_find_capability(dev, PCI_CAP_ID_EXP); 873 if (!save_state)
935 if (!save_state || pos <= 0)
936 return;
937 cap = (u16 *)&save_state->cap.data[0];
938
939 pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags);
940
941 type = pci_pcie_type(dev);
942 if (pcie_cap_has_devctl(type, flags))
943 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, cap[i++]);
944 if (pcie_cap_has_lnkctl(type, flags))
945 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
946 if (pcie_cap_has_sltctl(type, flags))
947 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
948 if (pcie_cap_has_rtctl(type, flags))
949 pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
950
951 pos = pci_pcie_cap2(dev);
952 if (!pos)
953 return; 874 return;
954 875
955 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, cap[i++]); 876 cap = (u16 *)&save_state->cap.data[0];
956 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL2, cap[i++]); 877 pcie_capability_write_word(dev, PCI_EXP_DEVCTL, cap[i++]);
957 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL2, cap[i++]); 878 pcie_capability_write_word(dev, PCI_EXP_LNKCTL, cap[i++]);
879 pcie_capability_write_word(dev, PCI_EXP_SLTCTL, cap[i++]);
880 pcie_capability_write_word(dev, PCI_EXP_RTCTL, cap[i++]);
881 pcie_capability_write_word(dev, PCI_EXP_DEVCTL2, cap[i++]);
882 pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, cap[i++]);
883 pcie_capability_write_word(dev, PCI_EXP_SLTCTL2, cap[i++]);
958} 884}
959 885
960 886
@@ -2068,35 +1994,24 @@ void pci_free_cap_save_buffers(struct pci_dev *dev)
2068 */ 1994 */
2069void pci_enable_ari(struct pci_dev *dev) 1995void pci_enable_ari(struct pci_dev *dev)
2070{ 1996{
2071 int pos;
2072 u32 cap; 1997 u32 cap;
2073 u16 ctrl;
2074 struct pci_dev *bridge; 1998 struct pci_dev *bridge;
2075 1999
2076 if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) 2000 if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn)
2077 return; 2001 return;
2078 2002
2079 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); 2003 if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI))
2080 if (!pos)
2081 return; 2004 return;
2082 2005
2083 bridge = dev->bus->self; 2006 bridge = dev->bus->self;
2084 if (!bridge) 2007 if (!bridge)
2085 return; 2008 return;
2086 2009
2087 /* ARI is a PCIe cap v2 feature */ 2010 pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap);
2088 pos = pci_pcie_cap2(bridge);
2089 if (!pos)
2090 return;
2091
2092 pci_read_config_dword(bridge, pos + PCI_EXP_DEVCAP2, &cap);
2093 if (!(cap & PCI_EXP_DEVCAP2_ARI)) 2011 if (!(cap & PCI_EXP_DEVCAP2_ARI))
2094 return; 2012 return;
2095 2013
2096 pci_read_config_word(bridge, pos + PCI_EXP_DEVCTL2, &ctrl); 2014 pcie_capability_set_word(bridge, PCI_EXP_DEVCTL2, PCI_EXP_DEVCTL2_ARI);
2097 ctrl |= PCI_EXP_DEVCTL2_ARI;
2098 pci_write_config_word(bridge, pos + PCI_EXP_DEVCTL2, ctrl);
2099
2100 bridge->ari_enabled = 1; 2015 bridge->ari_enabled = 1;
2101} 2016}
2102 2017
@@ -2111,20 +2026,14 @@ void pci_enable_ari(struct pci_dev *dev)
2111 */ 2026 */
2112void pci_enable_ido(struct pci_dev *dev, unsigned long type) 2027void pci_enable_ido(struct pci_dev *dev, unsigned long type)
2113{ 2028{
2114 int pos; 2029 u16 ctrl = 0;
2115 u16 ctrl;
2116 2030
2117 /* ID-based Ordering is a PCIe cap v2 feature */
2118 pos = pci_pcie_cap2(dev);
2119 if (!pos)
2120 return;
2121
2122 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
2123 if (type & PCI_EXP_IDO_REQUEST) 2031 if (type & PCI_EXP_IDO_REQUEST)
2124 ctrl |= PCI_EXP_IDO_REQ_EN; 2032 ctrl |= PCI_EXP_IDO_REQ_EN;
2125 if (type & PCI_EXP_IDO_COMPLETION) 2033 if (type & PCI_EXP_IDO_COMPLETION)
2126 ctrl |= PCI_EXP_IDO_CMP_EN; 2034 ctrl |= PCI_EXP_IDO_CMP_EN;
2127 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2035 if (ctrl)
2036 pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, ctrl);
2128} 2037}
2129EXPORT_SYMBOL(pci_enable_ido); 2038EXPORT_SYMBOL(pci_enable_ido);
2130 2039
@@ -2135,20 +2044,14 @@ EXPORT_SYMBOL(pci_enable_ido);
2135 */ 2044 */
2136void pci_disable_ido(struct pci_dev *dev, unsigned long type) 2045void pci_disable_ido(struct pci_dev *dev, unsigned long type)
2137{ 2046{
2138 int pos; 2047 u16 ctrl = 0;
2139 u16 ctrl;
2140 2048
2141 /* ID-based Ordering is a PCIe cap v2 feature */
2142 pos = pci_pcie_cap2(dev);
2143 if (!pos)
2144 return;
2145
2146 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
2147 if (type & PCI_EXP_IDO_REQUEST) 2049 if (type & PCI_EXP_IDO_REQUEST)
2148 ctrl &= ~PCI_EXP_IDO_REQ_EN; 2050 ctrl |= PCI_EXP_IDO_REQ_EN;
2149 if (type & PCI_EXP_IDO_COMPLETION) 2051 if (type & PCI_EXP_IDO_COMPLETION)
2150 ctrl &= ~PCI_EXP_IDO_CMP_EN; 2052 ctrl |= PCI_EXP_IDO_CMP_EN;
2151 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2053 if (ctrl)
2054 pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, ctrl);
2152} 2055}
2153EXPORT_SYMBOL(pci_disable_ido); 2056EXPORT_SYMBOL(pci_disable_ido);
2154 2057
@@ -2173,17 +2076,11 @@ EXPORT_SYMBOL(pci_disable_ido);
2173 */ 2076 */
2174int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type) 2077int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type)
2175{ 2078{
2176 int pos;
2177 u32 cap; 2079 u32 cap;
2178 u16 ctrl; 2080 u16 ctrl;
2179 int ret; 2081 int ret;
2180 2082
2181 /* OBFF is a PCIe cap v2 feature */ 2083 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap);
2182 pos = pci_pcie_cap2(dev);
2183 if (!pos)
2184 return -ENOTSUPP;
2185
2186 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap);
2187 if (!(cap & PCI_EXP_OBFF_MASK)) 2084 if (!(cap & PCI_EXP_OBFF_MASK))
2188 return -ENOTSUPP; /* no OBFF support at all */ 2085 return -ENOTSUPP; /* no OBFF support at all */
2189 2086
@@ -2194,7 +2091,7 @@ int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type)
2194 return ret; 2091 return ret;
2195 } 2092 }
2196 2093
2197 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); 2094 pcie_capability_read_word(dev, PCI_EXP_DEVCTL2, &ctrl);
2198 if (cap & PCI_EXP_OBFF_WAKE) 2095 if (cap & PCI_EXP_OBFF_WAKE)
2199 ctrl |= PCI_EXP_OBFF_WAKE_EN; 2096 ctrl |= PCI_EXP_OBFF_WAKE_EN;
2200 else { 2097 else {
@@ -2212,7 +2109,7 @@ int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type)
2212 return -ENOTSUPP; 2109 return -ENOTSUPP;
2213 } 2110 }
2214 } 2111 }
2215 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2112 pcie_capability_write_word(dev, PCI_EXP_DEVCTL2, ctrl);
2216 2113
2217 return 0; 2114 return 0;
2218} 2115}
@@ -2226,17 +2123,7 @@ EXPORT_SYMBOL(pci_enable_obff);
2226 */ 2123 */
2227void pci_disable_obff(struct pci_dev *dev) 2124void pci_disable_obff(struct pci_dev *dev)
2228{ 2125{
2229 int pos; 2126 pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, PCI_EXP_OBFF_WAKE_EN);
2230 u16 ctrl;
2231
2232 /* OBFF is a PCIe cap v2 feature */
2233 pos = pci_pcie_cap2(dev);
2234 if (!pos)
2235 return;
2236
2237 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
2238 ctrl &= ~PCI_EXP_OBFF_WAKE_EN;
2239 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl);
2240} 2127}
2241EXPORT_SYMBOL(pci_disable_obff); 2128EXPORT_SYMBOL(pci_disable_obff);
2242 2129
@@ -2249,15 +2136,9 @@ EXPORT_SYMBOL(pci_disable_obff);
2249 */ 2136 */
2250static bool pci_ltr_supported(struct pci_dev *dev) 2137static bool pci_ltr_supported(struct pci_dev *dev)
2251{ 2138{
2252 int pos;
2253 u32 cap; 2139 u32 cap;
2254 2140
2255 /* LTR is a PCIe cap v2 feature */ 2141 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap);
2256 pos = pci_pcie_cap2(dev);
2257 if (!pos)
2258 return false;
2259
2260 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap);
2261 2142
2262 return cap & PCI_EXP_DEVCAP2_LTR; 2143 return cap & PCI_EXP_DEVCAP2_LTR;
2263} 2144}
@@ -2274,22 +2155,15 @@ static bool pci_ltr_supported(struct pci_dev *dev)
2274 */ 2155 */
2275int pci_enable_ltr(struct pci_dev *dev) 2156int pci_enable_ltr(struct pci_dev *dev)
2276{ 2157{
2277 int pos;
2278 u16 ctrl;
2279 int ret; 2158 int ret;
2280 2159
2281 if (!pci_ltr_supported(dev))
2282 return -ENOTSUPP;
2283
2284 /* LTR is a PCIe cap v2 feature */
2285 pos = pci_pcie_cap2(dev);
2286 if (!pos)
2287 return -ENOTSUPP;
2288
2289 /* Only primary function can enable/disable LTR */ 2160 /* Only primary function can enable/disable LTR */
2290 if (PCI_FUNC(dev->devfn) != 0) 2161 if (PCI_FUNC(dev->devfn) != 0)
2291 return -EINVAL; 2162 return -EINVAL;
2292 2163
2164 if (!pci_ltr_supported(dev))
2165 return -ENOTSUPP;
2166
2293 /* Enable upstream ports first */ 2167 /* Enable upstream ports first */
2294 if (dev->bus->self) { 2168 if (dev->bus->self) {
2295 ret = pci_enable_ltr(dev->bus->self); 2169 ret = pci_enable_ltr(dev->bus->self);
@@ -2297,11 +2171,7 @@ int pci_enable_ltr(struct pci_dev *dev)
2297 return ret; 2171 return ret;
2298 } 2172 }
2299 2173
2300 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); 2174 return pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, PCI_EXP_LTR_EN);
2301 ctrl |= PCI_EXP_LTR_EN;
2302 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl);
2303
2304 return 0;
2305} 2175}
2306EXPORT_SYMBOL(pci_enable_ltr); 2176EXPORT_SYMBOL(pci_enable_ltr);
2307 2177
@@ -2311,24 +2181,14 @@ EXPORT_SYMBOL(pci_enable_ltr);
2311 */ 2181 */
2312void pci_disable_ltr(struct pci_dev *dev) 2182void pci_disable_ltr(struct pci_dev *dev)
2313{ 2183{
2314 int pos;
2315 u16 ctrl;
2316
2317 if (!pci_ltr_supported(dev))
2318 return;
2319
2320 /* LTR is a PCIe cap v2 feature */
2321 pos = pci_pcie_cap2(dev);
2322 if (!pos)
2323 return;
2324
2325 /* Only primary function can enable/disable LTR */ 2184 /* Only primary function can enable/disable LTR */
2326 if (PCI_FUNC(dev->devfn) != 0) 2185 if (PCI_FUNC(dev->devfn) != 0)
2327 return; 2186 return;
2328 2187
2329 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); 2188 if (!pci_ltr_supported(dev))
2330 ctrl &= ~PCI_EXP_LTR_EN; 2189 return;
2331 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); 2190
2191 pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, PCI_EXP_LTR_EN);
2332} 2192}
2333EXPORT_SYMBOL(pci_disable_ltr); 2193EXPORT_SYMBOL(pci_disable_ltr);
2334 2194
@@ -2411,9 +2271,6 @@ void pci_enable_acs(struct pci_dev *dev)
2411 if (!pci_acs_enable) 2271 if (!pci_acs_enable)
2412 return; 2272 return;
2413 2273
2414 if (!pci_is_pcie(dev))
2415 return;
2416
2417 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS); 2274 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
2418 if (!pos) 2275 if (!pos)
2419 return; 2276 return;
@@ -3178,15 +3035,10 @@ EXPORT_SYMBOL(pci_set_dma_seg_boundary);
3178static int pcie_flr(struct pci_dev *dev, int probe) 3035static int pcie_flr(struct pci_dev *dev, int probe)
3179{ 3036{
3180 int i; 3037 int i;
3181 int pos;
3182 u32 cap; 3038 u32 cap;
3183 u16 status, control; 3039 u16 status;
3184
3185 pos = pci_pcie_cap(dev);
3186 if (!pos)
3187 return -ENOTTY;
3188 3040
3189 pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap); 3041 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &cap);
3190 if (!(cap & PCI_EXP_DEVCAP_FLR)) 3042 if (!(cap & PCI_EXP_DEVCAP_FLR))
3191 return -ENOTTY; 3043 return -ENOTTY;
3192 3044
@@ -3198,7 +3050,7 @@ static int pcie_flr(struct pci_dev *dev, int probe)
3198 if (i) 3050 if (i)
3199 msleep((1 << (i - 1)) * 100); 3051 msleep((1 << (i - 1)) * 100);
3200 3052
3201 pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status); 3053 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
3202 if (!(status & PCI_EXP_DEVSTA_TRPND)) 3054 if (!(status & PCI_EXP_DEVSTA_TRPND))
3203 goto clear; 3055 goto clear;
3204 } 3056 }
@@ -3207,9 +3059,7 @@ static int pcie_flr(struct pci_dev *dev, int probe)
3207 "proceeding with reset anyway\n"); 3059 "proceeding with reset anyway\n");
3208 3060
3209clear: 3061clear:
3210 pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &control); 3062 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
3211 control |= PCI_EXP_DEVCTL_BCR_FLR;
3212 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, control);
3213 3063
3214 msleep(100); 3064 msleep(100);
3215 3065
@@ -3577,18 +3427,11 @@ EXPORT_SYMBOL(pcix_set_mmrbc);
3577 */ 3427 */
3578int pcie_get_readrq(struct pci_dev *dev) 3428int pcie_get_readrq(struct pci_dev *dev)
3579{ 3429{
3580 int ret, cap;
3581 u16 ctl; 3430 u16 ctl;
3582 3431
3583 cap = pci_pcie_cap(dev); 3432 pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl);
3584 if (!cap)
3585 return -EINVAL;
3586
3587 ret = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
3588 if (!ret)
3589 ret = 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12);
3590 3433
3591 return ret; 3434 return 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12);
3592} 3435}
3593EXPORT_SYMBOL(pcie_get_readrq); 3436EXPORT_SYMBOL(pcie_get_readrq);
3594 3437
@@ -3602,19 +3445,11 @@ EXPORT_SYMBOL(pcie_get_readrq);
3602 */ 3445 */
3603int pcie_set_readrq(struct pci_dev *dev, int rq) 3446int pcie_set_readrq(struct pci_dev *dev, int rq)
3604{ 3447{
3605 int cap, err = -EINVAL; 3448 u16 v;
3606 u16 ctl, v;
3607 3449
3608 if (rq < 128 || rq > 4096 || !is_power_of_2(rq)) 3450 if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
3609 goto out; 3451 return -EINVAL;
3610
3611 cap = pci_pcie_cap(dev);
3612 if (!cap)
3613 goto out;
3614 3452
3615 err = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
3616 if (err)
3617 goto out;
3618 /* 3453 /*
3619 * If using the "performance" PCIe config, we clamp the 3454 * If using the "performance" PCIe config, we clamp the
3620 * read rq size to the max packet size to prevent the 3455 * read rq size to the max packet size to prevent the
@@ -3632,14 +3467,8 @@ int pcie_set_readrq(struct pci_dev *dev, int rq)
3632 3467
3633 v = (ffs(rq) - 8) << 12; 3468 v = (ffs(rq) - 8) << 12;
3634 3469
3635 if ((ctl & PCI_EXP_DEVCTL_READRQ) != v) { 3470 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
3636 ctl &= ~PCI_EXP_DEVCTL_READRQ; 3471 PCI_EXP_DEVCTL_READRQ, v);
3637 ctl |= v;
3638 err = pci_write_config_word(dev, cap + PCI_EXP_DEVCTL, ctl);
3639 }
3640
3641out:
3642 return err;
3643} 3472}
3644EXPORT_SYMBOL(pcie_set_readrq); 3473EXPORT_SYMBOL(pcie_set_readrq);
3645 3474
@@ -3652,18 +3481,11 @@ EXPORT_SYMBOL(pcie_set_readrq);
3652 */ 3481 */
3653int pcie_get_mps(struct pci_dev *dev) 3482int pcie_get_mps(struct pci_dev *dev)
3654{ 3483{
3655 int ret, cap;
3656 u16 ctl; 3484 u16 ctl;
3657 3485
3658 cap = pci_pcie_cap(dev); 3486 pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl);
3659 if (!cap)
3660 return -EINVAL;
3661
3662 ret = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
3663 if (!ret)
3664 ret = 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
3665 3487
3666 return ret; 3488 return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
3667} 3489}
3668 3490
3669/** 3491/**
@@ -3676,32 +3498,18 @@ int pcie_get_mps(struct pci_dev *dev)
3676 */ 3498 */
3677int pcie_set_mps(struct pci_dev *dev, int mps) 3499int pcie_set_mps(struct pci_dev *dev, int mps)
3678{ 3500{
3679 int cap, err = -EINVAL; 3501 u16 v;
3680 u16 ctl, v;
3681 3502
3682 if (mps < 128 || mps > 4096 || !is_power_of_2(mps)) 3503 if (mps < 128 || mps > 4096 || !is_power_of_2(mps))
3683 goto out; 3504 return -EINVAL;
3684 3505
3685 v = ffs(mps) - 8; 3506 v = ffs(mps) - 8;
3686 if (v > dev->pcie_mpss) 3507 if (v > dev->pcie_mpss)
3687 goto out; 3508 return -EINVAL;
3688 v <<= 5; 3509 v <<= 5;
3689 3510
3690 cap = pci_pcie_cap(dev); 3511 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
3691 if (!cap) 3512 PCI_EXP_DEVCTL_PAYLOAD, v);
3692 goto out;
3693
3694 err = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl);
3695 if (err)
3696 goto out;
3697
3698 if ((ctl & PCI_EXP_DEVCTL_PAYLOAD) != v) {
3699 ctl &= ~PCI_EXP_DEVCTL_PAYLOAD;
3700 ctl |= v;
3701 err = pci_write_config_word(dev, cap + PCI_EXP_DEVCTL, ctl);
3702 }
3703out:
3704 return err;
3705} 3513}
3706 3514
3707/** 3515/**
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 8bcc985faa16..d8f513bdf95c 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -603,10 +603,10 @@ static void pci_set_bus_speed(struct pci_bus *bus)
603 u32 linkcap; 603 u32 linkcap;
604 u16 linksta; 604 u16 linksta;
605 605
606 pci_read_config_dword(bridge, pos + PCI_EXP_LNKCAP, &linkcap); 606 pcie_capability_read_dword(bridge, PCI_EXP_LNKCAP, &linkcap);
607 bus->max_bus_speed = pcie_link_speed[linkcap & 0xf]; 607 bus->max_bus_speed = pcie_link_speed[linkcap & 0xf];
608 608
609 pci_read_config_word(bridge, pos + PCI_EXP_LNKSTA, &linksta); 609 pcie_capability_read_word(bridge, PCI_EXP_LNKSTA, &linksta);
610 pcie_update_link_speed(bus, linksta); 610 pcie_update_link_speed(bus, linksta);
611 } 611 }
612} 612}
@@ -936,17 +936,9 @@ void set_pcie_port_type(struct pci_dev *pdev)
936 936
937void set_pcie_hotplug_bridge(struct pci_dev *pdev) 937void set_pcie_hotplug_bridge(struct pci_dev *pdev)
938{ 938{
939 int pos;
940 u16 reg16;
941 u32 reg32; 939 u32 reg32;
942 940
943 pos = pci_pcie_cap(pdev); 941 pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, &reg32);
944 if (!pos)
945 return;
946 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
947 if (!(reg16 & PCI_EXP_FLAGS_SLOT))
948 return;
949 pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &reg32);
950 if (reg32 & PCI_EXP_SLTCAP_HPC) 942 if (reg32 & PCI_EXP_SLTCAP_HPC)
951 pdev->is_hotplug_bridge = 1; 943 pdev->is_hotplug_bridge = 1;
952} 944}
@@ -1160,8 +1152,7 @@ int pci_cfg_space_size(struct pci_dev *dev)
1160 if (class == PCI_CLASS_BRIDGE_HOST) 1152 if (class == PCI_CLASS_BRIDGE_HOST)
1161 return pci_cfg_space_size_ext(dev); 1153 return pci_cfg_space_size_ext(dev);
1162 1154
1163 pos = pci_pcie_cap(dev); 1155 if (!pci_is_pcie(dev)) {
1164 if (!pos) {
1165 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); 1156 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
1166 if (!pos) 1157 if (!pos)
1167 goto fail; 1158 goto fail;
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 51553179e967..aa77538c50c7 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -3081,17 +3081,10 @@ static int reset_intel_generic_dev(struct pci_dev *dev, int probe)
3081 3081
3082static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe) 3082static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe)
3083{ 3083{
3084 int pos;
3085
3086 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
3087 if (!pos)
3088 return -ENOTTY;
3089
3090 if (probe) 3084 if (probe)
3091 return 0; 3085 return 0;
3092 3086
3093 pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, 3087 pcie_capability_write_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
3094 PCI_EXP_DEVCTL_BCR_FLR);
3095 msleep(100); 3088 msleep(100);
3096 3089
3097 return 0; 3090 return 0;