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>
12 #include <linux/slab.h>
15 const struct ata_port_operations sata_pmp_port_ops
= {
16 .inherits
= &sata_port_ops
,
17 .pmp_prereset
= ata_std_prereset
,
18 .pmp_hardreset
= sata_std_hardreset
,
19 .pmp_postreset
= ata_std_postreset
,
20 .error_handler
= sata_pmp_error_handler
,
24 * sata_pmp_read - read PMP register
25 * @link: link to read PMP register for
26 * @reg: register to read
27 * @r_val: resulting value
32 * Kernel thread context (may sleep).
35 * 0 on success, AC_ERR_* mask on failure.
37 static unsigned int sata_pmp_read(struct ata_link
*link
, int reg
, u32
*r_val
)
39 struct ata_port
*ap
= link
->ap
;
40 struct ata_device
*pmp_dev
= ap
->link
.device
;
41 struct ata_taskfile tf
;
42 unsigned int err_mask
;
44 ata_tf_init(pmp_dev
, &tf
);
45 tf
.command
= ATA_CMD_PMP_READ
;
46 tf
.protocol
= ATA_PROT_NODATA
;
47 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
| ATA_TFLAG_LBA48
;
49 tf
.device
= link
->pmp
;
51 err_mask
= ata_exec_internal(pmp_dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0,
56 *r_val
= tf
.nsect
| tf
.lbal
<< 8 | tf
.lbam
<< 16 | tf
.lbah
<< 24;
61 * sata_pmp_write - write PMP register
62 * @link: link to write PMP register for
63 * @reg: register to write
64 * @r_val: value to write
69 * Kernel thread context (may sleep).
72 * 0 on success, AC_ERR_* mask on failure.
74 static unsigned int sata_pmp_write(struct ata_link
*link
, int reg
, u32 val
)
76 struct ata_port
*ap
= link
->ap
;
77 struct ata_device
*pmp_dev
= ap
->link
.device
;
78 struct ata_taskfile tf
;
80 ata_tf_init(pmp_dev
, &tf
);
81 tf
.command
= ATA_CMD_PMP_WRITE
;
82 tf
.protocol
= ATA_PROT_NODATA
;
83 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
| ATA_TFLAG_LBA48
;
85 tf
.device
= link
->pmp
;
86 tf
.nsect
= val
& 0xff;
87 tf
.lbal
= (val
>> 8) & 0xff;
88 tf
.lbam
= (val
>> 16) & 0xff;
89 tf
.lbah
= (val
>> 24) & 0xff;
91 return ata_exec_internal(pmp_dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0,
96 * sata_pmp_qc_defer_cmd_switch - qc_defer for command switching PMP
97 * @qc: ATA command in question
99 * A host which has command switching PMP support cannot issue
100 * commands to multiple links simultaneously.
103 * spin_lock_irqsave(host lock)
106 * ATA_DEFER_* if deferring is needed, 0 otherwise.
108 int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd
*qc
)
110 struct ata_link
*link
= qc
->dev
->link
;
111 struct ata_port
*ap
= link
->ap
;
113 if (ap
->excl_link
== NULL
|| ap
->excl_link
== link
) {
114 if (ap
->nr_active_links
== 0 || ata_link_active(link
)) {
115 qc
->flags
|= ATA_QCFLAG_CLEAR_EXCL
;
116 return ata_std_qc_defer(qc
);
119 ap
->excl_link
= link
;
122 return ATA_DEFER_PORT
;
126 * sata_pmp_scr_read - read PSCR
127 * @link: ATA link to read PSCR for
129 * @r_val: resulting value
131 * Read PSCR @reg into @r_val for @link, to be called from
135 * Kernel thread context (may sleep).
138 * 0 on success, -errno on failure.
140 int sata_pmp_scr_read(struct ata_link
*link
, int reg
, u32
*r_val
)
142 unsigned int err_mask
;
144 if (reg
> SATA_PMP_PSCR_CONTROL
)
147 err_mask
= sata_pmp_read(link
, reg
, r_val
);
149 ata_link_printk(link
, KERN_WARNING
, "failed to read SCR %d "
150 "(Emask=0x%x)\n", reg
, err_mask
);
157 * sata_pmp_scr_write - write PSCR
158 * @link: ATA link to write PSCR for
159 * @reg: PSCR to write
160 * @val: value to be written
162 * Write @val to PSCR @reg for @link, to be called from
163 * ata_scr_write() and ata_scr_write_flush().
166 * Kernel thread context (may sleep).
169 * 0 on success, -errno on failure.
171 int sata_pmp_scr_write(struct ata_link
*link
, int reg
, u32 val
)
173 unsigned int err_mask
;
175 if (reg
> SATA_PMP_PSCR_CONTROL
)
178 err_mask
= sata_pmp_write(link
, reg
, val
);
180 ata_link_printk(link
, KERN_WARNING
, "failed to write SCR %d "
181 "(Emask=0x%x)\n", reg
, err_mask
);
188 * sata_pmp_read_gscr - read GSCR block of SATA PMP
190 * @gscr: buffer to read GSCR block into
192 * Read selected PMP GSCRs from the PMP at @dev. This will serve
193 * as configuration and identification info for the PMP.
196 * Kernel thread context (may sleep).
199 * 0 on success, -errno on failure.
201 static int sata_pmp_read_gscr(struct ata_device
*dev
, u32
*gscr
)
203 static const int gscr_to_read
[] = { 0, 1, 2, 32, 33, 64, 96 };
206 for (i
= 0; i
< ARRAY_SIZE(gscr_to_read
); i
++) {
207 int reg
= gscr_to_read
[i
];
208 unsigned int err_mask
;
210 err_mask
= sata_pmp_read(dev
->link
, reg
, &gscr
[reg
]);
212 ata_dev_printk(dev
, KERN_ERR
, "failed to read PMP "
213 "GSCR[%d] (Emask=0x%x)\n", reg
, err_mask
);
221 static const char *sata_pmp_spec_rev_str(const u32
*gscr
)
223 u32 rev
= gscr
[SATA_PMP_GSCR_REV
];
234 static int sata_pmp_configure(struct ata_device
*dev
, int print_info
)
236 struct ata_port
*ap
= dev
->link
->ap
;
237 u32
*gscr
= dev
->gscr
;
238 unsigned int err_mask
= 0;
242 nr_ports
= sata_pmp_gscr_ports(gscr
);
244 if (nr_ports
<= 0 || nr_ports
> SATA_PMP_MAX_PORTS
) {
246 reason
= "invalid nr_ports";
250 if ((ap
->flags
& ATA_FLAG_AN
) &&
251 (gscr
[SATA_PMP_GSCR_FEAT
] & SATA_PMP_FEAT_NOTIFY
))
252 dev
->flags
|= ATA_DFLAG_AN
;
254 /* monitor SERR_PHYRDY_CHG on fan-out ports */
255 err_mask
= sata_pmp_write(dev
->link
, SATA_PMP_GSCR_ERROR_EN
,
259 reason
= "failed to write GSCR_ERROR_EN";
264 ata_dev_printk(dev
, KERN_INFO
, "Port Multiplier %s, "
265 "0x%04x:0x%04x r%d, %d ports, feat 0x%x/0x%x\n",
266 sata_pmp_spec_rev_str(gscr
),
267 sata_pmp_gscr_vendor(gscr
),
268 sata_pmp_gscr_devid(gscr
),
269 sata_pmp_gscr_rev(gscr
),
270 nr_ports
, gscr
[SATA_PMP_GSCR_FEAT_EN
],
271 gscr
[SATA_PMP_GSCR_FEAT
]);
273 if (!(dev
->flags
& ATA_DFLAG_AN
))
274 ata_dev_printk(dev
, KERN_INFO
,
275 "Asynchronous notification not supported, "
276 "hotplug won't\n work on fan-out "
277 "ports. Use warm-plug instead.\n");
283 ata_dev_printk(dev
, KERN_ERR
,
284 "failed to configure Port Multiplier (%s, Emask=0x%x)\n",
289 static int sata_pmp_init_links(struct ata_port
*ap
, int nr_ports
)
291 struct ata_link
*pmp_link
= ap
->pmp_link
;
295 pmp_link
= kzalloc(sizeof(pmp_link
[0]) * SATA_PMP_MAX_PORTS
,
300 for (i
= 0; i
< SATA_PMP_MAX_PORTS
; i
++)
301 ata_link_init(ap
, &pmp_link
[i
], i
);
303 ap
->pmp_link
= pmp_link
;
306 for (i
= 0; i
< nr_ports
; i
++) {
307 struct ata_link
*link
= &pmp_link
[i
];
308 struct ata_eh_context
*ehc
= &link
->eh_context
;
311 ehc
->i
.probe_mask
|= ATA_ALL_DEVICES
;
312 ehc
->i
.action
|= ATA_EH_RESET
;
318 static void sata_pmp_quirks(struct ata_port
*ap
)
320 u32
*gscr
= ap
->link
.device
->gscr
;
321 u16 vendor
= sata_pmp_gscr_vendor(gscr
);
322 u16 devid
= sata_pmp_gscr_devid(gscr
);
323 struct ata_link
*link
;
325 if (vendor
== 0x1095 && devid
== 0x3726) {
327 ata_for_each_link(link
, ap
, EDGE
) {
328 /* Class code report is unreliable and SRST
329 * times out under certain configurations.
332 link
->flags
|= ATA_LFLAG_NO_SRST
|
333 ATA_LFLAG_ASSUME_ATA
;
335 /* port 5 is for SEMB device and it doesn't like SRST */
337 link
->flags
|= ATA_LFLAG_NO_SRST
|
338 ATA_LFLAG_ASSUME_SEMB
;
340 } else if (vendor
== 0x1095 && devid
== 0x4723) {
342 ata_for_each_link(link
, ap
, EDGE
) {
343 /* class code report is unreliable */
345 link
->flags
|= ATA_LFLAG_ASSUME_ATA
;
347 /* the config device at port 2 locks up on SRST */
349 link
->flags
|= ATA_LFLAG_NO_SRST
|
350 ATA_LFLAG_ASSUME_ATA
;
352 } else if (vendor
== 0x1095 && devid
== 0x4726) {
354 ata_for_each_link(link
, ap
, EDGE
) {
355 /* Class code report is unreliable and SRST
356 * times out under certain configurations.
357 * Config device can be at port 0 or 5 and
361 link
->flags
|= ATA_LFLAG_NO_SRST
|
362 ATA_LFLAG_ASSUME_ATA
;
364 /* Port 6 is for SEMB device which doesn't
368 link
->flags
|= ATA_LFLAG_NO_SRST
|
369 ATA_LFLAG_ASSUME_SEMB
;
371 } else if (vendor
== 0x1095 && (devid
== 0x5723 || devid
== 0x5733 ||
372 devid
== 0x5734 || devid
== 0x5744)) {
373 /* sil5723/5744 quirks */
375 /* sil5723/5744 has either two or three downstream
376 * ports depending on operation mode. The last port
377 * is empty if any actual IO device is available or
378 * occupied by a pseudo configuration device
379 * otherwise. Don't try hard to recover it.
381 ap
->pmp_link
[ap
->nr_pmp_links
- 1].flags
|= ATA_LFLAG_NO_RETRY
;
386 * sata_pmp_attach - attach a SATA PMP device
387 * @dev: SATA PMP device to attach
389 * Configure and attach SATA PMP device @dev. This function is
390 * also responsible for allocating and initializing PMP links.
393 * Kernel thread context (may sleep).
396 * 0 on success, -errno on failure.
398 int sata_pmp_attach(struct ata_device
*dev
)
400 struct ata_link
*link
= dev
->link
;
401 struct ata_port
*ap
= link
->ap
;
403 struct ata_link
*tlink
;
406 /* is it hanging off the right place? */
407 if (!sata_pmp_supported(ap
)) {
408 ata_dev_printk(dev
, KERN_ERR
,
409 "host does not support Port Multiplier\n");
413 if (!ata_is_host_link(link
)) {
414 ata_dev_printk(dev
, KERN_ERR
,
415 "Port Multipliers cannot be nested\n");
420 ata_dev_printk(dev
, KERN_ERR
,
421 "Port Multiplier must be the first device\n");
425 WARN_ON(link
->pmp
!= 0);
426 link
->pmp
= SATA_PMP_CTRL_PORT
;
428 /* read GSCR block */
429 rc
= sata_pmp_read_gscr(dev
, dev
->gscr
);
434 rc
= sata_pmp_configure(dev
, 1);
438 rc
= sata_pmp_init_links(ap
, sata_pmp_gscr_ports(dev
->gscr
));
440 ata_dev_printk(dev
, KERN_INFO
,
441 "failed to initialize PMP links\n");
446 spin_lock_irqsave(ap
->lock
, flags
);
447 WARN_ON(ap
->nr_pmp_links
);
448 ap
->nr_pmp_links
= sata_pmp_gscr_ports(dev
->gscr
);
449 spin_unlock_irqrestore(ap
->lock
, flags
);
453 if (ap
->ops
->pmp_attach
)
454 ap
->ops
->pmp_attach(ap
);
456 ata_for_each_link(tlink
, ap
, EDGE
)
457 sata_link_init_spd(tlink
);
459 ata_acpi_associate_sata_port(ap
);
469 * sata_pmp_detach - detach a SATA PMP device
470 * @dev: SATA PMP device to detach
472 * Detach SATA PMP device @dev. This function is also
473 * responsible for deconfiguring PMP links.
476 * Kernel thread context (may sleep).
478 static void sata_pmp_detach(struct ata_device
*dev
)
480 struct ata_link
*link
= dev
->link
;
481 struct ata_port
*ap
= link
->ap
;
482 struct ata_link
*tlink
;
485 ata_dev_printk(dev
, KERN_INFO
, "Port Multiplier detaching\n");
487 WARN_ON(!ata_is_host_link(link
) || dev
->devno
||
488 link
->pmp
!= SATA_PMP_CTRL_PORT
);
490 if (ap
->ops
->pmp_detach
)
491 ap
->ops
->pmp_detach(ap
);
493 ata_for_each_link(tlink
, ap
, EDGE
)
494 ata_eh_detach_dev(tlink
->device
);
496 spin_lock_irqsave(ap
->lock
, flags
);
497 ap
->nr_pmp_links
= 0;
499 spin_unlock_irqrestore(ap
->lock
, flags
);
501 ata_acpi_associate_sata_port(ap
);
505 * sata_pmp_same_pmp - does new GSCR matches the configured PMP?
506 * @dev: PMP device to compare against
507 * @new_gscr: GSCR block of the new device
509 * Compare @new_gscr against @dev and determine whether @dev is
510 * the PMP described by @new_gscr.
516 * 1 if @dev matches @new_gscr, 0 otherwise.
518 static int sata_pmp_same_pmp(struct ata_device
*dev
, const u32
*new_gscr
)
520 const u32
*old_gscr
= dev
->gscr
;
521 u16 old_vendor
, new_vendor
, old_devid
, new_devid
;
522 int old_nr_ports
, new_nr_ports
;
524 old_vendor
= sata_pmp_gscr_vendor(old_gscr
);
525 new_vendor
= sata_pmp_gscr_vendor(new_gscr
);
526 old_devid
= sata_pmp_gscr_devid(old_gscr
);
527 new_devid
= sata_pmp_gscr_devid(new_gscr
);
528 old_nr_ports
= sata_pmp_gscr_ports(old_gscr
);
529 new_nr_ports
= sata_pmp_gscr_ports(new_gscr
);
531 if (old_vendor
!= new_vendor
) {
532 ata_dev_printk(dev
, KERN_INFO
, "Port Multiplier "
533 "vendor mismatch '0x%x' != '0x%x'\n",
534 old_vendor
, new_vendor
);
538 if (old_devid
!= new_devid
) {
539 ata_dev_printk(dev
, KERN_INFO
, "Port Multiplier "
540 "device ID mismatch '0x%x' != '0x%x'\n",
541 old_devid
, new_devid
);
545 if (old_nr_ports
!= new_nr_ports
) {
546 ata_dev_printk(dev
, KERN_INFO
, "Port Multiplier "
547 "nr_ports mismatch '0x%x' != '0x%x'\n",
548 old_nr_ports
, new_nr_ports
);
556 * sata_pmp_revalidate - revalidate SATA PMP
557 * @dev: PMP device to revalidate
558 * @new_class: new class code
560 * Re-read GSCR block and make sure @dev is still attached to the
561 * port and properly configured.
564 * Kernel thread context (may sleep).
567 * 0 on success, -errno otherwise.
569 static int sata_pmp_revalidate(struct ata_device
*dev
, unsigned int new_class
)
571 struct ata_link
*link
= dev
->link
;
572 struct ata_port
*ap
= link
->ap
;
573 u32
*gscr
= (void *)ap
->sector_buf
;
578 ata_eh_about_to_do(link
, NULL
, ATA_EH_REVALIDATE
);
580 if (!ata_dev_enabled(dev
)) {
586 if (ata_class_enabled(new_class
) && new_class
!= ATA_DEV_PMP
) {
592 rc
= sata_pmp_read_gscr(dev
, gscr
);
596 /* is the pmp still there? */
597 if (!sata_pmp_same_pmp(dev
, gscr
)) {
602 memcpy(dev
->gscr
, gscr
, sizeof(gscr
[0]) * SATA_PMP_GSCR_DWORDS
);
604 rc
= sata_pmp_configure(dev
, 0);
608 ata_eh_done(link
, NULL
, ATA_EH_REVALIDATE
);
610 DPRINTK("EXIT, rc=0\n");
614 ata_dev_printk(dev
, KERN_ERR
,
615 "PMP revalidation failed (errno=%d)\n", rc
);
616 DPRINTK("EXIT, rc=%d\n", rc
);
621 * sata_pmp_revalidate_quick - revalidate SATA PMP quickly
622 * @dev: PMP device to revalidate
624 * Make sure the attached PMP is accessible.
627 * Kernel thread context (may sleep).
630 * 0 on success, -errno otherwise.
632 static int sata_pmp_revalidate_quick(struct ata_device
*dev
)
634 unsigned int err_mask
;
637 err_mask
= sata_pmp_read(dev
->link
, SATA_PMP_GSCR_PROD_ID
, &prod_id
);
639 ata_dev_printk(dev
, KERN_ERR
, "failed to read PMP product ID "
640 "(Emask=0x%x)\n", err_mask
);
644 if (prod_id
!= dev
->gscr
[SATA_PMP_GSCR_PROD_ID
]) {
645 ata_dev_printk(dev
, KERN_ERR
, "PMP product ID mismatch\n");
646 /* something weird is going on, request full PMP recovery */
654 * sata_pmp_eh_recover_pmp - recover PMP
655 * @ap: ATA port PMP is attached to
656 * @prereset: prereset method (can be NULL)
657 * @softreset: softreset method
658 * @hardreset: hardreset method
659 * @postreset: postreset method (can be NULL)
661 * Recover PMP attached to @ap. Recovery procedure is somewhat
662 * similar to that of ata_eh_recover() except that reset should
663 * always be performed in hard->soft sequence and recovery
664 * failure results in PMP detachment.
667 * Kernel thread context (may sleep).
670 * 0 on success, -errno on failure.
672 static int sata_pmp_eh_recover_pmp(struct ata_port
*ap
,
673 ata_prereset_fn_t prereset
, ata_reset_fn_t softreset
,
674 ata_reset_fn_t hardreset
, ata_postreset_fn_t postreset
)
676 struct ata_link
*link
= &ap
->link
;
677 struct ata_eh_context
*ehc
= &link
->eh_context
;
678 struct ata_device
*dev
= link
->device
;
679 int tries
= ATA_EH_PMP_TRIES
;
680 int detach
= 0, rc
= 0;
681 int reval_failed
= 0;
685 if (dev
->flags
& ATA_DFLAG_DETACH
) {
691 ehc
->classes
[0] = ATA_DEV_UNKNOWN
;
693 if (ehc
->i
.action
& ATA_EH_RESET
) {
694 struct ata_link
*tlink
;
697 rc
= ata_eh_reset(link
, 0, prereset
, softreset
, hardreset
,
700 ata_link_printk(link
, KERN_ERR
,
701 "failed to reset PMP, giving up\n");
705 /* PMP is reset, SErrors cannot be trusted, scan all */
706 ata_for_each_link(tlink
, ap
, EDGE
) {
707 struct ata_eh_context
*ehc
= &tlink
->eh_context
;
709 ehc
->i
.probe_mask
|= ATA_ALL_DEVICES
;
710 ehc
->i
.action
|= ATA_EH_RESET
;
714 /* If revalidation is requested, revalidate and reconfigure;
715 * otherwise, do quick revalidation.
717 if (ehc
->i
.action
& ATA_EH_REVALIDATE
)
718 rc
= sata_pmp_revalidate(dev
, ehc
->classes
[0]);
720 rc
= sata_pmp_revalidate_quick(dev
);
726 ehc
->i
.probe_mask
|= ATA_ALL_DEVICES
;
728 /* give it just two more chances */
729 tries
= min(tries
, 2);
733 /* consecutive revalidation failures? speed down */
735 sata_down_spd_limit(link
, 0);
739 ehc
->i
.action
|= ATA_EH_RESET
;
742 ata_dev_printk(dev
, KERN_ERR
, "failed to recover PMP "
743 "after %d tries, giving up\n",
749 /* okay, PMP resurrected */
752 DPRINTK("EXIT, rc=0\n");
756 sata_pmp_detach(dev
);
758 ata_eh_detach_dev(dev
);
760 ata_dev_disable(dev
);
762 DPRINTK("EXIT, rc=%d\n", rc
);
766 static int sata_pmp_eh_handle_disabled_links(struct ata_port
*ap
)
768 struct ata_link
*link
;
772 spin_lock_irqsave(ap
->lock
, flags
);
774 ata_for_each_link(link
, ap
, EDGE
) {
775 if (!(link
->flags
& ATA_LFLAG_DISABLED
))
778 spin_unlock_irqrestore(ap
->lock
, flags
);
780 /* Some PMPs require hardreset sequence to get
783 sata_link_hardreset(link
, sata_deb_timing_normal
,
784 ata_deadline(jiffies
, ATA_TMOUT_INTERNAL_QUICK
),
787 /* unconditionally clear SError.N */
788 rc
= sata_scr_write(link
, SCR_ERROR
, SERR_PHYRDY_CHG
);
790 ata_link_printk(link
, KERN_ERR
, "failed to clear "
791 "SError.N (errno=%d)\n", rc
);
795 spin_lock_irqsave(ap
->lock
, flags
);
798 spin_unlock_irqrestore(ap
->lock
, flags
);
803 static int sata_pmp_handle_link_fail(struct ata_link
*link
, int *link_tries
)
805 struct ata_port
*ap
= link
->ap
;
808 if (link_tries
[link
->pmp
] && --link_tries
[link
->pmp
])
811 /* disable this link */
812 if (!(link
->flags
& ATA_LFLAG_DISABLED
)) {
813 ata_link_printk(link
, KERN_WARNING
,
814 "failed to recover link after %d tries, disabling\n",
815 ATA_EH_PMP_LINK_TRIES
);
817 spin_lock_irqsave(ap
->lock
, flags
);
818 link
->flags
|= ATA_LFLAG_DISABLED
;
819 spin_unlock_irqrestore(ap
->lock
, flags
);
822 ata_dev_disable(link
->device
);
823 link
->eh_context
.i
.action
= 0;
829 * sata_pmp_eh_recover - recover PMP-enabled port
830 * @ap: ATA port to recover
832 * Drive EH recovery operation for PMP enabled port @ap. This
833 * function recovers host and PMP ports with proper retrials and
834 * fallbacks. Actual recovery operations are performed using
835 * ata_eh_recover() and sata_pmp_eh_recover_pmp().
838 * Kernel thread context (may sleep).
841 * 0 on success, -errno on failure.
843 static int sata_pmp_eh_recover(struct ata_port
*ap
)
845 struct ata_port_operations
*ops
= ap
->ops
;
846 int pmp_tries
, link_tries
[SATA_PMP_MAX_PORTS
];
847 struct ata_link
*pmp_link
= &ap
->link
;
848 struct ata_device
*pmp_dev
= pmp_link
->device
;
849 struct ata_eh_context
*pmp_ehc
= &pmp_link
->eh_context
;
850 u32
*gscr
= pmp_dev
->gscr
;
851 struct ata_link
*link
;
852 struct ata_device
*dev
;
853 unsigned int err_mask
;
854 u32 gscr_error
, sntf
;
857 pmp_tries
= ATA_EH_PMP_TRIES
;
858 ata_for_each_link(link
, ap
, EDGE
)
859 link_tries
[link
->pmp
] = ATA_EH_PMP_LINK_TRIES
;
863 if (!sata_pmp_attached(ap
)) {
864 rc
= ata_eh_recover(ap
, ops
->prereset
, ops
->softreset
,
865 ops
->hardreset
, ops
->postreset
, NULL
);
867 ata_for_each_dev(dev
, &ap
->link
, ALL
)
868 ata_dev_disable(dev
);
872 if (pmp_dev
->class != ATA_DEV_PMP
)
876 ata_for_each_link(link
, ap
, EDGE
)
877 link_tries
[link
->pmp
] = ATA_EH_PMP_LINK_TRIES
;
883 rc
= sata_pmp_eh_recover_pmp(ap
, ops
->prereset
, ops
->softreset
,
884 ops
->hardreset
, ops
->postreset
);
888 /* PHY event notification can disturb reset and other recovery
889 * operations. Turn it off.
891 if (gscr
[SATA_PMP_GSCR_FEAT_EN
] & SATA_PMP_FEAT_NOTIFY
) {
892 gscr
[SATA_PMP_GSCR_FEAT_EN
] &= ~SATA_PMP_FEAT_NOTIFY
;
894 err_mask
= sata_pmp_write(pmp_link
, SATA_PMP_GSCR_FEAT_EN
,
895 gscr
[SATA_PMP_GSCR_FEAT_EN
]);
897 ata_link_printk(pmp_link
, KERN_WARNING
,
898 "failed to disable NOTIFY (err_mask=0x%x)\n",
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 gscr
[SATA_PMP_GSCR_FEAT_EN
] |= SATA_PMP_FEAT_NOTIFY
;
928 err_mask
= sata_pmp_write(pmp_link
, SATA_PMP_GSCR_FEAT_EN
,
929 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_for_each_link(link
, ap
, EDGE
) {
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 pmp_ehc
->i
.action
|= ATA_EH_RESET
;
994 ata_port_printk(ap
, KERN_ERR
,
995 "failed to recover PMP after %d tries, giving up\n",
997 sata_pmp_detach(pmp_dev
);
998 ata_dev_disable(pmp_dev
);
1004 * sata_pmp_error_handler - do standard error handling for PMP-enabled host
1005 * @ap: host port to handle error for
1007 * Perform standard error handling sequence for PMP-enabled host
1011 * Kernel thread context (may sleep).
1013 void sata_pmp_error_handler(struct ata_port
*ap
)
1017 sata_pmp_eh_recover(ap
);
1021 EXPORT_SYMBOL_GPL(sata_pmp_port_ops
);
1022 EXPORT_SYMBOL_GPL(sata_pmp_qc_defer_cmd_switch
);
1023 EXPORT_SYMBOL_GPL(sata_pmp_error_handler
);