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