2 * libata-pmp.c - libata port multiplier support
4 * Copyright (c) 2007 SUSE Linux Products GmbH
5 * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
7 * This file is released under the GPLv2.
10 #include <linux/kernel.h>
11 #include <linux/libata.h>
14 const 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,
23 * sata_pmp_read - read PMP register
24 * @link: link to read PMP register for
25 * @reg: register to read
26 * @r_val: resulting value
31 * Kernel thread context (may sleep).
34 * 0 on success, AC_ERR_* mask on failure.
36 static unsigned int sata_pmp_read(struct ata_link *link, int reg, u32 *r_val)
38 struct ata_port *ap = link->ap;
39 struct ata_device *pmp_dev = ap->link.device;
40 struct ata_taskfile tf;
41 unsigned int err_mask;
43 ata_tf_init(pmp_dev, &tf);
44 tf.command = ATA_CMD_PMP_READ;
45 tf.protocol = ATA_PROT_NODATA;
46 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
48 tf.device = link->pmp;
50 err_mask = ata_exec_internal(pmp_dev, &tf, NULL, DMA_NONE, NULL, 0,
51 SATA_PMP_SCR_TIMEOUT);
55 *r_val = tf.nsect | tf.lbal << 8 | tf.lbam << 16 | tf.lbah << 24;
60 * sata_pmp_write - write PMP register
61 * @link: link to write PMP register for
62 * @reg: register to write
63 * @r_val: value to write
68 * Kernel thread context (may sleep).
71 * 0 on success, AC_ERR_* mask on failure.
73 static unsigned int sata_pmp_write(struct ata_link *link, int reg, u32 val)
75 struct ata_port *ap = link->ap;
76 struct ata_device *pmp_dev = ap->link.device;
77 struct ata_taskfile tf;
79 ata_tf_init(pmp_dev, &tf);
80 tf.command = ATA_CMD_PMP_WRITE;
81 tf.protocol = ATA_PROT_NODATA;
82 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
84 tf.device = link->pmp;
85 tf.nsect = val & 0xff;
86 tf.lbal = (val >> 8) & 0xff;
87 tf.lbam = (val >> 16) & 0xff;
88 tf.lbah = (val >> 24) & 0xff;
90 return ata_exec_internal(pmp_dev, &tf, NULL, DMA_NONE, NULL, 0,
91 SATA_PMP_SCR_TIMEOUT);
95 * sata_pmp_qc_defer_cmd_switch - qc_defer for command switching PMP
96 * @qc: ATA command in question
98 * A host which has command switching PMP support cannot issue
99 * commands to multiple links simultaneously.
102 * spin_lock_irqsave(host lock)
105 * ATA_DEFER_* if deferring is needed, 0 otherwise.
107 int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc)
109 struct ata_link *link = qc->dev->link;
110 struct ata_port *ap = link->ap;
112 if (ap->excl_link == NULL || ap->excl_link == link) {
113 if (ap->nr_active_links == 0 || ata_link_active(link)) {
114 qc->flags |= ATA_QCFLAG_CLEAR_EXCL;
115 return ata_std_qc_defer(qc);
118 ap->excl_link = link;
121 return ATA_DEFER_PORT;
125 * sata_pmp_scr_read - read PSCR
126 * @link: ATA link to read PSCR for
128 * @r_val: resulting value
130 * Read PSCR @reg into @r_val for @link, to be called from
134 * Kernel thread context (may sleep).
137 * 0 on success, -errno on failure.
139 int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *r_val)
141 unsigned int err_mask;
143 if (reg > SATA_PMP_PSCR_CONTROL)
146 err_mask = sata_pmp_read(link, reg, r_val);
148 ata_link_printk(link, KERN_WARNING, "failed to read SCR %d "
149 "(Emask=0x%x)\n", reg, err_mask);
156 * sata_pmp_scr_write - write PSCR
157 * @link: ATA link to write PSCR for
158 * @reg: PSCR to write
159 * @val: value to be written
161 * Write @val to PSCR @reg for @link, to be called from
162 * ata_scr_write() and ata_scr_write_flush().
165 * Kernel thread context (may sleep).
168 * 0 on success, -errno on failure.
170 int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val)
172 unsigned int err_mask;
174 if (reg > SATA_PMP_PSCR_CONTROL)
177 err_mask = sata_pmp_write(link, reg, val);
179 ata_link_printk(link, KERN_WARNING, "failed to write SCR %d "
180 "(Emask=0x%x)\n", reg, err_mask);
187 * sata_pmp_read_gscr - read GSCR block of SATA PMP
189 * @gscr: buffer to read GSCR block into
191 * Read selected PMP GSCRs from the PMP at @dev. This will serve
192 * as configuration and identification info for the PMP.
195 * Kernel thread context (may sleep).
198 * 0 on success, -errno on failure.
200 static int sata_pmp_read_gscr(struct ata_device *dev, u32 *gscr)
202 static const int gscr_to_read[] = { 0, 1, 2, 32, 33, 64, 96 };
205 for (i = 0; i < ARRAY_SIZE(gscr_to_read); i++) {
206 int reg = gscr_to_read[i];
207 unsigned int err_mask;
209 err_mask = sata_pmp_read(dev->link, reg, &gscr[reg]);
211 ata_dev_printk(dev, KERN_ERR, "failed to read PMP "
212 "GSCR[%d] (Emask=0x%x)\n", reg, err_mask);
220 static const char *sata_pmp_spec_rev_str(const u32 *gscr)
222 u32 rev = gscr[SATA_PMP_GSCR_REV];
231 static int sata_pmp_configure(struct ata_device *dev, int print_info)
233 struct ata_port *ap = dev->link->ap;
234 u32 *gscr = dev->gscr;
235 unsigned int err_mask = 0;
239 nr_ports = sata_pmp_gscr_ports(gscr);
241 if (nr_ports <= 0 || nr_ports > SATA_PMP_MAX_PORTS) {
243 reason = "invalid nr_ports";
247 if ((ap->flags & ATA_FLAG_AN) &&
248 (gscr[SATA_PMP_GSCR_FEAT] & SATA_PMP_FEAT_NOTIFY))
249 dev->flags |= ATA_DFLAG_AN;
251 /* monitor SERR_PHYRDY_CHG on fan-out ports */
252 err_mask = sata_pmp_write(dev->link, SATA_PMP_GSCR_ERROR_EN,
256 reason = "failed to write GSCR_ERROR_EN";
260 /* turn off notification till fan-out ports are reset and configured */
261 if (gscr[SATA_PMP_GSCR_FEAT_EN] & SATA_PMP_FEAT_NOTIFY) {
262 gscr[SATA_PMP_GSCR_FEAT_EN] &= ~SATA_PMP_FEAT_NOTIFY;
264 err_mask = sata_pmp_write(dev->link, SATA_PMP_GSCR_FEAT_EN,
265 gscr[SATA_PMP_GSCR_FEAT_EN]);
268 reason = "failed to write GSCR_FEAT_EN";
274 ata_dev_printk(dev, KERN_INFO, "Port Multiplier %s, "
275 "0x%04x:0x%04x r%d, %d ports, feat 0x%x/0x%x\n",
276 sata_pmp_spec_rev_str(gscr),
277 sata_pmp_gscr_vendor(gscr),
278 sata_pmp_gscr_devid(gscr),
279 sata_pmp_gscr_rev(gscr),
280 nr_ports, gscr[SATA_PMP_GSCR_FEAT_EN],
281 gscr[SATA_PMP_GSCR_FEAT]);
283 if (!(dev->flags & ATA_DFLAG_AN))
284 ata_dev_printk(dev, KERN_INFO,
285 "Asynchronous notification not supported, "
286 "hotplug won't\n work on fan-out "
287 "ports. Use warm-plug instead.\n");
293 ata_dev_printk(dev, KERN_ERR,
294 "failed to configure Port Multiplier (%s, Emask=0x%x)\n",
299 static int sata_pmp_init_links(struct ata_port *ap, int nr_ports)
301 struct ata_link *pmp_link = ap->pmp_link;
305 pmp_link = kzalloc(sizeof(pmp_link[0]) * SATA_PMP_MAX_PORTS,
310 for (i = 0; i < SATA_PMP_MAX_PORTS; i++)
311 ata_link_init(ap, &pmp_link[i], i);
313 ap->pmp_link = pmp_link;
316 for (i = 0; i < nr_ports; i++) {
317 struct ata_link *link = &pmp_link[i];
318 struct ata_eh_context *ehc = &link->eh_context;
321 ehc->i.probe_mask |= ATA_ALL_DEVICES;
322 ehc->i.action |= ATA_EH_RESET;
328 static void sata_pmp_quirks(struct ata_port *ap)
330 u32 *gscr = ap->link.device->gscr;
331 u16 vendor = sata_pmp_gscr_vendor(gscr);
332 u16 devid = sata_pmp_gscr_devid(gscr);
333 struct ata_link *link;
335 if (vendor == 0x1095 && devid == 0x3726) {
337 ata_port_for_each_link(link, ap) {
338 /* class code report is unreliable */
340 link->flags |= ATA_LFLAG_ASSUME_ATA;
342 /* port 5 is for SEMB device and it doesn't like SRST */
344 link->flags |= ATA_LFLAG_NO_SRST |
345 ATA_LFLAG_ASSUME_SEMB;
347 } else if (vendor == 0x1095 && devid == 0x4723) {
349 ata_port_for_each_link(link, ap) {
350 /* class code report is unreliable */
352 link->flags |= ATA_LFLAG_ASSUME_ATA;
354 /* the config device at port 2 locks up on SRST */
356 link->flags |= ATA_LFLAG_NO_SRST |
357 ATA_LFLAG_ASSUME_ATA;
359 } else if (vendor == 0x1095 && devid == 0x4726) {
361 ata_port_for_each_link(link, ap) {
362 /* Class code report is unreliable and SRST
363 * times out under certain configurations.
364 * Config device can be at port 0 or 5 and
368 link->flags |= ATA_LFLAG_NO_SRST |
369 ATA_LFLAG_ASSUME_ATA;
371 /* Port 6 is for SEMB device which doesn't
375 link->flags |= ATA_LFLAG_NO_SRST |
376 ATA_LFLAG_ASSUME_SEMB;
378 } else if (vendor == 0x1095 && (devid == 0x5723 || devid == 0x5733 ||
379 devid == 0x5734 || devid == 0x5744)) {
380 /* sil5723/5744 quirks */
382 /* sil5723/5744 has either two or three downstream
383 * ports depending on operation mode. The last port
384 * is empty if any actual IO device is available or
385 * occupied by a pseudo configuration device
386 * otherwise. Don't try hard to recover it.
388 ap->pmp_link[ap->nr_pmp_links - 1].flags |= ATA_LFLAG_NO_RETRY;
393 * sata_pmp_attach - attach a SATA PMP device
394 * @dev: SATA PMP device to attach
396 * Configure and attach SATA PMP device @dev. This function is
397 * also responsible for allocating and initializing PMP links.
400 * Kernel thread context (may sleep).
403 * 0 on success, -errno on failure.
405 int sata_pmp_attach(struct ata_device *dev)
407 struct ata_link *link = dev->link;
408 struct ata_port *ap = link->ap;
410 struct ata_link *tlink;
413 /* is it hanging off the right place? */
414 if (!sata_pmp_supported(ap)) {
415 ata_dev_printk(dev, KERN_ERR,
416 "host does not support Port Multiplier\n");
420 if (!ata_is_host_link(link)) {
421 ata_dev_printk(dev, KERN_ERR,
422 "Port Multipliers cannot be nested\n");
427 ata_dev_printk(dev, KERN_ERR,
428 "Port Multiplier must be the first device\n");
432 WARN_ON(link->pmp != 0);
433 link->pmp = SATA_PMP_CTRL_PORT;
435 /* read GSCR block */
436 rc = sata_pmp_read_gscr(dev, dev->gscr);
441 rc = sata_pmp_configure(dev, 1);
445 rc = sata_pmp_init_links(ap, sata_pmp_gscr_ports(dev->gscr));
447 ata_dev_printk(dev, KERN_INFO,
448 "failed to initialize PMP links\n");
453 spin_lock_irqsave(ap->lock, flags);
454 WARN_ON(ap->nr_pmp_links);
455 ap->nr_pmp_links = sata_pmp_gscr_ports(dev->gscr);
456 spin_unlock_irqrestore(ap->lock, flags);
460 if (ap->ops->pmp_attach)
461 ap->ops->pmp_attach(ap);
463 ata_port_for_each_link(tlink, ap)
464 sata_link_init_spd(tlink);
466 ata_acpi_associate_sata_port(ap);
476 * sata_pmp_detach - detach a SATA PMP device
477 * @dev: SATA PMP device to detach
479 * Detach SATA PMP device @dev. This function is also
480 * responsible for deconfiguring PMP links.
483 * Kernel thread context (may sleep).
485 static void sata_pmp_detach(struct ata_device *dev)
487 struct ata_link *link = dev->link;
488 struct ata_port *ap = link->ap;
489 struct ata_link *tlink;
492 ata_dev_printk(dev, KERN_INFO, "Port Multiplier detaching\n");
494 WARN_ON(!ata_is_host_link(link) || dev->devno ||
495 link->pmp != SATA_PMP_CTRL_PORT);
497 if (ap->ops->pmp_detach)
498 ap->ops->pmp_detach(ap);
500 ata_port_for_each_link(tlink, ap)
501 ata_eh_detach_dev(tlink->device);
503 spin_lock_irqsave(ap->lock, flags);
504 ap->nr_pmp_links = 0;
506 spin_unlock_irqrestore(ap->lock, flags);
508 ata_acpi_associate_sata_port(ap);
512 * sata_pmp_same_pmp - does new GSCR matches the configured PMP?
513 * @dev: PMP device to compare against
514 * @new_gscr: GSCR block of the new device
516 * Compare @new_gscr against @dev and determine whether @dev is
517 * the PMP described by @new_gscr.
523 * 1 if @dev matches @new_gscr, 0 otherwise.
525 static int sata_pmp_same_pmp(struct ata_device *dev, const u32 *new_gscr)
527 const u32 *old_gscr = dev->gscr;
528 u16 old_vendor, new_vendor, old_devid, new_devid;
529 int old_nr_ports, new_nr_ports;
531 old_vendor = sata_pmp_gscr_vendor(old_gscr);
532 new_vendor = sata_pmp_gscr_vendor(new_gscr);
533 old_devid = sata_pmp_gscr_devid(old_gscr);
534 new_devid = sata_pmp_gscr_devid(new_gscr);
535 old_nr_ports = sata_pmp_gscr_ports(old_gscr);
536 new_nr_ports = sata_pmp_gscr_ports(new_gscr);
538 if (old_vendor != new_vendor) {
539 ata_dev_printk(dev, KERN_INFO, "Port Multiplier "
540 "vendor mismatch '0x%x' != '0x%x'\n",
541 old_vendor, new_vendor);
545 if (old_devid != new_devid) {
546 ata_dev_printk(dev, KERN_INFO, "Port Multiplier "
547 "device ID mismatch '0x%x' != '0x%x'\n",
548 old_devid, new_devid);
552 if (old_nr_ports != new_nr_ports) {
553 ata_dev_printk(dev, KERN_INFO, "Port Multiplier "
554 "nr_ports mismatch '0x%x' != '0x%x'\n",
555 old_nr_ports, new_nr_ports);
563 * sata_pmp_revalidate - revalidate SATA PMP
564 * @dev: PMP device to revalidate
565 * @new_class: new class code
567 * Re-read GSCR block and make sure @dev is still attached to the
568 * port and properly configured.
571 * Kernel thread context (may sleep).
574 * 0 on success, -errno otherwise.
576 static int sata_pmp_revalidate(struct ata_device *dev, unsigned int new_class)
578 struct ata_link *link = dev->link;
579 struct ata_port *ap = link->ap;
580 u32 *gscr = (void *)ap->sector_buf;
585 ata_eh_about_to_do(link, NULL, ATA_EH_REVALIDATE);
587 if (!ata_dev_enabled(dev)) {
593 if (ata_class_enabled(new_class) && new_class != ATA_DEV_PMP) {
599 rc = sata_pmp_read_gscr(dev, gscr);
603 /* is the pmp still there? */
604 if (!sata_pmp_same_pmp(dev, gscr)) {
609 memcpy(dev->gscr, gscr, sizeof(gscr[0]) * SATA_PMP_GSCR_DWORDS);
611 rc = sata_pmp_configure(dev, 0);
615 ata_eh_done(link, NULL, ATA_EH_REVALIDATE);
617 DPRINTK("EXIT, rc=0\n");
621 ata_dev_printk(dev, KERN_ERR,
622 "PMP revalidation failed (errno=%d)\n", rc);
623 DPRINTK("EXIT, rc=%d\n", rc);
628 * sata_pmp_revalidate_quick - revalidate SATA PMP quickly
629 * @dev: PMP device to revalidate
631 * Make sure the attached PMP is accessible.
634 * Kernel thread context (may sleep).
637 * 0 on success, -errno otherwise.
639 static int sata_pmp_revalidate_quick(struct ata_device *dev)
641 unsigned int err_mask;
644 err_mask = sata_pmp_read(dev->link, SATA_PMP_GSCR_PROD_ID, &prod_id);
646 ata_dev_printk(dev, KERN_ERR, "failed to read PMP product ID "
647 "(Emask=0x%x)\n", err_mask);
651 if (prod_id != dev->gscr[SATA_PMP_GSCR_PROD_ID]) {
652 ata_dev_printk(dev, KERN_ERR, "PMP product ID mismatch\n");
653 /* something weird is going on, request full PMP recovery */
661 * sata_pmp_eh_recover_pmp - recover PMP
662 * @ap: ATA port PMP is attached to
663 * @prereset: prereset method (can be NULL)
664 * @softreset: softreset method
665 * @hardreset: hardreset method
666 * @postreset: postreset method (can be NULL)
668 * Recover PMP attached to @ap. Recovery procedure is somewhat
669 * similar to that of ata_eh_recover() except that reset should
670 * always be performed in hard->soft sequence and recovery
671 * failure results in PMP detachment.
674 * Kernel thread context (may sleep).
677 * 0 on success, -errno on failure.
679 static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
680 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
681 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
683 struct ata_link *link = &ap->link;
684 struct ata_eh_context *ehc = &link->eh_context;
685 struct ata_device *dev = link->device;
686 int tries = ATA_EH_PMP_TRIES;
687 int detach = 0, rc = 0;
688 int reval_failed = 0;
692 if (dev->flags & ATA_DFLAG_DETACH) {
698 ehc->classes[0] = ATA_DEV_UNKNOWN;
700 if (ehc->i.action & ATA_EH_RESET) {
701 struct ata_link *tlink;
703 ata_eh_freeze_port(ap);
706 rc = ata_eh_reset(link, 0, prereset, softreset, hardreset,
709 ata_link_printk(link, KERN_ERR,
710 "failed to reset PMP, giving up\n");
714 ata_eh_thaw_port(ap);
716 /* PMP is reset, SErrors cannot be trusted, scan all */
717 ata_port_for_each_link(tlink, ap) {
718 struct ata_eh_context *ehc = &tlink->eh_context;
720 ehc->i.probe_mask |= ATA_ALL_DEVICES;
721 ehc->i.action |= ATA_EH_RESET;
725 /* If revalidation is requested, revalidate and reconfigure;
726 * otherwise, do quick revalidation.
728 if (ehc->i.action & ATA_EH_REVALIDATE)
729 rc = sata_pmp_revalidate(dev, ehc->classes[0]);
731 rc = sata_pmp_revalidate_quick(dev);
737 ehc->i.probe_mask |= ATA_ALL_DEVICES;
739 /* give it just two more chances */
740 tries = min(tries, 2);
744 int sleep = ehc->i.flags & ATA_EHI_DID_RESET;
746 /* consecutive revalidation failures? speed down */
748 sata_down_spd_limit(link);
752 ata_dev_printk(dev, KERN_WARNING,
753 "retrying reset%s\n",
754 sleep ? " in 5 secs" : "");
757 ehc->i.action |= ATA_EH_RESET;
760 ata_dev_printk(dev, KERN_ERR, "failed to recover PMP "
761 "after %d tries, giving up\n",
767 /* okay, PMP resurrected */
770 DPRINTK("EXIT, rc=0\n");
774 sata_pmp_detach(dev);
776 ata_eh_detach_dev(dev);
778 ata_dev_disable(dev);
780 DPRINTK("EXIT, rc=%d\n", rc);
784 static int sata_pmp_eh_handle_disabled_links(struct ata_port *ap)
786 struct ata_link *link;
790 spin_lock_irqsave(ap->lock, flags);
792 ata_port_for_each_link(link, ap) {
793 if (!(link->flags & ATA_LFLAG_DISABLED))
796 spin_unlock_irqrestore(ap->lock, flags);
798 /* Some PMPs require hardreset sequence to get
801 sata_link_hardreset(link, sata_deb_timing_normal,
802 jiffies + ATA_TMOUT_INTERNAL_QUICK, NULL, NULL);
804 /* unconditionally clear SError.N */
805 rc = sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG);
807 ata_link_printk(link, KERN_ERR, "failed to clear "
808 "SError.N (errno=%d)\n", rc);
812 spin_lock_irqsave(ap->lock, flags);
815 spin_unlock_irqrestore(ap->lock, flags);
820 static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries)
822 struct ata_port *ap = link->ap;
825 if (link_tries[link->pmp] && --link_tries[link->pmp])
828 /* disable this link */
829 if (!(link->flags & ATA_LFLAG_DISABLED)) {
830 ata_link_printk(link, KERN_WARNING,
831 "failed to recover link after %d tries, disabling\n",
832 ATA_EH_PMP_LINK_TRIES);
834 spin_lock_irqsave(ap->lock, flags);
835 link->flags |= ATA_LFLAG_DISABLED;
836 spin_unlock_irqrestore(ap->lock, flags);
839 ata_dev_disable(link->device);
840 link->eh_context.i.action = 0;
846 * sata_pmp_eh_recover - recover PMP-enabled port
847 * @ap: ATA port to recover
849 * Drive EH recovery operation for PMP enabled port @ap. This
850 * function recovers host and PMP ports with proper retrials and
851 * fallbacks. Actual recovery operations are performed using
852 * ata_eh_recover() and sata_pmp_eh_recover_pmp().
855 * Kernel thread context (may sleep).
858 * 0 on success, -errno on failure.
860 static int sata_pmp_eh_recover(struct ata_port *ap)
862 struct ata_port_operations *ops = ap->ops;
863 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
864 struct ata_link *pmp_link = &ap->link;
865 struct ata_device *pmp_dev = pmp_link->device;
866 struct ata_eh_context *pmp_ehc = &pmp_link->eh_context;
867 struct ata_link *link;
868 struct ata_device *dev;
869 unsigned int err_mask;
870 u32 gscr_error, sntf;
873 pmp_tries = ATA_EH_PMP_TRIES;
874 ata_port_for_each_link(link, ap)
875 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
879 if (!sata_pmp_attached(ap)) {
880 rc = ata_eh_recover(ap, ops->prereset, ops->softreset,
881 ops->hardreset, ops->postreset, NULL);
883 ata_link_for_each_dev(dev, &ap->link)
884 ata_dev_disable(dev);
888 if (pmp_dev->class != ATA_DEV_PMP)
892 ata_port_for_each_link(link, ap)
893 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
899 rc = sata_pmp_eh_recover_pmp(ap, ops->prereset, ops->softreset,
900 ops->hardreset, ops->postreset);
904 /* handle disabled links */
905 rc = sata_pmp_eh_handle_disabled_links(ap);
910 rc = ata_eh_recover(ap, ops->pmp_prereset, ops->pmp_softreset,
911 ops->pmp_hardreset, ops->pmp_postreset, &link);
915 /* Connection status might have changed while resetting other
916 * links, check SATA_PMP_GSCR_ERROR before returning.
919 /* clear SNotification */
920 rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf);
922 sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf);
924 /* enable notification */
925 if (pmp_dev->flags & ATA_DFLAG_AN) {
926 pmp_dev->gscr[SATA_PMP_GSCR_FEAT_EN] |= SATA_PMP_FEAT_NOTIFY;
928 err_mask = sata_pmp_write(pmp_dev->link, SATA_PMP_GSCR_FEAT_EN,
929 pmp_dev->gscr[SATA_PMP_GSCR_FEAT_EN]);
931 ata_dev_printk(pmp_dev, KERN_ERR, "failed to write "
932 "PMP_FEAT_EN (Emask=0x%x)\n", err_mask);
938 /* check GSCR_ERROR */
939 err_mask = sata_pmp_read(pmp_link, SATA_PMP_GSCR_ERROR, &gscr_error);
941 ata_dev_printk(pmp_dev, KERN_ERR, "failed to read "
942 "PMP_GSCR_ERROR (Emask=0x%x)\n", err_mask);
948 ata_port_for_each_link(link, ap) {
949 if (!(gscr_error & (1 << link->pmp)))
952 if (sata_pmp_handle_link_fail(link, link_tries)) {
953 ata_ehi_hotplugged(&link->eh_context.i);
956 ata_link_printk(link, KERN_WARNING,
957 "PHY status changed but maxed out on retries, "
959 ata_link_printk(link, KERN_WARNING,
960 "Manully issue scan to resume this link\n");
965 ata_port_printk(ap, KERN_INFO, "PMP SError.N set for some "
966 "ports, repeating recovery\n");
973 if (sata_pmp_handle_link_fail(link, link_tries)) {
974 pmp_ehc->i.action |= ATA_EH_RESET;
980 /* Control always ends up here after detaching PMP. Shut up
981 * and return if we're unloading.
983 if (ap->pflags & ATA_PFLAG_UNLOADING)
986 if (!sata_pmp_attached(ap))
990 ata_port_printk(ap, KERN_WARNING,
991 "failed to recover PMP, retrying in 5 secs\n");
992 pmp_ehc->i.action |= ATA_EH_RESET;
997 ata_port_printk(ap, KERN_ERR,
998 "failed to recover PMP after %d tries, giving up\n",
1000 sata_pmp_detach(pmp_dev);
1001 ata_dev_disable(pmp_dev);
1007 * sata_pmp_error_handler - do standard error handling for PMP-enabled host
1008 * @ap: host port to handle error for
1010 * Perform standard error handling sequence for PMP-enabled host
1014 * Kernel thread context (may sleep).
1016 void sata_pmp_error_handler(struct ata_port *ap)
1020 sata_pmp_eh_recover(ap);
1024 EXPORT_SYMBOL_GPL(sata_pmp_port_ops);
1025 EXPORT_SYMBOL_GPL(sata_pmp_qc_defer_cmd_switch);
1026 EXPORT_SYMBOL_GPL(sata_pmp_error_handler);