Skip to content

Commit 565d065

Browse files
thenzlfloatious
authored andcommitted
ata: ahci: simplify init function
This patch moves all the IRQ vector allocations into a single function. Instead of having the allocations spread out over two separate call sites everything will be handled in ahci_init_irq. Also a direct call into pci(m)_intx will be removed. The main part of this change is done by adding a PCI_IRQ_INTX flag into an already existing pci_alloc_irq_vectors invocation. In the current implementation of the pci_alloc_irq_vectors is the sequence of calls msi-x -> msi -> legacy irq and whatever there succeeds stops the call chain. That makes it impossible to merge all instances into as a single call to pci_alloc_irq_vectors since the order of calls there is: multiple msi-x a single msi a single msi-x a legacy irq. The two last steps can be merged into a single one which are the msi-x and legacy irq option. When PCI_IRQ_INTX flag is set the pci_alloc_irq_vectors succeeds in almost all cases - that makes it possible to convert ahci_init_irq(msi) into a void function. The exception is when dev->irq is zero then the pci_alloc_irq_vectors may return with an error code also pci_intx isn't called from pci_alloc_irq_vectors and thus certain pci calls aren't performed. That's just a negligible issue as later in ahci_init_one the (zero) value of dev->irq is via pci_irq_vector assigned to hpriv->irq. That value is then later tested in ahci_host_activate->ata_host_activate where it is welcomed with a WARN_ON message and fails with setting up irq and then the probe function (ahci_init_one) fails. The special zero value's meaning is that polling mode is being be set up which isn't the case. No functional change. Signed-off-by: Tomas Henzl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Cassel <[email protected]>
1 parent 0507c77 commit 565d065

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

drivers/ata/ahci.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,13 +1676,15 @@ static int ahci_get_irq_vector(struct ata_host *host, int port)
16761676
return pci_irq_vector(to_pci_dev(host->dev), port);
16771677
}
16781678

1679-
static int ahci_init_msi(struct pci_dev *pdev, unsigned int n_ports,
1679+
static void ahci_init_irq(struct pci_dev *pdev, unsigned int n_ports,
16801680
struct ahci_host_priv *hpriv)
16811681
{
16821682
int nvec;
16831683

1684-
if (hpriv->flags & AHCI_HFLAG_NO_MSI)
1685-
return -ENODEV;
1684+
if (hpriv->flags & AHCI_HFLAG_NO_MSI) {
1685+
pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_INTX);
1686+
return;
1687+
}
16861688

16871689
/*
16881690
* If number of MSIs is less than number of ports then Sharing Last
@@ -1696,7 +1698,7 @@ static int ahci_init_msi(struct pci_dev *pdev, unsigned int n_ports,
16961698
if (!(readl(hpriv->mmio + HOST_CTL) & HOST_MRSM)) {
16971699
hpriv->get_irq_vector = ahci_get_irq_vector;
16981700
hpriv->flags |= AHCI_HFLAG_MULTI_MSI;
1699-
return nvec;
1701+
return;
17001702
}
17011703

17021704
/*
@@ -1711,12 +1713,13 @@ static int ahci_init_msi(struct pci_dev *pdev, unsigned int n_ports,
17111713

17121714
/*
17131715
* If the host is not capable of supporting per-port vectors, fall
1714-
* back to single MSI before finally attempting single MSI-X.
1716+
* back to single MSI before finally attempting single MSI-X or
1717+
* a legacy INTx.
17151718
*/
17161719
nvec = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI);
17171720
if (nvec == 1)
1718-
return nvec;
1719-
return pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSIX);
1721+
return;
1722+
pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSIX | PCI_IRQ_INTX);
17201723
}
17211724

17221725
static void ahci_mark_external_port(struct ata_port *ap)
@@ -1996,10 +1999,8 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
19961999
}
19972000
host->private_data = hpriv;
19982001

1999-
if (ahci_init_msi(pdev, n_ports, hpriv) < 0) {
2000-
/* legacy intx interrupts */
2001-
pcim_intx(pdev, 1);
2002-
}
2002+
ahci_init_irq(pdev, n_ports, hpriv);
2003+
20032004
hpriv->irq = pci_irq_vector(pdev, 0);
20042005

20052006
if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)

0 commit comments

Comments
 (0)