1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Minimal wrappers to allow compiling igb_uio on older kernels.
6 #ifndef RHEL_RELEASE_VERSION
7 #define RHEL_RELEASE_VERSION(a, b) (((a) << 8) + (b))
10 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
11 #define pci_cfg_access_lock pci_block_user_cfg_access
12 #define pci_cfg_access_unlock pci_unblock_user_cfg_access
15 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
16 #define HAVE_PTE_MASK_PAGE_IOMAP
19 #ifndef PCI_MSIX_ENTRY_SIZE
20 #define PCI_MSIX_ENTRY_SIZE 16
21 #define PCI_MSIX_ENTRY_VECTOR_CTRL 12
22 #define PCI_MSIX_ENTRY_CTRL_MASKBIT 1
26 * for kernels < 2.6.38 and backported patch that moves MSI-X entry definition
27 * to pci_regs.h Those kernels has PCI_MSIX_ENTRY_SIZE defined but not
28 * PCI_MSIX_ENTRY_CTRL_MASKBIT
30 #ifndef PCI_MSIX_ENTRY_CTRL_MASKBIT
31 #define PCI_MSIX_ENTRY_CTRL_MASKBIT 1
34 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) && \
35 (!(defined(RHEL_RELEASE_CODE) && \
36 RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5, 9)))
38 static int pci_num_vf(struct pci_dev *dev)
48 } *iov = (struct iov *)dev->sriov;
53 return iov->nr_virtfn;
58 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) && \
59 (!(defined(RHEL_RELEASE_CODE) && \
60 RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6, 4)))
62 #define kstrtoul strict_strtoul
66 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) && \
67 (!(defined(RHEL_RELEASE_CODE) && \
68 RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6, 3)))
70 /* Check if INTX works to control irq's.
71 * Set's INTX_DISABLE flag and reads it back
73 static bool pci_intx_mask_supported(struct pci_dev *pdev)
75 bool mask_supported = false;
78 pci_block_user_cfg_access(pdev);
79 pci_read_config_word(pdev, PCI_COMMAND, &orig);
80 pci_write_config_word(pdev, PCI_COMMAND,
81 orig ^ PCI_COMMAND_INTX_DISABLE);
82 pci_read_config_word(pdev, PCI_COMMAND, &new);
84 if ((new ^ orig) & ~PCI_COMMAND_INTX_DISABLE) {
85 dev_err(&pdev->dev, "Command register changed from "
86 "0x%x to 0x%x: driver or hardware bug?\n", orig, new);
87 } else if ((new ^ orig) & PCI_COMMAND_INTX_DISABLE) {
88 mask_supported = true;
89 pci_write_config_word(pdev, PCI_COMMAND, orig);
91 pci_unblock_user_cfg_access(pdev);
93 return mask_supported;
96 static bool pci_check_and_mask_intx(struct pci_dev *pdev)
101 pci_block_user_cfg_access(pdev);
102 pci_read_config_dword(pdev, PCI_COMMAND, &status);
104 /* interrupt is not ours, goes to out */
105 pending = (((status >> 16) & PCI_STATUS_INTERRUPT) != 0);
111 new = old & (~PCI_COMMAND_INTX_DISABLE);
113 new = old | PCI_COMMAND_INTX_DISABLE;
116 pci_write_config_word(pdev, PCI_COMMAND, new);
118 pci_unblock_user_cfg_access(pdev);
125 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
126 #define HAVE_PCI_IS_BRIDGE_API 1
129 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
130 #define HAVE_MSI_LIST_IN_GENERIC_DEVICE 1
133 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
134 #define HAVE_PCI_MSI_MASK_IRQ 1
137 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
138 #define HAVE_ALLOC_IRQ_VECTORS 1
141 static inline bool igbuio_kernel_is_locked_down(void)
143 #ifdef CONFIG_LOCK_DOWN_KERNEL
144 #ifdef CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT
145 return kernel_is_locked_down(NULL);
146 #elif defined(CONFIG_EFI_SECURE_BOOT_LOCK_DOWN)
147 return kernel_is_locked_down();