From 1cb341665379c3784605ac5c0297ce332da16161 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 16 Dec 2004 22:01:35 -0800 Subject: [PATCH] PCI: Cleanup PCI power states > > > > This is step 0 before adding type-safety to PCI layer... It introduces > > > > constants and uses them to clean driver up. I'd like this to go in > > > > now, so that I can convert drivers during 2.6.10... Please apply, Okay, here it is, slightly expanded version. It actually makes use of newly defined type for type-checking purposes; still no code changes. From: Pavel Machek Signed-off-by: Greg Kroah-Hartman --- include/linux/pci.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'include/linux') diff --git a/include/linux/pci.h b/include/linux/pci.h index 6e0973f334b1..f45a3d6a82c6 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -480,6 +480,14 @@ enum pci_mmap_state { #define DEVICE_COUNT_COMPATIBLE 4 #define DEVICE_COUNT_RESOURCE 12 +typedef int __bitwise pci_power_t; + +#define PCI_D0 ((pci_power_t __force) 0) +#define PCI_D1 ((pci_power_t __force) 1) +#define PCI_D2 ((pci_power_t __force) 2) +#define PCI_D3hot ((pci_power_t __force) 3) +#define PCI_D3cold ((pci_power_t __force) 4) + /* * The pci_dev structure is used to describe PCI devices. */ @@ -508,7 +516,7 @@ struct pci_dev { this if your device has broken DMA or supports 64-bit transfers. */ - u32 current_state; /* Current operating state. In ACPI-speak, + pci_power_t current_state; /* Current operating state. In ACPI-speak, this is D0-D3, D0 being fully functional, and D3 being off. */ @@ -797,8 +805,8 @@ void pci_remove_rom(struct pci_dev *pdev); /* Power management related routines */ int pci_save_state(struct pci_dev *dev); int pci_restore_state(struct pci_dev *dev); -int pci_set_power_state(struct pci_dev *dev, int state); -int pci_enable_wake(struct pci_dev *dev, u32 state, int enable); +int pci_set_power_state(struct pci_dev *dev, pci_power_t state); +int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable); /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */ void pci_bus_assign_resources(struct pci_bus *bus); -- cgit v1.2.3 From 9c57f57c50cdd8acff4005cb88d8b57adeb350d7 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 16 Dec 2004 22:02:40 -0800 Subject: [PATCH] PCI: fix up function calls for CONFIG_PCI=N Signed-off-by: Greg Kroah-Hartman --- include/linux/pci.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/linux') diff --git a/include/linux/pci.h b/include/linux/pci.h index f45a3d6a82c6..fe2b98de55ca 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -933,8 +933,8 @@ static inline const struct pci_device_id *pci_match_device(const struct pci_devi /* Power management related routines */ static inline int pci_save_state(struct pci_dev *dev) { return 0; } static inline int pci_restore_state(struct pci_dev *dev) { return 0; } -static inline int pci_set_power_state(struct pci_dev *dev, int state) { return 0; } -static inline int pci_enable_wake(struct pci_dev *dev, u32 state, int enable) { return 0; } +static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state) { return 0; } +static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) { return 0; } #define isa_bridge ((struct pci_dev *)NULL) -- cgit v1.2.3 From 1133b2d25f4e06fdec0dff18b942a311009a465f Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 20 Dec 2004 19:57:56 -0800 Subject: [PATCH] PCI: add prototype for pci_choose_state() This adds missing prototype for pci_choose_state. Signed-off-by: Pavel Machek Signed-off-by: Greg Kroah-Hartman --- include/linux/pci.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/linux') diff --git a/include/linux/pci.h b/include/linux/pci.h index fe2b98de55ca..32325b10d419 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -806,6 +806,7 @@ void pci_remove_rom(struct pci_dev *pdev); int pci_save_state(struct pci_dev *dev); int pci_restore_state(struct pci_dev *dev); int pci_set_power_state(struct pci_dev *dev, pci_power_t state); +pci_power_t pci_choose_state(struct pci_dev *dev, u32 state); int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable); /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */ @@ -934,6 +935,7 @@ static inline const struct pci_device_id *pci_match_device(const struct pci_devi static inline int pci_save_state(struct pci_dev *dev) { return 0; } static inline int pci_restore_state(struct pci_dev *dev) { return 0; } static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state) { return 0; } +static inline pci_power_t pci_choose_state(struct pci_dev *dev, u32 state) { return PCI_D0; } static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) { return 0; } #define isa_bridge ((struct pci_dev *)NULL) -- cgit v1.2.3 From c842b00abac4261b59f4c80094b264e40cc4f236 Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Tue, 21 Dec 2004 18:11:27 -0800 Subject: [PATCH] PCI: Software visible configuration request retry status PCI Express allows cards to return "Configuration Request Retry" if they're not ready to handle accesses to configuration space. The PCI Express 1.0a specification says that the Root Complex should retry the access. ECN 27 http://www.pcisig.com/specifications/pciexpress/ECN_CRS_Software_Visibility_No27.pdf allows software to handle the CRS. Signed-off-by: Matthew Wilcox Signed-off-by: Greg Kroah-Hartman --- drivers/pci/probe.c | 42 +++++++++++++++++++++++++++++++++++++++--- include/linux/pci.h | 14 ++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) (limited to 'include/linux') diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index d13ff06d2f7f..6f69ce367279 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2,6 +2,7 @@ * probe.c - PCI detection and setup code */ +#include #include #include #include @@ -336,6 +337,22 @@ struct pci_bus * __devinit pci_add_new_bus(struct pci_bus *parent, struct pci_de return child; } +static void pci_enable_crs(struct pci_dev *dev) +{ + u16 cap, rpctl; + int rpcap = pci_find_capability(dev, PCI_CAP_ID_EXP); + if (!rpcap) + return; + + pci_read_config_word(dev, rpcap + PCI_CAP_FLAGS, &cap); + if (((cap & PCI_EXP_FLAGS_TYPE) >> 4) != PCI_EXP_TYPE_ROOT_PORT) + return; + + pci_read_config_word(dev, rpcap + PCI_EXP_RTCTL, &rpctl); + rpctl |= PCI_EXP_RTCTL_CRSSVE; + pci_write_config_word(dev, rpcap + PCI_EXP_RTCTL, rpctl); +} + unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus); /* @@ -366,6 +383,8 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max pci_write_config_word(dev, PCI_BRIDGE_CONTROL, bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT); + pci_enable_crs(dev); + if ((buses & 0xffff00) && !pcibios_assign_all_busses() && !is_cardbus) { unsigned int cmax, busnr; /* @@ -614,9 +633,7 @@ pci_scan_device(struct pci_bus *bus, int devfn) struct pci_dev *dev; u32 l; u8 hdr_type; - - if (pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type)) - return NULL; + int delay = 1; if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, &l)) return NULL; @@ -626,6 +643,25 @@ pci_scan_device(struct pci_bus *bus, int devfn) l == 0x0000ffff || l == 0xffff0000) return NULL; + /* Configuration request Retry Status */ + while (l == 0xffff0001) { + msleep(delay); + delay *= 2; + if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, &l)) + return NULL; + /* Card hasn't responded in 60 seconds? Must be stuck. */ + if (delay > 60 * 1000) { + printk(KERN_WARNING "Device %04x:%02x:%02x.%d not " + "responding\n", pci_domain_nr(bus), + bus->number, PCI_SLOT(devfn), + PCI_FUNC(devfn)); + return NULL; + } + } + + if (pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type)) + return NULL; + dev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL); if (!dev) return NULL; diff --git a/include/linux/pci.h b/include/linux/pci.h index 32325b10d419..ee5456e9a5dd 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -364,6 +364,20 @@ #define PCI_EXP_DEVSTA_URD 0x08 /* Unsupported Request Detected */ #define PCI_EXP_DEVSTA_AUXPD 0x10 /* AUX Power Detected */ #define PCI_EXP_DEVSTA_TRPND 0x20 /* Transactions Pending */ +#define PCI_EXP_LNKCAP 12 /* Link Capabilities */ +#define PCI_EXP_LNKCTL 16 /* Link Control */ +#define PCI_EXP_LNKSTA 18 /* Link Status */ +#define PCI_EXP_SLTCAP 20 /* Slot Capabilities */ +#define PCI_EXP_SLTCTL 24 /* Slot Control */ +#define PCI_EXP_SLTSTA 26 /* Slot Status */ +#define PCI_EXP_RTCTL 28 /* Root Control */ +#define PCI_EXP_RTCTL_SECEE 0x01 /* System Error on Correctable Error */ +#define PCI_EXP_RTCTL_SENFEE 0x02 /* System Error on Non-Fatal Error */ +#define PCI_EXP_RTCTL_SEFEE 0x04 /* System Error on Fatal Error */ +#define PCI_EXP_RTCTL_PMEIE 0x08 /* PME Interrupt Enable */ +#define PCI_EXP_RTCTL_CRSSVE 0x10 /* CRS Software Visibility Enable */ +#define PCI_EXP_RTCAP 30 /* Root Capabilities */ +#define PCI_EXP_RTSTA 32 /* Root Status */ /* Extended Capabilities (PCI-X 2.0 and Express) */ #define PCI_EXT_CAP_ID(header) (header & 0x0000ffff) -- cgit v1.2.3