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;
144 if (ahci_poll(ccb, 1000, ahci_quick_timeout) != ATA_S_COMPLETE) {
145 kprintf("%s: PMPROBE First FIS failed\n", PORTNAME(ap));
147 ahci_put_err_ccb(ccb);
153 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
154 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
155 kprintf("%s: PMPROBE Busy after first FIS\n", PORTNAME(ap));
159 * The device may have muffed up the PHY when it reset.
163 ahci_pwrite(ap, AHCI_PREG_SERR, -1);
164 /* ahci_pm_phy_status(ap, 15, &cmd); */
167 * Prep second D2H command to read status and complete reset sequence
168 * AHCI 10.4.1 and "Serial ATA Revision 2.6". I can't find the ATA
169 * Rev 2.6 and it is unclear how the second FIS should be set up
170 * from the AHCI document.
172 * Give the device 3ms before sending the second FIS.
174 * It is unclear which other fields in the FIS are used. Just zero
177 ccb->ccb_xa.flags = ATA_F_POLL;
179 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
180 fis[0] = ATA_FIS_TYPE_H2D;
182 fis[15] = ATA_FIS_CONTROL_4BIT;
185 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
186 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_PMP); /* port 0xF */
188 ccb->ccb_xa.state = ATA_S_PENDING;
190 if (ahci_poll(ccb, 5000, ahci_quick_timeout) != ATA_S_COMPLETE) {
191 kprintf("%s: PMPROBE Second FIS failed\n", PORTNAME(ap));
193 ahci_put_err_ccb(ccb);
201 * What? We succeeded? Yup, but for some reason the signature
202 * is still latched from the original detect (that saw target 0
203 * behind the PM), and I don't know how to clear the condition
204 * other then by retrying the whole reset sequence.
208 ahci_put_err_ccb(ccb);
213 * Get the signature. The caller sets the ap fields.
215 if (ahci_port_signature_detect(ap, NULL) == ATA_PORT_T_PM) {
216 ap->ap_ata[15].at_probe = ATA_PROBE_GOOD;
223 * Fall through / clean up the CCB and perform error processing.
227 ahci_put_err_ccb(ccb);
229 if (error == 0 && ahci_pm_identify(ap)) {
230 kprintf("%s: PM - cannot identify port multiplier\n",
236 * If we probed the PM reset the state for the targets behind
237 * it so they get probed by the state machine.
240 for (i = 0; i < AHCI_MAX_PMPORTS; ++i) {
242 at->at_probe = ATA_PROBE_NEED_INIT;
243 at->at_features |= ATA_PORT_F_RESCAN;
245 ap->ap_type = ATA_PORT_T_PM;
250 * If we failed turn off PMA, otherwise identify the port multiplier.
251 * CAM will iterate the devices.
253 ahci_port_stop(ap, 0);
255 cmd = ahci_pread(ap, AHCI_PREG_CMD) & ~AHCI_PREG_CMD_ICC;
256 cmd &= ~AHCI_PREG_CMD_PMA;
257 ahci_pwrite(ap, AHCI_PREG_CMD, cmd);
259 if (orig_error == 0) {
260 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
261 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
262 kprintf("%s: PM probe: port will not come ready\n",
271 * Identify the port multiplier
274 ahci_pm_identify(struct ahci_port *ap)
282 ap->ap_probe = ATA_PROBE_FAILED;
283 if (ahci_pm_read(ap, 15, 0, &chipid))
285 if (ahci_pm_read(ap, 15, 1, &rev))
287 if (ahci_pm_read(ap, 15, 2, &nports))
289 nports &= 0x0000000F; /* only the low 4 bits */
290 ap->ap_probe = ATA_PROBE_GOOD;
291 kprintf("%s: Port multiplier: chip=%08x rev=0x%b nports=%d\n",
294 rev, SATA_PFMT_PM_REV,
296 ap->ap_pmcount = nports;
298 if (ahci_pm_read(ap, 15, SATA_PMREG_FEA, &data1)) {
299 kprintf("%s: Port multiplier: Warning, "
300 "cannot read feature register\n", PORTNAME(ap));
302 kprintf("%s: Port multiplier features: 0x%b\n",
307 if (ahci_pm_read(ap, 15, SATA_PMREG_FEAEN, &data2) == 0) {
308 kprintf("%s: Port multiplier defaults: 0x%b\n",
315 * Turn on async notification if we support and the PM supports it.
316 * This allows the PM to forward async notification events to us and
317 * it will also generate an event for target 15 for hot-plug events
318 * (or is supposed to anyway).
320 if ((ap->ap_sc->sc_cap & AHCI_REG_CAP_SSNTF) &&
321 (data1 & SATA_PMFEA_ASYNCNOTIFY)) {
322 u_int32_t serr_bits = AHCI_PREG_SERR_DIAG_N |
323 AHCI_PREG_SERR_DIAG_X;
324 data2 |= SATA_PMFEA_ASYNCNOTIFY;
325 if (ahci_pm_write(ap, 15, SATA_PMREG_FEAEN, data2)) {
326 kprintf("%s: Port multiplier: AsyncNotify cannot be "
327 "enabled\n", PORTNAME(ap));
328 } else if (ahci_pm_write(ap, 15, SATA_PMREG_EEENA, serr_bits)) {
329 kprintf("%s: Port mulltiplier: AsyncNotify unable "
330 "to enable error info bits\n", PORTNAME(ap));
332 kprintf("%s: Port multiplier: AsyncNotify enabled\n",
339 kprintf("%s: Port multiplier cannot be identified\n", PORTNAME(ap));
344 * Do a COMRESET sequence on the target behind a port multiplier.
346 * If hard is 2 we also cycle the phy on the target.
348 * This must be done prior to any softreset or probe attempts on
349 * targets behind the port multiplier.
351 * Returns 0 on success or an error.
354 ahci_pm_hardreset(struct ahci_port *ap, int target, int hard)
361 at = &ap->ap_ata[target];
364 * Turn off power management and kill the phy on the target
365 * if requested. Hold state for 10ms.
367 data = AHCI_PREG_SCTL_IPM_DISABLED;
369 data |= AHCI_PREG_SCTL_DET_DISABLE;
370 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1))
372 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
377 * Start transmitting COMRESET. COMRESET must be sent for at
380 at->at_probe = ATA_PROBE_FAILED;
381 at->at_type = ATA_PORT_T_NONE;
382 data = AHCI_PREG_SCTL_IPM_DISABLED | AHCI_PREG_SCTL_DET_INIT;
383 if (AhciForceGen1 & (1 << ap->ap_num)) {
384 kprintf("%s.%d: Force 1.5GBits\n", PORTNAME(ap), target);
385 data |= AHCI_PREG_SCTL_SPD_GEN1;
387 data |= AHCI_PREG_SCTL_SPD_ANY;
389 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
393 * It takes about 100ms for the DET logic to settle down,
394 * from trial and error testing. If this is too short
395 * the softreset code will fail.
399 if (ahci_pm_phy_status(ap, target, &data)) {
400 kprintf("%s: (A)Cannot clear phy status\n",
405 * Flush any status, then clear DET to initiate negotiation.
407 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
408 data = AHCI_PREG_SCTL_IPM_DISABLED | AHCI_PREG_SCTL_DET_NONE;
409 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
413 * Try to determine if there is a device on the port.
415 * Give the device 3/10 second to at least be detected.
416 * If we fail clear any pending status since we may have
417 * cycled the phy and probably caused another PRCS interrupt.
419 for (loop = 3; loop; --loop) {
420 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data))
422 if (data & AHCI_PREG_SSTS_DET)
427 kprintf("%s.%d: Port appears to be unplugged\n",
428 PORTNAME(ap), target);
434 * There is something on the port. Give the device 3 seconds
435 * to fully negotiate.
437 for (loop = 30; loop; --loop) {
438 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data))
440 if ((data & AHCI_PREG_SSTS_DET) == AHCI_PREG_SSTS_DET_DEV)
446 * Device not detected
449 kprintf("%s: Device may be powered down\n",
458 kprintf("%s.%d: Device detected data=%08x\n",
459 PORTNAME(ap), target, data);
461 * Clear SERR on the target so we get a new NOTIFY event if a hot-plug
462 * or hot-unplug occurs.
468 at->at_probe = error ? ATA_PROBE_FAILED : ATA_PROBE_NEED_SOFT_RESET;
473 * AHCI soft reset through port multiplier.
475 * This function keeps port communications intact and attempts to generate
476 * a reset to the connected device using device commands. Unlike
477 * hard-port operations we can't do fancy stop/starts or stuff like
478 * that without messing up other commands that might be running or
482 ahci_pm_softreset(struct ahci_port *ap, int target)
485 struct ahci_ccb *ccb;
486 struct ahci_cmd_hdr *cmd_slot;
494 at = &ap->ap_ata[target];
496 DPRINTF(AHCI_D_VERBOSE, "%s: soft reset\n", PORTNAME(ap));
502 * Try to clear the phy so we get a good signature, otherwise
503 * the PM may not latch a new signature.
505 * NOTE: This cannot be safely done between the first and second
506 * softreset FISs. It's now or never.
509 if (ahci_pm_phy_status(ap, target, &data)) {
510 kprintf("%s: (B)Cannot clear phy status\n",
513 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
517 * Prep first D2H command with SRST feature & clear busy/reset flags
519 * It is unclear which other fields in the FIS are used. Just zero
522 * When soft-resetting a port behind a multiplier at will be
523 * non-NULL, assigning it to the ccb prevents the port interrupt
524 * from hard-resetting the port if a problem crops up.
526 ccb = ahci_get_err_ccb(ap);
527 ccb->ccb_xa.flags = ATA_F_POLL | ATA_F_EXCLUSIVE | ATA_F_AUTOSENSE;
528 ccb->ccb_xa.complete = ahci_pm_dummy_done;
531 fis = ccb->ccb_cmd_table->cfis;
532 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
533 fis[0] = ATA_FIS_TYPE_H2D;
534 fis[1] = at->at_target;
535 fis[15] = ATA_FIS_CONTROL_SRST|ATA_FIS_CONTROL_4BIT;
537 cmd_slot = ccb->ccb_cmd_hdr;
539 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
540 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_C); /* Clear busy on OK */
541 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_R); /* Reset */
542 cmd_slot->flags |= htole16(at->at_target <<
543 AHCI_CMD_LIST_FLAG_PMP_SHIFT);
545 ccb->ccb_xa.state = ATA_S_PENDING;
548 * XXX hack to ignore IFS errors which can occur during the target
551 * If an IFS error occurs the target is probably powering up,
552 * so we try for a longer period of time.
554 ap->ap_flags |= AP_F_IGNORE_IFS;
555 ap->ap_flags &= ~(AP_F_IFS_IGNORED | AP_F_IFS_OCCURED);
557 if (ahci_poll(ccb, 1000, ahci_ata_cmd_timeout) != ATA_S_COMPLETE) {
558 kprintf("%s: (PM) First FIS failed\n", ATANAME(ap, at));
559 if (ap->ap_flags & AP_F_IFS_OCCURED) {
560 if (tried_longer == 0)
564 ahci_put_err_ccb(ccb);
571 * WARNING! SENSITIVE TIME PERIOD! WARNING!
573 * The first and second FISes are supposed to be back-to-back,
574 * I think the idea is to get the second sent and then after
575 * the device resets it will send a signature. Do not delay
576 * here and most definitely do not issue any commands to other
581 * Prep second D2H command to read status and complete reset sequence
582 * AHCI 10.4.1 and "Serial ATA Revision 2.6". I can't find the ATA
583 * Rev 2.6 and it is unclear how the second FIS should be set up
584 * from the AHCI document.
586 * Give the device 3ms before sending the second FIS.
588 * It is unclear which other fields in the FIS are used. Just zero
591 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
592 fis[0] = ATA_FIS_TYPE_H2D;
593 fis[1] = at->at_target;
594 fis[15] = ATA_FIS_CONTROL_4BIT;
597 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
598 cmd_slot->flags |= htole16(at->at_target <<
599 AHCI_CMD_LIST_FLAG_PMP_SHIFT);
601 ccb->ccb_xa.state = ATA_S_PENDING;
602 ccb->ccb_xa.flags = ATA_F_POLL | ATA_F_EXCLUSIVE | ATA_F_AUTOSENSE;
604 if (ahci_poll(ccb, 1000, ahci_ata_cmd_timeout) != ATA_S_COMPLETE) {
605 kprintf("%s: (PM) Second FIS failed\n", ATANAME(ap, at));
606 ahci_put_err_ccb(ccb);
614 ahci_put_err_ccb(ccb);
616 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
617 if (ahci_pm_phy_status(ap, target, &data)) {
618 kprintf("%s: (C)Cannot clear phy status\n",
621 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
624 * Do it again, even if we think we got a good result
632 * If the softreset is trying to clear a BSY condition after a
633 * normal portreset we assign the port type.
635 * If the softreset is being run first as part of the ccb error
636 * processing code then report if the device signature changed
639 if (at->at_type == ATA_PORT_T_NONE) {
640 at->at_type = ahci_port_signature_detect(ap, at);
642 if (ahci_port_signature_detect(ap, at) != at->at_type) {
643 kprintf("%s: device signature unexpectedly "
644 "changed\n", ATANAME(ap, at));
645 error = EBUSY; /* XXX */
651 * Who knows what kind of mess occured. We have exclusive access
652 * to the port so try to clean up potential problems.
657 * Clear error status so we can detect removal.
659 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1)) {
660 kprintf("%s: ahci_pm_softreset unable to clear SERR\n",
662 ap->ap_flags &= ~AP_F_IGNORE_IFS;
664 /* ahci_pwrite(ap, AHCI_PREG_SERR, -1);*/
666 at->at_probe = error ? ATA_PROBE_FAILED : ATA_PROBE_NEED_IDENT;
672 * Return the phy status for a target behind a port multiplier and
673 * reset SATA_PMREG_SERR.
675 * Returned bits follow AHCI_PREG_SSTS bits. The AHCI_PREG_SSTS_SPD
676 * bits can be used to determine the link speed and will be 0 if there
679 * 0 is returned if any communications error occurs.
682 ahci_pm_phy_status(struct ahci_port *ap, int target, u_int32_t *datap)
686 error = ahci_pm_read(ap, target, SATA_PMREG_SSTS, datap);
688 error = ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
695 ahci_pm_set_feature(struct ahci_port *ap, int feature, int enable)
700 xa = ahci_ata_get_xfer(ap, &ap->ap_ata[15]);
702 xa->fis->type = ATA_FIS_TYPE_H2D;
703 xa->fis->flags = ATA_H2D_FLAGS_CMD | 15;
704 xa->fis->command = enable ? ATA_C_SATA_FEATURE_ENA :
705 ATA_C_SATA_FEATURE_DIS;
706 xa->fis->sector_count = feature;
707 xa->fis->control = ATA_FIS_CONTROL_4BIT;
709 xa->complete = ahci_pm_dummy_done;
711 xa->flags = ATA_F_POLL;
714 if (ahci_ata_cmd(xa) == ATA_S_COMPLETE)
718 ahci_ata_put_xfer(xa);
723 * Check that a target is still good.
726 ahci_pm_check_good(struct ahci_port *ap, int target)
732 * It looks like we might have to read the EINFO register
733 * to allow the PM to generate a new event.
735 if (ahci_pm_read(ap, 15, SATA_PMREG_EINFO, &data)) {
736 kprintf("%s: Port multiplier EINFO could not be read\n",
740 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1)) {
741 kprintf("%s: Port multiplier: SERR could not be cleared\n",
745 if (target == CAM_TARGET_WILDCARD || target >= ap->ap_pmcount)
747 at = &ap->ap_ata[target];
750 * If the device needs an init or hard reset also make sure the
753 if (at->at_probe <= ATA_PROBE_NEED_HARD_RESET) {
754 /*kprintf("%s DOHARD\n", ATANAME(ap, at));*/
755 ahci_pm_hardreset(ap, target, 1);
759 * Read the detect status
761 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data)) {
762 kprintf("%s: Unable to access PM SSTS register target %d\n",
763 PORTNAME(ap), target);
766 if ((data & AHCI_PREG_SSTS_DET) != AHCI_PREG_SSTS_DET_DEV) {
767 /*kprintf("%s: DETECT %08x\n", ATANAME(ap, at), data);*/
768 if (at->at_probe != ATA_PROBE_FAILED) {
769 at->at_probe = ATA_PROBE_FAILED;
770 at->at_type = ATA_PORT_T_NONE;
771 at->at_features |= ATA_PORT_F_RESCAN;
772 kprintf("%s: HOTPLUG (PM) - Device removed\n",
776 if (at->at_probe == ATA_PROBE_FAILED) {
777 at->at_probe = ATA_PROBE_NEED_HARD_RESET;
778 at->at_features |= ATA_PORT_F_RESCAN;
779 kprintf("%s: HOTPLUG (PM) - Device inserted\n",
789 ahci_pm_read(struct ahci_port *ap, int target, int which, u_int32_t *datap)
794 xa = ahci_ata_get_xfer(ap, &ap->ap_ata[15]);
796 xa->fis->type = ATA_FIS_TYPE_H2D;
797 xa->fis->flags = ATA_H2D_FLAGS_CMD | 15;
798 xa->fis->command = ATA_C_READ_PM;
799 xa->fis->features = which;
800 xa->fis->device = target | ATA_H2D_DEVICE_LBA;
801 xa->fis->control = ATA_FIS_CONTROL_4BIT;
803 xa->complete = ahci_pm_dummy_done;
805 xa->flags = ATA_F_POLL | ATA_F_AUTOSENSE;
808 if (ahci_ata_cmd(xa) == ATA_S_COMPLETE) {
809 *datap = xa->rfis.sector_count | (xa->rfis.lba_low << 8) |
810 (xa->rfis.lba_mid << 16) | (xa->rfis.lba_high << 24);
813 kprintf("%s.%d pm_read SCA[%d] failed\n",
814 PORTNAME(ap), target, which);
818 ahci_ata_put_xfer(xa);
823 * Write a PM register
826 ahci_pm_write(struct ahci_port *ap, int target, int which, u_int32_t data)
831 xa = ahci_ata_get_xfer(ap, &ap->ap_ata[15]);
833 xa->fis->type = ATA_FIS_TYPE_H2D;
834 xa->fis->flags = ATA_H2D_FLAGS_CMD | 15;
835 xa->fis->command = ATA_C_WRITE_PM;
836 xa->fis->features = which;
837 xa->fis->device = target | ATA_H2D_DEVICE_LBA;
838 xa->fis->sector_count = (u_int8_t)data;
839 xa->fis->lba_low = (u_int8_t)(data >> 8);
840 xa->fis->lba_mid = (u_int8_t)(data >> 16);
841 xa->fis->lba_high = (u_int8_t)(data >> 24);
842 xa->fis->control = ATA_FIS_CONTROL_4BIT;
844 xa->complete = ahci_pm_dummy_done;
846 xa->flags = ATA_F_POLL;
849 if (ahci_ata_cmd(xa) == ATA_S_COMPLETE)
853 ahci_ata_put_xfer(xa);
858 * Dummy done callback for xa.
861 ahci_pm_dummy_done(struct ata_xfer *xa)