Skip to contentSkip to conversation

ata: Add APM X-Gene SoC SATA host controller support

PATCH Superseded Loc Ho 3 participants 15 messages Nov 14, 2013 – Nov 27, 2013

Subsystems (3)

v3 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Loc Ho

author
#0 lore raw

v3 cover ata: Add APM X-Gene SoC SATA host controller support

ata: Add APM X-Gene SoC SATA host controller support

This patch adds support for the APM X-Gene SoC SATA host controller. In order for the host controller to work, the corresponding SATA PHY driver musts also be available.

v3:
* Move out the SATA PHY to another driver
* Remove the clock-cells entry from DTS
* Remove debug wrapper
* Remove delay functions wrapper
* Clean up resource and IRQ query
* Remove query clock name
* Switch to use dma_set_mask/dma_coherent_mask
* Remove un-necessary devm_kfree
* Update GPL license header to v2
* Spilt up function xgene_ahci_hardreset
* Spilt up function xgene_ahci_probe
* Remove all reference of CONFIG_ARCH_MSLIM
* Clean up chip revision code

v2:
* Clean up file sata_xgene.c with Lindent and etc
* Clean up file sata_xgene_serdes.c with Lindent and etc
* Add description to each patch

v1:
* inital version

---
Loc Ho (4):
ata: Export required functions by APM X-Gene SATA driver
Documentation: Add documentation for APM X-Gene SATA controllor DTS
binding
ata: Add APM X-Gene SoC SATA host controller driver
arm64: Add APM X-Gene SoC SATA host controller DTS entries

 .../devicetree/bindings/ata/apm-xgene.txt          |   62 +-
 arch/arm64/boot/dts/apm-storm.dtsi                 |   70 ++
 drivers/ata/Kconfig                                |    8 +
 drivers/ata/Makefile                               |    1 +
 drivers/ata/ahci.h                                 |    6 +
 drivers/ata/libahci.c                              |   13 +-
 drivers/ata/sata_xgene.c                           | 1271 ++++++++++++++++++++
 drivers/ata/sata_xgene.h                           |   96 ++
 8 files changed, 1521 insertions(+), 6 deletions(-)
 create mode 100644 drivers/ata/sata_xgene.c
 create mode 100644 drivers/ata/sata_xgene.h
author
#1 lore raw

PATCH v3 1/4 ata: Export required functions by APM X-Gene SATA driver

ata: Export required functions by APM X-Gene SATA driver

This patch exports functions required by APM X-Gene SoC SATA host controller driver to avoid duplication of code.

---
 drivers/ata/ahci.h    |    6 ++++++
 drivers/ata/libahci.c |   13 ++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)
drivers/ata/ahci.h +6 -0
index 1145637..cf881e0 100644
@@ -368,6 +368,12 @@ irqreturn_t ahci_hw_interrupt(int irq, void *dev_instance);
 irqreturn_t ahci_thread_fn(int irq, void *dev_instance);
 void ahci_print_info(struct ata_host *host, const char *scc_s);
 int ahci_host_activate(struct ata_host *host, int irq, unsigned int n_msis);
+void ahci_sw_activity(struct ata_link *link);
+int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
+void ahci_error_intr(struct ata_port *ap, u32 irq_stat);
+int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
+				struct ata_taskfile *tf, int is_cmd, u16 flags,
+				unsigned long timeout_msec);
 
 static inline void __iomem *__ahci_port_base(struct ata_host *host,
 					     unsigned int port_no)
drivers/ata/libahci.c +8 -5
index aaac4fb..de7e074 100644
@@ -68,7 +68,6 @@ static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
 
 
 static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
-static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
 static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
 static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc);
 static int ahci_port_start(struct ata_port *ap);
@@ -553,7 +552,7 @@ static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
 	return -EINVAL;
 }
 
-static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
+int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
 {
 	void __iomem *port_mmio = ahci_port_base(link->ap);
 	int offset = ahci_scr_offset(link->ap, sc_reg);
@@ -564,6 +563,7 @@ static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
 	}
 	return -EINVAL;
 }
+EXPORT_SYMBOL_GPL(ahci_scr_write);
 
 void ahci_start_engine(struct ata_port *ap)
 {
@@ -869,7 +869,7 @@ int ahci_reset_controller(struct ata_host *host)
 }
 EXPORT_SYMBOL_GPL(ahci_reset_controller);
 
-static void ahci_sw_activity(struct ata_link *link)
+void ahci_sw_activity(struct ata_link *link)
 {
 	struct ata_port *ap = link->ap;
 	struct ahci_port_priv *pp = ap->private_data;
@@ -882,6 +882,7 @@ static void ahci_sw_activity(struct ata_link *link)
 	if (!timer_pending(&emp->timer))
 		mod_timer(&emp->timer, jiffies + msecs_to_jiffies(10));
 }
+EXPORT_SYMBOL_GPL(ahci_sw_activity);
 
 static void ahci_sw_activity_blink(unsigned long arg)
 {
@@ -1239,7 +1240,7 @@ int ahci_kick_engine(struct ata_port *ap)
 }
 EXPORT_SYMBOL_GPL(ahci_kick_engine);
 
-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
+int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
 				struct ata_taskfile *tf, int is_cmd, u16 flags,
 				unsigned long timeout_msec)
 {
@@ -1268,6 +1269,7 @@ static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(ahci_exec_polled_cmd);
 
 int ahci_do_softreset(struct ata_link *link, unsigned int *class,
 		      int pmp, unsigned long deadline,
@@ -1552,7 +1554,7 @@ static void ahci_fbs_dec_intr(struct ata_port *ap)
 		dev_err(ap->host->dev, "failed to clear device error\n");
 }
 
-static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
+void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
 {
 	struct ahci_host_priv *hpriv = ap->host->private_data;
 	struct ahci_port_priv *pp = ap->private_data;
@@ -1662,6 +1664,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
 	} else
 		ata_port_abort(ap);
 }
+EXPORT_SYMBOL_GPL(ahci_error_intr);
 
 static void ahci_handle_port_interrupt(struct ata_port *ap,
 				       void __iomem *port_mmio, u32 status)
Signature · 1 line
1.5.5
author
#2 lore raw

PATCH v3 2/4 Documentation: Add documentation for APM X-Gene SATA controllor DTS binding

Documentation:: Add documentation for APM X-Gene SoC SATA host controller DTS binding

---
 .../devicetree/bindings/ata/apm-xgene.txt          |   62 +++++++++++++++++++-
 1 files changed, 61 insertions(+), 1 deletions(-)
Documentation/devicetree/bindings/ata/apm-xgene.txt +61 -1
index d18db67..0d16bfe 100644
@@ -1,4 +1,4 @@
-* APM X-Gene 6.0 Gb/s SATA PHY nodes
+* APM X-Gene 6.0 Gb/s SATA PHY and controller nodes
 
 SATA PHY nodes are defined to describe on-chip Serial ATA PHY. Each SATA PHY
 (pair of PHY) has its own node.
@@ -67,3 +67,63 @@ Example:
 			status = "ok";
 		};
 
+SATA host controller nodes are defined to describe on-chip Serial ATA
+controllers. Each SATA controller (pair of ports) have its own node.
+
+Required properties:
+- compatible		: Shall be "apm,xgene-ahci"
+- reg			: First memory resource shall be the AHCI memory
+			  resource.
+			  Second memory resource shall be the host controller
+			  memory resource.
+- id			: Controller ID (0 = first, 1 = second, 2 = third)
+- interrupt-parent	: Interrupt controller
+- interrupts		: Interrupt mapping for SATA host controller IRQ
+- clocks		: Reference to the clock entry
+- phys			: PHY reference
+- phy-names		: Name of the PHY reference
+
+Optional properties:
+- status		: Shall be "ok" if enabled or "na" if disabled.
+			  Default is "ok".
+
+Example:
+		sata0: sata at 1a000000 {
+			compatible = "apm,xgene-ahci";
+			id = <0>;
+			reg =  <0x0 0x1a000000 0x0 0x100000
+				0x0 0x1f210000 0x0 0x10000>;
+			interrupt-parent = <&gic>;
+			interrupts = <0x0 0x86 0x4>;
+		        clocks = <&eth01clk 0>;
+			status = "na";
+			phys = <&sataphy0>;
+			phy-names = "sataphy0";
+		};
+
+		sata1: sata at 1a400000 {
+			compatible = "apm,xgene-ahci";
+			id = <1>;
+			reg =  <0x0 0x1a400000 0x0 0x100000
+				0x0 0x1f220000 0x0 0x10000>;
+			interrupt-parent = <&gic>;
+			interrupts = <0x0 0x87 0x4>;
+		        clocks = <&eth23clk 0>;
+			status = "ok";
+			phys = <&sataphy1>;
+			phy-names = "sataphy1";
+		};
+
+		sata2: sata at 1a800000 {
+			compatible = "apm,xgene-ahci";
+			id = <2>;
+			reg =  <0x0 0x1a800000 0x0 0x100000
+				0x0 0x1f230000 0x0 0x10000
+				0x0 0x1f2d0000 0x0 0x10000 >;
+			interrupt-parent = <&gic>;
+			interrupts = <0x0 0x88 0x4>;
+		        clocks = <&sata45clk 0>;
+			status = "ok";
+			phys = <&sataphy2>;
+			phy-names = "sataphy2";
+		};
Signature · 1 line
1.5.5
author
#3 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

ata: Add APM X-Gene SoC SATA host controller driver

This patch adds support for the APM X-Gene SoC SATA host controller driver.

---
 drivers/ata/Kconfig      |    8 +
 drivers/ata/Makefile     |    1 +
 drivers/ata/sata_xgene.c | 1271 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/ata/sata_xgene.h |   96 ++++
 4 files changed, 1376 insertions(+), 0 deletions(-)
 create mode 100644 drivers/ata/sata_xgene.c
 create mode 100644 drivers/ata/sata_xgene.h
drivers/ata/Kconfig +8 -0
index d467e06..60da4a2 100644
@@ -112,6 +112,14 @@ config SATA_XGENE_PHY
 	help
 	  This option enables support for APM X-Gene SoC SATA PHY.
 
+config SATA_XGENE
+	tristate "APM X-Gene 6.0Gbps SATA host controller support"
+	depends on SATA_AHCI_PLATFORM
+	default y if ARM64
+	select SATA_XGENE_PHY
+	help
+	  This option enables support for APM X-Gene SoC SATA host controller.
+
 config SATA_FSL
 	tristate "Freescale 3.0Gbps SATA support"
 	depends on FSL_SOC
drivers/ata/Makefile +1 -0
index be53890..f141566 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_SATA_DWC)		+= sata_dwc_460ex.o
 obj-$(CONFIG_SATA_HIGHBANK)	+= sata_highbank.o libahci.o
 obj-$(CONFIG_AHCI_IMX)		+= ahci_imx.o
 obj-$(CONFIG_SATA_XGENE_PHY)	+= sata_xgene_phy.o
+obj-$(CONFIG_SATA_XGENE)	+= sata_xgene.o
 
 # SFF w/ custom DMA
 obj-$(CONFIG_PDC_ADMA)		+= pdc_adma.o
drivers/ata/sata_xgene.c new file +1271 -0

1,271 lines not on this page · raw message

drivers/ata/sata_xgene.h new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
1.5.5
author
#4 lore raw

PATCH v4 4/4 arm64: Add APM X-Gene SoC SATA DTS entries

arm64: Add APM X-Gene SoC SATA host controller and clock DTS entries

---
 arch/arm64/boot/dts/apm-storm.dtsi |   70 ++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)
arch/arm64/boot/dts/apm-storm.dtsi +70 -0
index b29b465..14f3d5b 100644
@@ -176,6 +176,36 @@
 				reg-names = "csr-reg";
 				clock-output-names = "eth8clk";
 			};
+
+			eth01clk: eth01clk at 1f21c000 {
+				compatible = "apm,xgene-device-clock";
+				#clock-cells = <1>;
+				clocks = <&socplldiv2 0>;
+				clock-names = "eth01clk";
+	                        reg = <0x0 0x1f21c000 0x0 0x1000>;
+				reg-names = "csr-reg";
+				clock-output-names = "eth01clk";
+			};
+
+			eth23clk: eth23clk at 1f22c000 {
+				compatible = "apm,xgene-device-clock";
+				#clock-cells = <1>;
+				clocks = <&socplldiv2 0>;
+				clock-names = "eth23clk";
+	                        reg = <0x0 0x1f22c000 0x0 0x1000>;
+				reg-names = "csr-reg";
+				clock-output-names = "eth23clk";
+			};
+
+			sata45clk: sata45clk at 1f23c000 {
+				compatible = "apm,xgene-device-clock";
+				#clock-cells = <1>;
+				clocks = <&socplldiv2 0>;
+				clock-names = "sata45clk";
+	                        reg = <0x0 0x1f23c000 0x0 0x1000>;
+				reg-names = "csr-reg";
+				clock-output-names = "sata45clk";
+			};
 		};
 
 		serial0: serial at 1c020000 {
@@ -218,5 +248,45 @@
 			#phy-cells = <0>;
 			status = "ok";
 		};
+
+		sata0: sata at 1a000000 {
+			compatible = "apm,xgene-ahci";
+			id = <0>;
+			reg =  <0x0 0x1a000000 0x0 0x100000
+				0x0 0x1f210000 0x0 0x10000>;
+			interrupt-parent = <&gic>;
+			interrupts = <0x0 0x86 0x4>;
+		        clocks = <&eth01clk 0>;
+			status = "na";
+			phys = <&sataphy0>;
+			phy-names = "sataphy0";
+		};
+
+		sata1: sata at 1a400000 {
+			compatible = "apm,xgene-ahci";
+			id = <1>;
+			reg =  <0x0 0x1a400000 0x0 0x100000
+				0x0 0x1f220000 0x0 0x10000>;
+			interrupt-parent = <&gic>;
+			interrupts = <0x0 0x87 0x4>;
+		        clocks = <&eth23clk 0>;
+			status = "ok";
+			phys = <&sataphy1>;
+			phy-names = "sataphy1";
+		};
+
+		sata2: sata at 1a800000 {
+			compatible = "apm,xgene-ahci";
+			id = <2>;
+			reg =  <0x0 0x1a800000 0x0 0x100000
+				0x0 0x1f230000 0x0 0x10000
+				0x0 0x1f2d0000 0x0 0x10000 >;
+			interrupt-parent = <&gic>;
+			interrupts = <0x0 0x88 0x4>;
+		        clocks = <&sata45clk 0>;
+			status = "ok";
+			phys = <&sataphy2>;
+			phy-names = "sataphy2";
+		};
 	};
 };
Signature · 1 line
1.5.5
#5 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

In reply to Loc Ho

drivers/ata/Kconfig config SATA_XGENE_PHY · line 119

Quoted 6 lines · Loc Ho
drivers/ata/Kconfig +5 -0
+config SATA_XGENE
+	tristate "APM X-Gene 6.0Gbps SATA host controller support"
+	depends on SATA_AHCI_PLATFORM
+	default y if ARM64
+	select SATA_XGENE_PHY

I don't think the "default y" is appropriate here, since there are going to be lots of ARM64 platforms in the long run that don't have this. Also, there is a trend towards using CONFIG_COMPILE_TEST to limit the visibility.

I'd suggest something like

config SATA_XGENE

	tristate "APM X-Gene 6.0Gbps SATA host controller support"
	depends on ARM64 || COMPILE_TEST
	...

drivers/ata/sata_xgene.c line 33

Quoted 2 lines
drivers/ata/sata_xgene.c new file +2 -0
+/* Enable for dumping CSR read/write access */
+#undef XGENE_DBG_CSR

This should be removed now as well, along with the debug macro you already removed.

drivers/ata/sata_xgene.c line 96

Quoted 4 lines
drivers/ata/sata_xgene.c new file +4 -0
+
+/* Temporary function until the PHY parameter API */
+extern void xgene_ahci_phy_set_pq(struct phy *phy, int chan, int data);
+extern void xgene_ahci_phy_set_spd(struct phy *phy, int chan, int gen);

Ah, that should have been mentioned in the changeset text. Do you think you can remove these for the final version?

drivers/ata/sata_xgene.c line 104

Quoted 7 lines
drivers/ata/sata_xgene.c new file +7 -0
+static void xgene_rd(void *addr, u32 *val)
+{
+	*val = readl(addr);
+#if defined(XGENE_DBG_CSR)
+	printk(KERN_DEBUG "SATAPHY CSR RD: 0x%p value: 0x%08x\n", addr, *val);
+#endif
+}

The interface you are looking for is pr_debug() or dev_dbg(), which get built-in only if the DEBUG macro is set.

In a lot of cases, it's actually best to remove debug output like this from the driver once you have it working -- whoever is debugging problems in the driver next might need completely different debugging information or can add them back easily if needed.

It's your choice if you want to use pr_debug() or remove that output entirely. If you remove it, best remove the helper functions entirely and use readl/writel directly.

Quoted 4 lines
drivers/ata/sata_xgene.c new file +4 -0
+/* Flush the IOB to ensure all SATA controller writes completed before
+   servicing the completed command. */
+static int xgene_ahci_iob_flush(struct xgene_ahci_context *ctx)
+{

drivers/ata/sata_xgene.c line 470

Quoted 10 lines
drivers/ata/sata_xgene.c new file +10 -0
+	if (ctx->ahbc_io_base == NULL) {
+		void *ahbc_base;
+		u32 val;
+
+		/* The AHBC address is fixed in X-Gene */
+		ahbc_base = devm_ioremap(ctx->dev, 0x1F2A0000, 0x80000);
+		if (!ahbc_base) {
+			dev_err(ctx->dev, "can't map AHBC resource\n");
+			return -ENODEV;
+		}

I had an important comment about the misuse of hardcoded I/O addresses here. Please never just post a new version with the same issue. In general, your options are:

* rewrite the code in a more appropriate way
* reply to the comment, arguing why you think your code is correct
* ask for clarification if you don't know how to improve the code
* mark the code as TODO and mention in the patch description why you are still working on this and that the current version should not be seen as final.

If you don't do any of these, reviewers will get annoyed because you are wasting their time.

Quoted 9 lines
drivers/ata/sata_xgene.c new file +9 -0
+
+static int xgene_ahci_get_u32_param(struct platform_device *pdev,
+				    const char *of_name, char *acpi_name,
+				    u32 *param)
+{
+#ifdef CONFIG_ACPI
+	if (efi_enabled(EFI_BOOT)) {
+		unsigned long long value;
+		acpi_status status;

drivers/ata/sata_xgene.c line 905

Quoted 10 lines
drivers/ata/sata_xgene.c new file +10 -0
+		if (acpi_name == NULL)
+			return -ENODEV;
+		status = acpi_evaluate_integer(ACPI_HANDLE(&pdev->dev),
+					       acpi_name, NULL, &value);
+		if (ACPI_FAILURE(status))
+			return -ENODEV;
+		*param = value;
+		return 0;
+	}
+#endif

There are more previous comments that you have not addressed yet.

drivers/ata/sata_xgene.h

Quoted 5 lines
drivers/ata/sata_xgene.h new file +0 -0
new file mode 100644
index 0000000..51e73f6

This file should probably just be folded into the driver, since it contains no interfaces between modules, just internal definitions.

Arnd

author
#6 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

Hi,

Quoted 11 lines

drivers/ata/Kconfig config SATA_XGENE_PHY · line 119

Quoted 5 lines
drivers/ata/Kconfig +5 -0
+config SATA_XGENE
+     tristate "APM X-Gene 6.0Gbps SATA host controller support"
+     depends on SATA_AHCI_PLATFORM
+     default y if ARM64
+     select SATA_XGENE_PHY

I don't think the "default y" is appropriate here, since there are going to be lots of ARM64 platforms in the long run that don't have this. Also, there is a trend towards using CONFIG_COMPILE_TEST to limit the visibility.

Quoted 7 lines

I'd suggest something like

config SATA_XGENE

        tristate "APM X-Gene 6.0Gbps SATA host controller support"
        depends on ARM64 || COMPILE_TEST
        ...

[Loc Ho]
Okay. How about this?

depends on ARM64 || COMPILE_TEST
select SATA_XGENE_PHY && SATA_AHCI_PLATFORM

Quoted 4 lines

drivers/ata/sata_xgene.c line 33

Quoted 2 lines
drivers/ata/sata_xgene.c new file +2 -0
+/* Enable for dumping CSR read/write access */
+#undef XGENE_DBG_CSR

This should be removed now as well, along with the debug macro you already removed.

[Loc Ho]
This is very useful if one running into problem - one can enable all CSR dump. I would like to keep this around for the time being.

Quoted 8 lines

drivers/ata/sata_xgene.c line 96

Quoted 5 lines
drivers/ata/sata_xgene.c new file +4 -0
+
+/* Temporary function until the PHY parameter API */
+extern void xgene_ahci_phy_set_pq(struct phy *phy, int chan, int data);
+extern void xgene_ahci_phy_set_spd(struct phy *phy, int chan, int gen);

Ah, that should have been mentioned in the changeset text. Do you think you can remove these for the final version?

[Loc Ho]
Yes... Krishon, can you provide an patch that allows me to accommodate this? Or should I come up one? I will trying to get rip of the first one. But I will need the function to set the PHY speed - for Gen2/Gen1. Let's plan on add these function:

a. int (*set_speed)(int gen_speed) where gen_speed is either AUTO, GEN1, GEN2, or GEN3.
b. Change the PHY init function to take an optional parameter. This would help my first function in case I can get rip of it.

Quoted 12 lines

drivers/ata/sata_xgene.c line 104

Quoted 8 lines
drivers/ata/sata_xgene.c new file +7 -0
+static void xgene_rd(void *addr, u32 *val)
+{
+     *val = readl(addr);
+#if defined(XGENE_DBG_CSR)
+     printk(KERN_DEBUG "SATAPHY CSR RD: 0x%p value: 0x%08x\n", addr, *val);
+#endif
+}

The interface you are looking for is pr_debug() or dev_dbg(), which get built-in only if the DEBUG macro is set.

Quoted 8 lines

In a lot of cases, it's actually best to remove debug output like this from the driver once you have it working -- whoever is debugging problems in the driver next might need completely different debugging information or can add them back easily if needed.

It's your choice if you want to use pr_debug() or remove that output entirely. If you remove it, best remove the helper functions entirely and use readl/writel directly.

[Loc Ho]
I would like to keep this function for now until this driver actual being used in production. I will use pr_debug.

Quoted 27 lines
Quoted 5 lines
drivers/ata/sata_xgene.c new file +4 -0
+/* Flush the IOB to ensure all SATA controller writes completed before
+   servicing the completed command. */
+static int xgene_ahci_iob_flush(struct xgene_ahci_context *ctx)
+{

drivers/ata/sata_xgene.c line 470

Quoted 10 lines
drivers/ata/sata_xgene.c new file +10 -0
+     if (ctx->ahbc_io_base == NULL) {
+             void *ahbc_base;
+             u32 val;
+
+             /* The AHBC address is fixed in X-Gene */
+             ahbc_base = devm_ioremap(ctx->dev, 0x1F2A0000, 0x80000);
+             if (!ahbc_base) {
+                     dev_err(ctx->dev, "can't map AHBC resource\n");
+                     return -ENODEV;
+             }

I had an important comment about the misuse of hardcoded I/O addresses here. Please never just post a new version with the same issue. In general, your options are:

* rewrite the code in a more appropriate way
* reply to the comment, arguing why you think your code is correct
* ask for clarification if you don't know how to improve the code
* mark the code as TODO and mention in the patch description why you are still working on this and that the current version should not be seen as final.

Quoted 2 lines

If you don't do any of these, reviewers will get annoyed because you are wasting their time.

[Loc Ho]
Sorry about this one. I will add this to the DTS. If this resource isn't available, then it will be nop.

Quoted 13 lines
Quoted 13 lines
drivers/ata/sata_xgene.c new file +13 -0
+
+static int xgene_ahci_get_u32_param(struct platform_device *pdev,
+                                 const char *of_name, char *acpi_name,
+                                 u32 *param)
+{
+#ifdef CONFIG_ACPI
+     if (efi_enabled(EFI_BOOT)) {
+             unsigned long long value;
+             acpi_status status;
+             if (acpi_name == NULL)
+                     return -ENODEV;
+             status = acpi_evaluate_integer(ACPI_HANDLE(&pdev->dev),
+                                            acpi_name, NULL, &value);
Quoted 8 lines

drivers/ata/sata_xgene.c line 905

Quoted 6 lines
drivers/ata/sata_xgene.c new file +6 -0
+             if (ACPI_FAILURE(status))
+                     return -ENODEV;
+             *param = value;
+             return 0;
+     }
+#endif

There are more previous comments that you have not addressed yet.

[Loc Ho]
Original, I didn't want to get rip of this as ACPI isn't available in the 3.12 kernel yet. I will get rip of this as I don't need the ID any more. Also, I will also get rip of the clock interface. Don't need this as it is handled directly by the driver. This will address for DT as well as ACPI.

Quoted 9 lines

drivers/ata/sata_xgene.h

Quoted 6 lines
drivers/ata/sata_xgene.h new file +0 -0
new file mode 100644
index 0000000..51e73f6

This file should probably just be folded into the driver, since it contains no interfaces between modules, just internal definitions.

[Loc Ho]
I can get rip this header file now. But in the future I may need to add this back as I intended this driver to also support running from our co-processor (ARMv7 32-bit). For that, I will need anothe file and other function that will need knowledge of the context structure and etc.

-Loc

author
#7 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

Hi Kishon,

Quoted 13 lines
Quoted 7 lines

drivers/ata/sata_xgene.c line 96

Quoted 4 lines
drivers/ata/sata_xgene.c new file +4 -0
+
+/* Temporary function until the PHY parameter API */
+extern void xgene_ahci_phy_set_pq(struct phy *phy, int chan, int data);
+extern void xgene_ahci_phy_set_spd(struct phy *phy, int chan, int gen);

Ah, that should have been mentioned in the changeset text. Do you think you can remove these for the final version?

[Loc Ho]
Yes... Krishon, can you provide an patch that allows me to accommodate this? Or should I come up one? I will trying to get rip of the first one. But I will need the function to set the PHY speed - for Gen2/Gen1. Let's plan on add these function:

Quoted 5 lines

a. int (*set_speed)(int gen_speed) where gen_speed is either AUTO, GEN1, GEN2, or GEN3.
b. Change the PHY init function to take an optional parameter. This would help my first function in case I can get rip of it.

[Loc Ho]
I will provide this patch as part of my next version to include an function as follow:

int set_speed(struct *phy, int lane, u64 speed);

where lane indicates the lane of the PHY and speed is the PHY speed in hertz.

-Loc

#8 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

Hi,

Quoted 15 lines · Loc Ho

Hi Kishon,

Quoted 13 lines
Quoted 7 lines

drivers/ata/sata_xgene.c line 96

Quoted 4 lines
drivers/ata/sata_xgene.c new file +4 -0
+
+/* Temporary function until the PHY parameter API */
+extern void xgene_ahci_phy_set_pq(struct phy *phy, int chan, int data);
+extern void xgene_ahci_phy_set_spd(struct phy *phy, int chan, int gen);

Ah, that should have been mentioned in the changeset text. Do you think you can remove these for the final version?

[Loc Ho]
Yes... Krishon, can you provide an patch that allows me to accommodate this? Or should I come up one? I will trying to get rip of the first one. But I will need the function to set the PHY speed - for Gen2/Gen1. Let's plan on add these function:

Quoted 8 lines
Quoted 5 lines

a. int (*set_speed)(int gen_speed) where gen_speed is either AUTO, GEN1, GEN2, or GEN3.
b. Change the PHY init function to take an optional parameter. This would help my first function in case I can get rip of it.

[Loc Ho]
I will provide this patch as part of my next version to include an function as follow:

sure..

Quoted 2 lines

int set_speed(struct *phy, int lane, u64 speed);

it should be phy_set_speed.

Quoted 2 lines

where lane indicates the lane of the PHY and speed is the PHY speed in hertz.

Does lane here means the number of lanes? Is the lane also obtained after the training sequence?

Thanks
Kishon

author
#9 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

Hi,

Quoted 3 lines
Quoted 1 line

int set_speed(struct *phy, int lane, u64 speed);

it should be phy_set_speed.

[Loc Ho]
But your other functions don't repeat the prefix "phy"?

Quoted 5 lines
Quoted 2 lines

where lane indicates the lane of the PHY and speed is the PHY speed in hertz.

Does lane here means the number of lanes? Is the lane also obtained after the training sequence?

[Loc Ho]
Lane here is the lane with you are changing the speed. If there are two lanes, then 0 parameter would change lane 0. 1 would change lane 1.

-Loc

#10 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

Quoted 7 lines · Loc Ho

Hi,

Quoted 3 lines
Quoted 1 line

int set_speed(struct *phy, int lane, u64 speed);

it should be phy_set_speed.

[Loc Ho]
But your other functions don't repeat the prefix "phy"?

refer include/linux/phy/phy.h..

int phy_init(struct phy *phy); int phy_exit(struct phy *phy); int phy_power_on(struct phy *phy); int phy_power_off(struct phy *phy);

??

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

where lane indicates the lane of the PHY and speed is the PHY speed in hertz.

Does lane here means the number of lanes? Is the lane also obtained after the training sequence?

[Loc Ho]
Lane here is the lane with you are changing the speed. If there are two lanes, then 0 parameter would change lane 0. 1 would change lane 1.

can different lanes operate at different speed at the same time?

Thanks
Kishon

author
#11 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

Hi,

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

int set_speed(struct *phy, int lane, u64 speed);

it should be phy_set_speed.

[Loc Ho]
But your other functions don't repeat the prefix "phy"?

Quoted 6 lines

refer include/linux/phy/phy.h..

int phy_init(struct phy *phy); int phy_exit(struct phy *phy); int phy_power_on(struct phy *phy); int phy_power_off(struct phy *phy);

[Loc Ho]
For the top level function, it is phy_set_speed. For the operation function pointer, it is set_speed.

Quoted 12 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

where lane indicates the lane of the PHY and speed is the PHY speed in hertz.

Does lane here means the number of lanes? Is the lane also obtained after the training sequence?

[Loc Ho]
Lane here is the lane with you are changing the speed. If there are two lanes, then 0 parameter would change lane 0. 1 would change lane 1.

can different lanes operate at different speed at the same time?

[Loc Ho]
Yes. Each lane is suppose to be independent of each other.

-Loc

#12 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

In reply to Loc Ho
Quoted 11 lines · Loc Ho
Quoted 6 lines

config SATA_XGENE

        tristate "APM X-Gene 6.0Gbps SATA host controller support"
        depends on ARM64 || COMPILE_TEST
        ...

[Loc Ho]
Okay. How about this?

depends on ARM64 || COMPILE_TEST
select SATA_XGENE_PHY && SATA_AHCI_PLATFORM

I think you already found the mistake withis and corrected this in v4.

Quoted 8 lines
Quoted 8 lines

The interface you are looking for is pr_debug() or dev_dbg(), which get built-in only if the DEBUG macro is set.

In a lot of cases, it's actually best to remove debug output like this from the driver once you have it working -- whoever is debugging problems in the driver next might need completely different debugging information or can add them back easily if needed.

Quoted 6 lines
Quoted 3 lines

It's your choice if you want to use pr_debug() or remove that output entirely. If you remove it, best remove the helper functions entirely and use readl/writel directly.

[Loc Ho]
I would like to keep this function for now until this driver actual being used in production. I will use pr_debug.

Ok.

Quoted 8 lines
Quoted 8 lines

drivers/ata/sata_xgene.h

Quoted 5 lines
drivers/ata/sata_xgene.h new file +0 -0
new file mode 100644
index 0000000..51e73f6

This file should probably just be folded into the driver, since it contains no interfaces between modules, just internal definitions.

Quoted 6 lines

[Loc Ho]
I can get rip this header file now. But in the future I may need to add this back as I intended this driver to also support running from our co-processor (ARMv7 32-bit). For that, I will need anothe file and other function that will need knowledge of the context structure and etc.

Hmm, is the code for that coprocessor compiled from the kernel source? If not, it shouldn't really make a difference as it won't live in a shared code repository.

Arnd

author
#13 lore raw

PATCH v3 3/4 ata: Add APM X-Gene SoC SATA host controller driver

Hi,

Quoted 15 lines
Quoted 8 lines
Quoted 8 lines

drivers/ata/sata_xgene.h

Quoted 5 lines
drivers/ata/sata_xgene.h new file +0 -0
new file mode 100644
index 0000000..51e73f6

This file should probably just be folded into the driver, since it contains no interfaces between modules, just internal definitions.

Quoted 6 lines

[Loc Ho]
I can get rip this header file now. But in the future I may need to add this back as I intended this driver to also support running from our co-processor (ARMv7 32-bit). For that, I will need anothe file and other function that will need knowledge of the context structure and etc.

Quoted 4 lines

Hmm, is the code for that coprocessor compiled from the kernel source? If not, it shouldn't really make a difference as it won't live in a shared code repository.

[Loc Ho]
The co-processors are just ARM based core and the same kernel can be build to support it. Let's not worry about this yet.

-Loc

#14 lore raw

PATCH v3 2/4 Documentation: Add documentation for APM X-Gene SATA controllor DTS binding

In reply to Loc Ho

Documentation/devicetree/bindings/ata/apm-xgene.txt Example: · line 79

Quoted 7 lines · Loc Ho
Documentation/devicetree/bindings/ata/apm-xgene.txt +7 -0
+Required properties:
+- compatible           : Shall be "apm,xgene-ahci"
+- reg                  : First memory resource shall be the AHCI memory
+                         resource.
+                         Second memory resource shall be the host controller
+                         memory resource.
+- id                   : Controller ID (0 = first, 1 = second, 2 = third)

As in the PHY patch, it's probably best to drop the "id" property here and describe the actual differences between the instances directly, either by having distinct "compatible" properties for each model, or by adding binary flags to tell about a capability that only some instances have.

Also, I think you should have a separate file for the sata binding, especially since the PHY binding is not actually specific to SATA at all.

Aside from these, the binding looks good to me now.

Arnd