Skip to content

Commit 6ee195b

Browse files
Replace pci_enable_msix() with pci_alloc_irq_vectors()
Since kernel version 4.8. pci_enable_msix() isn't available any more. Therefore it is replaced with pci_alloc_irq_vectors() if used kernel version is >= 4.8 Signed-off-by: Andreas Rollbühler <andreas.rollbuehler@siemens.com>
1 parent f6545f3 commit 6ee195b

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

kernel_module/uio/uio_ivshmem.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* (C) 2009 Cam Macdonell
55
* (C) 2014 Henning Schild
6+
* (C) 2017 Andreas Rollbühler
67
* based on Hilscher CIF card driver (C) 2007 Hans J. Koch <hjk@linutronix.de>
78
*
89
* Licensed under GPL version 2 only.
@@ -15,6 +16,8 @@
1516
#include <linux/uio_driver.h>
1617
#include <linux/io.h>
1718

19+
#include <linux/version.h>
20+
1821
#define IntrStatus 0x04
1922
#define IntrMask 0x00
2023

@@ -59,7 +62,12 @@ static void free_msix_vectors(struct ivshmem_info *ivs_info,
5962
int i;
6063

6164
for (i = 0; i < max_vector; i++)
65+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
6266
free_irq(ivs_info->msix_entries[i].vector, ivs_info->uio);
67+
#else
68+
free_irq(pci_irq_vector(ivs_info->dev, ivs_info->msix_entries[i].entry),
69+
ivs_info->uio);
70+
#endif
6371
}
6472

6573
static int request_msix_vectors(struct ivshmem_info *ivs_info, int nvectors)
@@ -85,6 +93,8 @@ static int request_msix_vectors(struct ivshmem_info *ivs_info, int nvectors)
8593
for (i = 0; i < nvectors; ++i)
8694
ivs_info->msix_entries[i].entry = i;
8795

96+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
97+
8898
err = pci_enable_msix(ivs_info->dev, ivs_info->msix_entries,
8999
ivs_info->nvectors);
90100
if (err > 0) {
@@ -101,12 +111,27 @@ static int request_msix_vectors(struct ivshmem_info *ivs_info, int nvectors)
101111

102112
if (err)
103113
goto error;
114+
#else
115+
err = pci_alloc_irq_vectors(ivs_info->dev, 1, ivs_info->nvectors,
116+
PCI_IRQ_MSIX);
117+
118+
if (err <= 0) {
119+
dev_info(&ivs_info->dev->dev,
120+
"no MSI (%d). Back to INTx.\n", err);
121+
goto error;
122+
} else {
123+
ivs_info->nvectors = err;
124+
}
125+
#endif
126+
104127

105128
for (i = 0; i < ivs_info->nvectors; i++) {
106129

107130
snprintf(ivs_info->msix_names[i], sizeof(*ivs_info->msix_names),
108131
"%s-config", name);
109132

133+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
134+
110135
err = request_irq(ivs_info->msix_entries[i].vector,
111136
ivshmem_msix_handler, 0,
112137
ivs_info->msix_names[i], ivs_info->uio);
@@ -115,14 +140,26 @@ static int request_msix_vectors(struct ivshmem_info *ivs_info, int nvectors)
115140
free_msix_vectors(ivs_info, i - 1);
116141
goto error;
117142
}
143+
#else
144+
err = request_irq(pci_irq_vector(ivs_info->dev,
145+
ivs_info->msix_entries[i].entry), ivshmem_msix_handler, 0,
146+
ivs_info->msix_names[i], ivs_info->uio);
118147

148+
if (err < 0) {
149+
free_msix_vectors(ivs_info, i - 1);
150+
goto error;
151+
}
152+
#endif
119153
}
120154

121155
return 0;
122156
error:
123157
kfree(ivs_info->msix_entries);
124158
kfree(ivs_info->msix_names);
125159
ivs_info->nvectors = 0;
160+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)
161+
pci_free_irq_vectors(ivs_info->dev);
162+
#endif
126163
return err;
127164

128165
}

0 commit comments

Comments
 (0)