From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Gregory Clement <gregory.clement@bootlin.com>,
Jason Cooper <jason@lakedaemon.net>, Andrew Lunn <andrew@lunn.ch>,
Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>, Jens Axboe <axboe@kernel.dk>,
Hans de Goede <hdegoede@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Marc Zyngier <marc.zyngier@arm.com>
Cc: devicetree@vger.kernel.org,
Antoine Tenart <antoine.tenart@bootlin.com>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Nadav Haklai <nadavh@marvell.com>,
linux-ide@vger.kernel.org,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Miquel Raynal <miquel.raynal@bootlin.com>,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/5] irqchip/irq-mvebu-icu: Move the double SATA ports interrupt hack
Date: Fri, 22 Feb 2019 15:53:54 +0100 [thread overview]
Message-ID: <20190222145356.23072-4-miquel.raynal@bootlin.com> (raw)
In-Reply-To: <20190222145356.23072-1-miquel.raynal@bootlin.com>
When writing the driver, a hack was introduced to configure both SATA
interrupts regardless of the port in use to overcome a limitation in
the SATA core. Now that this limitation has been addressed, let's
clean this driver section and move the hack into the (historically)
responsible SATA driver: ahci_platform.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/ata/ahci_platform.c | 174 ++++++++++++++++++++++++++++++++
drivers/irqchip/irq-mvebu-icu.c | 18 ----
2 files changed, 174 insertions(+), 18 deletions(-)
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
index cf1e0e18a7a9..4401a137e6d5 100644
--- a/drivers/ata/ahci_platform.c
+++ b/drivers/ata/ahci_platform.c
@@ -17,6 +17,7 @@
#include <linux/pm.h>
#include <linux/device.h>
#include <linux/of_device.h>
+#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/libata.h>
#include <linux/ahci_platform.h>
@@ -26,6 +27,9 @@
#define DRV_NAME "ahci"
+#define ICU_SATA0_ICU_ID 109
+#define ICU_SATA1_ICU_ID 107
+
static const struct ata_port_info ahci_port_info = {
.flags = AHCI_FLAG_COMMON,
.pio_mask = ATA_PIO4,
@@ -44,6 +48,170 @@ static struct scsi_host_template ahci_platform_sht = {
AHCI_SHT(DRV_NAME),
};
+/*
+ * The Armada CP110 SATA unit (on A7k/A8k SoCs) 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, 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.
+ *
+ * Since then, this limitation has been addressed and the hack described
+ * above has been removed from the ICU driver. However, for compatibility
+ * it is needed to support DT with just one interrupt and no SATA ports.
+ * Instead of hacking everywhere in the ahci/libahci code, this quirk has been
+ * written to manually create the SATA port sub-nodes if they are missing,
+ * assign them the right port numbers through the "reg" properties and their
+ * respective "interrupts".
+ */
+static int ahci_armada_8k_quirk(struct device *dev)
+{
+ struct device_node *dn = dev->of_node;
+ struct property *interrupt = of_find_property(dn, "interrupts", NULL);
+ struct device_node *ports;
+ struct property *regs, *ints;
+ int rc, i;
+
+ if (!(of_device_is_compatible(dn, "marvell,armada-8k-ahci") &&
+ !of_get_child_count(dn)))
+ return 0;
+
+ if (!of_node_get(dn))
+ return -EINVAL;
+
+ /* Verify the main SATA node "interrupts" property validity */
+ if (!interrupt) {
+ rc = -EINVAL;
+ goto put_dn;
+ }
+
+ /* Create the two sub-nodes */
+ ports = kzalloc(2 * sizeof(*ports), GFP_KERNEL);
+ if (!ports) {
+ rc = -ENOMEM;
+ goto put_dn;
+ }
+
+ for (i = 0; i < 2; i++) {
+ of_node_set_flag(&ports[i], OF_DYNAMIC);
+ of_node_init(&ports[i]);
+ ports[i].parent = dn;
+ }
+
+ ports[0].full_name = kstrdup("sata-port@0", GFP_KERNEL);
+ ports[1].full_name = kstrdup("sata-port@1", GFP_KERNEL);
+ if (!ports[0].full_name || !ports[1].full_name) {
+ rc = -ENOMEM;
+ goto free_ports_names;
+ }
+
+ /* Create the two "reg" and "interrupts" property for the sub-nodes */
+ regs = kzalloc(2 * sizeof(*regs), GFP_KERNEL);
+ ints = kzalloc(2 * sizeof(*ints), GFP_KERNEL);
+ if (!regs || !ints) {
+ rc = -ENOMEM;
+ goto free_props;
+ }
+
+ for (i = 0; i < 2; i++) {
+ regs[i].name = kstrdup("reg", GFP_KERNEL);
+ regs[i].length = sizeof(u32);
+ regs[i].value = kmalloc(sizeof(regs[i].length), GFP_KERNEL);
+
+ ints[i].name = kstrdup("interrupts", GFP_KERNEL);
+ ints[i].length = interrupt->length;
+ ints[i].value = kmemdup(interrupt->value, interrupt->length,
+ GFP_KERNEL);
+
+ if (!regs[i].name || !regs[i].value ||
+ !ints[i].name || !ints[i].value) {
+ rc = -ENOMEM;
+ goto free_props_allocs;
+ }
+ }
+
+ /* Force the values of the ICU interrupts for both ports.
+ * In the past, "interrupts" properties had three values:
+ * 1/ ICU interrupt type, 2/ interrupt ID, 3/ interrupt type
+ * Now there are only two:
+ * 1/ interrupt ID, 2/ interrupt type
+ * In both case we want to access the penultimate.
+ */
+ for (i = 0; i < 2; i++) {
+ u32 *reg, *icu_int;
+ u8 *value;
+
+ reg = regs[i].value;
+ *reg = cpu_to_be32(i);
+
+ value = ints[i].value;
+ value = &value[ints[i].length - (2 * sizeof(u32))];
+ icu_int = (u32 *)value;
+ if (!i)
+ *icu_int = cpu_to_be32(ICU_SATA0_ICU_ID);
+ else
+ *icu_int = cpu_to_be32(ICU_SATA1_ICU_ID);
+ }
+
+ for (i = 0; i < 2; i++) {
+ ports[i].properties = ®s[i];
+ regs[i].next = &ints[i];
+ ints[i].next = NULL;
+ }
+
+ /* Create the two sub-nodes by attaching them */
+ rc = of_attach_node(&ports[0]);
+ if (rc) {
+ dev_err(dev, "Compat: cannot attach port0 (err %d)\n", rc);
+ goto free_props_allocs;
+ }
+
+ rc = of_attach_node(&ports[1]);
+ if (rc) {
+ dev_err(dev, "Compat: cannot attach port1 (err %d)\n", rc);
+ goto detach_port0;
+ }
+
+ /* Delete the "interrupts" property from the SATA host node */
+ rc = of_remove_property(dn, interrupt);
+ if (rc) {
+ dev_err(dev, "Compat: cannot delete SATA host interrupt\n");
+ goto detach_ports;
+ }
+
+ of_node_put(dn);
+
+ return 0;
+
+detach_ports:
+ of_detach_node(&ports[1]);
+
+detach_port0:
+ of_detach_node(&ports[0]);
+
+free_props_allocs:
+ for (i = 0; i < 2; i++) {
+ kfree(regs[i].name);
+ kfree(regs[i].value);
+ kfree(ints[i].name);
+ kfree(ints[i].value);
+ }
+
+free_props:
+ kfree(regs);
+ kfree(ints);
+
+free_ports_names:
+ for (i = 0; i < 2; i++)
+ kfree(ports[i].full_name);
+
+ kfree(ports);
+
+put_dn:
+ of_node_put(dn);
+
+ return rc;
+ }
+
static int ahci_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -51,6 +219,12 @@ static int ahci_probe(struct platform_device *pdev)
const struct ata_port_info *port;
int rc;
+ rc = ahci_armada_8k_quirk(dev);
+ if (rc) {
+ dev_err(dev, "Problem with CP110 backward compatibility\n");
+ return rc;
+ }
+
hpriv = ahci_platform_get_resources(pdev,
AHCI_PLATFORM_GET_RESETS);
if (IS_ERR(hpriv))
diff --git a/drivers/irqchip/irq-mvebu-icu.c b/drivers/irqchip/irq-mvebu-icu.c
index 547045d89c4b..f3b43f63fe2e 100644
--- a/drivers/irqchip/irq-mvebu-icu.c
+++ b/drivers/irqchip/irq-mvebu-icu.c
@@ -38,8 +38,6 @@
/* ICU definitions */
#define ICU_MAX_IRQS 207
-#define ICU_SATA0_ICU_ID 109
-#define ICU_SATA1_ICU_ID 107
struct mvebu_icu_subset_data {
unsigned int icu_group;
@@ -111,22 +109,6 @@ static void mvebu_icu_write_msg(struct msi_desc *desc, struct msi_msg *msg)
}
writel_relaxed(icu_int, icu->base + ICU_INT_CFG(d->hwirq));
-
- /*
- * The SATA unit has 2 ports, and a dedicated ICU entry per
- * port. The ahci sata driver supports only one irq interrupt
- * per SATA unit. To solve this conflict, we configure the 2
- * SATA wired interrupts in the south bridge into 1 GIC
- * interrupt in the north bridge. Even if only a single port
- * is enabled, if sata node is enabled, both interrupts are
- * configured (regardless of which port is actually in use).
- */
- if (d->hwirq == ICU_SATA0_ICU_ID || d->hwirq == ICU_SATA1_ICU_ID) {
- writel_relaxed(icu_int,
- icu->base + ICU_INT_CFG(ICU_SATA0_ICU_ID));
- writel_relaxed(icu_int,
- icu->base + ICU_INT_CFG(ICU_SATA1_ICU_ID));
- }
}
static struct irq_chip mvebu_icu_nsr_chip = {
--
2.19.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-02-22 14:55 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 14:53 [PATCH 0/5] Enable per-port SATA interrupts and drop an hack in the IRQ subsystem Miquel Raynal
2019-02-22 14:53 ` [PATCH 1/5] ata: libahci: Ensure the host interrupt status bits are cleared Miquel Raynal
2019-02-22 14:53 ` [PATCH 2/5] ata: libahci_platform: Support per-port interrupts Miquel Raynal
2019-02-22 15:26 ` Hans de Goede
2019-02-22 15:31 ` Miquel Raynal
2019-02-22 15:52 ` Hans de Goede
2019-02-22 16:03 ` Miquel Raynal
2019-02-22 16:10 ` Hans de Goede
2019-02-25 18:08 ` Jens Axboe
2019-02-22 16:41 ` Marc Zyngier
2019-02-22 14:53 ` Miquel Raynal [this message]
2019-02-23 19:19 ` [PATCH 3/5] irqchip/irq-mvebu-icu: Move the double SATA ports interrupt hack Marc Zyngier
2019-02-25 15:22 ` Miquel Raynal
2019-02-22 14:53 ` [PATCH 4/5] arm64: dts: marvell: armada-8040-clearfog: Drop non-existent SATA port Miquel Raynal
2019-02-24 5:29 ` Baruch Siach
2019-02-25 10:58 ` Miquel Raynal
2019-02-25 12:15 ` Baruch Siach
2019-02-25 13:05 ` Russell King - ARM Linux admin
2019-02-27 5:16 ` Baruch Siach
2019-02-22 14:53 ` [PATCH 5/5] arm64: dts: marvell: armada-cp110: Switch to per-port SATA interrupts Miquel Raynal
2019-02-22 15:13 ` Russell King - ARM Linux admin
2019-02-22 15:29 ` Miquel Raynal
2019-02-23 19:21 ` Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190222145356.23072-4-miquel.raynal@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=andrew@lunn.ch \
--cc=antoine.tenart@bootlin.com \
--cc=axboe@kernel.dk \
--cc=devicetree@vger.kernel.org \
--cc=gregory.clement@bootlin.com \
--cc=hdegoede@redhat.com \
--cc=jason@lakedaemon.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-ide@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=mark.rutland@arm.com \
--cc=maxime.chevallier@bootlin.com \
--cc=nadavh@marvell.com \
--cc=robh+dt@kernel.org \
--cc=sebastian.hesselbarth@gmail.com \
--cc=tglx@linutronix.de \
--cc=thomas.petazzoni@bootlin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).