4 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
6 * This code is derived from software contributed to The DragonFly Project
7 * by Matthew Dillon <dillon@backplane.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
19 * 3. Neither the name of The DragonFly Project nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific, prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 static void ahci_pm_dummy_done(struct ata_xfer *xa);
42 ahci_pm_port_init(struct ahci_port *ap, struct ata_port *at)
44 at->at_probe = ATA_PROBE_NEED_HARD_RESET;
49 * AHCI port multiplier probe. This routine is run by the hardreset code
50 * if it gets past the device detect, whether or not BSY is found to be
53 * We MUST use CLO to properly probe whether the port multiplier exists
56 * Return 0 on success, non-zero on failure.
59 ahci_pm_port_probe(struct ahci_port *ap, int orig_error)
61 struct ahci_cmd_hdr *cmd_slot;
63 struct ahci_ccb *ccb = NULL;
73 * This code is only called from hardreset, which does not
74 * high level command processing. The port should be stopped.
76 * Set PMA mode while the port is stopped.
78 * NOTE: On retry the port might be running, stopped, or failed.
80 ahci_port_stop(ap, 0);
81 ap->ap_state = AP_S_NORMAL;
82 cmd = ahci_pread(ap, AHCI_PREG_CMD) & ~AHCI_PREG_CMD_ICC;
83 if ((cmd & AHCI_PREG_CMD_PMA) == 0) {
84 cmd |= AHCI_PREG_CMD_PMA;
85 ahci_pwrite(ap, AHCI_PREG_CMD, cmd);
89 * Flush any errors and request CLO unconditionally, then start
94 if (ahci_port_start(ap)) {
95 kprintf("%s: PMPROBE failed to start port, cannot softreset\n",
102 * Check whether CLO worked
104 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
105 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
106 kprintf("%s: PMPROBE CLO %s, need port reset\n",
108 (ahci_read(ap->ap_sc, AHCI_REG_CAP) & AHCI_REG_CAP_SCLO)
109 ? "failed" : "unsupported");
115 * Use the error CCB for all commands
117 * NOTE! This CCB is used for both the first and second commands.
118 * The second command must use CCB slot 1 to properly load
121 ccb = ahci_get_err_ccb(ap);
122 ccb->ccb_xa.flags = ATA_F_POLL;
123 ccb->ccb_xa.complete = ahci_pm_dummy_done;
124 ccb->ccb_xa.at = ap->ap_ata[15];
125 cmd_slot = ccb->ccb_cmd_hdr;
126 KKASSERT(ccb->ccb_slot == 1);
129 * Prep the first H2D command with SRST feature & clear busy/reset
132 fis = ccb->ccb_cmd_table->cfis;
133 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
134 fis[0] = ATA_FIS_TYPE_H2D;
135 fis[1] = 0x0F; /* Target 15 */
136 fis[15] = ATA_FIS_CONTROL_SRST | ATA_FIS_CONTROL_4BIT;
139 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
140 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_C); /* Clear busy on OK */
141 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_R); /* Reset */
142 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_PMP); /* port 0xF */
144 ccb->ccb_xa.state = ATA_S_PENDING;
147 * The only way one can determine if a port multiplier is on the
148 * port is to probe target 15, and of course this will fail if
149 * there is no port multiplier.
151 * The probing has to be done whether or not a device is probed on
152 * target 0, because when a PM is attached target 0 represents
153 * slot #0 behind the PM.
155 if (ahci_poll(ccb, 1000, ahci_quick_timeout) != ATA_S_COMPLETE) {
156 kprintf("%s: PMPROBE First FIS failed,\n",
158 kprintf("%s: PMPROBE No Port Multiplier was found.\n",
161 ahci_put_err_ccb(ccb);
167 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
168 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
169 kprintf("%s: PMPROBE Busy after first FIS\n", PORTNAME(ap));
173 * The device may have muffed up the PHY when it reset.
177 ahci_pwrite(ap, AHCI_PREG_SERR, -1);
178 /* ahci_pm_phy_status(ap, 15, &cmd); */
181 * Prep second D2H command to read status and complete reset sequence
182 * AHCI 10.4.1 and "Serial ATA Revision 2.6". I can't find the ATA
183 * Rev 2.6 and it is unclear how the second FIS should be set up
184 * from the AHCI document.
186 * Give the device 3ms before sending the second FIS.
188 * It is unclear which other fields in the FIS are used. Just zero
191 ccb->ccb_xa.flags = ATA_F_POLL;
193 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
194 fis[0] = ATA_FIS_TYPE_H2D;
196 fis[15] = ATA_FIS_CONTROL_4BIT;
199 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
200 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_PMP); /* port 0xF */
202 ccb->ccb_xa.state = ATA_S_PENDING;
205 * The only way one can determine if a port multiplier is on the
206 * port is to probe target 15, and of course this will fail if
207 * there is no port multiplier.
209 * The probing has to be done whether or not a device is probed on
210 * target 0, because when a PM is attached target 0 represents
211 * slot #0 behind the PM.
213 if (ahci_poll(ccb, 5000, ahci_quick_timeout) != ATA_S_COMPLETE) {
214 kprintf("%s: PMPROBE Second FIS failed,\n",
216 kprintf("%s: PMPROBE No Port Multiplier was found.\n",
219 ahci_put_err_ccb(ccb);
227 * What? We succeeded? Yup, but for some reason the signature
228 * is still latched from the original detect (that saw target 0
229 * behind the PM), and I don't know how to clear the condition
230 * other then by retrying the whole reset sequence.
234 ahci_put_err_ccb(ccb);
239 * Get the signature. The caller sets the ap fields.
241 if (ahci_port_signature_detect(ap, NULL) == ATA_PORT_T_PM) {
242 ap->ap_ata[15]->at_probe = ATA_PROBE_GOOD;
249 * Fall through / clean up the CCB and perform error processing.
253 ahci_put_err_ccb(ccb);
255 if (error == 0 && ahci_pm_identify(ap)) {
256 kprintf("%s: PM - cannot identify port multiplier\n",
262 * If we probed the PM reset the state for the targets behind
263 * it so they get probed by the state machine.
266 for (i = 0; i < AHCI_MAX_PMPORTS; ++i) {
268 at->at_probe = ATA_PROBE_NEED_INIT;
269 at->at_features |= ATA_PORT_F_RESCAN;
271 ap->ap_type = ATA_PORT_T_PM;
276 * If we failed turn off PMA, otherwise identify the port multiplier.
277 * CAM will iterate the devices.
279 ahci_port_stop(ap, 0);
281 cmd = ahci_pread(ap, AHCI_PREG_CMD) & ~AHCI_PREG_CMD_ICC;
282 cmd &= ~AHCI_PREG_CMD_PMA;
283 ahci_pwrite(ap, AHCI_PREG_CMD, cmd);
285 if (orig_error == 0) {
286 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
287 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
288 kprintf("%s: PM probe: port will not come ready\n",
297 * Identify the port multiplier
300 ahci_pm_identify(struct ahci_port *ap)
309 ap->ap_probe = ATA_PROBE_FAILED;
310 if (ahci_pm_read(ap, 15, 0, &chipid))
312 if (ahci_pm_read(ap, 15, 1, &rev))
314 if (ahci_pm_read(ap, 15, 2, &nports))
316 nports &= 0x0000000F; /* only the low 4 bits */
317 ap->ap_probe = ATA_PROBE_GOOD;
320 * Ignore fake port on PMs which have it. We can probe it but the
321 * softreset will probably fail.
331 if (has_dummy_port) {
336 kprintf("%s: Port multiplier: chip=%08x rev=0x%b nports=%d\n",
339 rev, SATA_PFMT_PM_REV,
341 if (has_dummy_port) {
342 kprintf("%s: Port multiplier: Ignoring dummy port #%d\n",
343 PORTNAME(ap), nports);
345 ap->ap_pmcount = nports;
347 if (ahci_pm_read(ap, 15, SATA_PMREG_FEA, &data1)) {
348 kprintf("%s: Port multiplier: Warning, "
349 "cannot read feature register\n", PORTNAME(ap));
351 kprintf("%s: Port multiplier features: 0x%b\n",
356 if (ahci_pm_read(ap, 15, SATA_PMREG_FEAEN, &data2) == 0) {
357 kprintf("%s: Port multiplier defaults: 0x%b\n",
364 * Turn on async notification if we support and the PM supports it.
365 * This allows the PM to forward async notification events to us and
366 * it will also generate an event for target 15 for hot-plug events
367 * (or is supposed to anyway).
369 if ((ap->ap_sc->sc_cap & AHCI_REG_CAP_SSNTF) &&
370 (data1 & SATA_PMFEA_ASYNCNOTIFY)) {
371 u_int32_t serr_bits = AHCI_PREG_SERR_DIAG_N |
372 AHCI_PREG_SERR_DIAG_X;
373 data2 |= SATA_PMFEA_ASYNCNOTIFY;
374 if (ahci_pm_write(ap, 15, SATA_PMREG_FEAEN, data2)) {
375 kprintf("%s: Port multiplier: AsyncNotify cannot be "
376 "enabled\n", PORTNAME(ap));
377 } else if (ahci_pm_write(ap, 15, SATA_PMREG_EEENA, serr_bits)) {
378 kprintf("%s: Port mulltiplier: AsyncNotify unable "
379 "to enable error info bits\n", PORTNAME(ap));
381 kprintf("%s: Port multiplier: AsyncNotify enabled\n",
388 kprintf("%s: Port multiplier cannot be identified\n", PORTNAME(ap));
393 * Do a COMRESET sequence on the target behind a port multiplier.
395 * If hard is 2 we also cycle the phy on the target.
397 * This must be done prior to any softreset or probe attempts on
398 * targets behind the port multiplier.
400 * Returns 0 on success or an error.
403 ahci_pm_hardreset(struct ahci_port *ap, int target, int hard)
410 at = ap->ap_ata[target];
413 * Turn off power management and kill the phy on the target
414 * if requested. Hold state for 10ms.
416 data = AHCI_PREG_SCTL_IPM_DISABLED;
418 data |= AHCI_PREG_SCTL_DET_DISABLE;
419 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1))
421 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
426 * Start transmitting COMRESET. COMRESET must be sent for at
429 at->at_probe = ATA_PROBE_FAILED;
430 at->at_type = ATA_PORT_T_NONE;
431 data = AHCI_PREG_SCTL_IPM_DISABLED | AHCI_PREG_SCTL_DET_INIT;
432 if (AhciForceGen1 & (1 << ap->ap_num)) {
433 kprintf("%s.%d: Force 1.5GBits\n", PORTNAME(ap), target);
434 data |= AHCI_PREG_SCTL_SPD_GEN1;
436 data |= AHCI_PREG_SCTL_SPD_ANY;
438 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
442 * It takes about 100ms for the DET logic to settle down,
443 * from trial and error testing. If this is too short
444 * the softreset code will fail.
448 if (ahci_pm_phy_status(ap, target, &data)) {
449 kprintf("%s: (A)Cannot clear phy status\n",
454 * Flush any status, then clear DET to initiate negotiation.
456 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
457 data = AHCI_PREG_SCTL_IPM_DISABLED | AHCI_PREG_SCTL_DET_NONE;
458 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
462 * Try to determine if there is a device on the port.
464 * Give the device 3/10 second to at least be detected.
465 * If we fail clear any pending status since we may have
466 * cycled the phy and probably caused another PRCS interrupt.
468 for (loop = 3; loop; --loop) {
469 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data))
471 if (data & AHCI_PREG_SSTS_DET)
476 kprintf("%s.%d: Port appears to be unplugged\n",
477 PORTNAME(ap), target);
483 * There is something on the port. Give the device 3 seconds
484 * to fully negotiate.
486 for (loop = 30; loop; --loop) {
487 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data))
489 if ((data & AHCI_PREG_SSTS_DET) == AHCI_PREG_SSTS_DET_DEV)
495 * Device not detected
498 kprintf("%s: Device may be powered down\n",
507 kprintf("%s.%d: Device detected data=%08x\n",
508 PORTNAME(ap), target, data);
510 * Clear SERR on the target so we get a new NOTIFY event if a hot-plug
511 * or hot-unplug occurs.
517 at->at_probe = error ? ATA_PROBE_FAILED : ATA_PROBE_NEED_SOFT_RESET;
522 * AHCI soft reset through port multiplier.
524 * This function keeps port communications intact and attempts to generate
525 * a reset to the connected device using device commands. Unlike
526 * hard-port operations we can't do fancy stop/starts or stuff like
527 * that without messing up other commands that might be running or
531 ahci_pm_softreset(struct ahci_port *ap, int target)
534 struct ahci_ccb *ccb;
535 struct ahci_cmd_hdr *cmd_slot;
543 at = ap->ap_ata[target];
545 DPRINTF(AHCI_D_VERBOSE, "%s: soft reset\n", PORTNAME(ap));
551 * Try to clear the phy so we get a good signature, otherwise
552 * the PM may not latch a new signature.
554 * NOTE: This cannot be safely done between the first and second
555 * softreset FISs. It's now or never.
558 if (ahci_pm_phy_status(ap, target, &data)) {
559 kprintf("%s: (B)Cannot clear phy status\n",
562 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
566 * Prep first D2H command with SRST feature & clear busy/reset flags
568 * It is unclear which other fields in the FIS are used. Just zero
571 * When soft-resetting a port behind a multiplier at will be
572 * non-NULL, assigning it to the ccb prevents the port interrupt
573 * from hard-resetting the port if a problem crops up.
575 ccb = ahci_get_err_ccb(ap);
576 ccb->ccb_xa.flags = ATA_F_POLL | ATA_F_EXCLUSIVE | ATA_F_AUTOSENSE;
577 ccb->ccb_xa.complete = ahci_pm_dummy_done;
580 fis = ccb->ccb_cmd_table->cfis;
581 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
582 fis[0] = ATA_FIS_TYPE_H2D;
583 fis[1] = at->at_target;
584 fis[15] = ATA_FIS_CONTROL_SRST|ATA_FIS_CONTROL_4BIT;
586 cmd_slot = ccb->ccb_cmd_hdr;
588 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
589 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_C); /* Clear busy on OK */
590 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_R); /* Reset */
591 cmd_slot->flags |= htole16(at->at_target <<
592 AHCI_CMD_LIST_FLAG_PMP_SHIFT);
594 ccb->ccb_xa.state = ATA_S_PENDING;
597 * XXX hack to ignore IFS errors which can occur during the target
600 * If an IFS error occurs the target is probably powering up,
601 * so we try for a longer period of time.
603 ap->ap_flags |= AP_F_IGNORE_IFS;
604 ap->ap_flags &= ~(AP_F_IFS_IGNORED | AP_F_IFS_OCCURED);
606 if (ahci_poll(ccb, 1000, ahci_ata_cmd_timeout) != ATA_S_COMPLETE) {
607 kprintf("%s: (PM) First FIS failed\n", ATANAME(ap, at));
608 if (ap->ap_flags & AP_F_IFS_OCCURED) {
609 if (tried_longer == 0)
613 ahci_put_err_ccb(ccb);
620 * WARNING! SENSITIVE TIME PERIOD! WARNING!
622 * The first and second FISes are supposed to be back-to-back,
623 * I think the idea is to get the second sent and then after
624 * the device resets it will send a signature. Do not delay
625 * here and most definitely do not issue any commands to other
630 * Prep second D2H command to read status and complete reset sequence
631 * AHCI 10.4.1 and "Serial ATA Revision 2.6". I can't find the ATA
632 * Rev 2.6 and it is unclear how the second FIS should be set up
633 * from the AHCI document.
635 * Give the device 3ms before sending the second FIS.
637 * It is unclear which other fields in the FIS are used. Just zero
640 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
641 fis[0] = ATA_FIS_TYPE_H2D;
642 fis[1] = at->at_target;
643 fis[15] = ATA_FIS_CONTROL_4BIT;
646 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
647 cmd_slot->flags |= htole16(at->at_target <<
648 AHCI_CMD_LIST_FLAG_PMP_SHIFT);
650 ccb->ccb_xa.state = ATA_S_PENDING;
651 ccb->ccb_xa.flags = ATA_F_POLL | ATA_F_EXCLUSIVE | ATA_F_AUTOSENSE;
653 if (ahci_poll(ccb, 1000, ahci_ata_cmd_timeout) != ATA_S_COMPLETE) {
654 kprintf("%s: (PM) Second FIS failed\n", ATANAME(ap, at));
655 ahci_put_err_ccb(ccb);
663 ahci_put_err_ccb(ccb);
665 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
666 if (ahci_pm_phy_status(ap, target, &data)) {
667 kprintf("%s: (C)Cannot clear phy status\n",
670 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
673 * Do it again, even if we think we got a good result
681 * If the softreset is trying to clear a BSY condition after a
682 * normal portreset we assign the port type.
684 * If the softreset is being run first as part of the ccb error
685 * processing code then report if the device signature changed
688 if (at->at_type == ATA_PORT_T_NONE) {
689 at->at_type = ahci_port_signature_detect(ap, at);
691 if (ahci_port_signature_detect(ap, at) != at->at_type) {
692 kprintf("%s: device signature unexpectedly "
693 "changed\n", ATANAME(ap, at));
694 error = EBUSY; /* XXX */
700 * Who knows what kind of mess occured. We have exclusive access
701 * to the port so try to clean up potential problems.
706 * Clear error status so we can detect removal.
708 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1)) {
709 kprintf("%s: ahci_pm_softreset unable to clear SERR\n",
711 ap->ap_flags &= ~AP_F_IGNORE_IFS;
713 /* ahci_pwrite(ap, AHCI_PREG_SERR, -1);*/
715 at->at_probe = error ? ATA_PROBE_FAILED : ATA_PROBE_NEED_IDENT;
721 * Return the phy status for a target behind a port multiplier and
722 * reset SATA_PMREG_SERR.
724 * Returned bits follow AHCI_PREG_SSTS bits. The AHCI_PREG_SSTS_SPD
725 * bits can be used to determine the link speed and will be 0 if there
728 * 0 is returned if any communications error occurs.
731 ahci_pm_phy_status(struct ahci_port *ap, int target, u_int32_t *datap)
735 error = ahci_pm_read(ap, target, SATA_PMREG_SSTS, datap);
737 error = ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
744 * Check that a target is still good.
747 ahci_pm_check_good(struct ahci_port *ap, int target)
753 * It looks like we might have to read the EINFO register
754 * to allow the PM to generate a new event.
756 if (ahci_pm_read(ap, 15, SATA_PMREG_EINFO, &data)) {
757 kprintf("%s: Port multiplier EINFO could not be read\n",
761 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1)) {
762 kprintf("%s: Port multiplier: SERR could not be cleared\n",
766 if (target == CAM_TARGET_WILDCARD || target >= ap->ap_pmcount)
768 at = ap->ap_ata[target];
771 * If the device needs an init or hard reset also make sure the
774 if (at->at_probe <= ATA_PROBE_NEED_HARD_RESET) {
775 /*kprintf("%s DOHARD\n", ATANAME(ap, at));*/
776 ahci_pm_hardreset(ap, target, 1);
780 * Read the detect status
782 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data)) {
783 kprintf("%s: Unable to access PM SSTS register target %d\n",
784 PORTNAME(ap), target);
787 if ((data & AHCI_PREG_SSTS_DET) != AHCI_PREG_SSTS_DET_DEV) {
788 /*kprintf("%s: DETECT %08x\n", ATANAME(ap, at), data);*/
789 if (at->at_probe != ATA_PROBE_FAILED) {
790 at->at_probe = ATA_PROBE_FAILED;
791 at->at_type = ATA_PORT_T_NONE;
792 at->at_features |= ATA_PORT_F_RESCAN;
793 kprintf("%s: HOTPLUG (PM) - Device removed\n",
797 if (at->at_probe == ATA_PROBE_FAILED) {
798 at->at_probe = ATA_PROBE_NEED_HARD_RESET;
799 at->at_features |= ATA_PORT_F_RESCAN;
800 kprintf("%s: HOTPLUG (PM) - Device inserted\n",
810 ahci_pm_read(struct ahci_port *ap, int target, int which, u_int32_t *datap)
815 xa = ahci_ata_get_xfer(ap, ap->ap_ata[15]);
817 xa->fis->type = ATA_FIS_TYPE_H2D;
818 xa->fis->flags = ATA_H2D_FLAGS_CMD | 15;
819 xa->fis->command = ATA_C_READ_PM;
820 xa->fis->features = which;
821 xa->fis->device = target | ATA_H2D_DEVICE_LBA;
822 xa->fis->control = ATA_FIS_CONTROL_4BIT;
824 xa->complete = ahci_pm_dummy_done;
826 xa->flags = ATA_F_POLL | ATA_F_AUTOSENSE;
829 if (ahci_ata_cmd(xa) == ATA_S_COMPLETE) {
830 *datap = xa->rfis.sector_count | (xa->rfis.lba_low << 8) |
831 (xa->rfis.lba_mid << 16) | (xa->rfis.lba_high << 24);
834 kprintf("%s.%d pm_read SCA[%d] failed\n",
835 PORTNAME(ap), target, which);
839 ahci_ata_put_xfer(xa);
844 * Write a PM register
847 ahci_pm_write(struct ahci_port *ap, int target, int which, u_int32_t data)
852 xa = ahci_ata_get_xfer(ap, ap->ap_ata[15]);
854 xa->fis->type = ATA_FIS_TYPE_H2D;
855 xa->fis->flags = ATA_H2D_FLAGS_CMD | 15;
856 xa->fis->command = ATA_C_WRITE_PM;
857 xa->fis->features = which;
858 xa->fis->device = target | ATA_H2D_DEVICE_LBA;
859 xa->fis->sector_count = (u_int8_t)data;
860 xa->fis->lba_low = (u_int8_t)(data >> 8);
861 xa->fis->lba_mid = (u_int8_t)(data >> 16);
862 xa->fis->lba_high = (u_int8_t)(data >> 24);
863 xa->fis->control = ATA_FIS_CONTROL_4BIT;
865 xa->complete = ahci_pm_dummy_done;
867 xa->flags = ATA_F_POLL;
870 if (ahci_ata_cmd(xa) == ATA_S_COMPLETE)
874 ahci_ata_put_xfer(xa);
879 * Dummy done callback for xa.
882 ahci_pm_dummy_done(struct ata_xfer *xa)