2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 static void ahci_pm_dummy_done(struct ata_xfer *xa);
40 ahci_pm_port_init(struct ahci_port *ap, struct ata_port *at)
42 at->at_probe = ATA_PROBE_NEED_HARD_RESET;
47 * AHCI port multiplier probe. This routine is run by the hardreset code
48 * if it gets past the device detect, whether or not BSY is found to be
51 * We MUST use CLO to properly probe whether the port multiplier exists
54 * Return 0 on success, non-zero on failure.
57 ahci_pm_port_probe(struct ahci_port *ap, int orig_error)
59 struct ahci_cmd_hdr *cmd_slot;
61 struct ahci_ccb *ccb = NULL;
71 * This code is only called from hardreset, which does not
72 * high level command processing. The port should be stopped.
74 * Set PMA mode while the port is stopped.
76 * NOTE: On retry the port might be running, stopped, or failed.
78 ahci_port_stop(ap, 0);
79 ap->ap_state = AP_S_NORMAL;
80 cmd = ahci_pread(ap, AHCI_PREG_CMD) & ~AHCI_PREG_CMD_ICC;
81 if ((cmd & AHCI_PREG_CMD_PMA) == 0) {
82 cmd |= AHCI_PREG_CMD_PMA;
83 ahci_pwrite(ap, AHCI_PREG_CMD, cmd);
87 * Flush any errors and request CLO unconditionally, then start
92 if (ahci_port_start(ap)) {
93 kprintf("%s: PMPROBE failed to start port, cannot softreset\n",
100 * Check whether CLO worked
102 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
103 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
104 kprintf("%s: PMPROBE CLO %s, need port reset\n",
106 (ahci_read(ap->ap_sc, AHCI_REG_CAP) & AHCI_REG_CAP_SCLO)
107 ? "failed" : "unsupported");
113 * Use the error CCB for all commands
115 * NOTE! This CCB is used for both the first and second commands.
116 * The second command must use CCB slot 1 to properly load
119 ccb = ahci_get_err_ccb(ap);
120 ccb->ccb_xa.flags = ATA_F_POLL;
121 ccb->ccb_xa.complete = ahci_pm_dummy_done;
122 ccb->ccb_xa.at = ap->ap_ata[15];
123 cmd_slot = ccb->ccb_cmd_hdr;
124 KKASSERT(ccb->ccb_slot == 1);
127 * Prep the first H2D command with SRST feature & clear busy/reset
130 fis = ccb->ccb_cmd_table->cfis;
131 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
132 fis[0] = ATA_FIS_TYPE_H2D;
133 fis[1] = 0x0F; /* Target 15 */
134 fis[15] = ATA_FIS_CONTROL_SRST | ATA_FIS_CONTROL_4BIT;
137 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
138 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_C); /* Clear busy on OK */
139 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_R); /* Reset */
140 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_PMP); /* port 0xF */
142 ccb->ccb_xa.state = ATA_S_PENDING;
145 * The only way one can determine if a port multiplier is on the
146 * port is to probe target 15, and of course this will fail if
147 * there is no port multiplier.
149 * The probing has to be done whether or not a device is probed on
150 * target 0, because when a PM is attached target 0 represents
151 * slot #0 behind the PM.
153 if (ahci_poll(ccb, 1000, ahci_quick_timeout) != ATA_S_COMPLETE) {
154 kprintf("%s: PMPROBE First FIS failed,\n",
156 kprintf("%s: PMPROBE No Port Multiplier was found.\n",
159 ahci_put_err_ccb(ccb);
165 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
166 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
167 kprintf("%s: PMPROBE Busy after first FIS\n", PORTNAME(ap));
171 * The device may have muffed up the PHY when it reset.
175 ahci_pwrite(ap, AHCI_PREG_SERR, -1);
176 /* ahci_pm_phy_status(ap, 15, &cmd); */
179 * Prep second D2H command to read status and complete reset sequence
180 * AHCI 10.4.1 and "Serial ATA Revision 2.6". I can't find the ATA
181 * Rev 2.6 and it is unclear how the second FIS should be set up
182 * from the AHCI document.
184 * Give the device 3ms before sending the second FIS.
186 * It is unclear which other fields in the FIS are used. Just zero
189 ccb->ccb_xa.flags = ATA_F_POLL;
191 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
192 fis[0] = ATA_FIS_TYPE_H2D;
194 fis[15] = ATA_FIS_CONTROL_4BIT;
197 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
198 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_PMP); /* port 0xF */
200 ccb->ccb_xa.state = ATA_S_PENDING;
203 * The only way one can determine if a port multiplier is on the
204 * port is to probe target 15, and of course this will fail if
205 * there is no port multiplier.
207 * The probing has to be done whether or not a device is probed on
208 * target 0, because when a PM is attached target 0 represents
209 * slot #0 behind the PM.
211 if (ahci_poll(ccb, 5000, ahci_quick_timeout) != ATA_S_COMPLETE) {
212 kprintf("%s: PMPROBE Second FIS failed,\n",
214 kprintf("%s: PMPROBE No Port Multiplier was found.\n",
217 ahci_put_err_ccb(ccb);
225 * What? We succeeded? Yup, but for some reason the signature
226 * is still latched from the original detect (that saw target 0
227 * behind the PM), and I don't know how to clear the condition
228 * other then by retrying the whole reset sequence.
232 ahci_put_err_ccb(ccb);
237 * Get the signature. The caller sets the ap fields.
239 if (ahci_port_signature_detect(ap, NULL) == ATA_PORT_T_PM) {
240 ap->ap_ata[15]->at_probe = ATA_PROBE_GOOD;
247 * Fall through / clean up the CCB and perform error processing.
251 ahci_put_err_ccb(ccb);
253 if (error == 0 && ahci_pm_identify(ap)) {
254 kprintf("%s: PM - cannot identify port multiplier\n",
260 * If we probed the PM reset the state for the targets behind
261 * it so they get probed by the state machine.
264 for (i = 0; i < AHCI_MAX_PMPORTS; ++i) {
266 at->at_probe = ATA_PROBE_NEED_INIT;
267 at->at_features |= ATA_PORT_F_RESCAN;
269 ap->ap_type = ATA_PORT_T_PM;
274 * If we failed turn off PMA, otherwise identify the port multiplier.
275 * CAM will iterate the devices.
277 ahci_port_stop(ap, 0);
279 cmd = ahci_pread(ap, AHCI_PREG_CMD) & ~AHCI_PREG_CMD_ICC;
280 cmd &= ~AHCI_PREG_CMD_PMA;
281 ahci_pwrite(ap, AHCI_PREG_CMD, cmd);
283 if (orig_error == 0) {
284 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
285 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
286 kprintf("%s: PM probe: port will not come ready\n",
295 * Identify the port multiplier
298 ahci_pm_identify(struct ahci_port *ap)
307 ap->ap_probe = ATA_PROBE_FAILED;
308 if (ahci_pm_read(ap, 15, 0, &chipid))
310 if (ahci_pm_read(ap, 15, 1, &rev))
312 if (ahci_pm_read(ap, 15, 2, &nports))
314 nports &= 0x0000000F; /* only the low 4 bits */
315 ap->ap_probe = ATA_PROBE_GOOD;
318 * Ignore fake port on PMs which have it. We can probe it but the
319 * softreset will probably fail.
329 if (has_dummy_port) {
334 kprintf("%s: Port multiplier: chip=%08x rev=0x%b nports=%d\n",
337 rev, SATA_PFMT_PM_REV,
339 if (has_dummy_port) {
340 kprintf("%s: Port multiplier: Ignoring dummy port #%d\n",
341 PORTNAME(ap), nports);
343 ap->ap_pmcount = nports;
345 if (ahci_pm_read(ap, 15, SATA_PMREG_FEA, &data1)) {
346 kprintf("%s: Port multiplier: Warning, "
347 "cannot read feature register\n", PORTNAME(ap));
349 kprintf("%s: Port multiplier features: 0x%b\n",
354 if (ahci_pm_read(ap, 15, SATA_PMREG_FEAEN, &data2) == 0) {
355 kprintf("%s: Port multiplier defaults: 0x%b\n",
362 * Turn on async notification if we support and the PM supports it.
363 * This allows the PM to forward async notification events to us and
364 * it will also generate an event for target 15 for hot-plug events
365 * (or is supposed to anyway).
367 if ((ap->ap_sc->sc_cap & AHCI_REG_CAP_SSNTF) &&
368 (data1 & SATA_PMFEA_ASYNCNOTIFY)) {
369 u_int32_t serr_bits = AHCI_PREG_SERR_DIAG_N |
370 AHCI_PREG_SERR_DIAG_X;
371 data2 |= SATA_PMFEA_ASYNCNOTIFY;
372 if (ahci_pm_write(ap, 15, SATA_PMREG_FEAEN, data2)) {
373 kprintf("%s: Port multiplier: AsyncNotify cannot be "
374 "enabled\n", PORTNAME(ap));
375 } else if (ahci_pm_write(ap, 15, SATA_PMREG_EEENA, serr_bits)) {
376 kprintf("%s: Port mulltiplier: AsyncNotify unable "
377 "to enable error info bits\n", PORTNAME(ap));
379 kprintf("%s: Port multiplier: AsyncNotify enabled\n",
386 kprintf("%s: Port multiplier cannot be identified\n", PORTNAME(ap));
391 * Do a COMRESET sequence on the target behind a port multiplier.
393 * If hard is 2 we also cycle the phy on the target.
395 * This must be done prior to any softreset or probe attempts on
396 * targets behind the port multiplier.
398 * Returns 0 on success or an error.
401 ahci_pm_hardreset(struct ahci_port *ap, int target, int hard)
408 at = ap->ap_ata[target];
411 * Turn off power management and kill the phy on the target
412 * if requested. Hold state for 10ms.
414 data = AHCI_PREG_SCTL_IPM_DISABLED;
416 data |= AHCI_PREG_SCTL_DET_DISABLE;
417 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1))
419 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
424 * Start transmitting COMRESET. COMRESET must be sent for at
427 at->at_probe = ATA_PROBE_FAILED;
428 at->at_type = ATA_PORT_T_NONE;
429 data = AHCI_PREG_SCTL_IPM_DISABLED | AHCI_PREG_SCTL_DET_INIT;
430 if (AhciForceGen1 & (1 << ap->ap_num)) {
431 kprintf("%s.%d: Force 1.5GBits\n", PORTNAME(ap), target);
432 data |= AHCI_PREG_SCTL_SPD_GEN1;
434 data |= AHCI_PREG_SCTL_SPD_ANY;
436 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
440 * It takes about 100ms for the DET logic to settle down,
441 * from trial and error testing. If this is too short
442 * the softreset code will fail.
446 if (ahci_pm_phy_status(ap, target, &data)) {
447 kprintf("%s: (A)Cannot clear phy status\n",
452 * Flush any status, then clear DET to initiate negotiation.
454 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
455 data = AHCI_PREG_SCTL_IPM_DISABLED | AHCI_PREG_SCTL_DET_NONE;
456 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
460 * Try to determine if there is a device on the port.
462 * Give the device 3/10 second to at least be detected.
463 * If we fail clear any pending status since we may have
464 * cycled the phy and probably caused another PRCS interrupt.
466 for (loop = 3; loop; --loop) {
467 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data))
469 if (data & AHCI_PREG_SSTS_DET)
474 kprintf("%s.%d: Port appears to be unplugged\n",
475 PORTNAME(ap), target);
481 * There is something on the port. Give the device 3 seconds
482 * to fully negotiate.
484 for (loop = 30; loop; --loop) {
485 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data))
487 if ((data & AHCI_PREG_SSTS_DET) == AHCI_PREG_SSTS_DET_DEV)
493 * Device not detected
496 kprintf("%s: Device may be powered down\n",
505 kprintf("%s.%d: Device detected data=%08x\n",
506 PORTNAME(ap), target, data);
508 * Clear SERR on the target so we get a new NOTIFY event if a hot-plug
509 * or hot-unplug occurs.
515 at->at_probe = error ? ATA_PROBE_FAILED : ATA_PROBE_NEED_SOFT_RESET;
520 * AHCI soft reset through port multiplier.
522 * This function keeps port communications intact and attempts to generate
523 * a reset to the connected device using device commands. Unlike
524 * hard-port operations we can't do fancy stop/starts or stuff like
525 * that without messing up other commands that might be running or
529 ahci_pm_softreset(struct ahci_port *ap, int target)
532 struct ahci_ccb *ccb;
533 struct ahci_cmd_hdr *cmd_slot;
541 at = ap->ap_ata[target];
543 DPRINTF(AHCI_D_VERBOSE, "%s: soft reset\n", PORTNAME(ap));
549 * Try to clear the phy so we get a good signature, otherwise
550 * the PM may not latch a new signature.
552 * NOTE: This cannot be safely done between the first and second
553 * softreset FISs. It's now or never.
556 if (ahci_pm_phy_status(ap, target, &data)) {
557 kprintf("%s: (B)Cannot clear phy status\n",
560 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
564 * Prep first D2H command with SRST feature & clear busy/reset flags
566 * It is unclear which other fields in the FIS are used. Just zero
569 * When soft-resetting a port behind a multiplier at will be
570 * non-NULL, assigning it to the ccb prevents the port interrupt
571 * from hard-resetting the port if a problem crops up.
573 ccb = ahci_get_err_ccb(ap);
574 ccb->ccb_xa.flags = ATA_F_POLL | ATA_F_EXCLUSIVE | ATA_F_AUTOSENSE;
575 ccb->ccb_xa.complete = ahci_pm_dummy_done;
578 fis = ccb->ccb_cmd_table->cfis;
579 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
580 fis[0] = ATA_FIS_TYPE_H2D;
581 fis[1] = at->at_target;
582 fis[15] = ATA_FIS_CONTROL_SRST|ATA_FIS_CONTROL_4BIT;
584 cmd_slot = ccb->ccb_cmd_hdr;
586 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
587 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_C); /* Clear busy on OK */
588 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_R); /* Reset */
589 cmd_slot->flags |= htole16(at->at_target <<
590 AHCI_CMD_LIST_FLAG_PMP_SHIFT);
592 ccb->ccb_xa.state = ATA_S_PENDING;
595 * XXX hack to ignore IFS errors which can occur during the target
598 * If an IFS error occurs the target is probably powering up,
599 * so we try for a longer period of time.
601 ap->ap_flags |= AP_F_IGNORE_IFS;
602 ap->ap_flags &= ~(AP_F_IFS_IGNORED | AP_F_IFS_OCCURED);
604 if (ahci_poll(ccb, 1000, ahci_ata_cmd_timeout) != ATA_S_COMPLETE) {
605 kprintf("%s: (PM) First FIS failed\n", ATANAME(ap, at));
606 if (ap->ap_flags & AP_F_IFS_OCCURED) {
607 if (tried_longer == 0)
611 ahci_put_err_ccb(ccb);
618 * WARNING! SENSITIVE TIME PERIOD! WARNING!
620 * The first and second FISes are supposed to be back-to-back,
621 * I think the idea is to get the second sent and then after
622 * the device resets it will send a signature. Do not delay
623 * here and most definitely do not issue any commands to other
628 * Prep second D2H command to read status and complete reset sequence
629 * AHCI 10.4.1 and "Serial ATA Revision 2.6". I can't find the ATA
630 * Rev 2.6 and it is unclear how the second FIS should be set up
631 * from the AHCI document.
633 * Give the device 3ms before sending the second FIS.
635 * It is unclear which other fields in the FIS are used. Just zero
638 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
639 fis[0] = ATA_FIS_TYPE_H2D;
640 fis[1] = at->at_target;
641 fis[15] = ATA_FIS_CONTROL_4BIT;
644 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
645 cmd_slot->flags |= htole16(at->at_target <<
646 AHCI_CMD_LIST_FLAG_PMP_SHIFT);
648 ccb->ccb_xa.state = ATA_S_PENDING;
649 ccb->ccb_xa.flags = ATA_F_POLL | ATA_F_EXCLUSIVE | ATA_F_AUTOSENSE;
651 if (ahci_poll(ccb, 1000, ahci_ata_cmd_timeout) != ATA_S_COMPLETE) {
652 kprintf("%s: (PM) Second FIS failed\n", ATANAME(ap, at));
653 ahci_put_err_ccb(ccb);
661 ahci_put_err_ccb(ccb);
663 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
664 if (ahci_pm_phy_status(ap, target, &data)) {
665 kprintf("%s: (C)Cannot clear phy status\n",
668 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
671 * Do it again, even if we think we got a good result
679 * If the softreset is trying to clear a BSY condition after a
680 * normal portreset we assign the port type.
682 * If the softreset is being run first as part of the ccb error
683 * processing code then report if the device signature changed
686 if (at->at_type == ATA_PORT_T_NONE) {
687 at->at_type = ahci_port_signature_detect(ap, at);
689 if (ahci_port_signature_detect(ap, at) != at->at_type) {
690 kprintf("%s: device signature unexpectedly "
691 "changed\n", ATANAME(ap, at));
692 error = EBUSY; /* XXX */
698 * Who knows what kind of mess occured. We have exclusive access
699 * to the port so try to clean up potential problems.
704 * Clear error status so we can detect removal.
706 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1)) {
707 kprintf("%s: ahci_pm_softreset unable to clear SERR\n",
709 ap->ap_flags &= ~AP_F_IGNORE_IFS;
711 /* ahci_pwrite(ap, AHCI_PREG_SERR, -1);*/
713 at->at_probe = error ? ATA_PROBE_FAILED : ATA_PROBE_NEED_IDENT;
719 * Return the phy status for a target behind a port multiplier and
720 * reset SATA_PMREG_SERR.
722 * Returned bits follow AHCI_PREG_SSTS bits. The AHCI_PREG_SSTS_SPD
723 * bits can be used to determine the link speed and will be 0 if there
726 * 0 is returned if any communications error occurs.
729 ahci_pm_phy_status(struct ahci_port *ap, int target, u_int32_t *datap)
733 error = ahci_pm_read(ap, target, SATA_PMREG_SSTS, datap);
735 error = ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
742 * Check that a target is still good.
745 ahci_pm_check_good(struct ahci_port *ap, int target)
751 * It looks like we might have to read the EINFO register
752 * to allow the PM to generate a new event.
754 if (ahci_pm_read(ap, 15, SATA_PMREG_EINFO, &data)) {
755 kprintf("%s: Port multiplier EINFO could not be read\n",
759 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1)) {
760 kprintf("%s: Port multiplier: SERR could not be cleared\n",
764 if (target == CAM_TARGET_WILDCARD || target >= ap->ap_pmcount)
766 at = ap->ap_ata[target];
769 * If the device needs an init or hard reset also make sure the
772 if (at->at_probe <= ATA_PROBE_NEED_HARD_RESET) {
773 /*kprintf("%s DOHARD\n", ATANAME(ap, at));*/
774 ahci_pm_hardreset(ap, target, 1);
778 * Read the detect status
780 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data)) {
781 kprintf("%s: Unable to access PM SSTS register target %d\n",
782 PORTNAME(ap), target);
785 if ((data & AHCI_PREG_SSTS_DET) != AHCI_PREG_SSTS_DET_DEV) {
786 /*kprintf("%s: DETECT %08x\n", ATANAME(ap, at), data);*/
787 if (at->at_probe != ATA_PROBE_FAILED) {
788 at->at_probe = ATA_PROBE_FAILED;
789 at->at_type = ATA_PORT_T_NONE;
790 at->at_features |= ATA_PORT_F_RESCAN;
791 kprintf("%s: HOTPLUG (PM) - Device removed\n",
795 if (at->at_probe == ATA_PROBE_FAILED) {
796 at->at_probe = ATA_PROBE_NEED_HARD_RESET;
797 at->at_features |= ATA_PORT_F_RESCAN;
798 kprintf("%s: HOTPLUG (PM) - Device inserted\n",
808 ahci_pm_read(struct ahci_port *ap, int target, int which, u_int32_t *datap)
813 xa = ahci_ata_get_xfer(ap, ap->ap_ata[15]);
815 xa->fis->type = ATA_FIS_TYPE_H2D;
816 xa->fis->flags = ATA_H2D_FLAGS_CMD | 15;
817 xa->fis->command = ATA_C_READ_PM;
818 xa->fis->features = which;
819 xa->fis->device = target | ATA_H2D_DEVICE_LBA;
820 xa->fis->control = ATA_FIS_CONTROL_4BIT;
822 xa->complete = ahci_pm_dummy_done;
824 xa->flags = ATA_F_POLL | ATA_F_AUTOSENSE;
827 if (ahci_ata_cmd(xa) == ATA_S_COMPLETE) {
828 *datap = xa->rfis.sector_count | (xa->rfis.lba_low << 8) |
829 (xa->rfis.lba_mid << 16) | (xa->rfis.lba_high << 24);
832 kprintf("%s.%d pm_read SCA[%d] failed\n",
833 PORTNAME(ap), target, which);
837 ahci_ata_put_xfer(xa);
842 * Write a PM register
845 ahci_pm_write(struct ahci_port *ap, int target, int which, u_int32_t data)
850 xa = ahci_ata_get_xfer(ap, ap->ap_ata[15]);
852 xa->fis->type = ATA_FIS_TYPE_H2D;
853 xa->fis->flags = ATA_H2D_FLAGS_CMD | 15;
854 xa->fis->command = ATA_C_WRITE_PM;
855 xa->fis->features = which;
856 xa->fis->device = target | ATA_H2D_DEVICE_LBA;
857 xa->fis->sector_count = (u_int8_t)data;
858 xa->fis->lba_low = (u_int8_t)(data >> 8);
859 xa->fis->lba_mid = (u_int8_t)(data >> 16);
860 xa->fis->lba_high = (u_int8_t)(data >> 24);
861 xa->fis->control = ATA_FIS_CONTROL_4BIT;
863 xa->complete = ahci_pm_dummy_done;
865 xa->flags = ATA_F_POLL;
868 if (ahci_ata_cmd(xa) == ATA_S_COMPLETE)
872 ahci_ata_put_xfer(xa);
877 * Dummy done callback for xa.
880 ahci_pm_dummy_done(struct ata_xfer *xa)