aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/libata-pmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/libata-pmp.c')
-rw-r--r--drivers/ata/libata-pmp.c247
1 files changed, 42 insertions, 205 deletions
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index d91f5090ba9d..ff1822a7da38 100644
--- a/drivers/ata/libata-pmp.c
+++ b/drivers/ata/libata-pmp.c
@@ -11,6 +11,14 @@
11#include <linux/libata.h> 11#include <linux/libata.h>
12#include "libata.h" 12#include "libata.h"
13 13
14const struct ata_port_operations sata_pmp_port_ops = {
15 .inherits = &sata_port_ops,
16 .pmp_prereset = ata_std_prereset,
17 .pmp_hardreset = sata_std_hardreset,
18 .pmp_postreset = ata_std_postreset,
19 .error_handler = sata_pmp_error_handler,
20};
21
14/** 22/**
15 * sata_pmp_read - read PMP register 23 * sata_pmp_read - read PMP register
16 * @link: link to read PMP register for 24 * @link: link to read PMP register for
@@ -176,140 +184,6 @@ int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val)
176} 184}
177 185
178/** 186/**
179 * sata_pmp_std_prereset - prepare PMP link for reset
180 * @link: link to be reset
181 * @deadline: deadline jiffies for the operation
182 *
183 * @link is about to be reset. Initialize it.
184 *
185 * LOCKING:
186 * Kernel thread context (may sleep)
187 *
188 * RETURNS:
189 * 0 on success, -errno otherwise.
190 */
191int sata_pmp_std_prereset(struct ata_link *link, unsigned long deadline)
192{
193 struct ata_eh_context *ehc = &link->eh_context;
194 const unsigned long *timing = sata_ehc_deb_timing(ehc);
195 int rc;
196
197 /* force HRST? */
198 if (link->flags & ATA_LFLAG_NO_SRST)
199 ehc->i.action |= ATA_EH_HARDRESET;
200
201 /* handle link resume */
202 if ((ehc->i.flags & ATA_EHI_RESUME_LINK) &&
203 (link->flags & ATA_LFLAG_HRST_TO_RESUME))
204 ehc->i.action |= ATA_EH_HARDRESET;
205
206 /* if we're about to do hardreset, nothing more to do */
207 if (ehc->i.action & ATA_EH_HARDRESET)
208 return 0;
209
210 /* resume link */
211 rc = sata_link_resume(link, timing, deadline);
212 if (rc) {
213 /* phy resume failed */
214 ata_link_printk(link, KERN_WARNING, "failed to resume link "
215 "for reset (errno=%d)\n", rc);
216 return rc;
217 }
218
219 /* clear SError bits including .X which blocks the port when set */
220 rc = sata_scr_write(link, SCR_ERROR, 0xffffffff);
221 if (rc) {
222 ata_link_printk(link, KERN_ERR,
223 "failed to clear SError (errno=%d)\n", rc);
224 return rc;
225 }
226
227 return 0;
228}
229
230/**
231 * sata_pmp_std_hardreset - standard hardreset method for PMP link
232 * @link: link to be reset
233 * @class: resulting class of attached device
234 * @deadline: deadline jiffies for the operation
235 *
236 * Hardreset PMP port @link. Note that this function doesn't
237 * wait for BSY clearance. There simply isn't a generic way to
238 * wait the event. Instead, this function return -EAGAIN thus
239 * telling libata-EH to followup with softreset.
240 *
241 * LOCKING:
242 * Kernel thread context (may sleep)
243 *
244 * RETURNS:
245 * 0 on success, -errno otherwise.
246 */
247int sata_pmp_std_hardreset(struct ata_link *link, unsigned int *class,
248 unsigned long deadline)
249{
250 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
251 u32 tmp;
252 int rc;
253
254 DPRINTK("ENTER\n");
255
256 /* do hardreset */
257 rc = sata_link_hardreset(link, timing, deadline);
258 if (rc) {
259 ata_link_printk(link, KERN_ERR,
260 "COMRESET failed (errno=%d)\n", rc);
261 goto out;
262 }
263
264 /* clear SError bits including .X which blocks the port when set */
265 rc = sata_scr_write(link, SCR_ERROR, 0xffffffff);
266 if (rc) {
267 ata_link_printk(link, KERN_ERR, "failed to clear SError "
268 "during hardreset (errno=%d)\n", rc);
269 goto out;
270 }
271
272 /* if device is present, follow up with srst to wait for !BSY */
273 if (ata_link_online(link))
274 rc = -EAGAIN;
275 out:
276 /* if SCR isn't accessible, we need to reset the PMP */
277 if (rc && rc != -EAGAIN && sata_scr_read(link, SCR_STATUS, &tmp))
278 rc = -ERESTART;
279
280 DPRINTK("EXIT, rc=%d\n", rc);
281 return rc;
282}
283
284/**
285 * ata_std_postreset - standard postreset method for PMP link
286 * @link: the target ata_link
287 * @classes: classes of attached devices
288 *
289 * This function is invoked after a successful reset. Note that
290 * the device might have been reset more than once using
291 * different reset methods before postreset is invoked.
292 *
293 * LOCKING:
294 * Kernel thread context (may sleep)
295 */
296void sata_pmp_std_postreset(struct ata_link *link, unsigned int *class)
297{
298 u32 serror;
299
300 DPRINTK("ENTER\n");
301
302 /* clear SError */
303 if (sata_scr_read(link, SCR_ERROR, &serror) == 0)
304 sata_scr_write(link, SCR_ERROR, serror);
305
306 /* print link status */
307 sata_print_link_status(link);
308
309 DPRINTK("EXIT\n");
310}
311
312/**
313 * sata_pmp_read_gscr - read GSCR block of SATA PMP 187 * sata_pmp_read_gscr - read GSCR block of SATA PMP
314 * @dev: PMP device 188 * @dev: PMP device
315 * @gscr: buffer to read GSCR block into 189 * @gscr: buffer to read GSCR block into
@@ -444,9 +318,8 @@ static int sata_pmp_init_links(struct ata_port *ap, int nr_ports)
444 struct ata_eh_context *ehc = &link->eh_context; 318 struct ata_eh_context *ehc = &link->eh_context;
445 319
446 link->flags = 0; 320 link->flags = 0;
447 ehc->i.probe_mask |= 1; 321 ehc->i.probe_mask |= ATA_ALL_DEVICES;
448 ehc->i.action |= ATA_EH_SOFTRESET; 322 ehc->i.action |= ATA_EH_RESET;
449 ehc->i.flags |= ATA_EHI_RESUME_LINK;
450 } 323 }
451 324
452 return 0; 325 return 0;
@@ -462,9 +335,6 @@ static void sata_pmp_quirks(struct ata_port *ap)
462 if (vendor == 0x1095 && devid == 0x3726) { 335 if (vendor == 0x1095 && devid == 0x3726) {
463 /* sil3726 quirks */ 336 /* sil3726 quirks */
464 ata_port_for_each_link(link, ap) { 337 ata_port_for_each_link(link, ap) {
465 /* SError.N need a kick in the ass to get working */
466 link->flags |= ATA_LFLAG_HRST_TO_RESUME;
467
468 /* class code report is unreliable */ 338 /* class code report is unreliable */
469 if (link->pmp < 5) 339 if (link->pmp < 5)
470 link->flags |= ATA_LFLAG_ASSUME_ATA; 340 link->flags |= ATA_LFLAG_ASSUME_ATA;
@@ -477,9 +347,6 @@ static void sata_pmp_quirks(struct ata_port *ap)
477 } else if (vendor == 0x1095 && devid == 0x4723) { 347 } else if (vendor == 0x1095 && devid == 0x4723) {
478 /* sil4723 quirks */ 348 /* sil4723 quirks */
479 ata_port_for_each_link(link, ap) { 349 ata_port_for_each_link(link, ap) {
480 /* SError.N need a kick in the ass to get working */
481 link->flags |= ATA_LFLAG_HRST_TO_RESUME;
482
483 /* class code report is unreliable */ 350 /* class code report is unreliable */
484 if (link->pmp < 2) 351 if (link->pmp < 2)
485 link->flags |= ATA_LFLAG_ASSUME_ATA; 352 link->flags |= ATA_LFLAG_ASSUME_ATA;
@@ -492,9 +359,6 @@ static void sata_pmp_quirks(struct ata_port *ap)
492 } else if (vendor == 0x1095 && devid == 0x4726) { 359 } else if (vendor == 0x1095 && devid == 0x4726) {
493 /* sil4726 quirks */ 360 /* sil4726 quirks */
494 ata_port_for_each_link(link, ap) { 361 ata_port_for_each_link(link, ap) {
495 /* SError.N need a kick in the ass to get working */
496 link->flags |= ATA_LFLAG_HRST_TO_RESUME;
497
498 /* Class code report is unreliable and SRST 362 /* Class code report is unreliable and SRST
499 * times out under certain configurations. 363 * times out under certain configurations.
500 * Config device can be at port 0 or 5 and 364 * Config device can be at port 0 or 5 and
@@ -522,13 +386,6 @@ static void sata_pmp_quirks(struct ata_port *ap)
522 * otherwise. Don't try hard to recover it. 386 * otherwise. Don't try hard to recover it.
523 */ 387 */
524 ap->pmp_link[ap->nr_pmp_links - 1].flags |= ATA_LFLAG_NO_RETRY; 388 ap->pmp_link[ap->nr_pmp_links - 1].flags |= ATA_LFLAG_NO_RETRY;
525 } else if (vendor == 0x11ab && devid == 0x4140) {
526 /* Marvell 88SM4140 quirks. Fan-out ports require PHY
527 * reset to work; other than that, it behaves very
528 * nicely.
529 */
530 ata_port_for_each_link(link, ap)
531 link->flags |= ATA_LFLAG_HRST_TO_RESUME;
532 } 389 }
533} 390}
534 391
@@ -554,7 +411,7 @@ int sata_pmp_attach(struct ata_device *dev)
554 int rc; 411 int rc;
555 412
556 /* is it hanging off the right place? */ 413 /* is it hanging off the right place? */
557 if (!(ap->flags & ATA_FLAG_PMP)) { 414 if (!sata_pmp_supported(ap)) {
558 ata_dev_printk(dev, KERN_ERR, 415 ata_dev_printk(dev, KERN_ERR,
559 "host does not support Port Multiplier\n"); 416 "host does not support Port Multiplier\n");
560 return -EINVAL; 417 return -EINVAL;
@@ -840,13 +697,12 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
840 retry: 697 retry:
841 ehc->classes[0] = ATA_DEV_UNKNOWN; 698 ehc->classes[0] = ATA_DEV_UNKNOWN;
842 699
843 if (ehc->i.action & ATA_EH_RESET_MASK) { 700 if (ehc->i.action & ATA_EH_RESET) {
844 struct ata_link *tlink; 701 struct ata_link *tlink;
845 702
846 ata_eh_freeze_port(ap); 703 ata_eh_freeze_port(ap);
847 704
848 /* reset */ 705 /* reset */
849 ehc->i.action = ATA_EH_HARDRESET;
850 rc = ata_eh_reset(link, 0, prereset, softreset, hardreset, 706 rc = ata_eh_reset(link, 0, prereset, softreset, hardreset,
851 postreset); 707 postreset);
852 if (rc) { 708 if (rc) {
@@ -858,8 +714,12 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
858 ata_eh_thaw_port(ap); 714 ata_eh_thaw_port(ap);
859 715
860 /* PMP is reset, SErrors cannot be trusted, scan all */ 716 /* PMP is reset, SErrors cannot be trusted, scan all */
861 ata_port_for_each_link(tlink, ap) 717 ata_port_for_each_link(tlink, ap) {
862 ata_ehi_schedule_probe(&tlink->eh_context.i); 718 struct ata_eh_context *ehc = &tlink->eh_context;
719
720 ehc->i.probe_mask |= ATA_ALL_DEVICES;
721 ehc->i.action |= ATA_EH_RESET;
722 }
863 } 723 }
864 724
865 /* If revalidation is requested, revalidate and reconfigure; 725 /* If revalidation is requested, revalidate and reconfigure;
@@ -874,7 +734,7 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
874 tries--; 734 tries--;
875 735
876 if (rc == -ENODEV) { 736 if (rc == -ENODEV) {
877 ehc->i.probe_mask |= 1; 737 ehc->i.probe_mask |= ATA_ALL_DEVICES;
878 detach = 1; 738 detach = 1;
879 /* give it just two more chances */ 739 /* give it just two more chances */
880 tries = min(tries, 2); 740 tries = min(tries, 2);
@@ -890,11 +750,11 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
890 reval_failed = 1; 750 reval_failed = 1;
891 751
892 ata_dev_printk(dev, KERN_WARNING, 752 ata_dev_printk(dev, KERN_WARNING,
893 "retrying hardreset%s\n", 753 "retrying reset%s\n",
894 sleep ? " in 5 secs" : ""); 754 sleep ? " in 5 secs" : "");
895 if (sleep) 755 if (sleep)
896 ssleep(5); 756 ssleep(5);
897 ehc->i.action |= ATA_EH_HARDRESET; 757 ehc->i.action |= ATA_EH_RESET;
898 goto retry; 758 goto retry;
899 } else { 759 } else {
900 ata_dev_printk(dev, KERN_ERR, "failed to recover PMP " 760 ata_dev_printk(dev, KERN_ERR, "failed to recover PMP "
@@ -938,10 +798,8 @@ static int sata_pmp_eh_handle_disabled_links(struct ata_port *ap)
938 /* Some PMPs require hardreset sequence to get 798 /* Some PMPs require hardreset sequence to get
939 * SError.N working. 799 * SError.N working.
940 */ 800 */
941 if ((link->flags & ATA_LFLAG_HRST_TO_RESUME) && 801 sata_link_hardreset(link, sata_deb_timing_normal,
942 (link->eh_context.i.flags & ATA_EHI_RESUME_LINK)) 802 jiffies + ATA_TMOUT_INTERNAL_QUICK, NULL, NULL);
943 sata_link_hardreset(link, sata_deb_timing_normal,
944 jiffies + ATA_TMOUT_INTERNAL_QUICK);
945 803
946 /* unconditionally clear SError.N */ 804 /* unconditionally clear SError.N */
947 rc = sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG); 805 rc = sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG);
@@ -987,14 +845,6 @@ static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries)
987/** 845/**
988 * sata_pmp_eh_recover - recover PMP-enabled port 846 * sata_pmp_eh_recover - recover PMP-enabled port
989 * @ap: ATA port to recover 847 * @ap: ATA port to recover
990 * @prereset: prereset method (can be NULL)
991 * @softreset: softreset method
992 * @hardreset: hardreset method
993 * @postreset: postreset method (can be NULL)
994 * @pmp_prereset: PMP prereset method (can be NULL)
995 * @pmp_softreset: PMP softreset method (can be NULL)
996 * @pmp_hardreset: PMP hardreset method (can be NULL)
997 * @pmp_postreset: PMP postreset method (can be NULL)
998 * 848 *
999 * Drive EH recovery operation for PMP enabled port @ap. This 849 * Drive EH recovery operation for PMP enabled port @ap. This
1000 * function recovers host and PMP ports with proper retrials and 850 * function recovers host and PMP ports with proper retrials and
@@ -1007,12 +857,9 @@ static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries)
1007 * RETURNS: 857 * RETURNS:
1008 * 0 on success, -errno on failure. 858 * 0 on success, -errno on failure.
1009 */ 859 */
1010static int sata_pmp_eh_recover(struct ata_port *ap, 860static int sata_pmp_eh_recover(struct ata_port *ap)
1011 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
1012 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset,
1013 ata_prereset_fn_t pmp_prereset, ata_reset_fn_t pmp_softreset,
1014 ata_reset_fn_t pmp_hardreset, ata_postreset_fn_t pmp_postreset)
1015{ 861{
862 struct ata_port_operations *ops = ap->ops;
1016 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS]; 863 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
1017 struct ata_link *pmp_link = &ap->link; 864 struct ata_link *pmp_link = &ap->link;
1018 struct ata_device *pmp_dev = pmp_link->device; 865 struct ata_device *pmp_dev = pmp_link->device;
@@ -1029,9 +876,9 @@ static int sata_pmp_eh_recover(struct ata_port *ap,
1029 876
1030 retry: 877 retry:
1031 /* PMP attached? */ 878 /* PMP attached? */
1032 if (!ap->nr_pmp_links) { 879 if (!sata_pmp_attached(ap)) {
1033 rc = ata_eh_recover(ap, prereset, softreset, hardreset, 880 rc = ata_eh_recover(ap, ops->prereset, ops->softreset,
1034 postreset, NULL); 881 ops->hardreset, ops->postreset, NULL);
1035 if (rc) { 882 if (rc) {
1036 ata_link_for_each_dev(dev, &ap->link) 883 ata_link_for_each_dev(dev, &ap->link)
1037 ata_dev_disable(dev); 884 ata_dev_disable(dev);
@@ -1049,8 +896,8 @@ static int sata_pmp_eh_recover(struct ata_port *ap,
1049 } 896 }
1050 897
1051 /* recover pmp */ 898 /* recover pmp */
1052 rc = sata_pmp_eh_recover_pmp(ap, prereset, softreset, hardreset, 899 rc = sata_pmp_eh_recover_pmp(ap, ops->prereset, ops->softreset,
1053 postreset); 900 ops->hardreset, ops->postreset);
1054 if (rc) 901 if (rc)
1055 goto pmp_fail; 902 goto pmp_fail;
1056 903
@@ -1060,8 +907,8 @@ static int sata_pmp_eh_recover(struct ata_port *ap,
1060 goto pmp_fail; 907 goto pmp_fail;
1061 908
1062 /* recover links */ 909 /* recover links */
1063 rc = ata_eh_recover(ap, pmp_prereset, pmp_softreset, pmp_hardreset, 910 rc = ata_eh_recover(ap, ops->pmp_prereset, ops->pmp_softreset,
1064 pmp_postreset, &link); 911 ops->pmp_hardreset, ops->pmp_postreset, &link);
1065 if (rc) 912 if (rc)
1066 goto link_fail; 913 goto link_fail;
1067 914
@@ -1124,7 +971,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap,
1124 971
1125 link_fail: 972 link_fail:
1126 if (sata_pmp_handle_link_fail(link, link_tries)) { 973 if (sata_pmp_handle_link_fail(link, link_tries)) {
1127 pmp_ehc->i.action |= ATA_EH_HARDRESET; 974 pmp_ehc->i.action |= ATA_EH_RESET;
1128 goto retry; 975 goto retry;
1129 } 976 }
1130 977
@@ -1136,13 +983,13 @@ static int sata_pmp_eh_recover(struct ata_port *ap,
1136 if (ap->pflags & ATA_PFLAG_UNLOADING) 983 if (ap->pflags & ATA_PFLAG_UNLOADING)
1137 return rc; 984 return rc;
1138 985
1139 if (!ap->nr_pmp_links) 986 if (!sata_pmp_attached(ap))
1140 goto retry; 987 goto retry;
1141 988
1142 if (--pmp_tries) { 989 if (--pmp_tries) {
1143 ata_port_printk(ap, KERN_WARNING, 990 ata_port_printk(ap, KERN_WARNING,
1144 "failed to recover PMP, retrying in 5 secs\n"); 991 "failed to recover PMP, retrying in 5 secs\n");
1145 pmp_ehc->i.action |= ATA_EH_HARDRESET; 992 pmp_ehc->i.action |= ATA_EH_RESET;
1146 ssleep(5); 993 ssleep(5);
1147 goto retry; 994 goto retry;
1148 } 995 }
@@ -1157,16 +1004,8 @@ static int sata_pmp_eh_recover(struct ata_port *ap,
1157} 1004}
1158 1005
1159/** 1006/**
1160 * sata_pmp_do_eh - do standard error handling for PMP-enabled host 1007 * sata_pmp_error_handler - do standard error handling for PMP-enabled host
1161 * @ap: host port to handle error for 1008 * @ap: host port to handle error for
1162 * @prereset: prereset method (can be NULL)
1163 * @softreset: softreset method
1164 * @hardreset: hardreset method
1165 * @postreset: postreset method (can be NULL)
1166 * @pmp_prereset: PMP prereset method (can be NULL)
1167 * @pmp_softreset: PMP softreset method (can be NULL)
1168 * @pmp_hardreset: PMP hardreset method (can be NULL)
1169 * @pmp_postreset: PMP postreset method (can be NULL)
1170 * 1009 *
1171 * Perform standard error handling sequence for PMP-enabled host 1010 * Perform standard error handling sequence for PMP-enabled host
1172 * @ap. 1011 * @ap.
@@ -1174,16 +1013,14 @@ static int sata_pmp_eh_recover(struct ata_port *ap,
1174 * LOCKING: 1013 * LOCKING:
1175 * Kernel thread context (may sleep). 1014 * Kernel thread context (may sleep).
1176 */ 1015 */
1177void sata_pmp_do_eh(struct ata_port *ap, 1016void sata_pmp_error_handler(struct ata_port *ap)
1178 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
1179 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset,
1180 ata_prereset_fn_t pmp_prereset, ata_reset_fn_t pmp_softreset,
1181 ata_reset_fn_t pmp_hardreset, ata_postreset_fn_t pmp_postreset)
1182{ 1017{
1183 ata_eh_autopsy(ap); 1018 ata_eh_autopsy(ap);
1184 ata_eh_report(ap); 1019 ata_eh_report(ap);
1185 sata_pmp_eh_recover(ap, prereset, softreset, hardreset, postreset, 1020 sata_pmp_eh_recover(ap);
1186 pmp_prereset, pmp_softreset, pmp_hardreset,
1187 pmp_postreset);
1188 ata_eh_finish(ap); 1021 ata_eh_finish(ap);
1189} 1022}
1023
1024EXPORT_SYMBOL_GPL(sata_pmp_port_ops);
1025EXPORT_SYMBOL_GPL(sata_pmp_qc_defer_cmd_switch);
1026EXPORT_SYMBOL_GPL(sata_pmp_error_handler);