diff options
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r-- | drivers/pci/pci.c | 251 |
1 files changed, 163 insertions, 88 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 1a91bf9687af..6c93af5ced18 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -24,6 +24,11 @@ | |||
24 | #include <asm/setup.h> | 24 | #include <asm/setup.h> |
25 | #include "pci.h" | 25 | #include "pci.h" |
26 | 26 | ||
27 | const char *pci_power_names[] = { | ||
28 | "error", "D0", "D1", "D2", "D3hot", "D3cold", "unknown", | ||
29 | }; | ||
30 | EXPORT_SYMBOL_GPL(pci_power_names); | ||
31 | |||
27 | unsigned int pci_pm_d3_delay = PCI_PM_D3_WAIT; | 32 | unsigned int pci_pm_d3_delay = PCI_PM_D3_WAIT; |
28 | 33 | ||
29 | #ifdef CONFIG_PCI_DOMAINS | 34 | #ifdef CONFIG_PCI_DOMAINS |
@@ -480,6 +485,8 @@ static int pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
480 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; | 485 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
481 | pmcsr |= state; | 486 | pmcsr |= state; |
482 | break; | 487 | break; |
488 | case PCI_D3hot: | ||
489 | case PCI_D3cold: | ||
483 | case PCI_UNKNOWN: /* Boot-up */ | 490 | case PCI_UNKNOWN: /* Boot-up */ |
484 | if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot | 491 | if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot |
485 | && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) | 492 | && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) |
@@ -1203,7 +1210,7 @@ void pci_pme_active(struct pci_dev *dev, bool enable) | |||
1203 | * Error code depending on the platform is returned if both the platform and | 1210 | * Error code depending on the platform is returned if both the platform and |
1204 | * the native mechanism fail to enable the generation of wake-up events | 1211 | * the native mechanism fail to enable the generation of wake-up events |
1205 | */ | 1212 | */ |
1206 | int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) | 1213 | int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable) |
1207 | { | 1214 | { |
1208 | int error = 0; | 1215 | int error = 0; |
1209 | bool pme_done = false; | 1216 | bool pme_done = false; |
@@ -1282,15 +1289,14 @@ pci_power_t pci_target_state(struct pci_dev *dev) | |||
1282 | default: | 1289 | default: |
1283 | target_state = state; | 1290 | target_state = state; |
1284 | } | 1291 | } |
1292 | } else if (!dev->pm_cap) { | ||
1293 | target_state = PCI_D0; | ||
1285 | } else if (device_may_wakeup(&dev->dev)) { | 1294 | } else if (device_may_wakeup(&dev->dev)) { |
1286 | /* | 1295 | /* |
1287 | * Find the deepest state from which the device can generate | 1296 | * Find the deepest state from which the device can generate |
1288 | * wake-up events, make it the target state and enable device | 1297 | * wake-up events, make it the target state and enable device |
1289 | * to generate PME#. | 1298 | * to generate PME#. |
1290 | */ | 1299 | */ |
1291 | if (!dev->pm_cap) | ||
1292 | return PCI_POWER_ERROR; | ||
1293 | |||
1294 | if (dev->pme_support) { | 1300 | if (dev->pme_support) { |
1295 | while (target_state | 1301 | while (target_state |
1296 | && !(dev->pme_support & (1 << target_state))) | 1302 | && !(dev->pme_support & (1 << target_state))) |
@@ -1527,7 +1533,7 @@ pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge) | |||
1527 | if (!pin) | 1533 | if (!pin) |
1528 | return -1; | 1534 | return -1; |
1529 | 1535 | ||
1530 | while (dev->bus->parent) { | 1536 | while (!pci_is_root_bus(dev->bus)) { |
1531 | pin = pci_swizzle_interrupt_pin(dev, pin); | 1537 | pin = pci_swizzle_interrupt_pin(dev, pin); |
1532 | dev = dev->bus->self; | 1538 | dev = dev->bus->self; |
1533 | } | 1539 | } |
@@ -1547,7 +1553,7 @@ u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp) | |||
1547 | { | 1553 | { |
1548 | u8 pin = *pinp; | 1554 | u8 pin = *pinp; |
1549 | 1555 | ||
1550 | while (dev->bus->parent) { | 1556 | while (!pci_is_root_bus(dev->bus)) { |
1551 | pin = pci_swizzle_interrupt_pin(dev, pin); | 1557 | pin = pci_swizzle_interrupt_pin(dev, pin); |
1552 | dev = dev->bus->self; | 1558 | dev = dev->bus->self; |
1553 | } | 1559 | } |
@@ -2053,111 +2059,177 @@ int pci_set_dma_seg_boundary(struct pci_dev *dev, unsigned long mask) | |||
2053 | EXPORT_SYMBOL(pci_set_dma_seg_boundary); | 2059 | EXPORT_SYMBOL(pci_set_dma_seg_boundary); |
2054 | #endif | 2060 | #endif |
2055 | 2061 | ||
2056 | static int __pcie_flr(struct pci_dev *dev, int probe) | 2062 | static int pcie_flr(struct pci_dev *dev, int probe) |
2057 | { | 2063 | { |
2058 | u16 status; | 2064 | int i; |
2065 | int pos; | ||
2059 | u32 cap; | 2066 | u32 cap; |
2060 | int exppos = pci_find_capability(dev, PCI_CAP_ID_EXP); | 2067 | u16 status; |
2061 | 2068 | ||
2062 | if (!exppos) | 2069 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); |
2070 | if (!pos) | ||
2063 | return -ENOTTY; | 2071 | return -ENOTTY; |
2064 | pci_read_config_dword(dev, exppos + PCI_EXP_DEVCAP, &cap); | 2072 | |
2073 | pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap); | ||
2065 | if (!(cap & PCI_EXP_DEVCAP_FLR)) | 2074 | if (!(cap & PCI_EXP_DEVCAP_FLR)) |
2066 | return -ENOTTY; | 2075 | return -ENOTTY; |
2067 | 2076 | ||
2068 | if (probe) | 2077 | if (probe) |
2069 | return 0; | 2078 | return 0; |
2070 | 2079 | ||
2071 | pci_block_user_cfg_access(dev); | ||
2072 | |||
2073 | /* Wait for Transaction Pending bit clean */ | 2080 | /* Wait for Transaction Pending bit clean */ |
2074 | pci_read_config_word(dev, exppos + PCI_EXP_DEVSTA, &status); | 2081 | for (i = 0; i < 4; i++) { |
2075 | if (!(status & PCI_EXP_DEVSTA_TRPND)) | 2082 | if (i) |
2076 | goto transaction_done; | 2083 | msleep((1 << (i - 1)) * 100); |
2077 | 2084 | ||
2078 | msleep(100); | 2085 | pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status); |
2079 | pci_read_config_word(dev, exppos + PCI_EXP_DEVSTA, &status); | 2086 | if (!(status & PCI_EXP_DEVSTA_TRPND)) |
2080 | if (!(status & PCI_EXP_DEVSTA_TRPND)) | 2087 | goto clear; |
2081 | goto transaction_done; | 2088 | } |
2082 | 2089 | ||
2083 | dev_info(&dev->dev, "Busy after 100ms while trying to reset; " | 2090 | dev_err(&dev->dev, "transaction is not cleared; " |
2084 | "sleeping for 1 second\n"); | 2091 | "proceeding with reset anyway\n"); |
2085 | ssleep(1); | 2092 | |
2086 | pci_read_config_word(dev, exppos + PCI_EXP_DEVSTA, &status); | 2093 | clear: |
2087 | if (status & PCI_EXP_DEVSTA_TRPND) | 2094 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, |
2088 | dev_info(&dev->dev, "Still busy after 1s; " | ||
2089 | "proceeding with reset anyway\n"); | ||
2090 | |||
2091 | transaction_done: | ||
2092 | pci_write_config_word(dev, exppos + PCI_EXP_DEVCTL, | ||
2093 | PCI_EXP_DEVCTL_BCR_FLR); | 2095 | PCI_EXP_DEVCTL_BCR_FLR); |
2094 | mdelay(100); | 2096 | msleep(100); |
2095 | 2097 | ||
2096 | pci_unblock_user_cfg_access(dev); | ||
2097 | return 0; | 2098 | return 0; |
2098 | } | 2099 | } |
2099 | 2100 | ||
2100 | static int __pci_af_flr(struct pci_dev *dev, int probe) | 2101 | static int pci_af_flr(struct pci_dev *dev, int probe) |
2101 | { | 2102 | { |
2102 | int cappos = pci_find_capability(dev, PCI_CAP_ID_AF); | 2103 | int i; |
2103 | u8 status; | 2104 | int pos; |
2104 | u8 cap; | 2105 | u8 cap; |
2106 | u8 status; | ||
2105 | 2107 | ||
2106 | if (!cappos) | 2108 | pos = pci_find_capability(dev, PCI_CAP_ID_AF); |
2109 | if (!pos) | ||
2107 | return -ENOTTY; | 2110 | return -ENOTTY; |
2108 | pci_read_config_byte(dev, cappos + PCI_AF_CAP, &cap); | 2111 | |
2112 | pci_read_config_byte(dev, pos + PCI_AF_CAP, &cap); | ||
2109 | if (!(cap & PCI_AF_CAP_TP) || !(cap & PCI_AF_CAP_FLR)) | 2113 | if (!(cap & PCI_AF_CAP_TP) || !(cap & PCI_AF_CAP_FLR)) |
2110 | return -ENOTTY; | 2114 | return -ENOTTY; |
2111 | 2115 | ||
2112 | if (probe) | 2116 | if (probe) |
2113 | return 0; | 2117 | return 0; |
2114 | 2118 | ||
2115 | pci_block_user_cfg_access(dev); | ||
2116 | |||
2117 | /* Wait for Transaction Pending bit clean */ | 2119 | /* Wait for Transaction Pending bit clean */ |
2118 | pci_read_config_byte(dev, cappos + PCI_AF_STATUS, &status); | 2120 | for (i = 0; i < 4; i++) { |
2119 | if (!(status & PCI_AF_STATUS_TP)) | 2121 | if (i) |
2120 | goto transaction_done; | 2122 | msleep((1 << (i - 1)) * 100); |
2121 | 2123 | ||
2124 | pci_read_config_byte(dev, pos + PCI_AF_STATUS, &status); | ||
2125 | if (!(status & PCI_AF_STATUS_TP)) | ||
2126 | goto clear; | ||
2127 | } | ||
2128 | |||
2129 | dev_err(&dev->dev, "transaction is not cleared; " | ||
2130 | "proceeding with reset anyway\n"); | ||
2131 | |||
2132 | clear: | ||
2133 | pci_write_config_byte(dev, pos + PCI_AF_CTRL, PCI_AF_CTRL_FLR); | ||
2122 | msleep(100); | 2134 | msleep(100); |
2123 | pci_read_config_byte(dev, cappos + PCI_AF_STATUS, &status); | 2135 | |
2124 | if (!(status & PCI_AF_STATUS_TP)) | ||
2125 | goto transaction_done; | ||
2126 | |||
2127 | dev_info(&dev->dev, "Busy after 100ms while trying to" | ||
2128 | " reset; sleeping for 1 second\n"); | ||
2129 | ssleep(1); | ||
2130 | pci_read_config_byte(dev, cappos + PCI_AF_STATUS, &status); | ||
2131 | if (status & PCI_AF_STATUS_TP) | ||
2132 | dev_info(&dev->dev, "Still busy after 1s; " | ||
2133 | "proceeding with reset anyway\n"); | ||
2134 | |||
2135 | transaction_done: | ||
2136 | pci_write_config_byte(dev, cappos + PCI_AF_CTRL, PCI_AF_CTRL_FLR); | ||
2137 | mdelay(100); | ||
2138 | |||
2139 | pci_unblock_user_cfg_access(dev); | ||
2140 | return 0; | 2136 | return 0; |
2141 | } | 2137 | } |
2142 | 2138 | ||
2143 | static int __pci_reset_function(struct pci_dev *pdev, int probe) | 2139 | static int pci_pm_reset(struct pci_dev *dev, int probe) |
2144 | { | 2140 | { |
2145 | int res; | 2141 | u16 csr; |
2142 | |||
2143 | if (!dev->pm_cap) | ||
2144 | return -ENOTTY; | ||
2145 | |||
2146 | pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &csr); | ||
2147 | if (csr & PCI_PM_CTRL_NO_SOFT_RESET) | ||
2148 | return -ENOTTY; | ||
2149 | |||
2150 | if (probe) | ||
2151 | return 0; | ||
2152 | |||
2153 | if (dev->current_state != PCI_D0) | ||
2154 | return -EINVAL; | ||
2146 | 2155 | ||
2147 | res = __pcie_flr(pdev, probe); | 2156 | csr &= ~PCI_PM_CTRL_STATE_MASK; |
2148 | if (res != -ENOTTY) | 2157 | csr |= PCI_D3hot; |
2149 | return res; | 2158 | pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr); |
2159 | msleep(pci_pm_d3_delay); | ||
2150 | 2160 | ||
2151 | res = __pci_af_flr(pdev, probe); | 2161 | csr &= ~PCI_PM_CTRL_STATE_MASK; |
2152 | if (res != -ENOTTY) | 2162 | csr |= PCI_D0; |
2153 | return res; | 2163 | pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr); |
2164 | msleep(pci_pm_d3_delay); | ||
2154 | 2165 | ||
2155 | return res; | 2166 | return 0; |
2167 | } | ||
2168 | |||
2169 | static int pci_parent_bus_reset(struct pci_dev *dev, int probe) | ||
2170 | { | ||
2171 | u16 ctrl; | ||
2172 | struct pci_dev *pdev; | ||
2173 | |||
2174 | if (dev->subordinate) | ||
2175 | return -ENOTTY; | ||
2176 | |||
2177 | list_for_each_entry(pdev, &dev->bus->devices, bus_list) | ||
2178 | if (pdev != dev) | ||
2179 | return -ENOTTY; | ||
2180 | |||
2181 | if (probe) | ||
2182 | return 0; | ||
2183 | |||
2184 | pci_read_config_word(dev->bus->self, PCI_BRIDGE_CONTROL, &ctrl); | ||
2185 | ctrl |= PCI_BRIDGE_CTL_BUS_RESET; | ||
2186 | pci_write_config_word(dev->bus->self, PCI_BRIDGE_CONTROL, ctrl); | ||
2187 | msleep(100); | ||
2188 | |||
2189 | ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET; | ||
2190 | pci_write_config_word(dev->bus->self, PCI_BRIDGE_CONTROL, ctrl); | ||
2191 | msleep(100); | ||
2192 | |||
2193 | return 0; | ||
2194 | } | ||
2195 | |||
2196 | static int pci_dev_reset(struct pci_dev *dev, int probe) | ||
2197 | { | ||
2198 | int rc; | ||
2199 | |||
2200 | might_sleep(); | ||
2201 | |||
2202 | if (!probe) { | ||
2203 | pci_block_user_cfg_access(dev); | ||
2204 | /* block PM suspend, driver probe, etc. */ | ||
2205 | down(&dev->dev.sem); | ||
2206 | } | ||
2207 | |||
2208 | rc = pcie_flr(dev, probe); | ||
2209 | if (rc != -ENOTTY) | ||
2210 | goto done; | ||
2211 | |||
2212 | rc = pci_af_flr(dev, probe); | ||
2213 | if (rc != -ENOTTY) | ||
2214 | goto done; | ||
2215 | |||
2216 | rc = pci_pm_reset(dev, probe); | ||
2217 | if (rc != -ENOTTY) | ||
2218 | goto done; | ||
2219 | |||
2220 | rc = pci_parent_bus_reset(dev, probe); | ||
2221 | done: | ||
2222 | if (!probe) { | ||
2223 | up(&dev->dev.sem); | ||
2224 | pci_unblock_user_cfg_access(dev); | ||
2225 | } | ||
2226 | |||
2227 | return rc; | ||
2156 | } | 2228 | } |
2157 | 2229 | ||
2158 | /** | 2230 | /** |
2159 | * pci_execute_reset_function() - Reset a PCI device function | 2231 | * __pci_reset_function - reset a PCI device function |
2160 | * @dev: Device function to reset | 2232 | * @dev: PCI device to reset |
2161 | * | 2233 | * |
2162 | * Some devices allow an individual function to be reset without affecting | 2234 | * Some devices allow an individual function to be reset without affecting |
2163 | * other functions in the same device. The PCI device must be responsive | 2235 | * other functions in the same device. The PCI device must be responsive |
@@ -2169,18 +2241,18 @@ static int __pci_reset_function(struct pci_dev *pdev, int probe) | |||
2169 | * device including MSI, bus mastering, BARs, decoding IO and memory spaces, | 2241 | * device including MSI, bus mastering, BARs, decoding IO and memory spaces, |
2170 | * etc. | 2242 | * etc. |
2171 | * | 2243 | * |
2172 | * Returns 0 if the device function was successfully reset or -ENOTTY if the | 2244 | * Returns 0 if the device function was successfully reset or negative if the |
2173 | * device doesn't support resetting a single function. | 2245 | * device doesn't support resetting a single function. |
2174 | */ | 2246 | */ |
2175 | int pci_execute_reset_function(struct pci_dev *dev) | 2247 | int __pci_reset_function(struct pci_dev *dev) |
2176 | { | 2248 | { |
2177 | return __pci_reset_function(dev, 0); | 2249 | return pci_dev_reset(dev, 0); |
2178 | } | 2250 | } |
2179 | EXPORT_SYMBOL_GPL(pci_execute_reset_function); | 2251 | EXPORT_SYMBOL_GPL(__pci_reset_function); |
2180 | 2252 | ||
2181 | /** | 2253 | /** |
2182 | * pci_reset_function() - quiesce and reset a PCI device function | 2254 | * pci_reset_function - quiesce and reset a PCI device function |
2183 | * @dev: Device function to reset | 2255 | * @dev: PCI device to reset |
2184 | * | 2256 | * |
2185 | * Some devices allow an individual function to be reset without affecting | 2257 | * Some devices allow an individual function to be reset without affecting |
2186 | * other functions in the same device. The PCI device must be responsive | 2258 | * other functions in the same device. The PCI device must be responsive |
@@ -2188,32 +2260,33 @@ EXPORT_SYMBOL_GPL(pci_execute_reset_function); | |||
2188 | * | 2260 | * |
2189 | * This function does not just reset the PCI portion of a device, but | 2261 | * This function does not just reset the PCI portion of a device, but |
2190 | * clears all the state associated with the device. This function differs | 2262 | * clears all the state associated with the device. This function differs |
2191 | * from pci_execute_reset_function in that it saves and restores device state | 2263 | * from __pci_reset_function in that it saves and restores device state |
2192 | * over the reset. | 2264 | * over the reset. |
2193 | * | 2265 | * |
2194 | * Returns 0 if the device function was successfully reset or -ENOTTY if the | 2266 | * Returns 0 if the device function was successfully reset or negative if the |
2195 | * device doesn't support resetting a single function. | 2267 | * device doesn't support resetting a single function. |
2196 | */ | 2268 | */ |
2197 | int pci_reset_function(struct pci_dev *dev) | 2269 | int pci_reset_function(struct pci_dev *dev) |
2198 | { | 2270 | { |
2199 | int r = __pci_reset_function(dev, 1); | 2271 | int rc; |
2200 | 2272 | ||
2201 | if (r < 0) | 2273 | rc = pci_dev_reset(dev, 1); |
2202 | return r; | 2274 | if (rc) |
2275 | return rc; | ||
2203 | 2276 | ||
2204 | if (!dev->msi_enabled && !dev->msix_enabled && dev->irq != 0) | ||
2205 | disable_irq(dev->irq); | ||
2206 | pci_save_state(dev); | 2277 | pci_save_state(dev); |
2207 | 2278 | ||
2279 | /* | ||
2280 | * both INTx and MSI are disabled after the Interrupt Disable bit | ||
2281 | * is set and the Bus Master bit is cleared. | ||
2282 | */ | ||
2208 | pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE); | 2283 | pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE); |
2209 | 2284 | ||
2210 | r = pci_execute_reset_function(dev); | 2285 | rc = pci_dev_reset(dev, 0); |
2211 | 2286 | ||
2212 | pci_restore_state(dev); | 2287 | pci_restore_state(dev); |
2213 | if (!dev->msi_enabled && !dev->msix_enabled && dev->irq != 0) | ||
2214 | enable_irq(dev->irq); | ||
2215 | 2288 | ||
2216 | return r; | 2289 | return rc; |
2217 | } | 2290 | } |
2218 | EXPORT_SYMBOL_GPL(pci_reset_function); | 2291 | EXPORT_SYMBOL_GPL(pci_reset_function); |
2219 | 2292 | ||
@@ -2586,6 +2659,8 @@ static int __init pci_setup(char *str) | |||
2586 | } else if (!strncmp(str, "resource_alignment=", 19)) { | 2659 | } else if (!strncmp(str, "resource_alignment=", 19)) { |
2587 | pci_set_resource_alignment_param(str + 19, | 2660 | pci_set_resource_alignment_param(str + 19, |
2588 | strlen(str + 19)); | 2661 | strlen(str + 19)); |
2662 | } else if (!strncmp(str, "ecrc=", 5)) { | ||
2663 | pcie_ecrc_get_policy(str + 5); | ||
2589 | } else { | 2664 | } else { |
2590 | printk(KERN_ERR "PCI: Unknown option `%s'\n", | 2665 | printk(KERN_ERR "PCI: Unknown option `%s'\n", |
2591 | str); | 2666 | str); |