Skip to content

Commit 36a4a50

Browse files
Christoph Hellwigdavem330
authored andcommitted
net: ethernet: aquantia: switch to pci_alloc_irq_vectors
pci_enable_msix has been long deprecated, but this driver adds a new instance. Convert it to pci_alloc_irq_vectors so that no new instance of the deprecated function reaches mainline. Signed-off-by: Christoph Hellwig <hch@lst.de> Tested-by: Pavel Belous <pavel.belous@aquantia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dfb011d commit 36a4a50

File tree

1 file changed

+25
-76
lines changed

1 file changed

+25
-76
lines changed

drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c

Lines changed: 25 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ struct aq_pci_func_s {
2222
void *aq_vec[AQ_CFG_PCI_FUNC_MSIX_IRQS];
2323
resource_size_t mmio_pa;
2424
unsigned int msix_entry_mask;
25-
unsigned int irq_type;
2625
unsigned int ports;
2726
bool is_pci_enabled;
2827
bool is_regions;
2928
bool is_pci_using_dac;
3029
struct aq_hw_caps_s aq_hw_caps;
31-
struct msix_entry msix_entry[AQ_CFG_PCI_FUNC_MSIX_IRQS];
3230
};
3331

3432
struct aq_pci_func_s *aq_pci_func_alloc(struct aq_hw_ops *aq_hw_ops,
@@ -87,7 +85,6 @@ int aq_pci_func_init(struct aq_pci_func_s *self)
8785
int err = 0;
8886
unsigned int bar = 0U;
8987
unsigned int port = 0U;
90-
unsigned int i = 0U;
9188

9289
err = pci_enable_device(self->pdev);
9390
if (err < 0)
@@ -145,27 +142,16 @@ int aq_pci_func_init(struct aq_pci_func_s *self)
145142
}
146143
}
147144

148-
for (i = 0; i < self->aq_hw_caps.msix_irqs; i++)
149-
self->msix_entry[i].entry = i;
150-
151145
/*enable interrupts */
152-
#if AQ_CFG_FORCE_LEGACY_INT
153-
self->irq_type = AQ_HW_IRQ_LEGACY;
154-
#else
155-
err = pci_enable_msix(self->pdev, self->msix_entry,
156-
self->aq_hw_caps.msix_irqs);
146+
#if !AQ_CFG_FORCE_LEGACY_INT
147+
err = pci_alloc_irq_vectors(self->pdev, self->aq_hw_caps.msix_irqs,
148+
self->aq_hw_caps.msix_irqs, PCI_IRQ_MSIX);
157149

158-
if (err >= 0) {
159-
self->irq_type = AQ_HW_IRQ_MSIX;
160-
} else {
161-
err = pci_enable_msi(self->pdev);
162-
163-
if (err >= 0) {
164-
self->irq_type = AQ_HW_IRQ_MSI;
165-
} else {
166-
self->irq_type = AQ_HW_IRQ_LEGACY;
167-
err = 0;
168-
}
150+
if (err < 0) {
151+
err = pci_alloc_irq_vectors(self->pdev, 1, 1,
152+
PCI_IRQ_MSI | PCI_IRQ_LEGACY);
153+
if (err < 0)
154+
goto err_exit;
169155
}
170156
#endif
171157

@@ -196,34 +182,22 @@ int aq_pci_func_init(struct aq_pci_func_s *self)
196182
int aq_pci_func_alloc_irq(struct aq_pci_func_s *self, unsigned int i,
197183
char *name, void *aq_vec, cpumask_t *affinity_mask)
198184
{
185+
struct pci_dev *pdev = self->pdev;
199186
int err = 0;
200187

201-
switch (self->irq_type) {
202-
case AQ_HW_IRQ_MSIX:
203-
err = request_irq(self->msix_entry[i].vector, aq_vec_isr, 0,
188+
if (pdev->msix_enabled || pdev->msi_enabled)
189+
err = request_irq(pci_irq_vector(pdev, i), aq_vec_isr, 0,
204190
name, aq_vec);
205-
break;
206-
207-
case AQ_HW_IRQ_MSI:
208-
err = request_irq(self->pdev->irq, aq_vec_isr, 0, name, aq_vec);
209-
break;
210-
211-
case AQ_HW_IRQ_LEGACY:
212-
err = request_irq(self->pdev->irq, aq_vec_isr_legacy,
191+
else
192+
err = request_irq(pci_irq_vector(pdev, i), aq_vec_isr_legacy,
213193
IRQF_SHARED, name, aq_vec);
214-
break;
215-
216-
default:
217-
err = -EFAULT;
218-
break;
219-
}
220194

221195
if (err >= 0) {
222196
self->msix_entry_mask |= (1 << i);
223197
self->aq_vec[i] = aq_vec;
224198

225-
if (self->irq_type == AQ_HW_IRQ_MSIX)
226-
irq_set_affinity_hint(self->msix_entry[i].vector,
199+
if (pdev->msix_enabled)
200+
irq_set_affinity_hint(pci_irq_vector(pdev, i),
227201
affinity_mask);
228202
}
229203

@@ -232,30 +206,16 @@ int aq_pci_func_alloc_irq(struct aq_pci_func_s *self, unsigned int i,
232206

233207
void aq_pci_func_free_irqs(struct aq_pci_func_s *self)
234208
{
209+
struct pci_dev *pdev = self->pdev;
235210
unsigned int i = 0U;
236211

237212
for (i = 32U; i--;) {
238213
if (!((1U << i) & self->msix_entry_mask))
239214
continue;
240215

241-
switch (self->irq_type) {
242-
case AQ_HW_IRQ_MSIX:
243-
irq_set_affinity_hint(self->msix_entry[i].vector, NULL);
244-
free_irq(self->msix_entry[i].vector, self->aq_vec[i]);
245-
break;
246-
247-
case AQ_HW_IRQ_MSI:
248-
free_irq(self->pdev->irq, self->aq_vec[i]);
249-
break;
250-
251-
case AQ_HW_IRQ_LEGACY:
252-
free_irq(self->pdev->irq, self->aq_vec[i]);
253-
break;
254-
255-
default:
256-
break;
257-
}
258-
216+
free_irq(pci_irq_vector(pdev, i), self->aq_vec[i]);
217+
if (pdev->msix_enabled)
218+
irq_set_affinity_hint(pci_irq_vector(pdev, i), NULL);
259219
self->msix_entry_mask &= ~(1U << i);
260220
}
261221
}
@@ -267,7 +227,11 @@ void __iomem *aq_pci_func_get_mmio(struct aq_pci_func_s *self)
267227

268228
unsigned int aq_pci_func_get_irq_type(struct aq_pci_func_s *self)
269229
{
270-
return self->irq_type;
230+
if (self->pdev->msix_enabled)
231+
return AQ_HW_IRQ_MSIX;
232+
if (self->pdev->msi_enabled)
233+
return AQ_HW_IRQ_MSIX;
234+
return AQ_HW_IRQ_LEGACY;
271235
}
272236

273237
void aq_pci_func_deinit(struct aq_pci_func_s *self)
@@ -276,22 +240,7 @@ void aq_pci_func_deinit(struct aq_pci_func_s *self)
276240
goto err_exit;
277241

278242
aq_pci_func_free_irqs(self);
279-
280-
switch (self->irq_type) {
281-
case AQ_HW_IRQ_MSI:
282-
pci_disable_msi(self->pdev);
283-
break;
284-
285-
case AQ_HW_IRQ_MSIX:
286-
pci_disable_msix(self->pdev);
287-
break;
288-
289-
case AQ_HW_IRQ_LEGACY:
290-
break;
291-
292-
default:
293-
break;
294-
}
243+
pci_free_irq_vectors(self->pdev);
295244

296245
if (self->is_regions)
297246
pci_release_regions(self->pdev);

0 commit comments

Comments
 (0)