From: Hauke Mehrtens Date: Fri, 17 Dec 2010 22:41:38 +0000 (-0800) Subject: compat: backport pci_is_pcie and pci_pcie_cap X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=64bcd1b74a292b6baadb5a9f7c63eac8bf45ea5d;p=openwrt%2Fstaging%2Fblogic.git compat: backport pci_is_pcie and pci_pcie_cap compat_is_pcie already did the same thing as pci_is_pcie, but this method is now in kernel so the mainline drivers should use this function instead of accessing the member in the struct directly. We backported this function for older kernels. pci_pcie_cap is used in rtlwifi so we also need this. Signed-off-by: Hauke Mehrtens --- diff --git a/compat/compat-2.6.24.c b/compat/compat-2.6.24.c index a5c9c972cdcc..5e2a77d2a777 100644 --- a/compat/compat-2.6.24.c +++ b/compat/compat-2.6.24.c @@ -165,15 +165,3 @@ int eth_rebuild_header(struct sk_buff *skb) } EXPORT_SYMBOL(eth_rebuild_header); -/* 2.6.24 will introduce struct pci_dev is_pcie bit. To help - * with the compatibility code (compat.diff) being smaller, we provide a helper - * so in cases where that will be used we can simply slap ifdefs with this - * routine. Use compat_ prefex to not pollute namespace. */ -int compat_is_pcie(struct pci_dev *pdev) -{ - int cap; - cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); - return cap ? 1 : 0; -} -EXPORT_SYMBOL(compat_is_pcie); - diff --git a/include/linux/compat-2.6.24.h b/include/linux/compat-2.6.24.h index f9c777cace1e..6e09530d00e3 100644 --- a/include/linux/compat-2.6.24.h +++ b/include/linux/compat-2.6.24.h @@ -249,9 +249,6 @@ static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd) return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; } -/* Helper to make struct pci_dev is_pcie compatibility code smaller */ -int compat_is_pcie(struct pci_dev *pdev); - #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) */ #endif /* LINUX_26_24_COMPAT_H */ diff --git a/include/linux/compat-2.6.33.h b/include/linux/compat-2.6.33.h index c2dbc1bae392..2ccf141d090f 100644 --- a/include/linux/compat-2.6.33.h +++ b/include/linux/compat-2.6.33.h @@ -6,6 +6,7 @@ #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)) #include +#include #if defined(CONFIG_PCCARD) || defined(CONFIG_PCCARD_MODULE) #include #include @@ -147,6 +148,37 @@ static inline void compat_kfifo_free(struct kfifo **fifo) { #define sock_recv_ts_and_drops(msg, sk, skb) sock_recv_timestamp(msg, sk, skb) +/** + * pci_pcie_cap - get the saved PCIe capability offset + * @dev: PCI device + * + * PCIe capability offset is calculated at PCI device initialization + * time and saved in the data structure. This function returns saved + * PCIe capability offset. Using this instead of pci_find_capability() + * reduces unnecessary search in the PCI configuration space. If you + * need to calculate PCIe capability offset from raw device for some + * reasons, please use pci_find_capability() instead. + */ +static inline int pci_pcie_cap(struct pci_dev *dev) +{ + return pci_find_capability(dev, PCI_CAP_ID_EXP); +} + +/** + * pci_is_pcie - check if the PCI device is PCI Express capable + * @dev: PCI device + * + * Retrun true if the PCI device is PCI Express capable, false otherwise. + */ +static inline bool pci_is_pcie(struct pci_dev *dev) +{ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)) + return dev->is_pcie; +#else + return !!pci_pcie_cap(dev); +#endif +} + #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)) */ #endif /* LINUX_26_33_COMPAT_H */