Message ID | 20201104155237.77772-6-sven.auhagen@voleatech.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Armada8k enable per-port SATA interrupts and drop a hack in the IRQ subsystem | expand |
Hi, On 11/4/20 4:52 PM, sven.auhagen@voleatech.de wrote: > From: Sven Auhagen <sven.auhagen@voleatech.de> > > The CP110 SATA unit has 2 ports, and a dedicated ICU entry per > port. In the past, the AHCI SATA driver only supported one interrupt > per SATA unit. To solve this conflict, the 2 SATA wired interrupts in > the South-Bridge got configured as 1 GIC interrupt in the > North-Bridge, regardless of the number of SATA ports actually > enabled/in use, and the DT bindings only referenced the interrupt of > one port. > > Since then, this limitation has been addressed and this patch ensures > backward compatibility with old DTs not describing SATA ports > correctly directly from the AHCI MVEBU driver. This way, we will be > able to drop the hack from the ICU driver. IOW, when the A8k > compatible string is used and there is no sub-nodes in the DT, we > fake the creation and mapping of the second (missing) interrupt. > > Signed-off-by: Sven Auhagen <sven.auhagen@voleatech.de> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Much better, thank you. The patch looks good to me now: Reviewed-by: Hans de Goede <hdegoede@redhat.com> Regards, Hans > --- > drivers/ata/ahci_mvebu.c | 126 ++++++++++++++++++++++++++++++--- > drivers/ata/libahci_platform.c | 3 + > include/linux/ahci_platform.h | 1 + > 3 files changed, 120 insertions(+), 10 deletions(-) > > diff --git a/drivers/ata/ahci_mvebu.c b/drivers/ata/ahci_mvebu.c > index ed82381dc4a7..22447b1bb23f 100644 > --- a/drivers/ata/ahci_mvebu.c > +++ b/drivers/ata/ahci_mvebu.c > @@ -16,6 +16,7 @@ > #include <linux/mbus.h> > #include <linux/module.h> > #include <linux/of_device.h> > +#include <linux/of_irq.h> > #include <linux/platform_device.h> > #include "ahci.h" > > @@ -28,9 +29,15 @@ > #define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4)) > #define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4)) > > +#define ICU_SATA0_ICU_ID 109 > +#define ICU_SATA1_ICU_ID 107 > + > struct ahci_mvebu_plat_data { > - int (*plat_config)(struct ahci_host_priv *hpriv); > + int (*plat_config)(struct platform_device *pdev, > + struct ahci_host_priv *hpriv); > unsigned int host_flags; > + unsigned int resource_flags; > + unsigned int port_irq[2]; > }; > > static void ahci_mvebu_mbus_config(struct ahci_host_priv *hpriv, > @@ -67,7 +74,8 @@ static void ahci_mvebu_regret_option(struct ahci_host_priv *hpriv) > writel(0x80, hpriv->mmio + AHCI_VENDOR_SPECIFIC_0_DATA); > } > > -static int ahci_mvebu_armada_380_config(struct ahci_host_priv *hpriv) > +static int ahci_mvebu_armada_380_config(struct platform_device *pdev, > + struct ahci_host_priv *hpriv) > { > const struct mbus_dram_target_info *dram; > int rc = 0; > @@ -83,7 +91,8 @@ static int ahci_mvebu_armada_380_config(struct ahci_host_priv *hpriv) > return rc; > } > > -static int ahci_mvebu_armada_3700_config(struct ahci_host_priv *hpriv) > +static int ahci_mvebu_armada_3700_config(struct platform_device *pdev, > + struct ahci_host_priv *hpriv) > { > u32 reg; > > @@ -96,8 +105,94 @@ static int ahci_mvebu_armada_3700_config(struct ahci_host_priv *hpriv) > return 0; > } > > -static int ahci_mvebu_armada_8k_config(struct ahci_host_priv *hpriv) > +static int multi_irq_host_ack_armada8k(int irq, struct ata_port *ap) > { > + struct ahci_host_priv *hpriv = ap->host->private_data; > + void __iomem *mmio = hpriv->mmio; > + > + writel(BIT(ap->port_no), mmio + HOST_IRQ_STAT); > + > + return 0; > +} > + > +static int ahci_get_per_port_irq_armada8k(struct ata_host *host, int port) > +{ > + struct ahci_host_priv *hpriv = host->private_data; > + struct ahci_mvebu_plat_data *pdata = hpriv->plat_data; > + > + return pdata->port_irq[port]; > +} > + > +static int ahci_mvebu_armada_8k_irq_backwards(struct ahci_host_priv *hpriv, > + struct device *dev) > +{ > + struct device_node *np = of_irq_find_parent(dev->of_node); > + struct ahci_mvebu_plat_data *pdata = hpriv->plat_data; > + struct irq_data *irqd = irq_get_irq_data(pdata->port_irq[0]); > + int host_irq = irqd ? irqd_to_hwirq(irqd) : 0; > + int missing_irq = (host_irq == ICU_SATA1_ICU_ID) ? > + ICU_SATA0_ICU_ID : ICU_SATA1_ICU_ID; > + struct irq_fwspec fwspec = { > + .fwnode = of_node_to_fwnode(np), > + .param_count = 2, > + .param = {missing_irq, IRQ_TYPE_LEVEL_HIGH}, > + }; > + int irq; > + > + pdata->port_irq[1] = irq_create_fwspec_mapping(&fwspec); > + hpriv->mask_port_map = GENMASK(1, 0); > + > + if (missing_irq == ICU_SATA0_ICU_ID) { > + irq = pdata->port_irq[0]; > + pdata->port_irq[0] = pdata->port_irq[1]; > + pdata->port_irq[1] = irq; > + } > + > + return 0; > +} > + > +static int ahci_mvebu_armada_8k_config(struct platform_device *pdev, > + struct ahci_host_priv *hpriv) > +{ > + struct ahci_mvebu_plat_data *pdata = hpriv->plat_data; > + struct device *dev = &pdev->dev; > + struct device_node *child; > + int port_irq, child_nodes, port = 0; > + > + /* Get IRQs per port */ > + child_nodes = of_get_child_count(dev->of_node); > + if (child_nodes) { > + for_each_child_of_node(dev->of_node, child) { > + > + port_irq = of_irq_get(child, 0); > + if (!port_irq) > + port_irq = -EINVAL; > + > + if (port_irq < 0) > + goto compat; > + > + pdata->port_irq[port] = port_irq; > + port++; > + } > + > + goto out; > + } > + > +compat: > + /* Backwards Compatibility Check */ > + port_irq = platform_get_irq(pdev, 0); > + if (port_irq > 0) { > + pdata->port_irq[0] = port_irq; > + ahci_mvebu_armada_8k_irq_backwards(hpriv, dev); > + } else { > + dev_err(dev, "no irq\n"); > + return port_irq; > + } > + > +out: > + hpriv->flags |= AHCI_HFLAG_MULTI_MSI; > + hpriv->get_irq_vector = ahci_get_per_port_irq_armada8k; > + > return 0; > } > > @@ -167,7 +262,7 @@ static int ahci_mvebu_resume(struct platform_device *pdev) > struct ahci_host_priv *hpriv = host->private_data; > const struct ahci_mvebu_plat_data *pdata = hpriv->plat_data; > > - pdata->plat_config(hpriv); > + pdata->plat_config(pdev, hpriv); > > return ahci_platform_resume_host(&pdev->dev); > } > @@ -189,15 +284,22 @@ static struct scsi_host_template ahci_platform_sht = { > > static int ahci_mvebu_probe(struct platform_device *pdev) > { > - const struct ahci_mvebu_plat_data *pdata; > + const struct ahci_mvebu_plat_data *pdata_plat; > + struct ahci_mvebu_plat_data *pdata; > struct ahci_host_priv *hpriv; > int rc; > > - pdata = of_device_get_match_data(&pdev->dev); > - if (!pdata) > + pdata_plat = of_device_get_match_data(&pdev->dev); > + if (!pdata_plat) > return -EINVAL; > > - hpriv = ahci_platform_get_resources(pdev, 0); > + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); > + if (!pdata) > + return -ENOMEM; > + > + memcpy(pdata, pdata_plat, sizeof(*pdata)); > + > + hpriv = ahci_platform_get_resources(pdev, pdata->resource_flags); > if (IS_ERR(hpriv)) > return PTR_ERR(hpriv); > > @@ -210,10 +312,13 @@ static int ahci_mvebu_probe(struct platform_device *pdev) > > hpriv->stop_engine = ahci_mvebu_stop_engine; > > - rc = pdata->plat_config(hpriv); > + rc = pdata->plat_config(pdev, hpriv); > if (rc) > goto disable_resources; > > + if (pdata->resource_flags & AHCI_PLATFORM_ARMADA8K_QUIRK) > + hpriv->multi_irq_host_ack = multi_irq_host_ack_armada8k; > + > rc = ahci_platform_init_host(pdev, hpriv, &ahci_mvebu_port_info, > &ahci_platform_sht); > if (rc) > @@ -237,6 +342,7 @@ static const struct ahci_mvebu_plat_data ahci_mvebu_armada_3700_plat_data = { > > static const struct ahci_mvebu_plat_data ahci_mvebu_armada_8k_plat_data = { > .plat_config = ahci_mvebu_armada_8k_config, > + .resource_flags = AHCI_PLATFORM_ARMADA8K_QUIRK, > }; > > static const struct of_device_id ahci_mvebu_of_match[] = { > diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c > index f6f2a111d226..a5d06565a5c7 100644 > --- a/drivers/ata/libahci_platform.c > +++ b/drivers/ata/libahci_platform.c > @@ -464,6 +464,9 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, > if (!child_nodes) > hpriv->nports = 1; > > + if (!child_nodes && flags & AHCI_PLATFORM_ARMADA8K_QUIRK) > + hpriv->nports = 2; > + > hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); > if (!hpriv->phys) { > rc = -ENOMEM; > diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h > index 49e5383d4222..99ff30b6c37c 100644 > --- a/include/linux/ahci_platform.h > +++ b/include/linux/ahci_platform.h > @@ -42,5 +42,6 @@ int ahci_platform_suspend(struct device *dev); > int ahci_platform_resume(struct device *dev); > > #define AHCI_PLATFORM_GET_RESETS 0x01 > +#define AHCI_PLATFORM_ARMADA8K_QUIRK 0x02 > > #endif /* _AHCI_PLATFORM_H */ >
diff --git a/drivers/ata/ahci_mvebu.c b/drivers/ata/ahci_mvebu.c index ed82381dc4a7..22447b1bb23f 100644 --- a/drivers/ata/ahci_mvebu.c +++ b/drivers/ata/ahci_mvebu.c @@ -16,6 +16,7 @@ #include <linux/mbus.h> #include <linux/module.h> #include <linux/of_device.h> +#include <linux/of_irq.h> #include <linux/platform_device.h> #include "ahci.h" @@ -28,9 +29,15 @@ #define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4)) #define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4)) +#define ICU_SATA0_ICU_ID 109 +#define ICU_SATA1_ICU_ID 107 + struct ahci_mvebu_plat_data { - int (*plat_config)(struct ahci_host_priv *hpriv); + int (*plat_config)(struct platform_device *pdev, + struct ahci_host_priv *hpriv); unsigned int host_flags; + unsigned int resource_flags; + unsigned int port_irq[2]; }; static void ahci_mvebu_mbus_config(struct ahci_host_priv *hpriv, @@ -67,7 +74,8 @@ static void ahci_mvebu_regret_option(struct ahci_host_priv *hpriv) writel(0x80, hpriv->mmio + AHCI_VENDOR_SPECIFIC_0_DATA); } -static int ahci_mvebu_armada_380_config(struct ahci_host_priv *hpriv) +static int ahci_mvebu_armada_380_config(struct platform_device *pdev, + struct ahci_host_priv *hpriv) { const struct mbus_dram_target_info *dram; int rc = 0; @@ -83,7 +91,8 @@ static int ahci_mvebu_armada_380_config(struct ahci_host_priv *hpriv) return rc; } -static int ahci_mvebu_armada_3700_config(struct ahci_host_priv *hpriv) +static int ahci_mvebu_armada_3700_config(struct platform_device *pdev, + struct ahci_host_priv *hpriv) { u32 reg; @@ -96,8 +105,94 @@ static int ahci_mvebu_armada_3700_config(struct ahci_host_priv *hpriv) return 0; } -static int ahci_mvebu_armada_8k_config(struct ahci_host_priv *hpriv) +static int multi_irq_host_ack_armada8k(int irq, struct ata_port *ap) { + struct ahci_host_priv *hpriv = ap->host->private_data; + void __iomem *mmio = hpriv->mmio; + + writel(BIT(ap->port_no), mmio + HOST_IRQ_STAT); + + return 0; +} + +static int ahci_get_per_port_irq_armada8k(struct ata_host *host, int port) +{ + struct ahci_host_priv *hpriv = host->private_data; + struct ahci_mvebu_plat_data *pdata = hpriv->plat_data; + + return pdata->port_irq[port]; +} + +static int ahci_mvebu_armada_8k_irq_backwards(struct ahci_host_priv *hpriv, + struct device *dev) +{ + struct device_node *np = of_irq_find_parent(dev->of_node); + struct ahci_mvebu_plat_data *pdata = hpriv->plat_data; + struct irq_data *irqd = irq_get_irq_data(pdata->port_irq[0]); + int host_irq = irqd ? irqd_to_hwirq(irqd) : 0; + int missing_irq = (host_irq == ICU_SATA1_ICU_ID) ? + ICU_SATA0_ICU_ID : ICU_SATA1_ICU_ID; + struct irq_fwspec fwspec = { + .fwnode = of_node_to_fwnode(np), + .param_count = 2, + .param = {missing_irq, IRQ_TYPE_LEVEL_HIGH}, + }; + int irq; + + pdata->port_irq[1] = irq_create_fwspec_mapping(&fwspec); + hpriv->mask_port_map = GENMASK(1, 0); + + if (missing_irq == ICU_SATA0_ICU_ID) { + irq = pdata->port_irq[0]; + pdata->port_irq[0] = pdata->port_irq[1]; + pdata->port_irq[1] = irq; + } + + return 0; +} + +static int ahci_mvebu_armada_8k_config(struct platform_device *pdev, + struct ahci_host_priv *hpriv) +{ + struct ahci_mvebu_plat_data *pdata = hpriv->plat_data; + struct device *dev = &pdev->dev; + struct device_node *child; + int port_irq, child_nodes, port = 0; + + /* Get IRQs per port */ + child_nodes = of_get_child_count(dev->of_node); + if (child_nodes) { + for_each_child_of_node(dev->of_node, child) { + + port_irq = of_irq_get(child, 0); + if (!port_irq) + port_irq = -EINVAL; + + if (port_irq < 0) + goto compat; + + pdata->port_irq[port] = port_irq; + port++; + } + + goto out; + } + +compat: + /* Backwards Compatibility Check */ + port_irq = platform_get_irq(pdev, 0); + if (port_irq > 0) { + pdata->port_irq[0] = port_irq; + ahci_mvebu_armada_8k_irq_backwards(hpriv, dev); + } else { + dev_err(dev, "no irq\n"); + return port_irq; + } + +out: + hpriv->flags |= AHCI_HFLAG_MULTI_MSI; + hpriv->get_irq_vector = ahci_get_per_port_irq_armada8k; + return 0; } @@ -167,7 +262,7 @@ static int ahci_mvebu_resume(struct platform_device *pdev) struct ahci_host_priv *hpriv = host->private_data; const struct ahci_mvebu_plat_data *pdata = hpriv->plat_data; - pdata->plat_config(hpriv); + pdata->plat_config(pdev, hpriv); return ahci_platform_resume_host(&pdev->dev); } @@ -189,15 +284,22 @@ static struct scsi_host_template ahci_platform_sht = { static int ahci_mvebu_probe(struct platform_device *pdev) { - const struct ahci_mvebu_plat_data *pdata; + const struct ahci_mvebu_plat_data *pdata_plat; + struct ahci_mvebu_plat_data *pdata; struct ahci_host_priv *hpriv; int rc; - pdata = of_device_get_match_data(&pdev->dev); - if (!pdata) + pdata_plat = of_device_get_match_data(&pdev->dev); + if (!pdata_plat) return -EINVAL; - hpriv = ahci_platform_get_resources(pdev, 0); + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + memcpy(pdata, pdata_plat, sizeof(*pdata)); + + hpriv = ahci_platform_get_resources(pdev, pdata->resource_flags); if (IS_ERR(hpriv)) return PTR_ERR(hpriv); @@ -210,10 +312,13 @@ static int ahci_mvebu_probe(struct platform_device *pdev) hpriv->stop_engine = ahci_mvebu_stop_engine; - rc = pdata->plat_config(hpriv); + rc = pdata->plat_config(pdev, hpriv); if (rc) goto disable_resources; + if (pdata->resource_flags & AHCI_PLATFORM_ARMADA8K_QUIRK) + hpriv->multi_irq_host_ack = multi_irq_host_ack_armada8k; + rc = ahci_platform_init_host(pdev, hpriv, &ahci_mvebu_port_info, &ahci_platform_sht); if (rc) @@ -237,6 +342,7 @@ static const struct ahci_mvebu_plat_data ahci_mvebu_armada_3700_plat_data = { static const struct ahci_mvebu_plat_data ahci_mvebu_armada_8k_plat_data = { .plat_config = ahci_mvebu_armada_8k_config, + .resource_flags = AHCI_PLATFORM_ARMADA8K_QUIRK, }; static const struct of_device_id ahci_mvebu_of_match[] = { diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index f6f2a111d226..a5d06565a5c7 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -464,6 +464,9 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, if (!child_nodes) hpriv->nports = 1; + if (!child_nodes && flags & AHCI_PLATFORM_ARMADA8K_QUIRK) + hpriv->nports = 2; + hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); if (!hpriv->phys) { rc = -ENOMEM; diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h index 49e5383d4222..99ff30b6c37c 100644 --- a/include/linux/ahci_platform.h +++ b/include/linux/ahci_platform.h @@ -42,5 +42,6 @@ int ahci_platform_suspend(struct device *dev); int ahci_platform_resume(struct device *dev); #define AHCI_PLATFORM_GET_RESETS 0x01 +#define AHCI_PLATFORM_ARMADA8K_QUIRK 0x02 #endif /* _AHCI_PLATFORM_H */