ath79: add support for ON Networks N150R
[openwrt/openwrt.git] / target / linux / mvebu / patches-4.14 / 530-ATA-ahci_mvebu-enable-stop_engine-override.patch
1 From fa89f53bd7288d6aa7a982841119e7123faf5a53 Mon Sep 17 00:00:00 2001
2 From: Evan Wang <xswang@marvell.com>
3 Date: Fri, 13 Apr 2018 12:32:30 +0800
4 Subject: [PATCH] libahci: Allow drivers to override stop_engine
5
6 Marvell armada37xx, armada7k and armada8k share the same
7 AHCI sata controller IP, and currently there is an issue
8 (Errata Ref#226)that the SATA can not be detected via SATA
9 Port-MultiPlayer(PMP). After debugging, the reason is
10 found that the value of Port-x FIS-based Switching Control
11 (PxFBS@0x40) became wrong.
12 According to design, the bits[11:8, 0] of register PxFBS
13 are cleared when Port Command and Status (0x18) bit[0]
14 changes its value from 1 to 0, i.e. falling edge of Port
15 Command and Status bit[0] sends PULSE that resets PxFBS
16 bits[11:8; 0].
17 So it needs save the port PxFBS register before PxCMD
18 ST write and restore the port PxFBS register afterwards
19 in ahci_stop_engine().
20
21 This commit allows drivers to override ahci_stop_engine
22 behavior for use by the Marvell AHCI driver(and potentially
23 other drivers in the future).
24
25 Signed-off-by: Evan Wang <xswang@marvell.com>
26 Cc: Ofer Heifetz <oferh@marvell.com>
27 Cc: Tejun Heo <tj@kernel.org>
28 Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
29 Signed-off-by: Tejun Heo <tj@kernel.org>
30 ---
31 drivers/ata/ahci.c | 6 +++---
32 drivers/ata/ahci.h | 7 +++++++
33 drivers/ata/ahci_qoriq.c | 2 +-
34 drivers/ata/ahci_xgene.c | 4 ++--
35 drivers/ata/libahci.c | 20 ++++++++++++--------
36 drivers/ata/sata_highbank.c | 2 +-
37 6 files changed, 26 insertions(+), 15 deletions(-)
38
39 diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
40 index 1ff17799769d0..6389c88b3500a 100644
41 --- a/drivers/ata/ahci.c
42 +++ b/drivers/ata/ahci.c
43 @@ -698,7 +698,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
44
45 DPRINTK("ENTER\n");
46
47 - ahci_stop_engine(ap);
48 + hpriv->stop_engine(ap);
49
50 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
51 deadline, &online, NULL);
52 @@ -724,7 +724,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
53 bool online;
54 int rc;
55
56 - ahci_stop_engine(ap);
57 + hpriv->stop_engine(ap);
58
59 /* clear D2H reception area to properly wait for D2H FIS */
60 ata_tf_init(link->device, &tf);
61 @@ -788,7 +788,7 @@ static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
62
63 DPRINTK("ENTER\n");
64
65 - ahci_stop_engine(ap);
66 + hpriv->stop_engine(ap);
67
68 for (i = 0; i < 2; i++) {
69 u16 val;
70 diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
71 index a9d996e17d75e..824bd399f02ea 100644
72 --- a/drivers/ata/ahci.h
73 +++ b/drivers/ata/ahci.h
74 @@ -365,6 +365,13 @@ struct ahci_host_priv {
75 * be overridden anytime before the host is activated.
76 */
77 void (*start_engine)(struct ata_port *ap);
78 + /*
79 + * Optional ahci_stop_engine override, if not set this gets set to the
80 + * default ahci_stop_engine during ahci_save_initial_config, this can
81 + * be overridden anytime before the host is activated.
82 + */
83 + int (*stop_engine)(struct ata_port *ap);
84 +
85 irqreturn_t (*irq_handler)(int irq, void *dev_instance);
86
87 /* only required for per-port MSI(-X) support */
88 diff --git a/drivers/ata/ahci_qoriq.c b/drivers/ata/ahci_qoriq.c
89 index 2685f28160f70..cfdef4d44ae92 100644
90 --- a/drivers/ata/ahci_qoriq.c
91 +++ b/drivers/ata/ahci_qoriq.c
92 @@ -96,7 +96,7 @@ static int ahci_qoriq_hardreset(struct ata_link *link, unsigned int *class,
93
94 DPRINTK("ENTER\n");
95
96 - ahci_stop_engine(ap);
97 + hpriv->stop_engine(ap);
98
99 /*
100 * There is a errata on ls1021a Rev1.0 and Rev2.0 which is:
101 diff --git a/drivers/ata/ahci_xgene.c b/drivers/ata/ahci_xgene.c
102 index c2b5941d9184d..ad58da7c9affd 100644
103 --- a/drivers/ata/ahci_xgene.c
104 +++ b/drivers/ata/ahci_xgene.c
105 @@ -165,7 +165,7 @@ static int xgene_ahci_restart_engine(struct ata_port *ap)
106 PORT_CMD_ISSUE, 0x0, 1, 100))
107 return -EBUSY;
108
109 - ahci_stop_engine(ap);
110 + hpriv->stop_engine(ap);
111 ahci_start_fis_rx(ap);
112
113 /*
114 @@ -421,7 +421,7 @@ static int xgene_ahci_hardreset(struct ata_link *link, unsigned int *class,
115 portrxfis_saved = readl(port_mmio + PORT_FIS_ADDR);
116 portrxfishi_saved = readl(port_mmio + PORT_FIS_ADDR_HI);
117
118 - ahci_stop_engine(ap);
119 + hpriv->stop_engine(ap);
120
121 rc = xgene_ahci_do_hardreset(link, deadline, &online);
122
123 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
124 index 7adcf3caabd00..e5d90977caec2 100644
125 --- a/drivers/ata/libahci.c
126 +++ b/drivers/ata/libahci.c
127 @@ -560,6 +560,9 @@ void ahci_save_initial_config(struct device *dev, struct ahci_host_priv *hpriv)
128 if (!hpriv->start_engine)
129 hpriv->start_engine = ahci_start_engine;
130
131 + if (!hpriv->stop_engine)
132 + hpriv->stop_engine = ahci_stop_engine;
133 +
134 if (!hpriv->irq_handler)
135 hpriv->irq_handler = ahci_single_level_irq_intr;
136 }
137 @@ -897,9 +900,10 @@ static void ahci_start_port(struct ata_port *ap)
138 static int ahci_deinit_port(struct ata_port *ap, const char **emsg)
139 {
140 int rc;
141 + struct ahci_host_priv *hpriv = ap->host->private_data;
142
143 /* disable DMA */
144 - rc = ahci_stop_engine(ap);
145 + rc = hpriv->stop_engine(ap);
146 if (rc) {
147 *emsg = "failed to stop engine";
148 return rc;
149 @@ -1310,7 +1314,7 @@ int ahci_kick_engine(struct ata_port *ap)
150 int busy, rc;
151
152 /* stop engine */
153 - rc = ahci_stop_engine(ap);
154 + rc = hpriv->stop_engine(ap);
155 if (rc)
156 goto out_restart;
157
158 @@ -1549,7 +1553,7 @@ int ahci_do_hardreset(struct ata_link *link, unsigned int *class,
159
160 DPRINTK("ENTER\n");
161
162 - ahci_stop_engine(ap);
163 + hpriv->stop_engine(ap);
164
165 /* clear D2H reception area to properly wait for D2H FIS */
166 ata_tf_init(link->device, &tf);
167 @@ -2075,14 +2079,14 @@ void ahci_error_handler(struct ata_port *ap)
168
169 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
170 /* restart engine */
171 - ahci_stop_engine(ap);
172 + hpriv->stop_engine(ap);
173 hpriv->start_engine(ap);
174 }
175
176 sata_pmp_error_handler(ap);
177
178 if (!ata_dev_enabled(ap->link.device))
179 - ahci_stop_engine(ap);
180 + hpriv->stop_engine(ap);
181 }
182 EXPORT_SYMBOL_GPL(ahci_error_handler);
183
184 @@ -2129,7 +2133,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
185 return;
186
187 /* set DITO, MDAT, DETO and enable DevSlp, need to stop engine first */
188 - rc = ahci_stop_engine(ap);
189 + rc = hpriv->stop_engine(ap);
190 if (rc)
191 return;
192
193 @@ -2189,7 +2193,7 @@ static void ahci_enable_fbs(struct ata_port *ap)
194 return;
195 }
196
197 - rc = ahci_stop_engine(ap);
198 + rc = hpriv->stop_engine(ap);
199 if (rc)
200 return;
201
202 @@ -2222,7 +2226,7 @@ static void ahci_disable_fbs(struct ata_port *ap)
203 return;
204 }
205
206 - rc = ahci_stop_engine(ap);
207 + rc = hpriv->stop_engine(ap);
208 if (rc)
209 return;
210
211 diff --git a/drivers/ata/sata_highbank.c b/drivers/ata/sata_highbank.c
212 index aafb8cc035232..e67815b896fcc 100644
213 --- a/drivers/ata/sata_highbank.c
214 +++ b/drivers/ata/sata_highbank.c
215 @@ -410,7 +410,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
216 int rc;
217 int retry = 100;
218
219 - ahci_stop_engine(ap);
220 + hpriv->stop_engine(ap);
221
222 /* clear D2H reception area to properly wait for D2H FIS */
223 ata_tf_init(link->device, &tf);
224