ce37c289e70dcda828c3b11ce3b86d2e3264c4cb
[openwrt/staging/pepe2k.git] /
1 From 8b5d421b2bfa6800d182f74a60afa48cf305fb86 Mon Sep 17 00:00:00 2001
2 From: Jan Kiszka <jan.kiszka@siemens.com>
3 Date: Tue, 23 May 2017 17:41:00 +0200
4 Subject: [PATCH] ivshmem-net: Switch to pci_alloc_irq_vectors
5
6 Required by 4.12, and it also simplifies our code. Needs to be folded
7 into the initial patch eventually.
8
9 Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
10 (cherry picked from commit ea6e78c89582711f15a2711f0a35ac3a61d9d074)
11 ---
12 drivers/net/ivshmem-net.c | 66 ++++++++++++++++++++---------------------------
13 1 file changed, 28 insertions(+), 38 deletions(-)
14
15 --- a/drivers/net/ivshmem-net.c
16 +++ b/drivers/net/ivshmem-net.c
17 @@ -114,8 +114,6 @@ struct ivshm_net {
18 u32 peer_id;
19
20 struct pci_dev *pdev;
21 - struct msix_entry msix;
22 - bool using_msix;
23 };
24
25 static void *ivshm_net_desc_data(struct ivshm_net *in,
26 @@ -793,22 +791,21 @@ static int ivshm_net_probe(struct pci_de
27 struct ivshmem_regs __iomem *regs;
28 resource_size_t shmaddr;
29 resource_size_t shmlen;
30 - int interrupt;
31 char *device_name;
32 void *shm;
33 u32 ivpos;
34 - int err;
35 + int ret;
36
37 - err = pcim_enable_device(pdev);
38 - if (err) {
39 - dev_err(&pdev->dev, "pci_enable_device: %d\n", err);
40 - return err;
41 + ret = pcim_enable_device(pdev);
42 + if (ret) {
43 + dev_err(&pdev->dev, "pci_enable_device: %d\n", ret);
44 + return ret;
45 }
46
47 - err = pcim_iomap_regions(pdev, BIT(0), DRV_NAME);
48 - if (err) {
49 - dev_err(&pdev->dev, "pcim_iomap_regions: %d\n", err);
50 - return err;
51 + ret = pcim_iomap_regions(pdev, BIT(0), DRV_NAME);
52 + if (ret) {
53 + dev_err(&pdev->dev, "pcim_iomap_regions: %d\n", ret);
54 + return ret;
55 }
56
57 regs = pcim_iomap_table(pdev)[0];
58 @@ -869,8 +866,8 @@ static int ivshm_net_probe(struct pci_de
59 spin_lock_init(&in->tx_free_lock);
60 spin_lock_init(&in->tx_clean_lock);
61
62 - err = ivshm_net_calc_qsize(ndev);
63 - if (err)
64 + ret = ivshm_net_calc_qsize(ndev);
65 + if (ret)
66 goto err_free;
67
68 in->state_wq = alloc_ordered_workqueue(device_name, 0);
69 @@ -889,25 +886,21 @@ static int ivshm_net_probe(struct pci_de
70 netif_carrier_off(ndev);
71 netif_napi_add(ndev, &in->napi, ivshm_net_poll, NAPI_POLL_WEIGHT);
72
73 - err = register_netdev(ndev);
74 - if (err)
75 + ret = register_netdev(ndev);
76 + if (ret)
77 goto err_wq;
78
79 - err = pci_enable_msix(pdev, &in->msix, 1);
80 - if (!err) {
81 - interrupt = in->msix.vector;
82 - in->using_msix = true;
83 - } else {
84 - interrupt = pdev->irq;
85 - in->using_msix = false;
86 - }
87 -
88 - err = request_irq(interrupt, ivshm_net_int, 0, device_name, ndev);
89 - if (err)
90 - goto err_int;
91 + ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_LEGACY | PCI_IRQ_MSIX);
92 + if (ret < 0)
93 + goto err_alloc_irq;
94 +
95 + ret = request_irq(pci_irq_vector(pdev, 0), ivshm_net_int, 0,
96 + device_name, ndev);
97 + if (ret)
98 + goto err_request_irq;
99
100 pci_set_master(pdev);
101 - if (!in->using_msix)
102 + if (!pdev->msix_enabled)
103 writel(IVSHMEM_INTX_ENABLE, &in->ivshm_regs->intxctrl);
104
105 writel(IVSHM_NET_STATE_RESET, &in->ivshm_regs->lstate);
106 @@ -915,16 +908,16 @@ static int ivshm_net_probe(struct pci_de
107
108 return 0;
109
110 -err_int:
111 - if (in->using_msix)
112 - pci_disable_msix(pdev);
113 +err_request_irq:
114 + pci_free_irq_vectors(pdev);
115 +err_alloc_irq:
116 unregister_netdev(ndev);
117 err_wq:
118 destroy_workqueue(in->state_wq);
119 err_free:
120 free_netdev(ndev);
121
122 - return err;
123 + return ret;
124 }
125
126 static void ivshm_net_remove(struct pci_dev *pdev)
127 @@ -934,13 +927,10 @@ static void ivshm_net_remove(struct pci_
128
129 writel(IVSHM_NET_STATE_RESET, &in->ivshm_regs->lstate);
130
131 - if (in->using_msix) {
132 - free_irq(in->msix.vector, ndev);
133 - pci_disable_msix(pdev);
134 - } else {
135 + if (!pdev->msix_enabled)
136 writel(0, &in->ivshm_regs->intxctrl);
137 - free_irq(pdev->irq, ndev);
138 - }
139 + free_irq(pci_irq_vector(pdev, 0), ndev);
140 + pci_free_irq_vectors(pdev);
141
142 unregister_netdev(ndev);
143 cancel_work_sync(&in->state_work);