igb_uio: fix build on RHEL 6.3
[dpdk.git] / lib / librte_eal / linuxapp / igb_uio / compat.h
1 /*
2  * Minimal wrappers to allow compiling igb_uio on older kernels.
3  */
4
5 #ifndef RHEL_RELEASE_VERSION
6 #define RHEL_RELEASE_VERSION(a, b) (((a) << 8) + (b))
7 #endif
8
9 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
10 #define pci_cfg_access_lock   pci_block_user_cfg_access
11 #define pci_cfg_access_unlock pci_unblock_user_cfg_access
12 #endif
13
14 #ifndef PCI_MSIX_ENTRY_SIZE
15 #define PCI_MSIX_ENTRY_SIZE             16
16 #define  PCI_MSIX_ENTRY_LOWER_ADDR      0
17 #define  PCI_MSIX_ENTRY_UPPER_ADDR      4
18 #define  PCI_MSIX_ENTRY_DATA            8
19 #define  PCI_MSIX_ENTRY_VECTOR_CTRL     12
20 #define   PCI_MSIX_ENTRY_CTRL_MASKBIT   1
21 #endif
22
23 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) && \
24         !defined(CONFIG_PCI_IOV)
25
26 static int pci_num_vf(struct pci_dev *dev)
27 {
28         struct iov {
29                 int pos;
30                 int nres;
31                 u32 cap;
32                 u16 ctrl;
33                 u16 total;
34                 u16 initial;
35                 u16 nr_virtfn;
36         } *iov = (struct iov *)dev->sriov;
37
38         if (!dev->is_physfn)
39                 return 0;
40
41         return iov->nr_virtfn;
42 }
43
44 #endif /* < 2.6.34 */
45
46 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) && \
47         (!(defined(RHEL_RELEASE_CODE) && \
48            RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6, 3)))
49
50 /* Check if INTX works to control irq's.
51  * Set's INTX_DISABLE flag and reads it back
52  */
53 static bool pci_intx_mask_supported(struct pci_dev *pdev)
54 {
55         bool mask_supported = false;
56         uint16_t orig, new;
57
58         pci_block_user_cfg_access(pdev);
59         pci_read_config_word(pdev, PCI_COMMAND, &orig);
60         pci_write_config_word(pdev, PCI_COMMAND,
61                               orig ^ PCI_COMMAND_INTX_DISABLE);
62         pci_read_config_word(pdev, PCI_COMMAND, &new);
63
64         if ((new ^ orig) & ~PCI_COMMAND_INTX_DISABLE) {
65                 dev_err(&pdev->dev, "Command register changed from "
66                         "0x%x to 0x%x: driver or hardware bug?\n", orig, new);
67         } else if ((new ^ orig) & PCI_COMMAND_INTX_DISABLE) {
68                 mask_supported = true;
69                 pci_write_config_word(pdev, PCI_COMMAND, orig);
70         }
71         pci_unblock_user_cfg_access(pdev);
72
73         return mask_supported;
74 }
75
76 static bool pci_check_and_mask_intx(struct pci_dev *pdev)
77 {
78         bool pending;
79         uint32_t status;
80
81         pci_block_user_cfg_access(pdev);
82         pci_read_config_dword(pdev, PCI_COMMAND, &status);
83
84         /* interrupt is not ours, goes to out */
85         pending = (((status >> 16) & PCI_STATUS_INTERRUPT) != 0);
86         if (pending) {
87                 uint16_t old, new;
88
89                 old = status;
90                 if (status != 0)
91                         new = old & (~PCI_COMMAND_INTX_DISABLE);
92                 else
93                         new = old | PCI_COMMAND_INTX_DISABLE;
94
95                 if (old != new)
96                         pci_write_config_word(pdev, PCI_COMMAND, new);
97         }
98         pci_unblock_user_cfg_access(pdev);
99
100         return pending;
101 }
102
103 #endif /* < 3.3.0 */