1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SATA specific part of ATA helper library
5 * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
6 * Copyright 2003-2004 Jeff Garzik
7 * Copyright 2006 Tejun Heo <htejun@gmail.com>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <scsi/scsi_cmnd.h>
13 #include <scsi/scsi_device.h>
14 #include <scsi/scsi_eh.h>
15 #include <linux/libata.h>
16 #include <linux/unaligned.h>
19 #include "libata-transport.h"
21 /* debounce timing parameters in msecs { interval, duration, timeout } */
22 const unsigned int sata_deb_timing_normal
[] = { 5, 100, 2000 };
23 EXPORT_SYMBOL_GPL(sata_deb_timing_normal
);
24 const unsigned int sata_deb_timing_hotplug
[] = { 25, 500, 2000 };
25 EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug
);
26 const unsigned int sata_deb_timing_long
[] = { 100, 2000, 5000 };
27 EXPORT_SYMBOL_GPL(sata_deb_timing_long
);
30 * sata_scr_valid - test whether SCRs are accessible
31 * @link: ATA link to test SCR accessibility for
33 * Test whether SCRs are accessible for @link.
39 * 1 if SCRs are accessible, 0 otherwise.
41 int sata_scr_valid(struct ata_link
*link
)
43 struct ata_port
*ap
= link
->ap
;
45 return (ap
->flags
& ATA_FLAG_SATA
) && ap
->ops
->scr_read
;
47 EXPORT_SYMBOL_GPL(sata_scr_valid
);
50 * sata_scr_read - read SCR register of the specified port
51 * @link: ATA link to read SCR for
53 * @val: Place to store read value
55 * Read SCR register @reg of @link into *@val. This function is
56 * guaranteed to succeed if @link is ap->link, the cable type of
57 * the port is SATA and the port implements ->scr_read.
60 * None if @link is ap->link. Kernel thread context otherwise.
63 * 0 on success, negative errno on failure.
65 int sata_scr_read(struct ata_link
*link
, int reg
, u32
*val
)
67 if (ata_is_host_link(link
)) {
68 if (sata_scr_valid(link
))
69 return link
->ap
->ops
->scr_read(link
, reg
, val
);
73 return sata_pmp_scr_read(link
, reg
, val
);
75 EXPORT_SYMBOL_GPL(sata_scr_read
);
78 * sata_scr_write - write SCR register of the specified port
79 * @link: ATA link to write SCR for
81 * @val: value to write
83 * Write @val to SCR register @reg of @link. This function is
84 * guaranteed to succeed if @link is ap->link, the cable type of
85 * the port is SATA and the port implements ->scr_read.
88 * None if @link is ap->link. Kernel thread context otherwise.
91 * 0 on success, negative errno on failure.
93 int sata_scr_write(struct ata_link
*link
, int reg
, u32 val
)
95 if (ata_is_host_link(link
)) {
96 if (sata_scr_valid(link
))
97 return link
->ap
->ops
->scr_write(link
, reg
, val
);
101 return sata_pmp_scr_write(link
, reg
, val
);
103 EXPORT_SYMBOL_GPL(sata_scr_write
);
106 * sata_scr_write_flush - write SCR register of the specified port and flush
107 * @link: ATA link to write SCR for
109 * @val: value to write
111 * This function is identical to sata_scr_write() except that this
112 * function performs flush after writing to the register.
115 * None if @link is ap->link. Kernel thread context otherwise.
118 * 0 on success, negative errno on failure.
120 int sata_scr_write_flush(struct ata_link
*link
, int reg
, u32 val
)
122 if (ata_is_host_link(link
)) {
125 if (sata_scr_valid(link
)) {
126 rc
= link
->ap
->ops
->scr_write(link
, reg
, val
);
128 rc
= link
->ap
->ops
->scr_read(link
, reg
, &val
);
134 return sata_pmp_scr_write(link
, reg
, val
);
136 EXPORT_SYMBOL_GPL(sata_scr_write_flush
);
139 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
140 * @tf: Taskfile to convert
141 * @pmp: Port multiplier port
142 * @is_cmd: This FIS is for command
143 * @fis: Buffer into which data will output
145 * Converts a standard ATA taskfile to a Serial ATA
146 * FIS structure (Register - Host to Device).
149 * Inherited from caller.
151 void ata_tf_to_fis(const struct ata_taskfile
*tf
, u8 pmp
, int is_cmd
, u8
*fis
)
153 fis
[0] = 0x27; /* Register - Host to Device FIS */
154 fis
[1] = pmp
& 0xf; /* Port multiplier number*/
156 fis
[1] |= (1 << 7); /* bit 7 indicates Command FIS */
158 fis
[2] = tf
->command
;
159 fis
[3] = tf
->feature
;
166 fis
[8] = tf
->hob_lbal
;
167 fis
[9] = tf
->hob_lbam
;
168 fis
[10] = tf
->hob_lbah
;
169 fis
[11] = tf
->hob_feature
;
172 fis
[13] = tf
->hob_nsect
;
176 fis
[16] = tf
->auxiliary
& 0xff;
177 fis
[17] = (tf
->auxiliary
>> 8) & 0xff;
178 fis
[18] = (tf
->auxiliary
>> 16) & 0xff;
179 fis
[19] = (tf
->auxiliary
>> 24) & 0xff;
181 EXPORT_SYMBOL_GPL(ata_tf_to_fis
);
184 * ata_tf_from_fis - Convert SATA FIS to ATA taskfile
185 * @fis: Buffer from which data will be input
186 * @tf: Taskfile to output
188 * Converts a serial ATA FIS structure to a standard ATA taskfile.
191 * Inherited from caller.
194 void ata_tf_from_fis(const u8
*fis
, struct ata_taskfile
*tf
)
204 tf
->hob_lbal
= fis
[8];
205 tf
->hob_lbam
= fis
[9];
206 tf
->hob_lbah
= fis
[10];
209 tf
->hob_nsect
= fis
[13];
211 EXPORT_SYMBOL_GPL(ata_tf_from_fis
);
214 * sata_link_debounce - debounce SATA phy status
215 * @link: ATA link to debounce SATA phy status for
216 * @params: timing parameters { interval, duration, timeout } in msec
217 * @deadline: deadline jiffies for the operation
219 * Make sure SStatus of @link reaches stable state, determined by
220 * holding the same value where DET is not 1 for @duration polled
221 * every @interval, before @timeout. Timeout constraints the
222 * beginning of the stable state. Because DET gets stuck at 1 on
223 * some controllers after hot unplugging, this functions waits
224 * until timeout then returns 0 if DET is stable at 1.
226 * @timeout is further limited by @deadline. The sooner of the
230 * Kernel thread context (may sleep)
233 * 0 on success, -errno on failure.
235 int sata_link_debounce(struct ata_link
*link
, const unsigned int *params
,
236 unsigned long deadline
)
238 unsigned int interval
= params
[0];
239 unsigned int duration
= params
[1];
240 unsigned long last_jiffies
, t
;
244 t
= ata_deadline(jiffies
, params
[2]);
245 if (time_before(t
, deadline
))
248 if ((rc
= sata_scr_read(link
, SCR_STATUS
, &cur
)))
253 last_jiffies
= jiffies
;
256 ata_msleep(link
->ap
, interval
);
257 if ((rc
= sata_scr_read(link
, SCR_STATUS
, &cur
)))
263 if (cur
== 1 && time_before(jiffies
, deadline
))
265 if (time_after(jiffies
,
266 ata_deadline(last_jiffies
, duration
)))
271 /* unstable, start over */
273 last_jiffies
= jiffies
;
275 /* Check deadline. If debouncing failed, return
276 * -EPIPE to tell upper layer to lower link speed.
278 if (time_after(jiffies
, deadline
))
282 EXPORT_SYMBOL_GPL(sata_link_debounce
);
285 * sata_link_resume - resume SATA link
286 * @link: ATA link to resume SATA
287 * @params: timing parameters { interval, duration, timeout } in msec
288 * @deadline: deadline jiffies for the operation
290 * Resume SATA phy @link and debounce it.
293 * Kernel thread context (may sleep)
296 * 0 on success, -errno on failure.
298 int sata_link_resume(struct ata_link
*link
, const unsigned int *params
,
299 unsigned long deadline
)
301 int tries
= ATA_LINK_RESUME_TRIES
;
302 u32 scontrol
, serror
;
305 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
309 * Writes to SControl sometimes get ignored under certain
310 * controllers (ata_piix SIDPR). Make sure DET actually is
314 scontrol
= (scontrol
& 0x0f0) | 0x300;
315 if ((rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
)))
318 * Some PHYs react badly if SStatus is pounded
319 * immediately after resuming. Delay 200ms before
322 if (!(link
->flags
& ATA_LFLAG_NO_DEBOUNCE_DELAY
))
323 ata_msleep(link
->ap
, 200);
325 /* is SControl restored correctly? */
326 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
328 } while ((scontrol
& 0xf0f) != 0x300 && --tries
);
330 if ((scontrol
& 0xf0f) != 0x300) {
331 ata_link_warn(link
, "failed to resume link (SControl %X)\n",
336 if (tries
< ATA_LINK_RESUME_TRIES
)
337 ata_link_warn(link
, "link resume succeeded after %d retries\n",
338 ATA_LINK_RESUME_TRIES
- tries
);
340 if ((rc
= sata_link_debounce(link
, params
, deadline
)))
343 /* clear SError, some PHYs require this even for SRST to work */
344 if (!(rc
= sata_scr_read(link
, SCR_ERROR
, &serror
)))
345 rc
= sata_scr_write(link
, SCR_ERROR
, serror
);
347 return rc
!= -EINVAL
? rc
: 0;
349 EXPORT_SYMBOL_GPL(sata_link_resume
);
352 * sata_link_scr_lpm - manipulate SControl IPM and SPM fields
353 * @link: ATA link to manipulate SControl for
354 * @policy: LPM policy to configure
355 * @spm_wakeup: initiate LPM transition to active state
357 * Manipulate the IPM field of the SControl register of @link
358 * according to @policy. If @policy is ATA_LPM_MAX_POWER and
359 * @spm_wakeup is %true, the SPM field is manipulated to wake up
360 * the link. This function also clears PHYRDY_CHG before
367 * 0 on success, -errno otherwise.
369 int sata_link_scr_lpm(struct ata_link
*link
, enum ata_lpm_policy policy
,
372 struct ata_eh_context
*ehc
= &link
->eh_context
;
373 bool woken_up
= false;
377 rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
);
382 case ATA_LPM_MAX_POWER
:
383 /* disable all LPM transitions */
384 scontrol
|= (0x7 << 8);
385 /* initiate transition to active state */
387 scontrol
|= (0x4 << 12);
391 case ATA_LPM_MED_POWER
:
392 /* allow LPM to PARTIAL */
393 scontrol
&= ~(0x1 << 8);
394 scontrol
|= (0x6 << 8);
396 case ATA_LPM_MED_POWER_WITH_DIPM
:
397 case ATA_LPM_MIN_POWER_WITH_PARTIAL
:
398 case ATA_LPM_MIN_POWER
:
399 if (ata_link_nr_enabled(link
) > 0) {
400 /* assume no restrictions on LPM transitions */
401 scontrol
&= ~(0x7 << 8);
404 * If the controller does not support partial, slumber,
405 * or devsleep, then disallow these transitions.
407 if (link
->ap
->host
->flags
& ATA_HOST_NO_PART
)
408 scontrol
|= (0x1 << 8);
410 if (link
->ap
->host
->flags
& ATA_HOST_NO_SSC
)
411 scontrol
|= (0x2 << 8);
413 if (link
->ap
->host
->flags
& ATA_HOST_NO_DEVSLP
)
414 scontrol
|= (0x4 << 8);
416 /* empty port, power off */
418 scontrol
|= (0x1 << 2);
425 rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
);
429 /* give the link time to transit out of LPM state */
433 /* clear PHYRDY_CHG from SError */
434 ehc
->i
.serror
&= ~SERR_PHYRDY_CHG
;
435 return sata_scr_write(link
, SCR_ERROR
, SERR_PHYRDY_CHG
);
437 EXPORT_SYMBOL_GPL(sata_link_scr_lpm
);
439 static int __sata_set_spd_needed(struct ata_link
*link
, u32
*scontrol
)
441 struct ata_link
*host_link
= &link
->ap
->link
;
442 u32 limit
, target
, spd
;
444 limit
= link
->sata_spd_limit
;
446 /* Don't configure downstream link faster than upstream link.
447 * It doesn't speed up anything and some PMPs choke on such
450 if (!ata_is_host_link(link
) && host_link
->sata_spd
)
451 limit
&= (1 << host_link
->sata_spd
) - 1;
453 if (limit
== UINT_MAX
)
458 spd
= (*scontrol
>> 4) & 0xf;
459 *scontrol
= (*scontrol
& ~0xf0) | ((target
& 0xf) << 4);
461 return spd
!= target
;
465 * sata_set_spd_needed - is SATA spd configuration needed
466 * @link: Link in question
468 * Test whether the spd limit in SControl matches
469 * @link->sata_spd_limit. This function is used to determine
470 * whether hardreset is necessary to apply SATA spd
474 * Inherited from caller.
477 * 1 if SATA spd configuration is needed, 0 otherwise.
479 static int sata_set_spd_needed(struct ata_link
*link
)
483 if (sata_scr_read(link
, SCR_CONTROL
, &scontrol
))
486 return __sata_set_spd_needed(link
, &scontrol
);
490 * sata_set_spd - set SATA spd according to spd limit
491 * @link: Link to set SATA spd for
493 * Set SATA spd of @link according to sata_spd_limit.
496 * Inherited from caller.
499 * 0 if spd doesn't need to be changed, 1 if spd has been
500 * changed. Negative errno if SCR registers are inaccessible.
502 int sata_set_spd(struct ata_link
*link
)
507 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
510 if (!__sata_set_spd_needed(link
, &scontrol
))
513 if ((rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
)))
518 EXPORT_SYMBOL_GPL(sata_set_spd
);
521 * sata_down_spd_limit - adjust SATA spd limit downward
522 * @link: Link to adjust SATA spd limit for
523 * @spd_limit: Additional limit
525 * Adjust SATA spd limit of @link downward. Note that this
526 * function only adjusts the limit. The change must be applied
527 * using sata_set_spd().
529 * If @spd_limit is non-zero, the speed is limited to equal to or
530 * lower than @spd_limit if such speed is supported. If
531 * @spd_limit is slower than any supported speed, only the lowest
532 * supported speed is allowed.
535 * Inherited from caller.
538 * 0 on success, negative errno on failure
540 int sata_down_spd_limit(struct ata_link
*link
, u32 spd_limit
)
542 u32 sstatus
, spd
, mask
;
545 if (!sata_scr_valid(link
))
548 /* If SCR can be read, use it to determine the current SPD.
549 * If not, use cached value in link->sata_spd.
551 rc
= sata_scr_read(link
, SCR_STATUS
, &sstatus
);
552 if (rc
== 0 && ata_sstatus_online(sstatus
))
553 spd
= (sstatus
>> 4) & 0xf;
555 spd
= link
->sata_spd
;
557 mask
= link
->sata_spd_limit
;
561 /* unconditionally mask off the highest bit */
566 * Mask off all speeds higher than or equal to the current one. At
567 * this point, if current SPD is not available and we previously
568 * recorded the link speed from SStatus, the driver has already
569 * masked off the highest bit so mask should already be 1 or 0.
570 * Otherwise, we should not force 1.5Gbps on a link where we have
571 * not previously recorded speed from SStatus. Just return in this
575 mask
&= (1 << (spd
- 1)) - 1;
576 else if (link
->sata_spd
)
579 /* were we already at the bottom? */
584 if (mask
& ((1 << spd_limit
) - 1))
585 mask
&= (1 << spd_limit
) - 1;
592 link
->sata_spd_limit
= mask
;
594 ata_link_warn(link
, "limiting SATA link speed to %s\n",
595 sata_spd_string(fls(mask
)));
601 * sata_link_hardreset - reset link via SATA phy reset
602 * @link: link to reset
603 * @timing: timing parameters { interval, duration, timeout } in msec
604 * @deadline: deadline jiffies for the operation
605 * @online: optional out parameter indicating link onlineness
606 * @check_ready: optional callback to check link readiness
608 * SATA phy-reset @link using DET bits of SControl register.
609 * After hardreset, link readiness is waited upon using
610 * ata_wait_ready() if @check_ready is specified. LLDs are
611 * allowed to not specify @check_ready and wait itself after this
612 * function returns. Device classification is LLD's
615 * *@online is set to one iff reset succeeded and @link is online
619 * Kernel thread context (may sleep)
622 * 0 on success, -errno otherwise.
624 int sata_link_hardreset(struct ata_link
*link
, const unsigned int *timing
,
625 unsigned long deadline
,
626 bool *online
, int (*check_ready
)(struct ata_link
*))
634 if (sata_set_spd_needed(link
)) {
635 /* SATA spec says nothing about how to reconfigure
636 * spd. To be on the safe side, turn off phy during
637 * reconfiguration. This works for at least ICH7 AHCI
640 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
643 scontrol
= (scontrol
& 0x0f0) | 0x304;
645 if ((rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
)))
651 /* issue phy wake/reset */
652 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
655 scontrol
= (scontrol
& 0x0f0) | 0x301;
657 if ((rc
= sata_scr_write_flush(link
, SCR_CONTROL
, scontrol
)))
660 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
661 * 10.4.2 says at least 1 ms.
663 ata_msleep(link
->ap
, 1);
665 /* bring link back */
666 rc
= sata_link_resume(link
, timing
, deadline
);
669 /* if link is offline nothing more to do */
670 if (ata_phys_link_offline(link
))
673 /* Link is online. From this point, -ENODEV too is an error. */
677 if (sata_pmp_supported(link
->ap
) && ata_is_host_link(link
)) {
678 /* If PMP is supported, we have to do follow-up SRST.
679 * Some PMPs don't send D2H Reg FIS after hardreset if
680 * the first port is empty. Wait only for
681 * ATA_TMOUT_PMP_SRST_WAIT.
684 unsigned long pmp_deadline
;
686 pmp_deadline
= ata_deadline(jiffies
,
687 ATA_TMOUT_PMP_SRST_WAIT
);
688 if (time_after(pmp_deadline
, deadline
))
689 pmp_deadline
= deadline
;
690 ata_wait_ready(link
, pmp_deadline
, check_ready
);
698 rc
= ata_wait_ready(link
, deadline
, check_ready
);
700 if (rc
&& rc
!= -EAGAIN
) {
701 /* online is set iff link is online && reset succeeded */
707 EXPORT_SYMBOL_GPL(sata_link_hardreset
);
710 * sata_std_hardreset - COMRESET w/o waiting or classification
711 * @link: link to reset
712 * @class: resulting class of attached device
713 * @deadline: deadline jiffies for the operation
715 * Standard SATA COMRESET w/o waiting or classification.
718 * Kernel thread context (may sleep)
721 * 0 if link offline, -EAGAIN if link online, -errno on errors.
723 int sata_std_hardreset(struct ata_link
*link
, unsigned int *class,
724 unsigned long deadline
)
726 const unsigned int *timing
= sata_ehc_deb_timing(&link
->eh_context
);
730 rc
= sata_link_hardreset(link
, timing
, deadline
, &online
, NULL
);
735 EXPORT_SYMBOL_GPL(sata_std_hardreset
);
738 * ata_qc_complete_multiple - Complete multiple qcs successfully
739 * @ap: port in question
740 * @qc_active: new qc_active mask
742 * Complete in-flight commands. This functions is meant to be
743 * called from low-level driver's interrupt routine to complete
744 * requests normally. ap->qc_active and @qc_active is compared
745 * and commands are completed accordingly.
747 * Always use this function when completing multiple NCQ commands
748 * from IRQ handlers instead of calling ata_qc_complete()
749 * multiple times to keep IRQ expect status properly in sync.
752 * spin_lock_irqsave(host lock)
755 * Number of completed commands on success, -errno otherwise.
757 int ata_qc_complete_multiple(struct ata_port
*ap
, u64 qc_active
)
759 u64 done_mask
, ap_qc_active
= ap
->qc_active
;
763 * If the internal tag is set on ap->qc_active, then we care about
764 * bit0 on the passed in qc_active mask. Move that bit up to match
767 if (ap_qc_active
& (1ULL << ATA_TAG_INTERNAL
)) {
768 qc_active
|= (qc_active
& 0x01) << ATA_TAG_INTERNAL
;
769 qc_active
^= qc_active
& 0x01;
772 done_mask
= ap_qc_active
^ qc_active
;
774 if (unlikely(done_mask
& qc_active
)) {
775 ata_port_err(ap
, "illegal qc_active transition (%08llx->%08llx)\n",
776 ap
->qc_active
, qc_active
);
780 if (ap
->ops
->qc_ncq_fill_rtf
)
781 ap
->ops
->qc_ncq_fill_rtf(ap
, done_mask
);
784 struct ata_queued_cmd
*qc
;
785 unsigned int tag
= __ffs64(done_mask
);
787 qc
= ata_qc_from_tag(ap
, tag
);
792 done_mask
&= ~(1ULL << tag
);
797 EXPORT_SYMBOL_GPL(ata_qc_complete_multiple
);
800 * ata_slave_link_init - initialize slave link
801 * @ap: port to initialize slave link for
803 * Create and initialize slave link for @ap. This enables slave
804 * link handling on the port.
806 * In libata, a port contains links and a link contains devices.
807 * There is single host link but if a PMP is attached to it,
808 * there can be multiple fan-out links. On SATA, there's usually
809 * a single device connected to a link but PATA and SATA
810 * controllers emulating TF based interface can have two - master
813 * However, there are a few controllers which don't fit into this
814 * abstraction too well - SATA controllers which emulate TF
815 * interface with both master and slave devices but also have
816 * separate SCR register sets for each device. These controllers
817 * need separate links for physical link handling
818 * (e.g. onlineness, link speed) but should be treated like a
819 * traditional M/S controller for everything else (e.g. command
822 * slave_link is libata's way of handling this class of
823 * controllers without impacting core layer too much. For
824 * anything other than physical link handling, the default host
825 * link is used for both master and slave. For physical link
826 * handling, separate @ap->slave_link is used. All dirty details
827 * are implemented inside libata core layer. From LLD's POV, the
828 * only difference is that prereset, hardreset and postreset are
829 * called once more for the slave link, so the reset sequence
830 * looks like the following.
832 * prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
833 * softreset(M) -> postreset(M) -> postreset(S)
835 * Note that softreset is called only for the master. Softreset
836 * resets both M/S by definition, so SRST on master should handle
837 * both (the standard method will work just fine).
840 * Should be called before host is registered.
843 * 0 on success, -errno on failure.
845 int ata_slave_link_init(struct ata_port
*ap
)
847 struct ata_link
*link
;
849 WARN_ON(ap
->slave_link
);
850 WARN_ON(ap
->flags
& ATA_FLAG_PMP
);
852 link
= kzalloc(sizeof(*link
), GFP_KERNEL
);
856 ata_link_init(ap
, link
, 1);
857 ap
->slave_link
= link
;
860 EXPORT_SYMBOL_GPL(ata_slave_link_init
);
863 * sata_lpm_ignore_phy_events - test if PHY event should be ignored
864 * @link: Link receiving the event
866 * Test whether the received PHY event has to be ignored or not.
872 * True if the event has to be ignored.
874 bool sata_lpm_ignore_phy_events(struct ata_link
*link
)
876 unsigned long lpm_timeout
= link
->last_lpm_change
+
877 msecs_to_jiffies(ATA_TMOUT_SPURIOUS_PHY
);
879 /* if LPM is enabled, PHYRDY doesn't mean anything */
880 if (link
->lpm_policy
> ATA_LPM_MAX_POWER
)
883 /* ignore the first PHY event after the LPM policy changed
884 * as it is might be spurious
886 if ((link
->flags
& ATA_LFLAG_CHANGED
) &&
887 time_before(jiffies
, lpm_timeout
))
892 EXPORT_SYMBOL_GPL(sata_lpm_ignore_phy_events
);
894 static const char *ata_lpm_policy_names
[] = {
895 [ATA_LPM_UNKNOWN
] = "keep_firmware_settings",
896 [ATA_LPM_MAX_POWER
] = "max_performance",
897 [ATA_LPM_MED_POWER
] = "medium_power",
898 [ATA_LPM_MED_POWER_WITH_DIPM
] = "med_power_with_dipm",
899 [ATA_LPM_MIN_POWER_WITH_PARTIAL
] = "min_power_with_partial",
900 [ATA_LPM_MIN_POWER
] = "min_power",
903 static ssize_t
ata_scsi_lpm_store(struct device
*device
,
904 struct device_attribute
*attr
,
905 const char *buf
, size_t count
)
907 struct Scsi_Host
*shost
= class_to_shost(device
);
908 struct ata_port
*ap
= ata_shost_to_port(shost
);
909 struct ata_link
*link
;
910 struct ata_device
*dev
;
911 enum ata_lpm_policy policy
;
914 /* UNKNOWN is internal state, iterate from MAX_POWER */
915 for (policy
= ATA_LPM_MAX_POWER
;
916 policy
< ARRAY_SIZE(ata_lpm_policy_names
); policy
++) {
917 const char *name
= ata_lpm_policy_names
[policy
];
919 if (strncmp(name
, buf
, strlen(name
)) == 0)
922 if (policy
== ARRAY_SIZE(ata_lpm_policy_names
))
925 spin_lock_irqsave(ap
->lock
, flags
);
927 ata_for_each_link(link
, ap
, EDGE
) {
928 ata_for_each_dev(dev
, &ap
->link
, ENABLED
) {
929 if (dev
->quirks
& ATA_QUIRK_NOLPM
) {
936 ap
->target_lpm_policy
= policy
;
937 ata_port_schedule_eh(ap
);
939 spin_unlock_irqrestore(ap
->lock
, flags
);
943 static ssize_t
ata_scsi_lpm_show(struct device
*dev
,
944 struct device_attribute
*attr
, char *buf
)
946 struct Scsi_Host
*shost
= class_to_shost(dev
);
947 struct ata_port
*ap
= ata_shost_to_port(shost
);
949 if (ap
->target_lpm_policy
>= ARRAY_SIZE(ata_lpm_policy_names
))
952 return sysfs_emit(buf
, "%s\n",
953 ata_lpm_policy_names
[ap
->target_lpm_policy
]);
955 DEVICE_ATTR(link_power_management_policy
, S_IRUGO
| S_IWUSR
,
956 ata_scsi_lpm_show
, ata_scsi_lpm_store
);
957 EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy
);
960 * ata_ncq_prio_supported - Check if device supports NCQ Priority
961 * @ap: ATA port of the target device
963 * @supported: Address of a boolean to store the result
965 * Helper to check if device supports NCQ Priority feature.
967 * Context: Any context. Takes and releases @ap->lock.
970 * * %0 - OK. Status is stored into @supported
971 * * %-ENODEV - Failed to find the ATA device
973 int ata_ncq_prio_supported(struct ata_port
*ap
, struct scsi_device
*sdev
,
976 struct ata_device
*dev
;
980 spin_lock_irqsave(ap
->lock
, flags
);
981 dev
= ata_scsi_find_dev(ap
, sdev
);
985 *supported
= dev
->flags
& ATA_DFLAG_NCQ_PRIO
;
986 spin_unlock_irqrestore(ap
->lock
, flags
);
990 EXPORT_SYMBOL_GPL(ata_ncq_prio_supported
);
992 static ssize_t
ata_ncq_prio_supported_show(struct device
*device
,
993 struct device_attribute
*attr
,
996 struct scsi_device
*sdev
= to_scsi_device(device
);
997 struct ata_port
*ap
= ata_shost_to_port(sdev
->host
);
1001 rc
= ata_ncq_prio_supported(ap
, sdev
, &supported
);
1005 return sysfs_emit(buf
, "%d\n", supported
);
1008 DEVICE_ATTR(ncq_prio_supported
, S_IRUGO
, ata_ncq_prio_supported_show
, NULL
);
1009 EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_supported
);
1012 * ata_ncq_prio_enabled - Check if NCQ Priority is enabled
1013 * @ap: ATA port of the target device
1014 * @sdev: SCSI device
1015 * @enabled: Address of a boolean to store the result
1017 * Helper to check if NCQ Priority feature is enabled.
1019 * Context: Any context. Takes and releases @ap->lock.
1022 * * %0 - OK. Status is stored into @enabled
1023 * * %-ENODEV - Failed to find the ATA device
1025 int ata_ncq_prio_enabled(struct ata_port
*ap
, struct scsi_device
*sdev
,
1028 struct ata_device
*dev
;
1029 unsigned long flags
;
1032 spin_lock_irqsave(ap
->lock
, flags
);
1033 dev
= ata_scsi_find_dev(ap
, sdev
);
1037 *enabled
= dev
->flags
& ATA_DFLAG_NCQ_PRIO_ENABLED
;
1038 spin_unlock_irqrestore(ap
->lock
, flags
);
1042 EXPORT_SYMBOL_GPL(ata_ncq_prio_enabled
);
1044 static ssize_t
ata_ncq_prio_enable_show(struct device
*device
,
1045 struct device_attribute
*attr
,
1048 struct scsi_device
*sdev
= to_scsi_device(device
);
1049 struct ata_port
*ap
= ata_shost_to_port(sdev
->host
);
1053 rc
= ata_ncq_prio_enabled(ap
, sdev
, &enabled
);
1057 return sysfs_emit(buf
, "%d\n", enabled
);
1061 * ata_ncq_prio_enable - Enable/disable NCQ Priority
1062 * @ap: ATA port of the target device
1063 * @sdev: SCSI device
1064 * @enable: true - enable NCQ Priority, false - disable NCQ Priority
1066 * Helper to enable/disable NCQ Priority feature.
1068 * Context: Any context. Takes and releases @ap->lock.
1071 * * %0 - OK. Status is stored into @enabled
1072 * * %-ENODEV - Failed to find the ATA device
1073 * * %-EINVAL - NCQ Priority is not supported or CDL is enabled
1075 int ata_ncq_prio_enable(struct ata_port
*ap
, struct scsi_device
*sdev
,
1078 struct ata_device
*dev
;
1079 unsigned long flags
;
1082 spin_lock_irqsave(ap
->lock
, flags
);
1084 dev
= ata_scsi_find_dev(ap
, sdev
);
1090 if (!(dev
->flags
& ATA_DFLAG_NCQ_PRIO
)) {
1096 if (dev
->flags
& ATA_DFLAG_CDL_ENABLED
) {
1098 "CDL must be disabled to enable NCQ priority\n");
1102 dev
->flags
|= ATA_DFLAG_NCQ_PRIO_ENABLED
;
1104 dev
->flags
&= ~ATA_DFLAG_NCQ_PRIO_ENABLED
;
1108 spin_unlock_irqrestore(ap
->lock
, flags
);
1112 EXPORT_SYMBOL_GPL(ata_ncq_prio_enable
);
1114 static ssize_t
ata_ncq_prio_enable_store(struct device
*device
,
1115 struct device_attribute
*attr
,
1116 const char *buf
, size_t len
)
1118 struct scsi_device
*sdev
= to_scsi_device(device
);
1119 struct ata_port
*ap
= ata_shost_to_port(sdev
->host
);
1123 rc
= kstrtobool(buf
, &enable
);
1127 rc
= ata_ncq_prio_enable(ap
, sdev
, enable
);
1134 DEVICE_ATTR(ncq_prio_enable
, S_IRUGO
| S_IWUSR
,
1135 ata_ncq_prio_enable_show
, ata_ncq_prio_enable_store
);
1136 EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_enable
);
1138 static struct attribute
*ata_ncq_sdev_attrs
[] = {
1139 &dev_attr_unload_heads
.attr
,
1140 &dev_attr_ncq_prio_enable
.attr
,
1141 &dev_attr_ncq_prio_supported
.attr
,
1145 static const struct attribute_group ata_ncq_sdev_attr_group
= {
1146 .attrs
= ata_ncq_sdev_attrs
1149 const struct attribute_group
*ata_ncq_sdev_groups
[] = {
1150 &ata_ncq_sdev_attr_group
,
1153 EXPORT_SYMBOL_GPL(ata_ncq_sdev_groups
);
1156 ata_scsi_em_message_store(struct device
*dev
, struct device_attribute
*attr
,
1157 const char *buf
, size_t count
)
1159 struct Scsi_Host
*shost
= class_to_shost(dev
);
1160 struct ata_port
*ap
= ata_shost_to_port(shost
);
1161 if (ap
->ops
->em_store
&& (ap
->flags
& ATA_FLAG_EM
))
1162 return ap
->ops
->em_store(ap
, buf
, count
);
1167 ata_scsi_em_message_show(struct device
*dev
, struct device_attribute
*attr
,
1170 struct Scsi_Host
*shost
= class_to_shost(dev
);
1171 struct ata_port
*ap
= ata_shost_to_port(shost
);
1173 if (ap
->ops
->em_show
&& (ap
->flags
& ATA_FLAG_EM
))
1174 return ap
->ops
->em_show(ap
, buf
);
1177 DEVICE_ATTR(em_message
, S_IRUGO
| S_IWUSR
,
1178 ata_scsi_em_message_show
, ata_scsi_em_message_store
);
1179 EXPORT_SYMBOL_GPL(dev_attr_em_message
);
1182 ata_scsi_em_message_type_show(struct device
*dev
, struct device_attribute
*attr
,
1185 struct Scsi_Host
*shost
= class_to_shost(dev
);
1186 struct ata_port
*ap
= ata_shost_to_port(shost
);
1188 return sysfs_emit(buf
, "%d\n", ap
->em_message_type
);
1190 DEVICE_ATTR(em_message_type
, S_IRUGO
,
1191 ata_scsi_em_message_type_show
, NULL
);
1192 EXPORT_SYMBOL_GPL(dev_attr_em_message_type
);
1195 ata_scsi_activity_show(struct device
*dev
, struct device_attribute
*attr
,
1198 struct scsi_device
*sdev
= to_scsi_device(dev
);
1199 struct ata_port
*ap
= ata_shost_to_port(sdev
->host
);
1200 struct ata_device
*atadev
= ata_scsi_find_dev(ap
, sdev
);
1202 if (atadev
&& ap
->ops
->sw_activity_show
&&
1203 (ap
->flags
& ATA_FLAG_SW_ACTIVITY
))
1204 return ap
->ops
->sw_activity_show(atadev
, buf
);
1209 ata_scsi_activity_store(struct device
*dev
, struct device_attribute
*attr
,
1210 const char *buf
, size_t count
)
1212 struct scsi_device
*sdev
= to_scsi_device(dev
);
1213 struct ata_port
*ap
= ata_shost_to_port(sdev
->host
);
1214 struct ata_device
*atadev
= ata_scsi_find_dev(ap
, sdev
);
1215 enum sw_activity val
;
1218 if (atadev
&& ap
->ops
->sw_activity_store
&&
1219 (ap
->flags
& ATA_FLAG_SW_ACTIVITY
)) {
1220 val
= simple_strtoul(buf
, NULL
, 0);
1222 case OFF
: case BLINK_ON
: case BLINK_OFF
:
1223 rc
= ap
->ops
->sw_activity_store(atadev
, val
);
1232 DEVICE_ATTR(sw_activity
, S_IWUSR
| S_IRUGO
, ata_scsi_activity_show
,
1233 ata_scsi_activity_store
);
1234 EXPORT_SYMBOL_GPL(dev_attr_sw_activity
);
1237 * ata_change_queue_depth - Set a device maximum queue depth
1238 * @ap: ATA port of the target device
1239 * @sdev: SCSI device to configure queue depth for
1240 * @queue_depth: new queue depth
1242 * Helper to set a device maximum queue depth, usable with both libsas
1246 int ata_change_queue_depth(struct ata_port
*ap
, struct scsi_device
*sdev
,
1249 struct ata_device
*dev
;
1250 unsigned long flags
;
1251 int max_queue_depth
;
1253 spin_lock_irqsave(ap
->lock
, flags
);
1255 dev
= ata_scsi_find_dev(ap
, sdev
);
1256 if (!dev
|| queue_depth
< 1 || queue_depth
== sdev
->queue_depth
) {
1257 spin_unlock_irqrestore(ap
->lock
, flags
);
1258 return sdev
->queue_depth
;
1262 * Make sure that the queue depth requested does not exceed the device
1265 max_queue_depth
= min(ATA_MAX_QUEUE
, sdev
->host
->can_queue
);
1266 max_queue_depth
= min(max_queue_depth
, ata_id_queue_depth(dev
->id
));
1267 if (queue_depth
> max_queue_depth
) {
1268 spin_unlock_irqrestore(ap
->lock
, flags
);
1273 * If NCQ is not supported by the device or if the target queue depth
1274 * is 1 (to disable drive side command queueing), turn off NCQ.
1276 if (queue_depth
== 1 || !ata_ncq_supported(dev
)) {
1277 dev
->flags
|= ATA_DFLAG_NCQ_OFF
;
1280 dev
->flags
&= ~ATA_DFLAG_NCQ_OFF
;
1283 spin_unlock_irqrestore(ap
->lock
, flags
);
1285 if (queue_depth
== sdev
->queue_depth
)
1286 return sdev
->queue_depth
;
1288 return scsi_change_queue_depth(sdev
, queue_depth
);
1290 EXPORT_SYMBOL_GPL(ata_change_queue_depth
);
1293 * ata_scsi_change_queue_depth - SCSI callback for queue depth config
1294 * @sdev: SCSI device to configure queue depth for
1295 * @queue_depth: new queue depth
1297 * This is libata standard hostt->change_queue_depth callback.
1298 * SCSI will call into this callback when user tries to set queue
1302 * SCSI layer (we don't care)
1305 * Newly configured queue depth.
1307 int ata_scsi_change_queue_depth(struct scsi_device
*sdev
, int queue_depth
)
1309 struct ata_port
*ap
= ata_shost_to_port(sdev
->host
);
1311 return ata_change_queue_depth(ap
, sdev
, queue_depth
);
1313 EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth
);
1316 * ata_sas_device_configure - Default device_configure routine for libata
1318 * @sdev: SCSI device to configure
1319 * @lim: queue limits
1320 * @ap: ATA port to which SCSI device is attached
1326 int ata_sas_device_configure(struct scsi_device
*sdev
, struct queue_limits
*lim
,
1327 struct ata_port
*ap
)
1329 ata_scsi_sdev_config(sdev
);
1331 return ata_scsi_dev_config(sdev
, lim
, ap
->link
.device
);
1333 EXPORT_SYMBOL_GPL(ata_sas_device_configure
);
1336 * ata_sas_queuecmd - Issue SCSI cdb to libata-managed device
1337 * @cmd: SCSI command to be sent
1338 * @ap: ATA port to which the command is being sent
1341 * Return value from __ata_scsi_queuecmd() if @cmd can be queued,
1345 int ata_sas_queuecmd(struct scsi_cmnd
*cmd
, struct ata_port
*ap
)
1349 if (likely(ata_dev_enabled(ap
->link
.device
)))
1350 rc
= __ata_scsi_queuecmd(cmd
, ap
->link
.device
);
1352 cmd
->result
= (DID_BAD_TARGET
<< 16);
1357 EXPORT_SYMBOL_GPL(ata_sas_queuecmd
);
1360 * sata_async_notification - SATA async notification handler
1361 * @ap: ATA port where async notification is received
1363 * Handler to be called when async notification via SDB FIS is
1364 * received. This function schedules EH if necessary.
1367 * spin_lock_irqsave(host lock)
1370 * 1 if EH is scheduled, 0 otherwise.
1372 int sata_async_notification(struct ata_port
*ap
)
1377 if (!(ap
->flags
& ATA_FLAG_AN
))
1380 rc
= sata_scr_read(&ap
->link
, SCR_NOTIFICATION
, &sntf
);
1382 sata_scr_write(&ap
->link
, SCR_NOTIFICATION
, sntf
);
1384 if (!sata_pmp_attached(ap
) || rc
) {
1385 /* PMP is not attached or SNTF is not available */
1386 if (!sata_pmp_attached(ap
)) {
1387 /* PMP is not attached. Check whether ATAPI
1388 * AN is configured. If so, notify media
1391 struct ata_device
*dev
= ap
->link
.device
;
1393 if ((dev
->class == ATA_DEV_ATAPI
) &&
1394 (dev
->flags
& ATA_DFLAG_AN
))
1395 ata_scsi_media_change_notify(dev
);
1398 /* PMP is attached but SNTF is not available.
1399 * ATAPI async media change notification is
1400 * not used. The PMP must be reporting PHY
1401 * status change, schedule EH.
1403 ata_port_schedule_eh(ap
);
1407 /* PMP is attached and SNTF is available */
1408 struct ata_link
*link
;
1410 /* check and notify ATAPI AN */
1411 ata_for_each_link(link
, ap
, EDGE
) {
1412 if (!(sntf
& (1 << link
->pmp
)))
1415 if ((link
->device
->class == ATA_DEV_ATAPI
) &&
1416 (link
->device
->flags
& ATA_DFLAG_AN
))
1417 ata_scsi_media_change_notify(link
->device
);
1420 /* If PMP is reporting that PHY status of some
1421 * downstream ports has changed, schedule EH.
1423 if (sntf
& (1 << SATA_PMP_CTRL_PORT
)) {
1424 ata_port_schedule_eh(ap
);
1431 EXPORT_SYMBOL_GPL(sata_async_notification
);
1434 * ata_eh_read_log_10h - Read log page 10h for NCQ error details
1435 * @dev: Device to read log page 10h from
1436 * @tag: Resulting tag of the failed command
1437 * @tf: Resulting taskfile registers of the failed command
1439 * Read log page 10h to obtain NCQ error details and clear error
1443 * Kernel thread context (may sleep).
1446 * 0 on success, -errno otherwise.
1448 static int ata_eh_read_log_10h(struct ata_device
*dev
,
1449 int *tag
, struct ata_taskfile
*tf
)
1451 u8
*buf
= dev
->sector_buf
;
1452 unsigned int err_mask
;
1456 err_mask
= ata_read_log_page(dev
, ATA_LOG_SATA_NCQ
, 0, buf
, 1);
1461 for (i
= 0; i
< ATA_SECT_SIZE
; i
++)
1464 ata_dev_warn(dev
, "invalid checksum 0x%x on log page 10h\n",
1470 *tag
= buf
[0] & 0x1f;
1472 tf
->status
= buf
[2];
1477 tf
->device
= buf
[7];
1478 tf
->hob_lbal
= buf
[8];
1479 tf
->hob_lbam
= buf
[9];
1480 tf
->hob_lbah
= buf
[10];
1481 tf
->nsect
= buf
[12];
1482 tf
->hob_nsect
= buf
[13];
1483 if (ata_id_has_ncq_autosense(dev
->id
) && (tf
->status
& ATA_SENSE
))
1484 tf
->auxiliary
= buf
[14] << 16 | buf
[15] << 8 | buf
[16];
1490 * ata_eh_get_ncq_success_sense - Read and process the sense data for
1491 * successful NCQ commands log page
1492 * @link: ATA link to get sense data for
1494 * Read the sense data for successful NCQ commands log page to obtain
1495 * sense data for all NCQ commands that completed successfully with
1496 * the sense data available bit set.
1499 * Kernel thread context (may sleep).
1502 * 0 on success, -errno otherwise.
1504 int ata_eh_get_ncq_success_sense(struct ata_link
*link
)
1506 struct ata_device
*dev
= link
->device
;
1507 struct ata_port
*ap
= dev
->link
->ap
;
1508 u8
*buf
= dev
->cdl
->ncq_sense_log_buf
;
1509 struct ata_queued_cmd
*qc
;
1510 unsigned int err_mask
, tag
;
1511 u8
*sense
, sk
= 0, asc
= 0, ascq
= 0;
1512 u64 sense_valid
, val
;
1515 err_mask
= ata_read_log_page(dev
, ATA_LOG_SENSE_NCQ
, 0, buf
, 2);
1518 "Failed to read Sense Data for Successful NCQ Commands log\n");
1522 /* Check the log header */
1523 val
= get_unaligned_le64(&buf
[0]);
1524 if ((val
& 0xffff) != 1 || ((val
>> 16) & 0xff) != 0x0f) {
1526 "Invalid Sense Data for Successful NCQ Commands log\n");
1530 sense_valid
= (u64
)buf
[8] | ((u64
)buf
[9] << 8) |
1531 ((u64
)buf
[10] << 16) | ((u64
)buf
[11] << 24);
1533 ata_qc_for_each_raw(ap
, qc
, tag
) {
1534 if (!(qc
->flags
& ATA_QCFLAG_EH
) ||
1535 !(qc
->flags
& ATA_QCFLAG_EH_SUCCESS_CMD
) ||
1537 ata_dev_phys_link(qc
->dev
) != link
)
1541 * If the command does not have any sense data, clear ATA_SENSE.
1542 * Keep ATA_QCFLAG_EH_SUCCESS_CMD so that command is finished.
1544 if (!(sense_valid
& (1ULL << tag
))) {
1545 qc
->result_tf
.status
&= ~ATA_SENSE
;
1549 sense
= &buf
[32 + 24 * tag
];
1554 if (!ata_scsi_sense_is_valid(sk
, asc
, ascq
)) {
1559 /* Set sense without also setting scsicmd->result */
1560 scsi_build_sense_buffer(dev
->flags
& ATA_DFLAG_D_SENSE
,
1561 qc
->scsicmd
->sense_buffer
, sk
,
1563 qc
->flags
|= ATA_QCFLAG_SENSE_VALID
;
1566 * No point in checking the return value, since the command has
1567 * already completed successfully.
1569 ata_eh_decide_disposition(qc
);
1576 * ata_eh_analyze_ncq_error - analyze NCQ error
1577 * @link: ATA link to analyze NCQ error for
1579 * Read log page 10h, determine the offending qc and acquire
1580 * error status TF. For NCQ device errors, all LLDDs have to do
1581 * is setting AC_ERR_DEV in ehi->err_mask. This function takes
1585 * Kernel thread context (may sleep).
1587 void ata_eh_analyze_ncq_error(struct ata_link
*link
)
1589 struct ata_port
*ap
= link
->ap
;
1590 struct ata_eh_context
*ehc
= &link
->eh_context
;
1591 struct ata_device
*dev
= link
->device
;
1592 struct ata_queued_cmd
*qc
;
1593 struct ata_taskfile tf
;
1596 /* if frozen, we can't do much */
1597 if (ata_port_is_frozen(ap
))
1600 /* is it NCQ device error? */
1601 if (!link
->sactive
|| !(ehc
->i
.err_mask
& AC_ERR_DEV
))
1604 /* has LLDD analyzed already? */
1605 ata_qc_for_each_raw(ap
, qc
, tag
) {
1606 if (!(qc
->flags
& ATA_QCFLAG_EH
))
1613 /* okay, this error is ours */
1614 memset(&tf
, 0, sizeof(tf
));
1615 rc
= ata_eh_read_log_10h(dev
, &tag
, &tf
);
1617 ata_link_err(link
, "failed to read log page 10h (errno=%d)\n",
1622 if (!(link
->sactive
& (1 << tag
))) {
1623 ata_link_err(link
, "log page 10h reported inactive tag %d\n",
1628 /* we've got the perpetrator, condemn it */
1629 qc
= __ata_qc_from_tag(ap
, tag
);
1630 memcpy(&qc
->result_tf
, &tf
, sizeof(tf
));
1631 qc
->result_tf
.flags
= ATA_TFLAG_ISADDR
| ATA_TFLAG_LBA
| ATA_TFLAG_LBA48
;
1632 qc
->err_mask
|= AC_ERR_DEV
| AC_ERR_NCQ
;
1635 * If the device supports NCQ autosense, ata_eh_read_log_10h() will have
1636 * stored the sense data in qc->result_tf.auxiliary.
1638 if (qc
->result_tf
.auxiliary
) {
1639 char sense_key
, asc
, ascq
;
1641 sense_key
= (qc
->result_tf
.auxiliary
>> 16) & 0xff;
1642 asc
= (qc
->result_tf
.auxiliary
>> 8) & 0xff;
1643 ascq
= qc
->result_tf
.auxiliary
& 0xff;
1644 if (ata_scsi_sense_is_valid(sense_key
, asc
, ascq
)) {
1645 ata_scsi_set_sense(dev
, qc
->scsicmd
, sense_key
, asc
,
1647 ata_scsi_set_sense_information(dev
, qc
->scsicmd
,
1649 qc
->flags
|= ATA_QCFLAG_SENSE_VALID
;
1653 ata_qc_for_each_raw(ap
, qc
, tag
) {
1654 if (!(qc
->flags
& ATA_QCFLAG_EH
) ||
1655 qc
->flags
& ATA_QCFLAG_EH_SUCCESS_CMD
||
1656 ata_dev_phys_link(qc
->dev
) != link
)
1659 /* Skip the single QC which caused the NCQ error. */
1664 * For SATA, the STATUS and ERROR fields are shared for all NCQ
1665 * commands that were completed with the same SDB FIS.
1666 * Therefore, we have to clear the ATA_ERR bit for all QCs
1667 * except the one that caused the NCQ error.
1669 qc
->result_tf
.status
&= ~ATA_ERR
;
1670 qc
->result_tf
.error
= 0;
1673 * If we get a NCQ error, that means that a single command was
1674 * aborted. All other failed commands for our link should be
1675 * retried and has no business of going though further scrutiny
1676 * by ata_eh_link_autopsy().
1678 qc
->flags
|= ATA_QCFLAG_RETRY
;
1681 ehc
->i
.err_mask
&= ~AC_ERR_DEV
;
1683 EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error
);
1685 const struct ata_port_operations sata_port_ops
= {
1686 .inherits
= &ata_base_port_ops
,
1688 .qc_defer
= ata_std_qc_defer
,
1689 .hardreset
= sata_std_hardreset
,
1691 EXPORT_SYMBOL_GPL(sata_port_ops
);