From 3923fc5f4a489ab2b9e2f4ffe34c0c6ccabdb9e6 Mon Sep 17 00:00:00 2001 From: Vladimir Sokolovsky Date: Wed, 5 Nov 2014 14:50:03 +0200 Subject: [PATCH] Added pcie_get_mps/pcie_set_mps Signed-off-by: Vladimir Sokolovsky --- compat/Makefile | 1 + compat/compat-3.13.c | 42 +++++++++++++++++++++++++++++++++++++ include/linux/compat-3.13.h | 6 ++++++ 3 files changed, 49 insertions(+) create mode 100644 compat/compat-3.13.c diff --git a/compat/Makefile b/compat/Makefile index f025580..b58baac 100644 --- a/compat/Makefile +++ b/compat/Makefile @@ -52,6 +52,7 @@ compat-$(CONFIG_COMPAT_KERNEL_3_7) += compat-3.7.o compat-$(CONFIG_COMPAT_KERNEL_3_9) += compat-3.9.o compat-$(CONFIG_COMPAT_KERNEL_3_11) += compat-3.11.o compat-$(CONFIG_COMPAT_KERNEL_3_12) += compat-3.12.o +compat-$(CONFIG_COMPAT_KERNEL_3_13) += compat-3.13.o compat-$(CONFIG_COMPAT_KERNEL_3_16) += compat-3.16.o compat-$(CONFIG_COMPAT_KERNEL_3_18) += compat-3.18.o diff --git a/compat/compat-3.13.c b/compat/compat-3.13.c new file mode 100644 index 0000000..c65634c --- /dev/null +++ b/compat/compat-3.13.c @@ -0,0 +1,42 @@ +#include + +/** + * pcie_get_mps - get PCI Express maximum payload size + * @dev: PCI device to query + * + * Returns maximum payload size in bytes + */ +int pcie_get_mps(struct pci_dev *dev) +{ + u16 ctl; + + pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl); + + return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); +} +EXPORT_SYMBOL(pcie_get_mps); + +/** + * pcie_set_mps - set PCI Express maximum payload size + * @dev: PCI device to query + * @mps: maximum payload size in bytes + * valid values are 128, 256, 512, 1024, 2048, 4096 + * + * If possible sets maximum payload size + */ +int pcie_set_mps(struct pci_dev *dev, int mps) +{ + u16 v; + + if (mps < 128 || mps > 4096 || !is_power_of_2(mps)) + return -EINVAL; + + v = ffs(mps) - 8; + if (v > dev->pcie_mpss) + return -EINVAL; + v <<= 5; + + return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL, + PCI_EXP_DEVCTL_PAYLOAD, v); +} +EXPORT_SYMBOL(pcie_set_mps); diff --git a/include/linux/compat-3.13.h b/include/linux/compat-3.13.h index 619b8f9..9d40500 100644 --- a/include/linux/compat-3.13.h +++ b/include/linux/compat-3.13.h @@ -16,6 +16,12 @@ static inline void reinit_completion(struct completion *x) #endif +#define pcie_get_mps LINUX_BACKPORT(pcie_get_mps) +int pcie_get_mps(struct pci_dev *dev); + +#define pcie_set_mps LINUX_BACKPORT(pcie_set_mps) +int pcie_set_mps(struct pci_dev *dev, int mps); + #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)) */ #endif /* LINUX_3_13_COMPAT_H */ -- 2.41.0