Skip to contentSkip to conversation

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

PATCH Superseded Loc Ho 2 participants 10 messages Jan 3, 2014

Subsystems (3)

v7 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Loc Ho

author
#0 lore raw

v7 cover 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 PHY driver musts also be available.

v7:
* Update the clock code by toggle the clock
* Update the DTS clock mask values due to the clock spilt between host and v5 of the PHY drivers

v6:
* Update binding documentation
* Change select PHY_XGENE_SATA to PHY_XGENE
* Add ULL to constants
* Change indentation and comments
* Clean up the probe functions a bit more
* Remove xgene_ahci_remove function
* Add the flush register to DTS
* Remove the interrupt-parent from DTS

v5:
* Sync up to v3 of the PHY driver
* Remove MSLIM wrapper functions
* Change the memory shutdown loop to use usleep_range
* Use devm_ioremap_resource instead devm_ioremap
* Remove suspend/resume functions as not needed

v4:
* Remove the ID property in DT
* Remove the temporary PHY direct function call and use PHY function
* Change printk to pr_debug
* Move the IOB flush addresses into the DT
* Remove the parameters retrieval function as no longer needed
* Remove the header file as no longer needed
* Require v2 patch of the SATA PHY driver. Require slightly modification in the Kconfig as it is moved to folder driver/phy and use Kconfig PHY_XGENE_SATA instead SATA_XGENE_PHY.

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 SoC SATA host
controller 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          |   68 ++
 arch/arm64/boot/dts/apm-storm.dtsi                 |   81 ++
 drivers/ata/Kconfig                                |    8 +
 drivers/ata/Makefile                               |    1 +
 drivers/ata/ahci.h                                 |    9 +
 drivers/ata/libahci.c                              |   16 +-
 drivers/ata/sata_xgene.c                           | 1071 ++++++++++++++++++++
 7 files changed, 1248 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/ata/apm-xgene.txt
 create mode 100644 drivers/ata/sata_xgene.c
author
#1 lore raw

PATCH v7 1/4 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    |    9 +++++++++
 drivers/ata/libahci.c |   16 ++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)
drivers/ata/ahci.h +9 -0
index 2289efd..8163b59 100644
@@ -370,6 +370,15 @@ 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_error_handler(struct ata_port *ap);
+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);
+void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
+                        u32 opts);
+unsigned int ahci_fill_sg(struct ata_queued_cmd *qc, void *cmd_tbl);
 
 static inline void __iomem *__ahci_port_base(struct ata_host *host,
 					     unsigned int port_no)
drivers/ata/libahci.c +10 -6
index c482f8c..1d24bf5 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,
@@ -1472,7 +1474,7 @@ static void ahci_postreset(struct ata_link *link, unsigned int *class)
 	}
 }
 
-static unsigned int ahci_fill_sg(struct ata_queued_cmd *qc, void *cmd_tbl)
+unsigned int ahci_fill_sg(struct ata_queued_cmd *qc, void *cmd_tbl)
 {
 	struct scatterlist *sg;
 	struct ahci_sg *ahci_sg = cmd_tbl + AHCI_CMD_TBL_HDR_SZ;
@@ -1494,6 +1496,7 @@ static unsigned int ahci_fill_sg(struct ata_queued_cmd *qc, void *cmd_tbl)
 
 	return si;
 }
+EXPORT_SYMBOL_GPL(ahci_fill_sg);
 
 static int ahci_pmp_qc_defer(struct ata_queued_cmd *qc)
 {
@@ -1568,7 +1571,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;
@@ -1678,6 +1681,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 v7 2/4 Documentation: Add documentation for APM X-Gene SoC SATA host controller DTS binding

---
 .../devicetree/bindings/ata/apm-xgene.txt          |   68 ++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/ata/apm-xgene.txt
Documentation/devicetree/bindings/ata/apm-xgene.txt new file +68 -0
new file mode 100644
index 0000000..3d1421a
@@ -0,0 +1,68 @@
+* APM X-Gene 6.0 Gb/s SATA host controller nodes
+
+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-sgmii" if mux'ed with SGMII
+			  or "apm,xgene-ahci-pcie" if mux'ed with PCIe.
+- reg			: First memory resource shall be the AHCI memory
+			  resource.
+			  Second memory resource shall be the host controller
+			  memory resource.
+- interrupts		: Interrupt mapping for SATA host controller IRQ.
+- clocks		: Reference to the clock entry.
+- phys			: PHY reference with parameter 0.
+- phy-names		: Name of the PHY. Shall be "sata-6g".
+
+Optional properties:
+- status		: Shall be "ok" if enabled or "disabled" if disabled.
+			  Default is "ok".
+- interrupt-parent	: Interrupt controller.
+
+Example:
+		sataclk: sataclk {
+			compatible = "fixed-clock";
+			#clock-cells = <1>;
+			clock-frequency = <100000000>;
+			clock-output-names = "sataclk";
+		};
+
+		phy2: phy at 1f22a000 {
+			compatible = "apm,xgene-phy";
+			reg = <0x0 0x1f22a000 0x0 0x100>,
+			      <0x0 0x1f22c000 0x0 0x100>;
+			#phy-cells = <1>;
+		};
+
+		phy3: phy at 1f23a000 {
+			compatible = "apm,xgene-phy-ext";
+			reg = <0x0 0x1f23a000 0x0 0x100>,
+			      <0x0 0x1f23c000 0x0 0x100>,
+			      <0x0 0x1f2d0000 0x0 0x100>;
+			#phy-cells = <1>;
+		};
+
+		sata2: sata at 1a400000 {
+			compatible = "apm,xgene-ahci-sgmii";
+			reg = <0x0 0x1a400000 0x0 0x1000>,
+			      <0x0 0x1f220000 0x0 0x10000>;
+			interrupt-parent = <&gic>;
+			interrupts = <0x0 0x87 0x4>;
+			status = "ok";
+			clocks = <&sataclk 0>;
+			phys = <&phy2 0>;
+			phy-names = "sata-6g";
+		};
+
+		sata3: sata at 1a800000 {
+			compatible = "apm,xgene-ahci-pcie";
+			reg = <0x0 0x1a800000 0x0 0x1000>,
+			      <0x0 0x1f230000 0x0 0x10000>;
+			interrupt-parent = <&gic>;
+			interrupts = <0x0 0x88 0x4>;
+			status = "ok";
+			clocks = <&sataclk 0>;
+			phys = <&phy3 0>;
+			phy-names = "sata-6g";
+		};
Signature · 1 line
1.5.5
author
#3 lore raw

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

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

---
 drivers/ata/Kconfig      |    8 +
 drivers/ata/Makefile     |    1 +
 drivers/ata/sata_xgene.c | 1071 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1080 insertions(+), 0 deletions(-)
 create mode 100644 drivers/ata/sata_xgene.c
drivers/ata/Kconfig +8 -0
index 4e73772..cd1bc3c 100644
@@ -106,6 +106,14 @@ config AHCI_IMX
 
 	  If unsure, say N.
 
+config SATA_XGENE
+	tristate "APM X-Gene 6.0Gbps SATA host controller support"
+	depends on ARM64 || COMPILE_TEST
+	select SATA_AHCI_PLATFORM
+	select PHY_XGENE
+	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 46518c6..1c0fabe 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_SATA_SIL24)	+= sata_sil24.o
 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)	+= sata_xgene.o
 
 # SFF w/ custom DMA
 obj-$(CONFIG_PDC_ADMA)		+= pdc_adma.o
drivers/ata/sata_xgene.c new file +1071 -0

1,071 lines not on this page · raw message

Signature · 1 line
1.5.5
author
#4 lore raw

PATCH v7 4/4 arm64: Add APM X-Gene SoC SATA host controller DTS entries

---
 arch/arm64/boot/dts/apm-storm.dtsi |   81 ++++++++++++++++++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)
arch/arm64/boot/dts/apm-storm.dtsi +81 -0
index fd2b662..5b09797 100644
@@ -218,6 +218,48 @@
 				enable-offset = <0x0>;
 				enable-mask = <0x06>;
 			};
+
+			sata01clk: sata01clk at 1f21c000 {
+				compatible = "apm,xgene-device-clock";
+				#clock-cells = <1>;
+				clocks = <&socplldiv2 0>;
+				clock-names = "sata01clk";
+				reg = <0x0 0x1f21c000 0x0 0x1000>;
+				reg-names = "csr-reg";
+				clock-output-names = "sata01clk";
+				csr-offset = <0x4>;
+				csr-mask = <0x05>;
+				enable-offset = <0x0>;
+				enable-mask = <0x39>;
+			};
+
+			sata23clk: sata23clk at 1f22c000 {
+				compatible = "apm,xgene-device-clock";
+				#clock-cells = <1>;
+				clocks = <&socplldiv2 0>;
+				clock-names = "sata23clk";
+				reg = <0x0 0x1f22c000 0x0 0x1000>;
+				reg-names = "csr-reg";
+				clock-output-names = "sata23clk";
+				csr-offset = <0x4>;
+				csr-mask = <0x05>;
+				enable-offset = <0x0>;
+				enable-mask = <0x39>;
+			};
+
+			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";
+				csr-offset = <0x4>;
+				csr-mask = <0x05>;
+				enable-offset = <0x0>;
+				enable-mask = <0x39>;
+			};
 		};
 
 		serial0: serial at 1c020000 {
@@ -266,5 +308,44 @@
 			apm,tx-boost-gain = <2 3 3 2 3 3>;
 			apm,tx-eye-tuning = <2 10 10 2 10 12>;
 		};
+
+		sata1: sata at 1a000000 {
+			compatible = "apm,xgene-ahci-sgmii";
+			reg = <0x0 0x1a000000 0x0 0x1000>,
+			      <0x0 0x1f210000 0x0 0x10000>,
+			      <0x0 0x1f2a0000 0x0 0x10000>,
+			      <0x0 0x1c000200 0x0 0x100>;
+			interrupts = <0x0 0x86 0x4>;
+			status = "disabled";
+			clocks = <&sata01clk 0>;
+			phys = <&phy1 0>;
+			phy-names = "sata-6g";
+		};
+
+		sata2: sata at 1a400000 {
+			compatible = "apm,xgene-ahci-sgmii";
+			reg = <0x0 0x1a400000 0x0 0x1000>,
+			      <0x0 0x1f220000 0x0 0x10000>,
+			      <0x0 0x1f2a0000 0x0 0x10000>,
+			      <0x0 0x1c000200 0x0 0x100>;
+			interrupts = <0x0 0x87 0x4>;
+			status = "ok";
+			clocks = <&sata23clk 0>;
+			phys = <&phy2 0>;
+			phy-names = "sata-6g";
+		};
+
+		sata3: sata at 1a800000 {
+			compatible = "apm,xgene-ahci-pcie";
+			reg = <0x0 0x1a800000 0x0 0x1000>,
+			      <0x0 0x1f230000 0x0 0x10000>,
+			      <0x0 0x1f2a0000 0x0 0x10000>,
+			      <0x0 0x1c000200 0x0 0x100>;
+			interrupts = <0x0 0x88 0x4>;
+			status = "ok";
+			clocks = <&sata45clk 0>;
+			phys = <&phy3 0>;
+			phy-names = "sata-6g";
+		};
 	};
 };
Signature · 1 line
1.5.5
#5 lore raw

PATCH v7 4/4 arm64: Add APM X-Gene SoC SATA host controller DTS entries

arch/arm64/boot/dts/apm-storm.dtsi line 254

Quoted 13 lines · Loc Ho
arch/arm64/boot/dts/apm-storm.dtsi +12 -0
+                       sata23clk: sata23clk at 1f22c000 {
+                               compatible = "apm,xgene-device-clock";
+                               #clock-cells = <1>;
+                               clocks = <&socplldiv2 0>;
+                               clock-names = "sata23clk";
 
+                       };
+
+                       sata45clk: sata45clk at 1f23c000 {
+                               compatible = "apm,xgene-device-clock";
+                               #clock-cells = <1>;
+                               clocks = <&socplldiv2 0>;
+                               clock-names = "sata45clk";

Something is wrong here: You have two devices with the same "compatible" string but using different "clock-names" strings. The binding document lists this as an optional property with the description "shall be the name of the device clock. If missing, use the device name", which doesn't seem to make any sense.

Please fix the binding and the existing users of this, and don't introduce any more broken instances. Since each device clock is documented to have only one parent anyway, please just make it an anonymous clock.

Arnd

author
#6 lore raw

PATCH v7 4/4 arm64: Add APM X-Gene SoC SATA host controller DTS entries

Hi,

Quoted 20 lines

arch/arm64/boot/dts/apm-storm.dtsi line 254

Quoted 13 lines
arch/arm64/boot/dts/apm-storm.dtsi +12 -0
+                       sata23clk: sata23clk at 1f22c000 {
+                               compatible = "apm,xgene-device-clock";
+                               #clock-cells = <1>;
+                               clocks = <&socplldiv2 0>;
+                               clock-names = "sata23clk";
 
+                       };
+
+                       sata45clk: sata45clk at 1f23c000 {
+                               compatible = "apm,xgene-device-clock";
+                               #clock-cells = <1>;
+                               clocks = <&socplldiv2 0>;
+                               clock-names = "sata45clk";

Something is wrong here: You have two devices with the same "compatible" string but using different "clock-names" strings. The binding document lists this as an optional property with the description "shall be the name of the device clock. If missing, use the device name", which doesn't seem to make any sense.

Quoted 3 lines

Please fix the binding and the existing users of this, and don't introduce any more broken instances. Since each device clock is documented to have only one parent anyway, please just make it an anonymous clock.

Okay I miss understood this... I will need to fix the X-Gene device parent clocks as well in an separate patch to the clock driver owner.

-Loc

#7 lore raw

PATCH v7 4/4 arm64: Add APM X-Gene SoC SATA host controller DTS entries

Quoted 2 lines · Loc Ho

Okay I miss understood this... I will need to fix the X-Gene device parent clocks as well in an separate patch to the clock driver owner.

Ok, thanks!

Arnd

#8 lore raw

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

In reply to Loc Ho

drivers/ata/sata_xgene.c line 36

Quoted 6 lines · Loc Ho
drivers/ata/sata_xgene.c new file +6 -0
+
+/* Controller who PHY shared with SGMII Ethernet PHY */
+#define XGENE_AHCI_SGMII_DTS		"apm,xgene-ahci-sgmii"
+
+/* Controller who PHY (internal reference clock macro) shared with PCIe */
+#define XGENE_AHCI_PCIE_DTS		"apm,xgene-ahci-pcie"

Kill these macros. I've commented on this in the past.

Also, there really shouldn't be any difference to the SATA driver based on what PHY is used, so the strings shouldn't be different either.

drivers/ata/sata_xgene.c line 58

Quoted 6 lines
drivers/ata/sata_xgene.c new file +6 -0
+/* SATA host controller CSR */
+#define SLVRDERRATTRIBUTES_ADDR		0x00000000
+#define SLVWRERRATTRIBUTES_ADDR		0x00000004
+#define MSTRDERRATTRIBUTES_ADDR		0x00000008
+#define MSTWRERRATTRIBUTES_ADDR		0x0000000c
+#define BUSCTLREG_ADDR			0x00000014

Are these strings taken literally from the data sheet? You can probably drop the _ADDR part.

drivers/ata/sata_xgene.c line 62

Quoted 4 lines
drivers/ata/sata_xgene.c new file +4 -0
+#define  MSTAWAUX_COHERENT_BYPASS_SET(dst, src) \
+		(((dst) & ~0x00000002) | (((u32)(src)<<1) & 0x00000002))
+#define  MSTARAUX_COHERENT_BYPASS_SET(dst, src) \
+		(((dst) & ~0x00000001) | (((u32)(src)) & 0x00000001))

The macros are only used once and don't really help readability. Just open-code them. If you have complex macros like these and use them multiple times, it may be better to use an inline function.

Quoted 28 lines
drivers/ata/sata_xgene.c new file +28 -0
+static void xgene_ahci_enable_phy(struct xgene_ahci_context *ctx,
+				  int channel, int enable)
+{
+	void *mmio = ctx->mmio_base;
+	u32 val;
+
+	xgene_rd(mmio + PORTCFG_ADDR, &val);
+	val = PORTADDR_SET(val, channel == 0 ? 2 : 3);
+	xgene_wr_flush(mmio + PORTCFG_ADDR, val);
+	xgene_rd(mmio + PORTPHY1CFG_ADDR, &val);
+	val = PORTPHY1CFG_FRCPHYRDY_SET(val, enable);
+	xgene_wr(mmio + PORTPHY1CFG_ADDR, val);
+}
+
+static void xgene_ahci_set_phy_cfg(struct xgene_ahci_context *ctx, int channel)
+{
+	void *mmio = ctx->mmio_base;
+	u32 val;
+
+	dev_dbg(ctx->dev, "port configure mmio 0x%p channel %d\n",
+		mmio, channel);
+	xgene_rd(mmio + PORTCFG_ADDR, &val);
+	val = PORTADDR_SET(val, channel == 0 ? 2 : 3);
+	xgene_wr_flush(mmio + PORTCFG_ADDR, val);
+	/* Disable fix rate */
+	xgene_wr_flush(mmio + PORTPHY1CFG_ADDR, 0x0001fffe);
+	xgene_wr_flush(mmio + PORTPHY2CFG_ADDR, 0x5018461c);
+	xgene_wr_flush(mmio + PORTPHY3CFG_ADDR, 0x1c081907);

drivers/ata/sata_xgene.c line 295

Quoted 10 lines
drivers/ata/sata_xgene.c new file +10 -0
+	xgene_wr_flush(mmio + PORTPHY4CFG_ADDR, 0x1c080815);
+	xgene_rd(mmio + PORTPHY5CFG_ADDR, &val);
+	/* Window negotiation 0x800 to 0x400 */
+	val = PORTPHY5CFG_RTCHG_SET(val, 0x300);
+	xgene_wr_flush(mmio + PORTPHY5CFG_ADDR, val);
+	xgene_rd(mmio + PORTAXICFG_ADDR, &val);
+	val = PORTAXICFG_EN_CONTEXT_SET(val, 0x1); /* enable context mgmt */
+	val = PORTAXICFG_OUTTRANS_SET(val, 0xe); /* Outstanding */
+	xgene_wr_flush(mmio + PORTAXICFG_ADDR, val);
+}

This looks like it should be part of the PHY driver?

drivers/ata/sata_xgene.c line 844

Quoted 7 lines
drivers/ata/sata_xgene.c new file +7 -0
+	/*
+	 * When both ACPI and DTS are enabled, custom ACPI built-in ACPI
+	 * table, and booting via DTS, we need to skip the probe of the
+	 * built-in ACPI table probe.
+	 */
+	if (!efi_enabled(EFI_BOOT) && dev->of_node == NULL)
+		return -ENODEV;

I think I've commented on this one before too. The comment talks about ACPI, but the code is about EFI, which is completely unrelated. Neither the code nor the comment seems to make sense here and you wouldn't be in this function in the first place if the device is not defined in ACPI or in DT.

drivers/ata/sata_xgene.c line 879

Quoted 6 lines
drivers/ata/sata_xgene.c new file +6 -0
+	/* Can't use devm_ioremap_resource due to overlapping region */
+	hpriv->csr_base = devm_ioremap(dev, res->start, resource_size(res));
+	if (!hpriv->csr_base) {
+		dev_err(dev, "can't map %pR\n", res);
+		return -ENOMEM;
+	}

Why are the regions overlapping? That should not happen!

drivers/ata/sata_xgene.c line 926

Quoted 8 lines
drivers/ata/sata_xgene.c new file +8 -0
+	/* Select ATA */
+	if (of_device_is_compatible(pdev->dev.of_node,
+		XGENE_AHCI_SGMII_DTS)) {
+		if (xgene_ahci_mux_select(hpriv)) {
+			dev_err(dev, "SATA mux selection failed\n");
+			return -ENODEV;
+		}
+	}

What kind of mux is this? Why does the SATA driver need to care about it? It sounds like this should be part of the pinctrl driver.

drivers/ata/sata_xgene.c line 1029

Quoted 11 lines
drivers/ata/sata_xgene.c new file +11 -0
+	/* Setup DMA mask */
+	rc = dma_set_mask(dev, DMA_BIT_MASK(64));
+	if (rc) {
+		dev_err(dev, "Unable to set dma mask\n");
+		goto error;
+	}
+	rc = dma_set_coherent_mask(dev, DMA_BIT_MASK(64));
+	if (rc) {
+		dev_err(dev, "Unable to set dma coherent mask\n");
+		goto error;
+	}

dma_set_mask_and_coherent?

drivers/ata/sata_xgene.c line 1047

Quoted 6 lines
drivers/ata/sata_xgene.c new file +6 -0
+
+static const struct acpi_device_id xgene_ahci_acpi_match[] = {
+	{"APMC0D00", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(acpi, xgene_ahci_acpi_match);

Just drop the ACPI part for now. It's clear that the driver won't work with ACPI in this state, since it would need to handle the PHY and clock management completely differently. It's better to add the code once it has a chance to actually work.

Arnd

author
#9 lore raw

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

Hi,

Quoted 11 lines

drivers/ata/sata_xgene.c line 36

Quoted 5 lines
drivers/ata/sata_xgene.c new file +5 -0
+/* Controller who PHY shared with SGMII Ethernet PHY */
+#define XGENE_AHCI_SGMII_DTS         "apm,xgene-ahci-sgmii"
+
+/* Controller who PHY (internal reference clock macro) shared with PCIe */
+#define XGENE_AHCI_PCIE_DTS          "apm,xgene-ahci-pcie"

Kill these macros. I've commented on this in the past.

Also, there really shouldn't be any difference to the SATA driver based on what PHY is used, so the strings shouldn't be different either.

The only need for this is the MUX when the PHY is shared between SGMII and SATA. If we get rip of the MUX code, we can drop this. MUX discussion is below.

Quoted 10 lines

drivers/ata/sata_xgene.c line 58

Quoted 7 lines
drivers/ata/sata_xgene.c new file +6 -0
+/* SATA host controller CSR */
+#define SLVRDERRATTRIBUTES_ADDR              0x00000000
+#define SLVWRERRATTRIBUTES_ADDR              0x00000004
+#define MSTRDERRATTRIBUTES_ADDR              0x00000008
+#define MSTWRERRATTRIBUTES_ADDR              0x0000000c
+#define BUSCTLREG_ADDR                       0x00000014

Are these strings taken literally from the data sheet? You can probably drop the _ADDR part.

These names are directly from the programming reference manual. I will get rip of the _ADDR for both drivers - host and PHY.

Quoted 10 lines

drivers/ata/sata_xgene.c line 62

Quoted 5 lines
drivers/ata/sata_xgene.c new file +4 -0
+#define  MSTAWAUX_COHERENT_BYPASS_SET(dst, src) \
+             (((dst) & ~0x00000002) | (((u32)(src)<<1) & 0x00000002))
+#define  MSTARAUX_COHERENT_BYPASS_SET(dst, src) \
+             (((dst) & ~0x00000001) | (((u32)(src)) & 0x00000001))

The macros are only used once and don't really help readability. Just open-code them. If you have complex macros like these and use them multiple times, it may be better to use an inline function.

For these particular one, I will get rip of them.

Quoted 33 lines
Quoted 33 lines
drivers/ata/sata_xgene.c new file +32 -0
+static void xgene_ahci_enable_phy(struct xgene_ahci_context *ctx,
+                               int channel, int enable)
+{
+     void *mmio = ctx->mmio_base;
+     u32 val;
+
+     xgene_rd(mmio + PORTCFG_ADDR, &val);
+     val = PORTADDR_SET(val, channel == 0 ? 2 : 3);
+     xgene_wr_flush(mmio + PORTCFG_ADDR, val);
+     xgene_rd(mmio + PORTPHY1CFG_ADDR, &val);
+     val = PORTPHY1CFG_FRCPHYRDY_SET(val, enable);
+     xgene_wr(mmio + PORTPHY1CFG_ADDR, val);
+}
+
+static void xgene_ahci_set_phy_cfg(struct xgene_ahci_context *ctx, int channel)
+{
+     void *mmio = ctx->mmio_base;
+     u32 val;
+
+     dev_dbg(ctx->dev, "port configure mmio 0x%p channel %d\n",
+             mmio, channel);
+     xgene_rd(mmio + PORTCFG_ADDR, &val);
+     val = PORTADDR_SET(val, channel == 0 ? 2 : 3);
+     xgene_wr_flush(mmio + PORTCFG_ADDR, val);
+     /* Disable fix rate */
+     xgene_wr_flush(mmio + PORTPHY1CFG_ADDR, 0x0001fffe);
+     xgene_wr_flush(mmio + PORTPHY2CFG_ADDR, 0x5018461c);
+     xgene_wr_flush(mmio + PORTPHY3CFG_ADDR, 0x1c081907);
+     xgene_wr_flush(mmio + PORTPHY4CFG_ADDR, 0x1c080815);
+     xgene_rd(mmio + PORTPHY5CFG_ADDR, &val);
+     /* Window negotiation 0x800 to 0x400 */
+     val = PORTPHY5CFG_RTCHG_SET(val, 0x300);
Quoted 8 lines

drivers/ata/sata_xgene.c line 295

Quoted 6 lines
drivers/ata/sata_xgene.c new file +6 -0
+     xgene_wr_flush(mmio + PORTPHY5CFG_ADDR, val);
+     xgene_rd(mmio + PORTAXICFG_ADDR, &val);
+     val = PORTAXICFG_EN_CONTEXT_SET(val, 0x1); /* enable context mgmt */
+     val = PORTAXICFG_OUTTRANS_SET(val, 0xe); /* Outstanding */
+     xgene_wr_flush(mmio + PORTAXICFG_ADDR, val);
+}

This looks like it should be part of the PHY driver?

There are the corresponding configure on the host controller side. It is not part of the PHY. Each host such as SATA, SGMII, or PCIe has its own version of these registers. It can be completely different between SATA and PCIe for example.

Quoted 9 lines

drivers/ata/sata_xgene.c line 844

Quoted 8 lines
drivers/ata/sata_xgene.c new file +7 -0
+     /*
+      * When both ACPI and DTS are enabled, custom ACPI built-in ACPI
+      * table, and booting via DTS, we need to skip the probe of the
+      * built-in ACPI table probe.
+      */
+     if (!efi_enabled(EFI_BOOT) && dev->of_node == NULL)
+             return -ENODEV;
Quoted 5 lines

I think I've commented on this one before too. The comment talks about ACPI, but the code is about EFI, which is completely unrelated. Neither the code nor the comment seems to make sense here and you wouldn't be in this function in the first place if the device is not defined in ACPI or in DT.

Let remove them for the time being. Unless one has an custom ACPI table built in the kernel, it isn't a problem.

Quoted 9 lines

drivers/ata/sata_xgene.c line 879

Quoted 7 lines
drivers/ata/sata_xgene.c new file +6 -0
+     /* Can't use devm_ioremap_resource due to overlapping region */
+     hpriv->csr_base = devm_ioremap(dev, res->start, resource_size(res));
+     if (!hpriv->csr_base) {
+             dev_err(dev, "can't map %pR\n", res);
+             return -ENOMEM;
+     }

Why are the regions overlapping? That should not happen!

Each host controller/PHY includes the following resource:

0xXXXX.0000 for the host core register 0xXXXX.7000 for the mux select if shared with SGMII 0xXXXX.A000 for the PHY indirect access 0xXXXX.C000 for the host/PHY clocks 0xXXXX.D000 for the RAM shutdown removal

As I only used one resource register of size 64K, it overlapped with the 0xXXXX.A000 mapped by the PHY already. If you believe it is better that I have two resources to map the host core/mux and the RAM shutdown removal resources, then ok. let me know.

Quoted 10 lines

drivers/ata/sata_xgene.c line 926

Quoted 9 lines
drivers/ata/sata_xgene.c new file +8 -0
+     /* Select ATA */
+     if (of_device_is_compatible(pdev->dev.of_node,
+             XGENE_AHCI_SGMII_DTS)) {
+             if (xgene_ahci_mux_select(hpriv)) {
+                     dev_err(dev, "SATA mux selection failed\n");
+                     return -ENODEV;
+             }
+     }
Quoted 2 lines

What kind of mux is this? Why does the SATA driver need to care about it? It sounds like this should be part of the pinctrl driver.

This is an internal mux that select either the SGMII or SATA. The default value is to select SGMII. Therefore, to enable SATA, it musts be cleared to 0. Are you suggesting that I write another driver to clear this register? It is an simple register writes - far too simple to worth an driver itself as it only applies to SATA.

Quoted 13 lines

drivers/ata/sata_xgene.c line 1029

Quoted 12 lines
drivers/ata/sata_xgene.c new file +11 -0
+     /* Setup DMA mask */
+     rc = dma_set_mask(dev, DMA_BIT_MASK(64));
+     if (rc) {
+             dev_err(dev, "Unable to set dma mask\n");
+             goto error;
+     }
+     rc = dma_set_coherent_mask(dev, DMA_BIT_MASK(64));
+     if (rc) {
+             dev_err(dev, "Unable to set dma coherent mask\n");
+             goto error;
+     }
Quoted 1 line

dma_set_mask_and_coherent?

okay.

Quoted 13 lines

drivers/ata/sata_xgene.c line 1047

Quoted 7 lines
drivers/ata/sata_xgene.c new file +6 -0
+
+static const struct acpi_device_id xgene_ahci_acpi_match[] = {
+     {"APMC0D00", 0},
+     {},
+};
+MODULE_DEVICE_TABLE(acpi, xgene_ahci_acpi_match);

Just drop the ACPI part for now. It's clear that the driver won't work with ACPI in this state, since it would need to handle the PHY and clock management completely differently. It's better to add the code once it has a chance to actually work.

Okay... I will remove all ACPI stuff for now.

-Loc