diff options
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r-- | drivers/pci/pci.c | 558 |
1 files changed, 265 insertions, 293 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 07369f32e8bb..fdbc294821e6 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -431,6 +431,32 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res) | |||
431 | } | 431 | } |
432 | 432 | ||
433 | /** | 433 | /** |
434 | * pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos | ||
435 | * @dev: the PCI device to operate on | ||
436 | * @pos: config space offset of status word | ||
437 | * @mask: mask of bit(s) to care about in status word | ||
438 | * | ||
439 | * Return 1 when mask bit(s) in status word clear, 0 otherwise. | ||
440 | */ | ||
441 | int pci_wait_for_pending(struct pci_dev *dev, int pos, u16 mask) | ||
442 | { | ||
443 | int i; | ||
444 | |||
445 | /* Wait for Transaction Pending bit clean */ | ||
446 | for (i = 0; i < 4; i++) { | ||
447 | u16 status; | ||
448 | if (i) | ||
449 | msleep((1 << (i - 1)) * 100); | ||
450 | |||
451 | pci_read_config_word(dev, pos, &status); | ||
452 | if (!(status & mask)) | ||
453 | return 1; | ||
454 | } | ||
455 | |||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | /** | ||
434 | * pci_restore_bars - restore a devices BAR values (e.g. after wake-up) | 460 | * pci_restore_bars - restore a devices BAR values (e.g. after wake-up) |
435 | * @dev: PCI device to have its BARs restored | 461 | * @dev: PCI device to have its BARs restored |
436 | * | 462 | * |
@@ -657,6 +683,28 @@ static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state) | |||
657 | } | 683 | } |
658 | 684 | ||
659 | /** | 685 | /** |
686 | * pci_wakeup - Wake up a PCI device | ||
687 | * @pci_dev: Device to handle. | ||
688 | * @ign: ignored parameter | ||
689 | */ | ||
690 | static int pci_wakeup(struct pci_dev *pci_dev, void *ign) | ||
691 | { | ||
692 | pci_wakeup_event(pci_dev); | ||
693 | pm_request_resume(&pci_dev->dev); | ||
694 | return 0; | ||
695 | } | ||
696 | |||
697 | /** | ||
698 | * pci_wakeup_bus - Walk given bus and wake up devices on it | ||
699 | * @bus: Top bus of the subtree to walk. | ||
700 | */ | ||
701 | static void pci_wakeup_bus(struct pci_bus *bus) | ||
702 | { | ||
703 | if (bus) | ||
704 | pci_walk_bus(bus, pci_wakeup, NULL); | ||
705 | } | ||
706 | |||
707 | /** | ||
660 | * __pci_start_power_transition - Start power transition of a PCI device | 708 | * __pci_start_power_transition - Start power transition of a PCI device |
661 | * @dev: PCI device to handle. | 709 | * @dev: PCI device to handle. |
662 | * @state: State to put the device into. | 710 | * @state: State to put the device into. |
@@ -835,18 +883,28 @@ EXPORT_SYMBOL(pci_choose_state); | |||
835 | #define PCI_EXP_SAVE_REGS 7 | 883 | #define PCI_EXP_SAVE_REGS 7 |
836 | 884 | ||
837 | 885 | ||
838 | static struct pci_cap_saved_state *pci_find_saved_cap( | 886 | static struct pci_cap_saved_state *_pci_find_saved_cap(struct pci_dev *pci_dev, |
839 | struct pci_dev *pci_dev, char cap) | 887 | u16 cap, bool extended) |
840 | { | 888 | { |
841 | struct pci_cap_saved_state *tmp; | 889 | struct pci_cap_saved_state *tmp; |
842 | 890 | ||
843 | hlist_for_each_entry(tmp, &pci_dev->saved_cap_space, next) { | 891 | hlist_for_each_entry(tmp, &pci_dev->saved_cap_space, next) { |
844 | if (tmp->cap.cap_nr == cap) | 892 | if (tmp->cap.cap_extended == extended && tmp->cap.cap_nr == cap) |
845 | return tmp; | 893 | return tmp; |
846 | } | 894 | } |
847 | return NULL; | 895 | return NULL; |
848 | } | 896 | } |
849 | 897 | ||
898 | struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap) | ||
899 | { | ||
900 | return _pci_find_saved_cap(dev, cap, false); | ||
901 | } | ||
902 | |||
903 | struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev, u16 cap) | ||
904 | { | ||
905 | return _pci_find_saved_cap(dev, cap, true); | ||
906 | } | ||
907 | |||
850 | static int pci_save_pcie_state(struct pci_dev *dev) | 908 | static int pci_save_pcie_state(struct pci_dev *dev) |
851 | { | 909 | { |
852 | int i = 0; | 910 | int i = 0; |
@@ -948,6 +1006,8 @@ pci_save_state(struct pci_dev *dev) | |||
948 | return i; | 1006 | return i; |
949 | if ((i = pci_save_pcix_state(dev)) != 0) | 1007 | if ((i = pci_save_pcix_state(dev)) != 0) |
950 | return i; | 1008 | return i; |
1009 | if ((i = pci_save_vc_state(dev)) != 0) | ||
1010 | return i; | ||
951 | return 0; | 1011 | return 0; |
952 | } | 1012 | } |
953 | 1013 | ||
@@ -1010,6 +1070,7 @@ void pci_restore_state(struct pci_dev *dev) | |||
1010 | /* PCI Express register must be restored first */ | 1070 | /* PCI Express register must be restored first */ |
1011 | pci_restore_pcie_state(dev); | 1071 | pci_restore_pcie_state(dev); |
1012 | pci_restore_ats_state(dev); | 1072 | pci_restore_ats_state(dev); |
1073 | pci_restore_vc_state(dev); | ||
1013 | 1074 | ||
1014 | pci_restore_config_space(dev); | 1075 | pci_restore_config_space(dev); |
1015 | 1076 | ||
@@ -1071,7 +1132,8 @@ EXPORT_SYMBOL_GPL(pci_store_saved_state); | |||
1071 | * @dev: PCI device that we're dealing with | 1132 | * @dev: PCI device that we're dealing with |
1072 | * @state: Saved state returned from pci_store_saved_state() | 1133 | * @state: Saved state returned from pci_store_saved_state() |
1073 | */ | 1134 | */ |
1074 | int pci_load_saved_state(struct pci_dev *dev, struct pci_saved_state *state) | 1135 | static int pci_load_saved_state(struct pci_dev *dev, |
1136 | struct pci_saved_state *state) | ||
1075 | { | 1137 | { |
1076 | struct pci_cap_saved_data *cap; | 1138 | struct pci_cap_saved_data *cap; |
1077 | 1139 | ||
@@ -1087,7 +1149,7 @@ int pci_load_saved_state(struct pci_dev *dev, struct pci_saved_state *state) | |||
1087 | while (cap->size) { | 1149 | while (cap->size) { |
1088 | struct pci_cap_saved_state *tmp; | 1150 | struct pci_cap_saved_state *tmp; |
1089 | 1151 | ||
1090 | tmp = pci_find_saved_cap(dev, cap->cap_nr); | 1152 | tmp = _pci_find_saved_cap(dev, cap->cap_nr, cap->cap_extended); |
1091 | if (!tmp || tmp->cap.size != cap->size) | 1153 | if (!tmp || tmp->cap.size != cap->size) |
1092 | return -EINVAL; | 1154 | return -EINVAL; |
1093 | 1155 | ||
@@ -1099,7 +1161,6 @@ int pci_load_saved_state(struct pci_dev *dev, struct pci_saved_state *state) | |||
1099 | dev->state_saved = true; | 1161 | dev->state_saved = true; |
1100 | return 0; | 1162 | return 0; |
1101 | } | 1163 | } |
1102 | EXPORT_SYMBOL_GPL(pci_load_saved_state); | ||
1103 | 1164 | ||
1104 | /** | 1165 | /** |
1105 | * pci_load_and_free_saved_state - Reload the save state pointed to by state, | 1166 | * pci_load_and_free_saved_state - Reload the save state pointed to by state, |
@@ -1120,6 +1181,8 @@ EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state); | |||
1120 | static int do_pci_enable_device(struct pci_dev *dev, int bars) | 1181 | static int do_pci_enable_device(struct pci_dev *dev, int bars) |
1121 | { | 1182 | { |
1122 | int err; | 1183 | int err; |
1184 | u16 cmd; | ||
1185 | u8 pin; | ||
1123 | 1186 | ||
1124 | err = pci_set_power_state(dev, PCI_D0); | 1187 | err = pci_set_power_state(dev, PCI_D0); |
1125 | if (err < 0 && err != -EIO) | 1188 | if (err < 0 && err != -EIO) |
@@ -1129,6 +1192,17 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) | |||
1129 | return err; | 1192 | return err; |
1130 | pci_fixup_device(pci_fixup_enable, dev); | 1193 | pci_fixup_device(pci_fixup_enable, dev); |
1131 | 1194 | ||
1195 | if (dev->msi_enabled || dev->msix_enabled) | ||
1196 | return 0; | ||
1197 | |||
1198 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); | ||
1199 | if (pin) { | ||
1200 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | ||
1201 | if (cmd & PCI_COMMAND_INTX_DISABLE) | ||
1202 | pci_write_config_word(dev, PCI_COMMAND, | ||
1203 | cmd & ~PCI_COMMAND_INTX_DISABLE); | ||
1204 | } | ||
1205 | |||
1132 | return 0; | 1206 | return 0; |
1133 | } | 1207 | } |
1134 | 1208 | ||
@@ -1531,27 +1605,6 @@ void pci_pme_wakeup_bus(struct pci_bus *bus) | |||
1531 | pci_walk_bus(bus, pci_pme_wakeup, (void *)true); | 1605 | pci_walk_bus(bus, pci_pme_wakeup, (void *)true); |
1532 | } | 1606 | } |
1533 | 1607 | ||
1534 | /** | ||
1535 | * pci_wakeup - Wake up a PCI device | ||
1536 | * @pci_dev: Device to handle. | ||
1537 | * @ign: ignored parameter | ||
1538 | */ | ||
1539 | static int pci_wakeup(struct pci_dev *pci_dev, void *ign) | ||
1540 | { | ||
1541 | pci_wakeup_event(pci_dev); | ||
1542 | pm_request_resume(&pci_dev->dev); | ||
1543 | return 0; | ||
1544 | } | ||
1545 | |||
1546 | /** | ||
1547 | * pci_wakeup_bus - Walk given bus and wake up devices on it | ||
1548 | * @bus: Top bus of the subtree to walk. | ||
1549 | */ | ||
1550 | void pci_wakeup_bus(struct pci_bus *bus) | ||
1551 | { | ||
1552 | if (bus) | ||
1553 | pci_walk_bus(bus, pci_wakeup, NULL); | ||
1554 | } | ||
1555 | 1608 | ||
1556 | /** | 1609 | /** |
1557 | * pci_pme_capable - check the capability of PCI device to generate PME# | 1610 | * pci_pme_capable - check the capability of PCI device to generate PME# |
@@ -1765,7 +1818,7 @@ int pci_wake_from_d3(struct pci_dev *dev, bool enable) | |||
1765 | * If the platform can't manage @dev, return the deepest state from which it | 1818 | * If the platform can't manage @dev, return the deepest state from which it |
1766 | * can generate wake events, based on any available PME info. | 1819 | * can generate wake events, based on any available PME info. |
1767 | */ | 1820 | */ |
1768 | pci_power_t pci_target_state(struct pci_dev *dev) | 1821 | static pci_power_t pci_target_state(struct pci_dev *dev) |
1769 | { | 1822 | { |
1770 | pci_power_t target_state = PCI_D3hot; | 1823 | pci_power_t target_state = PCI_D3hot; |
1771 | 1824 | ||
@@ -2021,18 +2074,24 @@ static void pci_add_saved_cap(struct pci_dev *pci_dev, | |||
2021 | } | 2074 | } |
2022 | 2075 | ||
2023 | /** | 2076 | /** |
2024 | * pci_add_cap_save_buffer - allocate buffer for saving given capability registers | 2077 | * _pci_add_cap_save_buffer - allocate buffer for saving given |
2078 | * capability registers | ||
2025 | * @dev: the PCI device | 2079 | * @dev: the PCI device |
2026 | * @cap: the capability to allocate the buffer for | 2080 | * @cap: the capability to allocate the buffer for |
2081 | * @extended: Standard or Extended capability ID | ||
2027 | * @size: requested size of the buffer | 2082 | * @size: requested size of the buffer |
2028 | */ | 2083 | */ |
2029 | static int pci_add_cap_save_buffer( | 2084 | static int _pci_add_cap_save_buffer(struct pci_dev *dev, u16 cap, |
2030 | struct pci_dev *dev, char cap, unsigned int size) | 2085 | bool extended, unsigned int size) |
2031 | { | 2086 | { |
2032 | int pos; | 2087 | int pos; |
2033 | struct pci_cap_saved_state *save_state; | 2088 | struct pci_cap_saved_state *save_state; |
2034 | 2089 | ||
2035 | pos = pci_find_capability(dev, cap); | 2090 | if (extended) |
2091 | pos = pci_find_ext_capability(dev, cap); | ||
2092 | else | ||
2093 | pos = pci_find_capability(dev, cap); | ||
2094 | |||
2036 | if (pos <= 0) | 2095 | if (pos <= 0) |
2037 | return 0; | 2096 | return 0; |
2038 | 2097 | ||
@@ -2041,12 +2100,23 @@ static int pci_add_cap_save_buffer( | |||
2041 | return -ENOMEM; | 2100 | return -ENOMEM; |
2042 | 2101 | ||
2043 | save_state->cap.cap_nr = cap; | 2102 | save_state->cap.cap_nr = cap; |
2103 | save_state->cap.cap_extended = extended; | ||
2044 | save_state->cap.size = size; | 2104 | save_state->cap.size = size; |
2045 | pci_add_saved_cap(dev, save_state); | 2105 | pci_add_saved_cap(dev, save_state); |
2046 | 2106 | ||
2047 | return 0; | 2107 | return 0; |
2048 | } | 2108 | } |
2049 | 2109 | ||
2110 | int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size) | ||
2111 | { | ||
2112 | return _pci_add_cap_save_buffer(dev, cap, false, size); | ||
2113 | } | ||
2114 | |||
2115 | int pci_add_ext_cap_save_buffer(struct pci_dev *dev, u16 cap, unsigned int size) | ||
2116 | { | ||
2117 | return _pci_add_cap_save_buffer(dev, cap, true, size); | ||
2118 | } | ||
2119 | |||
2050 | /** | 2120 | /** |
2051 | * pci_allocate_cap_save_buffers - allocate buffers for saving capabilities | 2121 | * pci_allocate_cap_save_buffers - allocate buffers for saving capabilities |
2052 | * @dev: the PCI device | 2122 | * @dev: the PCI device |
@@ -2065,6 +2135,8 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev) | |||
2065 | if (error) | 2135 | if (error) |
2066 | dev_err(&dev->dev, | 2136 | dev_err(&dev->dev, |
2067 | "unable to preallocate PCI-X save buffer\n"); | 2137 | "unable to preallocate PCI-X save buffer\n"); |
2138 | |||
2139 | pci_allocate_vc_save_buffers(dev); | ||
2068 | } | 2140 | } |
2069 | 2141 | ||
2070 | void pci_free_cap_save_buffers(struct pci_dev *dev) | 2142 | void pci_free_cap_save_buffers(struct pci_dev *dev) |
@@ -2110,242 +2182,6 @@ void pci_configure_ari(struct pci_dev *dev) | |||
2110 | } | 2182 | } |
2111 | } | 2183 | } |
2112 | 2184 | ||
2113 | /** | ||
2114 | * pci_enable_ido - enable ID-based Ordering on a device | ||
2115 | * @dev: the PCI device | ||
2116 | * @type: which types of IDO to enable | ||
2117 | * | ||
2118 | * Enable ID-based ordering on @dev. @type can contain the bits | ||
2119 | * %PCI_EXP_IDO_REQUEST and/or %PCI_EXP_IDO_COMPLETION to indicate | ||
2120 | * which types of transactions are allowed to be re-ordered. | ||
2121 | */ | ||
2122 | void pci_enable_ido(struct pci_dev *dev, unsigned long type) | ||
2123 | { | ||
2124 | u16 ctrl = 0; | ||
2125 | |||
2126 | if (type & PCI_EXP_IDO_REQUEST) | ||
2127 | ctrl |= PCI_EXP_DEVCTL2_IDO_REQ_EN; | ||
2128 | if (type & PCI_EXP_IDO_COMPLETION) | ||
2129 | ctrl |= PCI_EXP_DEVCTL2_IDO_CMP_EN; | ||
2130 | if (ctrl) | ||
2131 | pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, ctrl); | ||
2132 | } | ||
2133 | EXPORT_SYMBOL(pci_enable_ido); | ||
2134 | |||
2135 | /** | ||
2136 | * pci_disable_ido - disable ID-based ordering on a device | ||
2137 | * @dev: the PCI device | ||
2138 | * @type: which types of IDO to disable | ||
2139 | */ | ||
2140 | void pci_disable_ido(struct pci_dev *dev, unsigned long type) | ||
2141 | { | ||
2142 | u16 ctrl = 0; | ||
2143 | |||
2144 | if (type & PCI_EXP_IDO_REQUEST) | ||
2145 | ctrl |= PCI_EXP_DEVCTL2_IDO_REQ_EN; | ||
2146 | if (type & PCI_EXP_IDO_COMPLETION) | ||
2147 | ctrl |= PCI_EXP_DEVCTL2_IDO_CMP_EN; | ||
2148 | if (ctrl) | ||
2149 | pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, ctrl); | ||
2150 | } | ||
2151 | EXPORT_SYMBOL(pci_disable_ido); | ||
2152 | |||
2153 | /** | ||
2154 | * pci_enable_obff - enable optimized buffer flush/fill | ||
2155 | * @dev: PCI device | ||
2156 | * @type: type of signaling to use | ||
2157 | * | ||
2158 | * Try to enable @type OBFF signaling on @dev. It will try using WAKE# | ||
2159 | * signaling if possible, falling back to message signaling only if | ||
2160 | * WAKE# isn't supported. @type should indicate whether the PCIe link | ||
2161 | * be brought out of L0s or L1 to send the message. It should be either | ||
2162 | * %PCI_EXP_OBFF_SIGNAL_ALWAYS or %PCI_OBFF_SIGNAL_L0. | ||
2163 | * | ||
2164 | * If your device can benefit from receiving all messages, even at the | ||
2165 | * power cost of bringing the link back up from a low power state, use | ||
2166 | * %PCI_EXP_OBFF_SIGNAL_ALWAYS. Otherwise, use %PCI_OBFF_SIGNAL_L0 (the | ||
2167 | * preferred type). | ||
2168 | * | ||
2169 | * RETURNS: | ||
2170 | * Zero on success, appropriate error number on failure. | ||
2171 | */ | ||
2172 | int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type) | ||
2173 | { | ||
2174 | u32 cap; | ||
2175 | u16 ctrl; | ||
2176 | int ret; | ||
2177 | |||
2178 | pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap); | ||
2179 | if (!(cap & PCI_EXP_DEVCAP2_OBFF_MASK)) | ||
2180 | return -ENOTSUPP; /* no OBFF support at all */ | ||
2181 | |||
2182 | /* Make sure the topology supports OBFF as well */ | ||
2183 | if (dev->bus->self) { | ||
2184 | ret = pci_enable_obff(dev->bus->self, type); | ||
2185 | if (ret) | ||
2186 | return ret; | ||
2187 | } | ||
2188 | |||
2189 | pcie_capability_read_word(dev, PCI_EXP_DEVCTL2, &ctrl); | ||
2190 | if (cap & PCI_EXP_DEVCAP2_OBFF_WAKE) | ||
2191 | ctrl |= PCI_EXP_DEVCTL2_OBFF_WAKE_EN; | ||
2192 | else { | ||
2193 | switch (type) { | ||
2194 | case PCI_EXP_OBFF_SIGNAL_L0: | ||
2195 | if (!(ctrl & PCI_EXP_DEVCTL2_OBFF_WAKE_EN)) | ||
2196 | ctrl |= PCI_EXP_DEVCTL2_OBFF_MSGA_EN; | ||
2197 | break; | ||
2198 | case PCI_EXP_OBFF_SIGNAL_ALWAYS: | ||
2199 | ctrl &= ~PCI_EXP_DEVCTL2_OBFF_WAKE_EN; | ||
2200 | ctrl |= PCI_EXP_DEVCTL2_OBFF_MSGB_EN; | ||
2201 | break; | ||
2202 | default: | ||
2203 | WARN(1, "bad OBFF signal type\n"); | ||
2204 | return -ENOTSUPP; | ||
2205 | } | ||
2206 | } | ||
2207 | pcie_capability_write_word(dev, PCI_EXP_DEVCTL2, ctrl); | ||
2208 | |||
2209 | return 0; | ||
2210 | } | ||
2211 | EXPORT_SYMBOL(pci_enable_obff); | ||
2212 | |||
2213 | /** | ||
2214 | * pci_disable_obff - disable optimized buffer flush/fill | ||
2215 | * @dev: PCI device | ||
2216 | * | ||
2217 | * Disable OBFF on @dev. | ||
2218 | */ | ||
2219 | void pci_disable_obff(struct pci_dev *dev) | ||
2220 | { | ||
2221 | pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, | ||
2222 | PCI_EXP_DEVCTL2_OBFF_WAKE_EN); | ||
2223 | } | ||
2224 | EXPORT_SYMBOL(pci_disable_obff); | ||
2225 | |||
2226 | /** | ||
2227 | * pci_ltr_supported - check whether a device supports LTR | ||
2228 | * @dev: PCI device | ||
2229 | * | ||
2230 | * RETURNS: | ||
2231 | * True if @dev supports latency tolerance reporting, false otherwise. | ||
2232 | */ | ||
2233 | static bool pci_ltr_supported(struct pci_dev *dev) | ||
2234 | { | ||
2235 | u32 cap; | ||
2236 | |||
2237 | pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap); | ||
2238 | |||
2239 | return cap & PCI_EXP_DEVCAP2_LTR; | ||
2240 | } | ||
2241 | |||
2242 | /** | ||
2243 | * pci_enable_ltr - enable latency tolerance reporting | ||
2244 | * @dev: PCI device | ||
2245 | * | ||
2246 | * Enable LTR on @dev if possible, which means enabling it first on | ||
2247 | * upstream ports. | ||
2248 | * | ||
2249 | * RETURNS: | ||
2250 | * Zero on success, errno on failure. | ||
2251 | */ | ||
2252 | int pci_enable_ltr(struct pci_dev *dev) | ||
2253 | { | ||
2254 | int ret; | ||
2255 | |||
2256 | /* Only primary function can enable/disable LTR */ | ||
2257 | if (PCI_FUNC(dev->devfn) != 0) | ||
2258 | return -EINVAL; | ||
2259 | |||
2260 | if (!pci_ltr_supported(dev)) | ||
2261 | return -ENOTSUPP; | ||
2262 | |||
2263 | /* Enable upstream ports first */ | ||
2264 | if (dev->bus->self) { | ||
2265 | ret = pci_enable_ltr(dev->bus->self); | ||
2266 | if (ret) | ||
2267 | return ret; | ||
2268 | } | ||
2269 | |||
2270 | return pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, | ||
2271 | PCI_EXP_DEVCTL2_LTR_EN); | ||
2272 | } | ||
2273 | EXPORT_SYMBOL(pci_enable_ltr); | ||
2274 | |||
2275 | /** | ||
2276 | * pci_disable_ltr - disable latency tolerance reporting | ||
2277 | * @dev: PCI device | ||
2278 | */ | ||
2279 | void pci_disable_ltr(struct pci_dev *dev) | ||
2280 | { | ||
2281 | /* Only primary function can enable/disable LTR */ | ||
2282 | if (PCI_FUNC(dev->devfn) != 0) | ||
2283 | return; | ||
2284 | |||
2285 | if (!pci_ltr_supported(dev)) | ||
2286 | return; | ||
2287 | |||
2288 | pcie_capability_clear_word(dev, PCI_EXP_DEVCTL2, | ||
2289 | PCI_EXP_DEVCTL2_LTR_EN); | ||
2290 | } | ||
2291 | EXPORT_SYMBOL(pci_disable_ltr); | ||
2292 | |||
2293 | static int __pci_ltr_scale(int *val) | ||
2294 | { | ||
2295 | int scale = 0; | ||
2296 | |||
2297 | while (*val > 1023) { | ||
2298 | *val = (*val + 31) / 32; | ||
2299 | scale++; | ||
2300 | } | ||
2301 | return scale; | ||
2302 | } | ||
2303 | |||
2304 | /** | ||
2305 | * pci_set_ltr - set LTR latency values | ||
2306 | * @dev: PCI device | ||
2307 | * @snoop_lat_ns: snoop latency in nanoseconds | ||
2308 | * @nosnoop_lat_ns: nosnoop latency in nanoseconds | ||
2309 | * | ||
2310 | * Figure out the scale and set the LTR values accordingly. | ||
2311 | */ | ||
2312 | int pci_set_ltr(struct pci_dev *dev, int snoop_lat_ns, int nosnoop_lat_ns) | ||
2313 | { | ||
2314 | int pos, ret, snoop_scale, nosnoop_scale; | ||
2315 | u16 val; | ||
2316 | |||
2317 | if (!pci_ltr_supported(dev)) | ||
2318 | return -ENOTSUPP; | ||
2319 | |||
2320 | snoop_scale = __pci_ltr_scale(&snoop_lat_ns); | ||
2321 | nosnoop_scale = __pci_ltr_scale(&nosnoop_lat_ns); | ||
2322 | |||
2323 | if (snoop_lat_ns > PCI_LTR_VALUE_MASK || | ||
2324 | nosnoop_lat_ns > PCI_LTR_VALUE_MASK) | ||
2325 | return -EINVAL; | ||
2326 | |||
2327 | if ((snoop_scale > (PCI_LTR_SCALE_MASK >> PCI_LTR_SCALE_SHIFT)) || | ||
2328 | (nosnoop_scale > (PCI_LTR_SCALE_MASK >> PCI_LTR_SCALE_SHIFT))) | ||
2329 | return -EINVAL; | ||
2330 | |||
2331 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR); | ||
2332 | if (!pos) | ||
2333 | return -ENOTSUPP; | ||
2334 | |||
2335 | val = (snoop_scale << PCI_LTR_SCALE_SHIFT) | snoop_lat_ns; | ||
2336 | ret = pci_write_config_word(dev, pos + PCI_LTR_MAX_SNOOP_LAT, val); | ||
2337 | if (ret != 4) | ||
2338 | return -EIO; | ||
2339 | |||
2340 | val = (nosnoop_scale << PCI_LTR_SCALE_SHIFT) | nosnoop_lat_ns; | ||
2341 | ret = pci_write_config_word(dev, pos + PCI_LTR_MAX_NOSNOOP_LAT, val); | ||
2342 | if (ret != 4) | ||
2343 | return -EIO; | ||
2344 | |||
2345 | return 0; | ||
2346 | } | ||
2347 | EXPORT_SYMBOL(pci_set_ltr); | ||
2348 | |||
2349 | static int pci_acs_enable; | 2185 | static int pci_acs_enable; |
2350 | 2186 | ||
2351 | /** | 2187 | /** |
@@ -3138,7 +2974,7 @@ bool pci_check_and_mask_intx(struct pci_dev *dev) | |||
3138 | EXPORT_SYMBOL_GPL(pci_check_and_mask_intx); | 2974 | EXPORT_SYMBOL_GPL(pci_check_and_mask_intx); |
3139 | 2975 | ||
3140 | /** | 2976 | /** |
3141 | * pci_check_and_mask_intx - unmask INTx of no interrupt is pending | 2977 | * pci_check_and_unmask_intx - unmask INTx if no interrupt is pending |
3142 | * @dev: the PCI device to operate on | 2978 | * @dev: the PCI device to operate on |
3143 | * | 2979 | * |
3144 | * Check if the device dev has its INTx line asserted, unmask it if not | 2980 | * Check if the device dev has its INTx line asserted, unmask it if not |
@@ -3204,20 +3040,10 @@ EXPORT_SYMBOL(pci_set_dma_seg_boundary); | |||
3204 | */ | 3040 | */ |
3205 | int pci_wait_for_pending_transaction(struct pci_dev *dev) | 3041 | int pci_wait_for_pending_transaction(struct pci_dev *dev) |
3206 | { | 3042 | { |
3207 | int i; | 3043 | if (!pci_is_pcie(dev)) |
3208 | u16 status; | 3044 | return 1; |
3209 | |||
3210 | /* Wait for Transaction Pending bit clean */ | ||
3211 | for (i = 0; i < 4; i++) { | ||
3212 | if (i) | ||
3213 | msleep((1 << (i - 1)) * 100); | ||
3214 | |||
3215 | pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status); | ||
3216 | if (!(status & PCI_EXP_DEVSTA_TRPND)) | ||
3217 | return 1; | ||
3218 | } | ||
3219 | 3045 | ||
3220 | return 0; | 3046 | return pci_wait_for_pending(dev, PCI_EXP_DEVSTA, PCI_EXP_DEVSTA_TRPND); |
3221 | } | 3047 | } |
3222 | EXPORT_SYMBOL(pci_wait_for_pending_transaction); | 3048 | EXPORT_SYMBOL(pci_wait_for_pending_transaction); |
3223 | 3049 | ||
@@ -3244,10 +3070,8 @@ static int pcie_flr(struct pci_dev *dev, int probe) | |||
3244 | 3070 | ||
3245 | static int pci_af_flr(struct pci_dev *dev, int probe) | 3071 | static int pci_af_flr(struct pci_dev *dev, int probe) |
3246 | { | 3072 | { |
3247 | int i; | ||
3248 | int pos; | 3073 | int pos; |
3249 | u8 cap; | 3074 | u8 cap; |
3250 | u8 status; | ||
3251 | 3075 | ||
3252 | pos = pci_find_capability(dev, PCI_CAP_ID_AF); | 3076 | pos = pci_find_capability(dev, PCI_CAP_ID_AF); |
3253 | if (!pos) | 3077 | if (!pos) |
@@ -3261,14 +3085,8 @@ static int pci_af_flr(struct pci_dev *dev, int probe) | |||
3261 | return 0; | 3085 | return 0; |
3262 | 3086 | ||
3263 | /* Wait for Transaction Pending bit clean */ | 3087 | /* Wait for Transaction Pending bit clean */ |
3264 | for (i = 0; i < 4; i++) { | 3088 | if (pci_wait_for_pending(dev, PCI_AF_STATUS, PCI_AF_STATUS_TP)) |
3265 | if (i) | 3089 | goto clear; |
3266 | msleep((1 << (i - 1)) * 100); | ||
3267 | |||
3268 | pci_read_config_byte(dev, pos + PCI_AF_STATUS, &status); | ||
3269 | if (!(status & PCI_AF_STATUS_TP)) | ||
3270 | goto clear; | ||
3271 | } | ||
3272 | 3090 | ||
3273 | dev_err(&dev->dev, "transaction is not cleared; " | 3091 | dev_err(&dev->dev, "transaction is not cleared; " |
3274 | "proceeding with reset anyway\n"); | 3092 | "proceeding with reset anyway\n"); |
@@ -3445,6 +3263,18 @@ static void pci_dev_lock(struct pci_dev *dev) | |||
3445 | device_lock(&dev->dev); | 3263 | device_lock(&dev->dev); |
3446 | } | 3264 | } |
3447 | 3265 | ||
3266 | /* Return 1 on successful lock, 0 on contention */ | ||
3267 | static int pci_dev_trylock(struct pci_dev *dev) | ||
3268 | { | ||
3269 | if (pci_cfg_access_trylock(dev)) { | ||
3270 | if (device_trylock(&dev->dev)) | ||
3271 | return 1; | ||
3272 | pci_cfg_access_unlock(dev); | ||
3273 | } | ||
3274 | |||
3275 | return 0; | ||
3276 | } | ||
3277 | |||
3448 | static void pci_dev_unlock(struct pci_dev *dev) | 3278 | static void pci_dev_unlock(struct pci_dev *dev) |
3449 | { | 3279 | { |
3450 | device_unlock(&dev->dev); | 3280 | device_unlock(&dev->dev); |
@@ -3588,6 +3418,34 @@ int pci_reset_function(struct pci_dev *dev) | |||
3588 | } | 3418 | } |
3589 | EXPORT_SYMBOL_GPL(pci_reset_function); | 3419 | EXPORT_SYMBOL_GPL(pci_reset_function); |
3590 | 3420 | ||
3421 | /** | ||
3422 | * pci_try_reset_function - quiesce and reset a PCI device function | ||
3423 | * @dev: PCI device to reset | ||
3424 | * | ||
3425 | * Same as above, except return -EAGAIN if unable to lock device. | ||
3426 | */ | ||
3427 | int pci_try_reset_function(struct pci_dev *dev) | ||
3428 | { | ||
3429 | int rc; | ||
3430 | |||
3431 | rc = pci_dev_reset(dev, 1); | ||
3432 | if (rc) | ||
3433 | return rc; | ||
3434 | |||
3435 | pci_dev_save_and_disable(dev); | ||
3436 | |||
3437 | if (pci_dev_trylock(dev)) { | ||
3438 | rc = __pci_dev_reset(dev, 0); | ||
3439 | pci_dev_unlock(dev); | ||
3440 | } else | ||
3441 | rc = -EAGAIN; | ||
3442 | |||
3443 | pci_dev_restore(dev); | ||
3444 | |||
3445 | return rc; | ||
3446 | } | ||
3447 | EXPORT_SYMBOL_GPL(pci_try_reset_function); | ||
3448 | |||
3591 | /* Lock devices from the top of the tree down */ | 3449 | /* Lock devices from the top of the tree down */ |
3592 | static void pci_bus_lock(struct pci_bus *bus) | 3450 | static void pci_bus_lock(struct pci_bus *bus) |
3593 | { | 3451 | { |
@@ -3612,6 +3470,32 @@ static void pci_bus_unlock(struct pci_bus *bus) | |||
3612 | } | 3470 | } |
3613 | } | 3471 | } |
3614 | 3472 | ||
3473 | /* Return 1 on successful lock, 0 on contention */ | ||
3474 | static int pci_bus_trylock(struct pci_bus *bus) | ||
3475 | { | ||
3476 | struct pci_dev *dev; | ||
3477 | |||
3478 | list_for_each_entry(dev, &bus->devices, bus_list) { | ||
3479 | if (!pci_dev_trylock(dev)) | ||
3480 | goto unlock; | ||
3481 | if (dev->subordinate) { | ||
3482 | if (!pci_bus_trylock(dev->subordinate)) { | ||
3483 | pci_dev_unlock(dev); | ||
3484 | goto unlock; | ||
3485 | } | ||
3486 | } | ||
3487 | } | ||
3488 | return 1; | ||
3489 | |||
3490 | unlock: | ||
3491 | list_for_each_entry_continue_reverse(dev, &bus->devices, bus_list) { | ||
3492 | if (dev->subordinate) | ||
3493 | pci_bus_unlock(dev->subordinate); | ||
3494 | pci_dev_unlock(dev); | ||
3495 | } | ||
3496 | return 0; | ||
3497 | } | ||
3498 | |||
3615 | /* Lock devices from the top of the tree down */ | 3499 | /* Lock devices from the top of the tree down */ |
3616 | static void pci_slot_lock(struct pci_slot *slot) | 3500 | static void pci_slot_lock(struct pci_slot *slot) |
3617 | { | 3501 | { |
@@ -3640,6 +3524,37 @@ static void pci_slot_unlock(struct pci_slot *slot) | |||
3640 | } | 3524 | } |
3641 | } | 3525 | } |
3642 | 3526 | ||
3527 | /* Return 1 on successful lock, 0 on contention */ | ||
3528 | static int pci_slot_trylock(struct pci_slot *slot) | ||
3529 | { | ||
3530 | struct pci_dev *dev; | ||
3531 | |||
3532 | list_for_each_entry(dev, &slot->bus->devices, bus_list) { | ||
3533 | if (!dev->slot || dev->slot != slot) | ||
3534 | continue; | ||
3535 | if (!pci_dev_trylock(dev)) | ||
3536 | goto unlock; | ||
3537 | if (dev->subordinate) { | ||
3538 | if (!pci_bus_trylock(dev->subordinate)) { | ||
3539 | pci_dev_unlock(dev); | ||
3540 | goto unlock; | ||
3541 | } | ||
3542 | } | ||
3543 | } | ||
3544 | return 1; | ||
3545 | |||
3546 | unlock: | ||
3547 | list_for_each_entry_continue_reverse(dev, | ||
3548 | &slot->bus->devices, bus_list) { | ||
3549 | if (!dev->slot || dev->slot != slot) | ||
3550 | continue; | ||
3551 | if (dev->subordinate) | ||
3552 | pci_bus_unlock(dev->subordinate); | ||
3553 | pci_dev_unlock(dev); | ||
3554 | } | ||
3555 | return 0; | ||
3556 | } | ||
3557 | |||
3643 | /* Save and disable devices from the top of the tree down */ | 3558 | /* Save and disable devices from the top of the tree down */ |
3644 | static void pci_bus_save_and_disable(struct pci_bus *bus) | 3559 | static void pci_bus_save_and_disable(struct pci_bus *bus) |
3645 | { | 3560 | { |
@@ -3763,6 +3678,35 @@ int pci_reset_slot(struct pci_slot *slot) | |||
3763 | } | 3678 | } |
3764 | EXPORT_SYMBOL_GPL(pci_reset_slot); | 3679 | EXPORT_SYMBOL_GPL(pci_reset_slot); |
3765 | 3680 | ||
3681 | /** | ||
3682 | * pci_try_reset_slot - Try to reset a PCI slot | ||
3683 | * @slot: PCI slot to reset | ||
3684 | * | ||
3685 | * Same as above except return -EAGAIN if the slot cannot be locked | ||
3686 | */ | ||
3687 | int pci_try_reset_slot(struct pci_slot *slot) | ||
3688 | { | ||
3689 | int rc; | ||
3690 | |||
3691 | rc = pci_slot_reset(slot, 1); | ||
3692 | if (rc) | ||
3693 | return rc; | ||
3694 | |||
3695 | pci_slot_save_and_disable(slot); | ||
3696 | |||
3697 | if (pci_slot_trylock(slot)) { | ||
3698 | might_sleep(); | ||
3699 | rc = pci_reset_hotplug_slot(slot->hotplug, 0); | ||
3700 | pci_slot_unlock(slot); | ||
3701 | } else | ||
3702 | rc = -EAGAIN; | ||
3703 | |||
3704 | pci_slot_restore(slot); | ||
3705 | |||
3706 | return rc; | ||
3707 | } | ||
3708 | EXPORT_SYMBOL_GPL(pci_try_reset_slot); | ||
3709 | |||
3766 | static int pci_bus_reset(struct pci_bus *bus, int probe) | 3710 | static int pci_bus_reset(struct pci_bus *bus, int probe) |
3767 | { | 3711 | { |
3768 | if (!bus->self) | 3712 | if (!bus->self) |
@@ -3822,6 +3766,35 @@ int pci_reset_bus(struct pci_bus *bus) | |||
3822 | EXPORT_SYMBOL_GPL(pci_reset_bus); | 3766 | EXPORT_SYMBOL_GPL(pci_reset_bus); |
3823 | 3767 | ||
3824 | /** | 3768 | /** |
3769 | * pci_try_reset_bus - Try to reset a PCI bus | ||
3770 | * @bus: top level PCI bus to reset | ||
3771 | * | ||
3772 | * Same as above except return -EAGAIN if the bus cannot be locked | ||
3773 | */ | ||
3774 | int pci_try_reset_bus(struct pci_bus *bus) | ||
3775 | { | ||
3776 | int rc; | ||
3777 | |||
3778 | rc = pci_bus_reset(bus, 1); | ||
3779 | if (rc) | ||
3780 | return rc; | ||
3781 | |||
3782 | pci_bus_save_and_disable(bus); | ||
3783 | |||
3784 | if (pci_bus_trylock(bus)) { | ||
3785 | might_sleep(); | ||
3786 | pci_reset_bridge_secondary_bus(bus->self); | ||
3787 | pci_bus_unlock(bus); | ||
3788 | } else | ||
3789 | rc = -EAGAIN; | ||
3790 | |||
3791 | pci_bus_restore(bus); | ||
3792 | |||
3793 | return rc; | ||
3794 | } | ||
3795 | EXPORT_SYMBOL_GPL(pci_try_reset_bus); | ||
3796 | |||
3797 | /** | ||
3825 | * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count | 3798 | * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count |
3826 | * @dev: PCI device to query | 3799 | * @dev: PCI device to query |
3827 | * | 3800 | * |
@@ -4450,7 +4423,6 @@ EXPORT_SYMBOL(pci_restore_state); | |||
4450 | EXPORT_SYMBOL(pci_pme_capable); | 4423 | EXPORT_SYMBOL(pci_pme_capable); |
4451 | EXPORT_SYMBOL(pci_pme_active); | 4424 | EXPORT_SYMBOL(pci_pme_active); |
4452 | EXPORT_SYMBOL(pci_wake_from_d3); | 4425 | EXPORT_SYMBOL(pci_wake_from_d3); |
4453 | EXPORT_SYMBOL(pci_target_state); | ||
4454 | EXPORT_SYMBOL(pci_prepare_to_sleep); | 4426 | EXPORT_SYMBOL(pci_prepare_to_sleep); |
4455 | EXPORT_SYMBOL(pci_back_from_sleep); | 4427 | EXPORT_SYMBOL(pci_back_from_sleep); |
4456 | EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state); | 4428 | EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state); |