Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
557848c3 ZY |
2 | #ifndef DRIVERS_PCI_H |
3 | #define DRIVERS_PCI_H | |
4 | ||
2209e06f AG |
5 | #include <linux/pci.h> |
6 | ||
01352558 IJ |
7 | struct pcie_tlp_log; |
8 | ||
f8bf2aeb JS |
9 | /* Number of possible devfns: 0.0 to 1f.7 inclusive */ |
10 | #define MAX_NR_DEVFNS 256 | |
11 | ||
57a4591d KCC |
12 | #define MAX_NR_LANES 16 |
13 | ||
fff905f3 WY |
14 | #define PCI_FIND_CAP_TTL 48 |
15 | ||
8531e283 LW |
16 | #define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */ |
17 | ||
33a176ab MR |
18 | #define PCIE_LINK_RETRAIN_TIMEOUT_MS 1000 |
19 | ||
6aa9c09f TR |
20 | /* |
21 | * Power stable to PERST# inactive. | |
22 | * | |
23 | * See the "Power Sequencing and Reset Signal Timings" table of the PCI Express | |
24 | * Card Electromechanical Specification, Revision 5.1, Section 2.9.2, Symbol | |
25 | * "T_PVPERL". | |
26 | */ | |
164f66be YS |
27 | #define PCIE_T_PVPERL_MS 100 |
28 | ||
6aa9c09f TR |
29 | /* |
30 | * REFCLK stable before PERST# inactive. | |
31 | * | |
32 | * See the "Power Sequencing and Reset Signal Timings" table of the PCI Express | |
33 | * Card Electromechanical Specification, Revision 5.1, Section 2.9.2, Symbol | |
34 | * "T_PERST-CLK". | |
35 | */ | |
36 | #define PCIE_T_PERST_CLK_US 100 | |
37 | ||
70a7bfb1 DLM |
38 | /* |
39 | * End of conventional reset (PERST# de-asserted) to first configuration | |
40 | * request (device able to respond with a "Request Retry Status" completion), | |
41 | * from PCIe r6.0, sec 6.6.1. | |
42 | */ | |
43 | #define PCIE_T_RRS_READY_MS 100 | |
44 | ||
e78bd50b FL |
45 | /* |
46 | * PCIe r6.0, sec 5.3.3.2.1 <PME Synchronization> | |
47 | * Recommends 1ms to 10ms timeout to check L2 ready. | |
48 | */ | |
49 | #define PCIE_PME_TO_L2_TIMEOUT_US 10000 | |
50 | ||
d5ceb949 KX |
51 | /* |
52 | * PCIe r6.0, sec 6.6.1 <Conventional Reset> | |
53 | * | |
54 | * - "With a Downstream Port that does not support Link speeds greater | |
55 | * than 5.0 GT/s, software must wait a minimum of 100 ms following exit | |
56 | * from a Conventional Reset before sending a Configuration Request to | |
57 | * the device immediately below that Port." | |
58 | * | |
59 | * - "With a Downstream Port that supports Link speeds greater than | |
60 | * 5.0 GT/s, software must wait a minimum of 100 ms after Link training | |
61 | * completes before sending a Configuration Request to the device | |
62 | * immediately below that Port." | |
63 | */ | |
64 | #define PCIE_RESET_CONFIG_DEVICE_WAIT_MS 100 | |
65 | ||
95cb8ff6 YS |
66 | /* Message Routing (r[2:0]); PCIe r6.0, sec 2.2.8 */ |
67 | #define PCIE_MSG_TYPE_R_RC 0 | |
68 | #define PCIE_MSG_TYPE_R_ADDR 1 | |
69 | #define PCIE_MSG_TYPE_R_ID 2 | |
70 | #define PCIE_MSG_TYPE_R_BC 3 | |
71 | #define PCIE_MSG_TYPE_R_LOCAL 4 | |
72 | #define PCIE_MSG_TYPE_R_GATHER 5 | |
73 | ||
9972b177 FL |
74 | /* Power Management Messages; PCIe r6.0, sec 2.2.8.2 */ |
75 | #define PCIE_MSG_CODE_PME_TURN_OFF 0x19 | |
76 | ||
95cb8ff6 YS |
77 | /* INTx Mechanism Messages; PCIe r6.0, sec 2.2.8.1 */ |
78 | #define PCIE_MSG_CODE_ASSERT_INTA 0x20 | |
79 | #define PCIE_MSG_CODE_ASSERT_INTB 0x21 | |
80 | #define PCIE_MSG_CODE_ASSERT_INTC 0x22 | |
81 | #define PCIE_MSG_CODE_ASSERT_INTD 0x23 | |
82 | #define PCIE_MSG_CODE_DEASSERT_INTA 0x24 | |
83 | #define PCIE_MSG_CODE_DEASSERT_INTB 0x25 | |
84 | #define PCIE_MSG_CODE_DEASSERT_INTC 0x26 | |
85 | #define PCIE_MSG_CODE_DEASSERT_INTD 0x27 | |
86 | ||
343e51ae | 87 | extern const unsigned char pcie_link_speed[]; |
11eb0e0e | 88 | extern bool pci_early_dump; |
343e51ae | 89 | |
7a1562d4 | 90 | bool pcie_cap_has_lnkctl(const struct pci_dev *dev); |
503fa236 | 91 | bool pcie_cap_has_lnkctl2(const struct pci_dev *dev); |
af65d1ad | 92 | bool pcie_cap_has_rtctl(const struct pci_dev *dev); |
7a1562d4 | 93 | |
1da177e4 LT |
94 | /* Functions internal to the PCI core code */ |
95 | ||
506140f9 KW |
96 | #ifdef CONFIG_DMI |
97 | extern const struct attribute_group pci_dev_smbios_attr_group; | |
98 | #endif | |
f7195824 | 99 | |
3b519e4e MW |
100 | enum pci_mmap_api { |
101 | PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */ | |
102 | PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */ | |
103 | }; | |
f39d5b72 BH |
104 | int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai, |
105 | enum pci_mmap_api mmap_api); | |
f7195824 | 106 | |
e20afa06 AN |
107 | bool pci_reset_supported(struct pci_dev *dev); |
108 | void pci_init_reset_methods(struct pci_dev *dev); | |
381634ca | 109 | int pci_bridge_secondary_bus_reset(struct pci_dev *dev); |
c4eed62a | 110 | int pci_bus_error_reset(struct pci_dev *dev); |
2fa04644 | 111 | int __pci_reset_bus(struct pci_bus *bus); |
ce5ccdef | 112 | |
f0ab0017 BH |
113 | struct pci_cap_saved_data { |
114 | u16 cap_nr; | |
115 | bool cap_extended; | |
116 | unsigned int size; | |
117 | u32 data[]; | |
118 | }; | |
119 | ||
120 | struct pci_cap_saved_state { | |
121 | struct hlist_node next; | |
122 | struct pci_cap_saved_data cap; | |
123 | }; | |
124 | ||
125 | void pci_allocate_cap_save_buffers(struct pci_dev *dev); | |
126 | void pci_free_cap_save_buffers(struct pci_dev *dev); | |
127 | int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size); | |
128 | int pci_add_ext_cap_save_buffer(struct pci_dev *dev, | |
129 | u16 cap, unsigned int size); | |
130 | struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap); | |
131 | struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev, | |
132 | u16 cap); | |
133 | ||
638c133e BH |
134 | #define PCI_PM_D2_DELAY 200 /* usec; see PCIe r4.0, sec 5.9.1 */ |
135 | #define PCI_PM_D3HOT_WAIT 10 /* msec */ | |
136 | #define PCI_PM_D3COLD_WAIT 100 /* msec */ | |
c776dd50 | 137 | |
f39d5b72 | 138 | void pci_update_current_state(struct pci_dev *dev, pci_power_t state); |
b51033e0 | 139 | void pci_refresh_power_state(struct pci_dev *dev); |
adfac8f6 | 140 | int pci_power_up(struct pci_dev *dev); |
f39d5b72 BH |
141 | void pci_disable_enabled_device(struct pci_dev *dev); |
142 | int pci_finish_runtime_suspend(struct pci_dev *dev); | |
600a5b4f | 143 | void pcie_clear_device_status(struct pci_dev *dev); |
dcb0453d | 144 | void pcie_clear_root_pme_status(struct pci_dev *dev); |
669696eb KS |
145 | bool pci_check_pme_status(struct pci_dev *dev); |
146 | void pci_pme_wakeup_bus(struct pci_bus *bus); | |
0ce3fcaf | 147 | void pci_pme_restore(struct pci_dev *dev); |
0c7376ad RW |
148 | bool pci_dev_need_resume(struct pci_dev *dev); |
149 | void pci_dev_adjust_pme(struct pci_dev *dev); | |
2cef548a | 150 | void pci_dev_complete_resume(struct pci_dev *pci_dev); |
f39d5b72 BH |
151 | void pci_config_pm_runtime_get(struct pci_dev *dev); |
152 | void pci_config_pm_runtime_put(struct pci_dev *dev); | |
4d4c10f7 | 153 | void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev); |
f39d5b72 | 154 | void pci_pm_init(struct pci_dev *dev); |
938174e5 | 155 | void pci_ea_init(struct pci_dev *dev); |
cbc40d5c BH |
156 | void pci_msi_init(struct pci_dev *dev); |
157 | void pci_msix_init(struct pci_dev *dev); | |
c6a63307 | 158 | bool pci_bridge_d3_possible(struct pci_dev *dev); |
1ed276a7 | 159 | void pci_bridge_d3_update(struct pci_dev *dev); |
e74b2b58 | 160 | int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type); |
aa8c6c93 | 161 | |
87f10faf | 162 | static inline bool pci_bus_rrs_vendor_id(u32 l) |
d591f680 BH |
163 | { |
164 | return (l & 0xffff) == PCI_VENDOR_ID_PCI_SIG; | |
165 | } | |
166 | ||
b6e335ae RW |
167 | static inline void pci_wakeup_event(struct pci_dev *dev) |
168 | { | |
169 | /* Wait 100 ms before the system can be put into a sleep state. */ | |
170 | pm_wakeup_event(&dev->dev, 100); | |
171 | } | |
172 | ||
b1a7f999 PS |
173 | /** |
174 | * pci_bar_index_is_valid - Check whether a BAR index is within valid range | |
175 | * @bar: BAR index | |
176 | * | |
177 | * Protects against overflowing &struct pci_dev.resource array. | |
178 | * | |
179 | * Return: true for valid index, false otherwise. | |
180 | */ | |
181 | static inline bool pci_bar_index_is_valid(int bar) | |
182 | { | |
183 | if (bar >= 0 && bar < PCI_NUM_RESOURCES) | |
184 | return true; | |
185 | ||
186 | return false; | |
187 | } | |
188 | ||
326c1cda | 189 | static inline bool pci_has_subordinate(struct pci_dev *pci_dev) |
aa8c6c93 RW |
190 | { |
191 | return !!(pci_dev->subordinate); | |
192 | } | |
0f64474b | 193 | |
9d26d3a8 MW |
194 | static inline bool pci_power_manageable(struct pci_dev *pci_dev) |
195 | { | |
196 | /* | |
197 | * Currently we allow normal PCI devices and PCI bridges transition | |
198 | * into D3 if their bridge_d3 is set. | |
199 | */ | |
200 | return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3; | |
201 | } | |
202 | ||
984998e3 MW |
203 | static inline bool pcie_downstream_port(const struct pci_dev *dev) |
204 | { | |
205 | int type = pci_pcie_type(dev); | |
206 | ||
207 | return type == PCI_EXP_TYPE_ROOT_PORT || | |
208 | type == PCI_EXP_TYPE_DOWNSTREAM || | |
209 | type == PCI_EXP_TYPE_PCIE_BRIDGE; | |
210 | } | |
211 | ||
e947e7b1 | 212 | void pci_vpd_init(struct pci_dev *dev); |
d93f8399 | 213 | extern const struct attribute_group pci_dev_vpd_attr_group; |
94e61088 | 214 | |
440589dd KS |
215 | /* PCI Virtual Channel */ |
216 | int pci_save_vc_state(struct pci_dev *dev); | |
217 | void pci_restore_vc_state(struct pci_dev *dev); | |
218 | void pci_allocate_vc_save_buffers(struct pci_dev *dev); | |
219 | ||
1da177e4 LT |
220 | /* PCI /proc functions */ |
221 | #ifdef CONFIG_PROC_FS | |
f39d5b72 BH |
222 | int pci_proc_attach_device(struct pci_dev *dev); |
223 | int pci_proc_detach_device(struct pci_dev *dev); | |
224 | int pci_proc_detach_bus(struct pci_bus *bus); | |
1da177e4 LT |
225 | #else |
226 | static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; } | |
227 | static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; } | |
1da177e4 LT |
228 | static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; } |
229 | #endif | |
230 | ||
231 | /* Functions for PCI Hotplug drivers to use */ | |
a8e4b9c1 | 232 | int pci_hp_add_bridge(struct pci_dev *dev); |
2af781a9 | 233 | bool pci_hp_spurious_link_change(struct pci_dev *pdev); |
1da177e4 | 234 | |
be9c3a4c | 235 | #if defined(CONFIG_SYSFS) && defined(HAVE_PCI_LEGACY) |
f39d5b72 BH |
236 | void pci_create_legacy_files(struct pci_bus *bus); |
237 | void pci_remove_legacy_files(struct pci_bus *bus); | |
f19aeb1f | 238 | #else |
eb6723b4 BH |
239 | static inline void pci_create_legacy_files(struct pci_bus *bus) { } |
240 | static inline void pci_remove_legacy_files(struct pci_bus *bus) { } | |
f19aeb1f | 241 | #endif |
1da177e4 LT |
242 | |
243 | /* Lock for read/write access to pci device and bus lists */ | |
d71374da | 244 | extern struct rw_semaphore pci_bus_sem; |
c4eed62a | 245 | extern struct mutex pci_slot_mutex; |
1da177e4 | 246 | |
a2e27787 JK |
247 | extern raw_spinlock_t pci_lock; |
248 | ||
3789af9a | 249 | extern unsigned int pci_pm_d3hot_delay; |
88187dfa | 250 | |
4b47b0ee | 251 | #ifdef CONFIG_PCI_MSI |
309e57df | 252 | void pci_no_msi(void); |
4b47b0ee | 253 | #else |
309e57df | 254 | static inline void pci_no_msi(void) { } |
4b47b0ee | 255 | #endif |
8fed4b65 | 256 | |
b55438fd | 257 | void pci_realloc_get_opt(char *); |
f483d392 | 258 | |
ffadcc2f KCA |
259 | static inline int pci_no_d1d2(struct pci_dev *dev) |
260 | { | |
261 | unsigned int parent_dstates = 0; | |
4b47b0ee | 262 | |
ffadcc2f KCA |
263 | if (dev->bus->self) |
264 | parent_dstates = dev->bus->self->no_d1d2; | |
265 | return (dev->no_d1d2 || parent_dstates); | |
266 | ||
267 | } | |
be9c3a4c LW |
268 | |
269 | #ifdef CONFIG_SYSFS | |
270 | int pci_create_sysfs_dev_files(struct pci_dev *pdev); | |
271 | void pci_remove_sysfs_dev_files(struct pci_dev *pdev); | |
5136b2da | 272 | extern const struct attribute_group *pci_dev_groups[]; |
be9c3a4c | 273 | extern const struct attribute_group *pci_dev_attr_groups[]; |
56039e65 | 274 | extern const struct attribute_group *pcibus_groups[]; |
0f49ba55 | 275 | extern const struct attribute_group *pci_bus_groups[]; |
2311ab18 | 276 | extern const struct attribute_group pci_doe_sysfs_group; |
be9c3a4c LW |
277 | #else |
278 | static inline int pci_create_sysfs_dev_files(struct pci_dev *pdev) { return 0; } | |
279 | static inline void pci_remove_sysfs_dev_files(struct pci_dev *pdev) { } | |
280 | #define pci_dev_groups NULL | |
281 | #define pci_dev_attr_groups NULL | |
282 | #define pcibus_groups NULL | |
283 | #define pci_bus_groups NULL | |
284 | #endif | |
705b1aaa | 285 | |
003d3b2c | 286 | extern unsigned long pci_hotplug_io_size; |
d7b8a217 NJ |
287 | extern unsigned long pci_hotplug_mmio_size; |
288 | extern unsigned long pci_hotplug_mmio_pref_size; | |
003d3b2c | 289 | extern unsigned long pci_hotplug_bus_size; |
cc7a371b IJ |
290 | extern unsigned long pci_cardbus_io_size; |
291 | extern unsigned long pci_cardbus_mem_size; | |
1da177e4 LT |
292 | |
293 | /** | |
294 | * pci_match_one_device - Tell if a PCI device structure has a matching | |
0aa0f5d1 | 295 | * PCI device id structure |
1da177e4 LT |
296 | * @id: single PCI device id structure to match |
297 | * @dev: the PCI device structure to match against | |
367b09fe | 298 | * |
1da177e4 LT |
299 | * Returns the matching pci_device_id structure or %NULL if there is no match. |
300 | */ | |
301 | static inline const struct pci_device_id * | |
302 | pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev) | |
303 | { | |
304 | if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) && | |
305 | (id->device == PCI_ANY_ID || id->device == dev->device) && | |
306 | (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) && | |
307 | (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) && | |
308 | !((id->class ^ dev->class) & id->class_mask)) | |
309 | return id; | |
310 | return NULL; | |
311 | } | |
312 | ||
f46753c5 AC |
313 | /* PCI slot sysfs helper code */ |
314 | #define to_pci_slot(s) container_of(s, struct pci_slot, kobj) | |
315 | ||
316 | extern struct kset *pci_slots_kset; | |
317 | ||
318 | struct pci_slot_attribute { | |
319 | struct attribute attr; | |
320 | ssize_t (*show)(struct pci_slot *, char *); | |
321 | ssize_t (*store)(struct pci_slot *, const char *, size_t); | |
322 | }; | |
323 | #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr) | |
324 | ||
0b400c7e YZ |
325 | enum pci_bar_type { |
326 | pci_bar_unknown, /* Standard PCI BAR probe */ | |
0aa0f5d1 | 327 | pci_bar_io, /* An I/O port BAR */ |
0b400c7e YZ |
328 | pci_bar_mem32, /* A 32-bit memory BAR */ |
329 | pci_bar_mem64, /* A 64-bit memory BAR */ | |
330 | }; | |
331 | ||
975e1ac1 KS |
332 | struct device *pci_get_host_bridge_device(struct pci_dev *dev); |
333 | void pci_put_host_bridge_device(struct device *dev); | |
334 | ||
95c4e6d4 | 335 | unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge); |
7d4bcc0f IJ |
336 | int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type); |
337 | int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resource_size_t add_size, resource_size_t align); | |
95c4e6d4 | 338 | |
62ce94a7 | 339 | int pci_configure_extended_tags(struct pci_dev *dev, void *ign); |
efdc87da | 340 | bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl, |
87f10faf | 341 | int rrs_timeout); |
aa667c64 | 342 | bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl, |
87f10faf BH |
343 | int rrs_timeout); |
344 | int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int rrs_timeout); | |
aa667c64 | 345 | |
f39d5b72 | 346 | int pci_setup_device(struct pci_dev *dev); |
4453f360 AW |
347 | void __pci_size_stdbars(struct pci_dev *dev, int count, |
348 | unsigned int pos, u32 *sizes); | |
f39d5b72 | 349 | int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, |
4453f360 | 350 | struct resource *res, unsigned int reg, u32 *sizes); |
f39d5b72 | 351 | void pci_configure_ari(struct pci_dev *dev); |
10874f5a | 352 | void __pci_bus_size_bridges(struct pci_bus *bus, |
d66ecb72 | 353 | struct list_head *realloc_head); |
10874f5a BH |
354 | void __pci_bus_assign_resources(const struct pci_bus *bus, |
355 | struct list_head *realloc_head, | |
356 | struct list_head *fail_head); | |
0f7e7aee | 357 | bool pci_bus_clip_resource(struct pci_dev *dev, int idx); |
38a18dfe KB |
358 | void pci_walk_bus_locked(struct pci_bus *top, |
359 | int (*cb)(struct pci_dev *, void *), | |
360 | void *userdata); | |
939de1d6 | 361 | |
65f8e0be | 362 | const char *pci_resource_name(struct pci_dev *dev, unsigned int i); |
9caf4ea2 | 363 | bool pci_resource_is_optional(const struct pci_dev *dev, int resno); |
65f8e0be | 364 | |
e4728eed IJ |
365 | /** |
366 | * pci_resource_num - Reverse lookup resource number from device resources | |
367 | * @dev: PCI device | |
368 | * @res: Resource to lookup index for (MUST be a @dev's resource) | |
369 | * | |
370 | * Perform reverse lookup to determine the resource number for @res within | |
371 | * @dev resource array. NOTE: The caller is responsible for ensuring @res is | |
372 | * among @dev's resources! | |
373 | * | |
374 | * Returns: resource number. | |
375 | */ | |
376 | static inline int pci_resource_num(const struct pci_dev *dev, | |
377 | const struct resource *res) | |
378 | { | |
379 | int resno = res - &dev->resource[0]; | |
380 | ||
381 | /* Passing a resource that is not among dev's resources? */ | |
382 | WARN_ON_ONCE(resno >= PCI_NUM_RESOURCES); | |
383 | ||
384 | return resno; | |
385 | } | |
65f8e0be | 386 | |
2069ecfb | 387 | void pci_reassigndev_resource_alignment(struct pci_dev *dev); |
f39d5b72 | 388 | void pci_disable_bridge_window(struct pci_dev *dev); |
ecd29c1a KS |
389 | struct pci_bus *pci_bus_get(struct pci_bus *bus); |
390 | void pci_bus_put(struct pci_bus *bus); | |
32a9a682 | 391 | |
de9a6c8d IJ |
392 | #define PCIE_LNKCAP_SLS2SPEED(lnkcap) \ |
393 | ({ \ | |
394 | ((lnkcap) == PCI_EXP_LNKCAP_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ | |
395 | (lnkcap) == PCI_EXP_LNKCAP_SLS_32_0GB ? PCIE_SPEED_32_0GT : \ | |
396 | (lnkcap) == PCI_EXP_LNKCAP_SLS_16_0GB ? PCIE_SPEED_16_0GT : \ | |
397 | (lnkcap) == PCI_EXP_LNKCAP_SLS_8_0GB ? PCIE_SPEED_8_0GT : \ | |
398 | (lnkcap) == PCI_EXP_LNKCAP_SLS_5_0GB ? PCIE_SPEED_5_0GT : \ | |
399 | (lnkcap) == PCI_EXP_LNKCAP_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ | |
400 | PCI_SPEED_UNKNOWN); \ | |
401 | }) | |
402 | ||
757bfaa2 YY |
403 | /* PCIe link information from Link Capabilities 2 */ |
404 | #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \ | |
34191749 GP |
405 | ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ |
406 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_32_0GB ? PCIE_SPEED_32_0GT : \ | |
757bfaa2 YY |
407 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_16_0GB ? PCIE_SPEED_16_0GT : \ |
408 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_8_0GB ? PCIE_SPEED_8_0GT : \ | |
409 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_5_0GB ? PCIE_SPEED_5_0GT : \ | |
410 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ | |
411 | PCI_SPEED_UNKNOWN) | |
6cf57be0 | 412 | |
de9a6c8d IJ |
413 | #define PCIE_LNKCTL2_TLS2SPEED(lnkctl2) \ |
414 | ((lnkctl2) == PCI_EXP_LNKCTL2_TLS_64_0GT ? PCIE_SPEED_64_0GT : \ | |
415 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_32_0GT ? PCIE_SPEED_32_0GT : \ | |
416 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_16_0GT ? PCIE_SPEED_16_0GT : \ | |
417 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_8_0GT ? PCIE_SPEED_8_0GT : \ | |
418 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_5_0GT ? PCIE_SPEED_5_0GT : \ | |
419 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \ | |
420 | PCI_SPEED_UNKNOWN) | |
421 | ||
b852f63a TG |
422 | /* PCIe speed to Mb/s reduced by encoding overhead */ |
423 | #define PCIE_SPEED2MBS_ENC(speed) \ | |
ac4f1897 | 424 | ((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \ |
34191749 | 425 | (speed) == PCIE_SPEED_32_0GT ? 32000*128/130 : \ |
9cb3985a | 426 | (speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \ |
b852f63a TG |
427 | (speed) == PCIE_SPEED_8_0GT ? 8000*128/130 : \ |
428 | (speed) == PCIE_SPEED_5_0GT ? 5000*8/10 : \ | |
429 | (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \ | |
430 | 0) | |
431 | ||
100ae5d7 K |
432 | static inline int pcie_dev_speed_mbps(enum pci_bus_speed speed) |
433 | { | |
434 | switch (speed) { | |
435 | case PCIE_SPEED_2_5GT: | |
436 | return 2500; | |
437 | case PCIE_SPEED_5_0GT: | |
438 | return 5000; | |
439 | case PCIE_SPEED_8_0GT: | |
440 | return 8000; | |
441 | case PCIE_SPEED_16_0GT: | |
442 | return 16000; | |
443 | case PCIE_SPEED_32_0GT: | |
444 | return 32000; | |
445 | case PCIE_SPEED_64_0GT: | |
446 | return 64000; | |
447 | default: | |
448 | break; | |
449 | } | |
450 | ||
451 | return -EINVAL; | |
452 | } | |
453 | ||
d2bd39c0 | 454 | u8 pcie_get_supported_speeds(struct pci_dev *dev); |
e56faff5 | 455 | const char *pci_speed_string(enum pci_bus_speed speed); |
2d1ce5ec | 456 | void __pcie_print_link_status(struct pci_dev *dev, bool verbose); |
0fa635ae | 457 | void pcie_report_downtraining(struct pci_dev *dev); |
e93d9fcf | 458 | |
79c731e2 | 459 | static inline void __pcie_update_link_speed(struct pci_bus *bus, u16 linksta, u16 linksta2) |
e93d9fcf IJ |
460 | { |
461 | bus->cur_bus_speed = pcie_link_speed[linksta & PCI_EXP_LNKSTA_CLS]; | |
79c731e2 | 462 | bus->flit_mode = (linksta2 & PCI_EXP_LNKSTA2_FLIT) ? 1 : 0; |
e93d9fcf IJ |
463 | } |
464 | void pcie_update_link_speed(struct pci_bus *bus); | |
6cf57be0 | 465 | |
d1b054da YZ |
466 | /* Single Root I/O Virtualization */ |
467 | struct pci_sriov { | |
0aa0f5d1 BH |
468 | int pos; /* Capability position */ |
469 | int nres; /* Number of resources */ | |
470 | u32 cap; /* SR-IOV Capabilities */ | |
471 | u16 ctrl; /* SR-IOV Control */ | |
472 | u16 total_VFs; /* Total VFs associated with the PF */ | |
473 | u16 initial_VFs; /* Initial VFs associated with the PF */ | |
474 | u16 num_VFs; /* Number of VFs available */ | |
475 | u16 offset; /* First VF Routing ID offset */ | |
476 | u16 stride; /* Following VF stride */ | |
477 | u16 vf_device; /* VF device ID */ | |
478 | u32 pgsz; /* Page size for BAR alignment */ | |
479 | u8 link; /* Function Dependency Link */ | |
480 | u8 max_VF_buses; /* Max buses consumed by VFs */ | |
481 | u16 driver_max_VFs; /* Max num VFs driver supports */ | |
482 | struct pci_dev *dev; /* Lowest numbered PF */ | |
483 | struct pci_dev *self; /* This PF */ | |
cf0921be KA |
484 | u32 class; /* VF device */ |
485 | u8 hdr_type; /* VF header type */ | |
486 | u16 subsystem_vendor; /* VF subsystem vendor */ | |
487 | u16 subsystem_device; /* VF subsystem device */ | |
0aa0f5d1 BH |
488 | resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ |
489 | bool drivers_autoprobe; /* Auto probing of VFs by driver */ | |
d1b054da YZ |
490 | }; |
491 | ||
ac048403 LW |
492 | #ifdef CONFIG_PCI_DOE |
493 | void pci_doe_init(struct pci_dev *pdev); | |
494 | void pci_doe_destroy(struct pci_dev *pdev); | |
495 | void pci_doe_disconnected(struct pci_dev *pdev); | |
496 | #else | |
497 | static inline void pci_doe_init(struct pci_dev *pdev) { } | |
498 | static inline void pci_doe_destroy(struct pci_dev *pdev) { } | |
499 | static inline void pci_doe_disconnected(struct pci_dev *pdev) { } | |
500 | #endif | |
501 | ||
4e893545 MT |
502 | #ifdef CONFIG_PCI_NPEM |
503 | void pci_npem_create(struct pci_dev *dev); | |
504 | void pci_npem_remove(struct pci_dev *dev); | |
505 | #else | |
506 | static inline void pci_npem_create(struct pci_dev *dev) { } | |
507 | static inline void pci_npem_remove(struct pci_dev *dev) { } | |
508 | #endif | |
509 | ||
2311ab18 AF |
510 | #if defined(CONFIG_PCI_DOE) && defined(CONFIG_SYSFS) |
511 | void pci_doe_sysfs_init(struct pci_dev *pci_dev); | |
512 | void pci_doe_sysfs_teardown(struct pci_dev *pdev); | |
513 | #else | |
514 | static inline void pci_doe_sysfs_init(struct pci_dev *pdev) { } | |
515 | static inline void pci_doe_sysfs_teardown(struct pci_dev *pdev) { } | |
516 | #endif | |
517 | ||
a6bd101b KB |
518 | /** |
519 | * pci_dev_set_io_state - Set the new error state if possible. | |
520 | * | |
347269c1 KW |
521 | * @dev: PCI device to set new error_state |
522 | * @new: the state we want dev to be in | |
a6bd101b | 523 | * |
74ff8864 LW |
524 | * If the device is experiencing perm_failure, it has to remain in that state. |
525 | * Any other transition is allowed. | |
a6bd101b KB |
526 | * |
527 | * Returns true if state has been changed to the requested state. | |
528 | */ | |
529 | static inline bool pci_dev_set_io_state(struct pci_dev *dev, | |
530 | pci_channel_state_t new) | |
531 | { | |
74ff8864 | 532 | pci_channel_state_t old; |
a6bd101b | 533 | |
a6bd101b KB |
534 | switch (new) { |
535 | case pci_channel_io_perm_failure: | |
74ff8864 LW |
536 | xchg(&dev->error_state, pci_channel_io_perm_failure); |
537 | return true; | |
a6bd101b | 538 | case pci_channel_io_frozen: |
74ff8864 LW |
539 | old = cmpxchg(&dev->error_state, pci_channel_io_normal, |
540 | pci_channel_io_frozen); | |
541 | return old != pci_channel_io_perm_failure; | |
a6bd101b | 542 | case pci_channel_io_normal: |
74ff8864 LW |
543 | old = cmpxchg(&dev->error_state, pci_channel_io_frozen, |
544 | pci_channel_io_normal); | |
545 | return old != pci_channel_io_perm_failure; | |
546 | default: | |
547 | return false; | |
a6bd101b | 548 | } |
a6bd101b | 549 | } |
89ee9f76 KB |
550 | |
551 | static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused) | |
552 | { | |
a6bd101b | 553 | pci_dev_set_io_state(dev, pci_channel_io_perm_failure); |
ac048403 | 554 | pci_doe_disconnected(dev); |
a6bd101b | 555 | |
89ee9f76 KB |
556 | return 0; |
557 | } | |
558 | ||
a6bd101b KB |
559 | /* pci_dev priv_flags */ |
560 | #define PCI_DEV_ADDED 0 | |
a97396c6 LW |
561 | #define PCI_DPC_RECOVERED 1 |
562 | #define PCI_DPC_RECOVERING 2 | |
e3f30d56 | 563 | #define PCI_DEV_REMOVED 3 |
2af781a9 LW |
564 | #define PCI_LINK_CHANGED 4 |
565 | #define PCI_LINK_CHANGING 5 | |
2389d8dc | 566 | #define PCI_LINK_LBMS_SEEN 6 |
ce45dc4b | 567 | #define PCI_DEV_ALLOW_BINDING 7 |
a6bd101b | 568 | |
93093ea1 | 569 | static inline void pci_dev_assign_added(struct pci_dev *dev) |
44bda4b7 | 570 | { |
93093ea1 KB |
571 | smp_mb__before_atomic(); |
572 | set_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
573 | smp_mb__after_atomic(); | |
574 | } | |
575 | ||
576 | static inline bool pci_dev_test_and_clear_added(struct pci_dev *dev) | |
577 | { | |
578 | return test_and_clear_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
44bda4b7 HV |
579 | } |
580 | ||
581 | static inline bool pci_dev_is_added(const struct pci_dev *dev) | |
582 | { | |
583 | return test_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
584 | } | |
585 | ||
e3f30d56 KB |
586 | static inline bool pci_dev_test_and_set_removed(struct pci_dev *dev) |
587 | { | |
588 | return test_and_set_bit(PCI_DEV_REMOVED, &dev->priv_flags); | |
589 | } | |
590 | ||
ce45dc4b LW |
591 | static inline void pci_dev_allow_binding(struct pci_dev *dev) |
592 | { | |
593 | set_bit(PCI_DEV_ALLOW_BINDING, &dev->priv_flags); | |
594 | } | |
595 | ||
596 | static inline bool pci_dev_binding_disallowed(struct pci_dev *dev) | |
597 | { | |
598 | return !test_bit(PCI_DEV_ALLOW_BINDING, &dev->priv_flags); | |
599 | } | |
600 | ||
1e451160 KB |
601 | #ifdef CONFIG_PCIEAER |
602 | #include <linux/aer.h> | |
603 | ||
604 | #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */ | |
605 | ||
606 | struct aer_err_info { | |
607 | struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES]; | |
a57f2bfb | 608 | int ratelimit_print[AER_MAX_MULTI_ERR_DEVICES]; |
1e451160 | 609 | int error_dev_num; |
c8f6791e | 610 | const char *level; /* printk level */ |
1e451160 KB |
611 | |
612 | unsigned int id:16; | |
613 | ||
614 | unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */ | |
a57f2bfb JPD |
615 | unsigned int root_ratelimit_print:1; /* 0=skip, 1=print */ |
616 | unsigned int __pad1:4; | |
1e451160 KB |
617 | unsigned int multi_error_valid:1; |
618 | ||
619 | unsigned int first_error:5; | |
620 | unsigned int __pad2:2; | |
621 | unsigned int tlp_header_valid:1; | |
622 | ||
623 | unsigned int status; /* COR/UNCOR Error Status */ | |
624 | unsigned int mask; /* COR/UNCOR Error Mask */ | |
0a5a46a6 | 625 | struct pcie_tlp_log tlp; /* TLP Header */ |
1e451160 KB |
626 | }; |
627 | ||
94bc15c3 BH |
628 | int aer_get_device_error_info(struct aer_err_info *info, int i); |
629 | void aer_print_error(struct aer_err_info *info, int i); | |
1e451160 | 630 | |
ad41ddee | 631 | int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2, |
7e077e67 IJ |
632 | unsigned int tlp_len, bool flit, |
633 | struct pcie_tlp_log *log); | |
ad41ddee | 634 | unsigned int aer_tlp_log_len(struct pci_dev *dev, u32 aercc); |
f68ea779 | 635 | void pcie_print_tlp_log(const struct pci_dev *dev, |
82013ff3 BH |
636 | const struct pcie_tlp_log *log, const char *level, |
637 | const char *pfx); | |
1e451160 KB |
638 | #endif /* CONFIG_PCIEAER */ |
639 | ||
90655631 SK |
640 | #ifdef CONFIG_PCIEPORTBUS |
641 | /* Cached RCEC Endpoint Association */ | |
642 | struct rcec_ea { | |
643 | u8 nextbusn; | |
644 | u8 lastbusn; | |
645 | u32 bitmap; | |
646 | }; | |
647 | #endif | |
648 | ||
4f802170 KB |
649 | #ifdef CONFIG_PCIE_DPC |
650 | void pci_save_dpc_state(struct pci_dev *dev); | |
651 | void pci_restore_dpc_state(struct pci_dev *dev); | |
27005618 | 652 | void pci_dpc_init(struct pci_dev *pdev); |
aea47413 KS |
653 | void dpc_process_error(struct pci_dev *pdev); |
654 | pci_ers_result_t dpc_reset_link(struct pci_dev *pdev); | |
a97396c6 | 655 | bool pci_dpc_recovered(struct pci_dev *pdev); |
ad41ddee | 656 | unsigned int dpc_tlp_log_len(struct pci_dev *dev); |
4f802170 | 657 | #else |
eb6723b4 BH |
658 | static inline void pci_save_dpc_state(struct pci_dev *dev) { } |
659 | static inline void pci_restore_dpc_state(struct pci_dev *dev) { } | |
660 | static inline void pci_dpc_init(struct pci_dev *pdev) { } | |
a97396c6 | 661 | static inline bool pci_dpc_recovered(struct pci_dev *pdev) { return false; } |
4f802170 KB |
662 | #endif |
663 | ||
90655631 SK |
664 | #ifdef CONFIG_PCIEPORTBUS |
665 | void pci_rcec_init(struct pci_dev *dev); | |
666 | void pci_rcec_exit(struct pci_dev *dev); | |
507b460f | 667 | void pcie_link_rcec(struct pci_dev *rcec); |
af113553 SK |
668 | void pcie_walk_rcec(struct pci_dev *rcec, |
669 | int (*cb)(struct pci_dev *, void *), | |
670 | void *userdata); | |
90655631 | 671 | #else |
eb6723b4 BH |
672 | static inline void pci_rcec_init(struct pci_dev *dev) { } |
673 | static inline void pci_rcec_exit(struct pci_dev *dev) { } | |
674 | static inline void pcie_link_rcec(struct pci_dev *rcec) { } | |
af113553 SK |
675 | static inline void pcie_walk_rcec(struct pci_dev *rcec, |
676 | int (*cb)(struct pci_dev *, void *), | |
eb6723b4 | 677 | void *userdata) { } |
90655631 SK |
678 | #endif |
679 | ||
1900ca13 | 680 | #ifdef CONFIG_PCI_ATS |
b92b512a KS |
681 | /* Address Translation Service */ |
682 | void pci_ats_init(struct pci_dev *dev); | |
f39d5b72 | 683 | void pci_restore_ats_state(struct pci_dev *dev); |
1900ca13 | 684 | #else |
b92b512a KS |
685 | static inline void pci_ats_init(struct pci_dev *d) { } |
686 | static inline void pci_restore_ats_state(struct pci_dev *dev) { } | |
1900ca13 HX |
687 | #endif /* CONFIG_PCI_ATS */ |
688 | ||
c065190b KS |
689 | #ifdef CONFIG_PCI_PRI |
690 | void pci_pri_init(struct pci_dev *dev); | |
fef2dd8b | 691 | void pci_restore_pri_state(struct pci_dev *pdev); |
c065190b KS |
692 | #else |
693 | static inline void pci_pri_init(struct pci_dev *dev) { } | |
fef2dd8b | 694 | static inline void pci_restore_pri_state(struct pci_dev *pdev) { } |
c065190b KS |
695 | #endif |
696 | ||
751035b8 KS |
697 | #ifdef CONFIG_PCI_PASID |
698 | void pci_pasid_init(struct pci_dev *dev); | |
fef2dd8b | 699 | void pci_restore_pasid_state(struct pci_dev *pdev); |
751035b8 KS |
700 | #else |
701 | static inline void pci_pasid_init(struct pci_dev *dev) { } | |
fef2dd8b | 702 | static inline void pci_restore_pasid_state(struct pci_dev *pdev) { } |
751035b8 KS |
703 | #endif |
704 | ||
d1b054da | 705 | #ifdef CONFIG_PCI_IOV |
f39d5b72 BH |
706 | int pci_iov_init(struct pci_dev *dev); |
707 | void pci_iov_release(struct pci_dev *dev); | |
38972375 | 708 | void pci_iov_remove(struct pci_dev *dev); |
6ffa2489 | 709 | void pci_iov_update_resource(struct pci_dev *dev, int resno); |
f39d5b72 BH |
710 | resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); |
711 | void pci_restore_iov_state(struct pci_dev *dev); | |
712 | int pci_iov_bus_range(struct pci_bus *bus); | |
cbd38438 MW |
713 | static inline bool pci_resource_is_iov(int resno) |
714 | { | |
715 | return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END; | |
716 | } | |
c3d5c2d9 LR |
717 | extern const struct attribute_group sriov_pf_dev_attr_group; |
718 | extern const struct attribute_group sriov_vf_dev_attr_group; | |
d1b054da YZ |
719 | #else |
720 | static inline int pci_iov_init(struct pci_dev *dev) | |
721 | { | |
722 | return -ENODEV; | |
723 | } | |
eb6723b4 BH |
724 | static inline void pci_iov_release(struct pci_dev *dev) { } |
725 | static inline void pci_iov_remove(struct pci_dev *dev) { } | |
cbd38438 MW |
726 | static inline void pci_iov_update_resource(struct pci_dev *dev, int resno) { } |
727 | static inline resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, | |
728 | int resno) | |
729 | { | |
730 | return 0; | |
731 | } | |
eb6723b4 | 732 | static inline void pci_restore_iov_state(struct pci_dev *dev) { } |
a28724b0 YZ |
733 | static inline int pci_iov_bus_range(struct pci_bus *bus) |
734 | { | |
735 | return 0; | |
736 | } | |
cbd38438 MW |
737 | static inline bool pci_resource_is_iov(int resno) |
738 | { | |
739 | return false; | |
740 | } | |
d1b054da YZ |
741 | #endif /* CONFIG_PCI_IOV */ |
742 | ||
f69767a1 WH |
743 | #ifdef CONFIG_PCIE_TPH |
744 | void pci_restore_tph_state(struct pci_dev *dev); | |
745 | void pci_save_tph_state(struct pci_dev *dev); | |
746 | void pci_no_tph(void); | |
747 | void pci_tph_init(struct pci_dev *dev); | |
748 | #else | |
749 | static inline void pci_restore_tph_state(struct pci_dev *dev) { } | |
750 | static inline void pci_save_tph_state(struct pci_dev *dev) { } | |
751 | static inline void pci_no_tph(void) { } | |
752 | static inline void pci_tph_init(struct pci_dev *dev) { } | |
753 | #endif | |
754 | ||
39850ed5 | 755 | #ifdef CONFIG_PCIE_PTM |
d736d292 | 756 | void pci_ptm_init(struct pci_dev *dev); |
39850ed5 DB |
757 | void pci_save_ptm_state(struct pci_dev *dev); |
758 | void pci_restore_ptm_state(struct pci_dev *dev); | |
e8bdc5ea BH |
759 | void pci_suspend_ptm(struct pci_dev *dev); |
760 | void pci_resume_ptm(struct pci_dev *dev); | |
39850ed5 | 761 | #else |
d736d292 | 762 | static inline void pci_ptm_init(struct pci_dev *dev) { } |
39850ed5 DB |
763 | static inline void pci_save_ptm_state(struct pci_dev *dev) { } |
764 | static inline void pci_restore_ptm_state(struct pci_dev *dev) { } | |
e8bdc5ea BH |
765 | static inline void pci_suspend_ptm(struct pci_dev *dev) { } |
766 | static inline void pci_resume_ptm(struct pci_dev *dev) { } | |
39850ed5 DB |
767 | #endif |
768 | ||
f39d5b72 | 769 | unsigned long pci_cardbus_resource_alignment(struct resource *); |
0a2daa1c | 770 | |
0e52247a | 771 | static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, |
f39d5b72 | 772 | struct resource *res) |
6faf17f6 | 773 | { |
e4728eed | 774 | int resno = pci_resource_num(dev, res); |
6faf17f6 | 775 | |
cbd38438 | 776 | if (pci_resource_is_iov(resno)) |
6faf17f6 | 777 | return pci_sriov_resource_alignment(dev, resno); |
0aa0f5d1 | 778 | if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS) |
0a2daa1c | 779 | return pci_cardbus_resource_alignment(res); |
6faf17f6 CW |
780 | return resource_alignment(res); |
781 | } | |
782 | ||
52fbf5bd | 783 | void pci_acs_init(struct pci_dev *dev); |
bd2e9567 BH |
784 | #ifdef CONFIG_PCI_QUIRKS |
785 | int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags); | |
786 | int pci_dev_specific_enable_acs(struct pci_dev *dev); | |
73c47dde | 787 | int pci_dev_specific_disable_acs_redir(struct pci_dev *dev); |
59100eb2 | 788 | int pcie_failed_link_retrain(struct pci_dev *dev); |
bd2e9567 BH |
789 | #else |
790 | static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, | |
791 | u16 acs_flags) | |
792 | { | |
793 | return -ENOTTY; | |
794 | } | |
795 | static inline int pci_dev_specific_enable_acs(struct pci_dev *dev) | |
796 | { | |
797 | return -ENOTTY; | |
798 | } | |
73c47dde LG |
799 | static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev) |
800 | { | |
801 | return -ENOTTY; | |
802 | } | |
59100eb2 | 803 | static inline int pcie_failed_link_retrain(struct pci_dev *dev) |
a89c8224 | 804 | { |
59100eb2 | 805 | return -ENOTTY; |
a89c8224 | 806 | } |
bd2e9567 | 807 | #endif |
ae21ee65 | 808 | |
2e28bc84 | 809 | /* PCI error reporting and recovery */ |
e8e5ff2a | 810 | pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, |
8f1bbfbc SK |
811 | pci_channel_state_t state, |
812 | pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)); | |
2e28bc84 | 813 | |
9f5a70f1 | 814 | bool pcie_wait_for_link(struct pci_dev *pdev, bool active); |
1abb4739 | 815 | int pcie_retrain_link(struct pci_dev *pdev, bool use_lt); |
1e11b549 DB |
816 | |
817 | /* ASPM-related functionality we need even without CONFIG_PCIEASPM */ | |
818 | void pci_save_ltr_state(struct pci_dev *dev); | |
819 | void pci_restore_ltr_state(struct pci_dev *dev); | |
17423360 DB |
820 | void pci_configure_aspm_l1ss(struct pci_dev *dev); |
821 | void pci_save_aspm_l1ss_state(struct pci_dev *dev); | |
822 | void pci_restore_aspm_l1ss_state(struct pci_dev *dev); | |
1e11b549 | 823 | |
7d8e7d19 BH |
824 | #ifdef CONFIG_PCIEASPM |
825 | void pcie_aspm_init_link_state(struct pci_dev *pdev); | |
826 | void pcie_aspm_exit_link_state(struct pci_dev *pdev); | |
1e560864 | 827 | void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked); |
7d8e7d19 | 828 | void pcie_aspm_powersave_config_link(struct pci_dev *pdev); |
fa84f443 DB |
829 | void pci_configure_ltr(struct pci_dev *pdev); |
830 | void pci_bridge_reconfigure_ltr(struct pci_dev *pdev); | |
7d8e7d19 BH |
831 | #else |
832 | static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { } | |
833 | static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { } | |
1e560864 | 834 | static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked) { } |
7d8e7d19 | 835 | static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { } |
fa84f443 DB |
836 | static inline void pci_configure_ltr(struct pci_dev *pdev) { } |
837 | static inline void pci_bridge_reconfigure_ltr(struct pci_dev *pdev) { } | |
7d8e7d19 BH |
838 | #endif |
839 | ||
72bde9ce KS |
840 | #ifdef CONFIG_PCIE_ECRC |
841 | void pcie_set_ecrc_checking(struct pci_dev *dev); | |
842 | void pcie_ecrc_get_policy(char *str); | |
843 | #else | |
844 | static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { } | |
845 | static inline void pcie_ecrc_get_policy(char *str) { } | |
846 | #endif | |
847 | ||
665745f2 | 848 | #ifdef CONFIG_PCIEPORTBUS |
2389d8dc | 849 | void pcie_reset_lbms(struct pci_dev *port); |
665745f2 | 850 | #else |
2389d8dc | 851 | static inline void pcie_reset_lbms(struct pci_dev *port) {} |
665745f2 IJ |
852 | #endif |
853 | ||
b9c3b266 DC |
854 | struct pci_dev_reset_methods { |
855 | u16 vendor; | |
856 | u16 device; | |
9bdc81ce | 857 | int (*reset)(struct pci_dev *dev, bool probe); |
b9c3b266 DC |
858 | }; |
859 | ||
e20afa06 | 860 | struct pci_reset_fn_method { |
9bdc81ce | 861 | int (*reset_fn)(struct pci_dev *pdev, bool probe); |
e20afa06 | 862 | char *name; |
b9c3b266 | 863 | }; |
10269d57 | 864 | extern const struct pci_reset_fn_method pci_reset_fn_methods[]; |
b9c3b266 | 865 | |
93177a74 | 866 | #ifdef CONFIG_PCI_QUIRKS |
9bdc81ce | 867 | int pci_dev_specific_reset(struct pci_dev *dev, bool probe); |
93177a74 | 868 | #else |
9bdc81ce | 869 | static inline int pci_dev_specific_reset(struct pci_dev *dev, bool probe) |
93177a74 RW |
870 | { |
871 | return -ENOTTY; | |
872 | } | |
873 | #endif | |
b9c3b266 | 874 | |
169de969 DL |
875 | #if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64) |
876 | int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment, | |
877 | struct resource *res); | |
16f7ae59 AB |
878 | #else |
879 | static inline int acpi_get_rc_resources(struct device *dev, const char *hid, | |
880 | u16 segment, struct resource *res) | |
881 | { | |
882 | return -ENODEV; | |
883 | } | |
169de969 DL |
884 | #endif |
885 | ||
a7eb9124 | 886 | void pci_rebar_init(struct pci_dev *pdev); |
276b738d CK |
887 | int pci_rebar_get_current_size(struct pci_dev *pdev, int bar); |
888 | int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size); | |
889 | static inline u64 pci_rebar_size_to_bytes(int size) | |
890 | { | |
891 | return 1ULL << (size + 20); | |
892 | } | |
893 | ||
9e2aee80 RH |
894 | struct device_node; |
895 | ||
57a4591d KCC |
896 | #define PCI_EQ_RESV 0xff |
897 | ||
898 | enum equalization_preset_type { | |
899 | EQ_PRESET_TYPE_8GTS, | |
900 | EQ_PRESET_TYPE_16GTS, | |
901 | EQ_PRESET_TYPE_32GTS, | |
902 | EQ_PRESET_TYPE_64GTS, | |
903 | EQ_PRESET_TYPE_MAX | |
904 | }; | |
905 | ||
906 | struct pci_eq_presets { | |
907 | u16 eq_presets_8gts[MAX_NR_LANES]; | |
908 | u8 eq_presets_Ngts[EQ_PRESET_TYPE_MAX - 1][MAX_NR_LANES]; | |
909 | }; | |
910 | ||
9e2aee80 | 911 | #ifdef CONFIG_OF |
9e2aee80 RH |
912 | int of_get_pci_domain_nr(struct device_node *node); |
913 | int of_pci_get_max_link_speed(struct device_node *node); | |
35662423 PR |
914 | u32 of_pci_get_slot_power_limit(struct device_node *node, |
915 | u8 *slot_power_limit_value, | |
916 | u8 *slot_power_limit_scale); | |
407abde9 | 917 | bool of_pci_preserve_config(struct device_node *node); |
0d21e71a | 918 | int pci_set_of_node(struct pci_dev *dev); |
621f7e35 KS |
919 | void pci_release_of_node(struct pci_dev *dev); |
920 | void pci_set_bus_of_node(struct pci_bus *bus); | |
921 | void pci_release_bus_of_node(struct pci_bus *bus); | |
9e2aee80 | 922 | |
669cbc70 | 923 | int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge); |
278dd091 | 924 | bool of_pci_supply_present(struct device_node *np); |
57a4591d KCC |
925 | int of_pci_get_equalization_presets(struct device *dev, |
926 | struct pci_eq_presets *presets, | |
927 | int num_lanes); | |
9e2aee80 | 928 | #else |
9e2aee80 RH |
929 | static inline int |
930 | of_get_pci_domain_nr(struct device_node *node) | |
931 | { | |
932 | return -1; | |
933 | } | |
934 | ||
935 | static inline int | |
936 | of_pci_get_max_link_speed(struct device_node *node) | |
937 | { | |
938 | return -EINVAL; | |
939 | } | |
621f7e35 | 940 | |
35662423 PR |
941 | static inline u32 |
942 | of_pci_get_slot_power_limit(struct device_node *node, | |
943 | u8 *slot_power_limit_value, | |
944 | u8 *slot_power_limit_scale) | |
945 | { | |
946 | if (slot_power_limit_value) | |
947 | *slot_power_limit_value = 0; | |
948 | if (slot_power_limit_scale) | |
949 | *slot_power_limit_scale = 0; | |
950 | return 0; | |
951 | } | |
952 | ||
407abde9 VS |
953 | static inline bool of_pci_preserve_config(struct device_node *node) |
954 | { | |
955 | return false; | |
956 | } | |
957 | ||
0d21e71a | 958 | static inline int pci_set_of_node(struct pci_dev *dev) { return 0; } |
621f7e35 KS |
959 | static inline void pci_release_of_node(struct pci_dev *dev) { } |
960 | static inline void pci_set_bus_of_node(struct pci_bus *bus) { } | |
961 | static inline void pci_release_bus_of_node(struct pci_bus *bus) { } | |
669cbc70 RH |
962 | |
963 | static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge) | |
964 | { | |
965 | return 0; | |
966 | } | |
967 | ||
278dd091 MS |
968 | static inline bool of_pci_supply_present(struct device_node *np) |
969 | { | |
970 | return false; | |
971 | } | |
57a4591d KCC |
972 | |
973 | static inline int of_pci_get_equalization_presets(struct device *dev, | |
974 | struct pci_eq_presets *presets, | |
975 | int num_lanes) | |
976 | { | |
977 | presets->eq_presets_8gts[0] = PCI_EQ_RESV; | |
978 | for (int i = 0; i < EQ_PRESET_TYPE_MAX - 1; i++) | |
979 | presets->eq_presets_Ngts[i][0] = PCI_EQ_RESV; | |
980 | ||
981 | return 0; | |
982 | } | |
9e2aee80 RH |
983 | #endif /* CONFIG_OF */ |
984 | ||
407d1a51 LH |
985 | struct of_changeset; |
986 | ||
987 | #ifdef CONFIG_PCI_DYNAMIC_OF_NODES | |
988 | void of_pci_make_dev_node(struct pci_dev *pdev); | |
989 | void of_pci_remove_node(struct pci_dev *pdev); | |
990 | int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs, | |
991 | struct device_node *np); | |
1f340724 HC |
992 | void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge); |
993 | void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge); | |
994 | int of_pci_add_host_bridge_properties(struct pci_host_bridge *bridge, | |
995 | struct of_changeset *ocs, | |
996 | struct device_node *np); | |
407d1a51 LH |
997 | #else |
998 | static inline void of_pci_make_dev_node(struct pci_dev *pdev) { } | |
999 | static inline void of_pci_remove_node(struct pci_dev *pdev) { } | |
1f340724 HC |
1000 | static inline void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge) { } |
1001 | static inline void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge) { } | |
407d1a51 LH |
1002 | #endif |
1003 | ||
60ed982a RJ |
1004 | #ifdef CONFIG_PCIEAER |
1005 | void pci_no_aer(void); | |
1006 | void pci_aer_init(struct pci_dev *dev); | |
db89ccbe | 1007 | void pci_aer_exit(struct pci_dev *dev); |
81aa5206 | 1008 | extern const struct attribute_group aer_stats_attr_group; |
b4fe7398 | 1009 | extern const struct attribute_group aer_attr_group; |
7ab92e89 | 1010 | void pci_aer_clear_fatal_status(struct pci_dev *dev); |
894020fd | 1011 | int pci_aer_clear_status(struct pci_dev *dev); |
20e15e67 | 1012 | int pci_aer_raw_clear_status(struct pci_dev *dev); |
ba3da667 BH |
1013 | void pci_save_aer_state(struct pci_dev *dev); |
1014 | void pci_restore_aer_state(struct pci_dev *dev); | |
60ed982a RJ |
1015 | #else |
1016 | static inline void pci_no_aer(void) { } | |
31f996ef | 1017 | static inline void pci_aer_init(struct pci_dev *d) { } |
db89ccbe | 1018 | static inline void pci_aer_exit(struct pci_dev *d) { } |
7ab92e89 | 1019 | static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { } |
894020fd | 1020 | static inline int pci_aer_clear_status(struct pci_dev *dev) { return -EINVAL; } |
20e15e67 | 1021 | static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL; } |
ba3da667 BH |
1022 | static inline void pci_save_aer_state(struct pci_dev *dev) { } |
1023 | static inline void pci_restore_aer_state(struct pci_dev *dev) { } | |
60ed982a RJ |
1024 | #endif |
1025 | ||
8c3aac6e | 1026 | #ifdef CONFIG_ACPI |
9d7d5db8 | 1027 | bool pci_acpi_preserve_config(struct pci_host_bridge *bridge); |
4a2dbedd | 1028 | int pci_acpi_program_hp_params(struct pci_dev *dev); |
506140f9 | 1029 | extern const struct attribute_group pci_dev_acpi_attr_group; |
3a15955d | 1030 | void pci_set_acpi_fwnode(struct pci_dev *dev); |
9bdc81ce | 1031 | int pci_dev_acpi_reset(struct pci_dev *dev, bool probe); |
d97c5d4c RW |
1032 | bool acpi_pci_power_manageable(struct pci_dev *dev); |
1033 | bool acpi_pci_bridge_d3(struct pci_dev *dev); | |
1034 | int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state); | |
1035 | pci_power_t acpi_pci_get_power_state(struct pci_dev *dev); | |
1036 | void acpi_pci_refresh_power_state(struct pci_dev *dev); | |
1037 | int acpi_pci_wakeup(struct pci_dev *dev, bool enable); | |
1038 | bool acpi_pci_need_resume(struct pci_dev *dev); | |
1039 | pci_power_t acpi_pci_choose_state(struct pci_dev *pdev); | |
8c3aac6e | 1040 | #else |
9d7d5db8 VS |
1041 | static inline bool pci_acpi_preserve_config(struct pci_host_bridge *bridge) |
1042 | { | |
1043 | return false; | |
1044 | } | |
9bdc81ce | 1045 | static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe) |
6937b7dd SD |
1046 | { |
1047 | return -ENOTTY; | |
1048 | } | |
eb6723b4 | 1049 | static inline void pci_set_acpi_fwnode(struct pci_dev *dev) { } |
4a2dbedd | 1050 | static inline int pci_acpi_program_hp_params(struct pci_dev *dev) |
8c3aac6e KW |
1051 | { |
1052 | return -ENODEV; | |
1053 | } | |
d97c5d4c RW |
1054 | static inline bool acpi_pci_power_manageable(struct pci_dev *dev) |
1055 | { | |
1056 | return false; | |
1057 | } | |
1058 | static inline bool acpi_pci_bridge_d3(struct pci_dev *dev) | |
1059 | { | |
1060 | return false; | |
1061 | } | |
1062 | static inline int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |
1063 | { | |
1064 | return -ENODEV; | |
1065 | } | |
1066 | static inline pci_power_t acpi_pci_get_power_state(struct pci_dev *dev) | |
1067 | { | |
1068 | return PCI_UNKNOWN; | |
1069 | } | |
eb6723b4 | 1070 | static inline void acpi_pci_refresh_power_state(struct pci_dev *dev) { } |
d97c5d4c RW |
1071 | static inline int acpi_pci_wakeup(struct pci_dev *dev, bool enable) |
1072 | { | |
1073 | return -ENODEV; | |
1074 | } | |
1075 | static inline bool acpi_pci_need_resume(struct pci_dev *dev) | |
1076 | { | |
1077 | return false; | |
1078 | } | |
1079 | static inline pci_power_t acpi_pci_choose_state(struct pci_dev *pdev) | |
1080 | { | |
1081 | return PCI_POWER_ERROR; | |
1082 | } | |
8c3aac6e KW |
1083 | #endif |
1084 | ||
72ea91af HK |
1085 | #ifdef CONFIG_PCIEASPM |
1086 | extern const struct attribute_group aspm_ctrl_attr_group; | |
1087 | #endif | |
1088 | ||
d5b0d883 RW |
1089 | #ifdef CONFIG_X86_INTEL_MID |
1090 | bool pci_use_mid_pm(void); | |
1091 | int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state); | |
1092 | pci_power_t mid_pci_get_power_state(struct pci_dev *pdev); | |
1093 | #else | |
1094 | static inline bool pci_use_mid_pm(void) | |
1095 | { | |
1096 | return false; | |
1097 | } | |
1098 | static inline int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state) | |
1099 | { | |
1100 | return -ENODEV; | |
1101 | } | |
1102 | static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) | |
1103 | { | |
1104 | return PCI_UNKNOWN; | |
1105 | } | |
1106 | #endif | |
1107 | ||
d5124a99 TG |
1108 | #ifdef CONFIG_PCI_MSI |
1109 | int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int index, u16 tag); | |
1110 | #else | |
1111 | static inline int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int index, u16 tag) | |
1112 | { | |
1113 | return -ENODEV; | |
1114 | } | |
1115 | #endif | |
1116 | ||
8a9b7ef7 PR |
1117 | /* |
1118 | * Config Address for PCI Configuration Mechanism #1 | |
1119 | * | |
1120 | * See PCI Local Bus Specification, Revision 3.0, | |
1121 | * Section 3.2.2.3.2, Figure 3-2, p. 50. | |
1122 | */ | |
1123 | ||
1124 | #define PCI_CONF1_BUS_SHIFT 16 /* Bus number */ | |
1125 | #define PCI_CONF1_DEV_SHIFT 11 /* Device number */ | |
1126 | #define PCI_CONF1_FUNC_SHIFT 8 /* Function number */ | |
1127 | ||
1128 | #define PCI_CONF1_BUS_MASK 0xff | |
1129 | #define PCI_CONF1_DEV_MASK 0x1f | |
1130 | #define PCI_CONF1_FUNC_MASK 0x7 | |
1131 | #define PCI_CONF1_REG_MASK 0xfc /* Limit aligned offset to a maximum of 256B */ | |
1132 | ||
1133 | #define PCI_CONF1_ENABLE BIT(31) | |
1134 | #define PCI_CONF1_BUS(x) (((x) & PCI_CONF1_BUS_MASK) << PCI_CONF1_BUS_SHIFT) | |
1135 | #define PCI_CONF1_DEV(x) (((x) & PCI_CONF1_DEV_MASK) << PCI_CONF1_DEV_SHIFT) | |
1136 | #define PCI_CONF1_FUNC(x) (((x) & PCI_CONF1_FUNC_MASK) << PCI_CONF1_FUNC_SHIFT) | |
1137 | #define PCI_CONF1_REG(x) ((x) & PCI_CONF1_REG_MASK) | |
1138 | ||
1139 | #define PCI_CONF1_ADDRESS(bus, dev, func, reg) \ | |
1140 | (PCI_CONF1_ENABLE | \ | |
1141 | PCI_CONF1_BUS(bus) | \ | |
1142 | PCI_CONF1_DEV(dev) | \ | |
1143 | PCI_CONF1_FUNC(func) | \ | |
1144 | PCI_CONF1_REG(reg)) | |
1145 | ||
1146 | /* | |
1147 | * Extension of PCI Config Address for accessing extended PCIe registers | |
1148 | * | |
1149 | * No standardized specification, but used on lot of non-ECAM-compliant ARM SoCs | |
1150 | * or on AMD Barcelona and new CPUs. Reserved bits [27:24] of PCI Config Address | |
1151 | * are used for specifying additional 4 high bits of PCI Express register. | |
1152 | */ | |
1153 | ||
1154 | #define PCI_CONF1_EXT_REG_SHIFT 16 | |
1155 | #define PCI_CONF1_EXT_REG_MASK 0xf00 | |
1156 | #define PCI_CONF1_EXT_REG(x) (((x) & PCI_CONF1_EXT_REG_MASK) << PCI_CONF1_EXT_REG_SHIFT) | |
1157 | ||
1158 | #define PCI_CONF1_EXT_ADDRESS(bus, dev, func, reg) \ | |
1159 | (PCI_CONF1_ADDRESS(bus, dev, func, reg) | \ | |
1160 | PCI_CONF1_EXT_REG(reg)) | |
1161 | ||
557848c3 | 1162 | #endif /* DRIVERS_PCI_H */ |