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 | ATA_F_SILENT;
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 * Port multipliers are expected to answer more quickly than normal
156 * devices, use a shorter timeout than normal.
158 * If there is no PM here this command can still succeed due to
161 if (ahci_poll(ccb, 500, ahci_quick_timeout) != ATA_S_COMPLETE) {
162 kprintf("%s: PMPROBE(1) No Port Multiplier was found.\n",
165 ahci_put_err_ccb(ccb);
172 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
173 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
174 kprintf("%s: PMPROBE Busy after first FIS\n", PORTNAME(ap));
178 * The device may have muffed up the PHY when it reset.
181 ahci_pwrite(ap, AHCI_PREG_SERR, -1);
182 /* ahci_pm_phy_status(ap, 15, &cmd); */
185 * Prep second D2H command to read status and complete reset sequence
186 * AHCI 10.4.1 and "Serial ATA Revision 2.6". I can't find the ATA
187 * Rev 2.6 and it is unclear how the second FIS should be set up
188 * from the AHCI document.
190 * Give the device 3ms before sending the second FIS.
192 * It is unclear which other fields in the FIS are used. Just zero
195 ccb->ccb_xa.flags = ATA_F_POLL | ATA_F_SILENT;
197 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
198 fis[0] = ATA_FIS_TYPE_H2D;
200 fis[15] = ATA_FIS_CONTROL_4BIT;
203 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
204 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_PMP); /* port 0xF */
206 ccb->ccb_xa.state = ATA_S_PENDING;
209 * The only way one can determine if a port multiplier is on the
210 * port is to probe target 15, and of course this will fail if
211 * there is no port multiplier.
213 * The probing has to be done whether or not a device is probed on
214 * target 0, because when a PM is attached target 0 represents
215 * slot #0 behind the PM.
217 if (ahci_poll(ccb, 5000, ahci_quick_timeout) != ATA_S_COMPLETE) {
218 kprintf("%s: PMPROBE(2) No Port Multiplier was found.\n",
221 ahci_put_err_ccb(ccb);
229 * What? We succeeded? Yup, but for some reason the signature
230 * is still latched from the original detect (that saw target 0
231 * behind the PM), and I don't know how to clear the condition
232 * other then by retrying the whole reset sequence.
236 ahci_put_err_ccb(ccb);
241 * Get the signature. The caller sets the ap fields.
243 if (ahci_port_signature_detect(ap, NULL) == ATA_PORT_T_PM) {
244 ap->ap_ata[15]->at_probe = ATA_PROBE_GOOD;
251 * Fall through / clean up the CCB and perform error processing.
255 ahci_put_err_ccb(ccb);
257 if (error == 0 && ahci_pm_identify(ap)) {
258 kprintf("%s: PM - cannot identify port multiplier\n",
264 * If we probed the PM reset the state for the targets behind
265 * it so they get probed by the state machine.
268 for (i = 0; i < AHCI_MAX_PMPORTS; ++i) {
270 at->at_probe = ATA_PROBE_NEED_INIT;
271 at->at_features |= ATA_PORT_F_RESCAN;
273 ap->ap_type = ATA_PORT_T_PM;
278 * If we failed turn off PMA, otherwise identify the port multiplier.
279 * CAM will iterate the devices.
281 ahci_port_stop(ap, 0);
283 cmd = ahci_pread(ap, AHCI_PREG_CMD) & ~AHCI_PREG_CMD_ICC;
284 cmd &= ~AHCI_PREG_CMD_PMA;
285 ahci_pwrite(ap, AHCI_PREG_CMD, cmd);
286 if (orig_error == 0) {
287 if (ahci_pwait_clr(ap, AHCI_PREG_TFD,
288 AHCI_PREG_TFD_STS_BSY | AHCI_PREG_TFD_STS_DRQ)) {
289 kprintf("%s: PM probe: port will not come ready\n",
299 * Identify the port multiplier
302 ahci_pm_identify(struct ahci_port *ap)
311 ap->ap_probe = ATA_PROBE_FAILED;
312 if (ahci_pm_read(ap, 15, 0, &chipid))
314 if (ahci_pm_read(ap, 15, 1, &rev))
316 if (ahci_pm_read(ap, 15, 2, &nports))
318 nports &= 0x0000000F; /* only the low 4 bits */
319 ap->ap_probe = ATA_PROBE_GOOD;
322 * Ignore fake port on PMs which have it. We can probe it but the
323 * softreset will probably fail.
333 if (has_dummy_port) {
338 kprintf("%s: Port multiplier: chip=%08x rev=0x%b nports=%d\n",
341 rev, SATA_PFMT_PM_REV,
343 if (has_dummy_port) {
344 kprintf("%s: Port multiplier: Ignoring dummy port #%d\n",
345 PORTNAME(ap), nports);
347 ap->ap_pmcount = nports;
349 if (ahci_pm_read(ap, 15, SATA_PMREG_FEA, &data1)) {
350 kprintf("%s: Port multiplier: Warning, "
351 "cannot read feature register\n", PORTNAME(ap));
353 kprintf("%s: Port multiplier features: 0x%b\n",
358 if (ahci_pm_read(ap, 15, SATA_PMREG_FEAEN, &data2) == 0) {
359 kprintf("%s: Port multiplier defaults: 0x%b\n",
366 * Turn on async notification if we support and the PM supports it.
367 * This allows the PM to forward async notification events to us and
368 * it will also generate an event for target 15 for hot-plug events
369 * (or is supposed to anyway).
371 if ((ap->ap_sc->sc_cap & AHCI_REG_CAP_SSNTF) &&
372 (data1 & SATA_PMFEA_ASYNCNOTIFY)) {
373 u_int32_t serr_bits = AHCI_PREG_SERR_DIAG_N |
374 AHCI_PREG_SERR_DIAG_X;
375 data2 |= SATA_PMFEA_ASYNCNOTIFY;
376 if (ahci_pm_write(ap, 15, SATA_PMREG_FEAEN, data2)) {
377 kprintf("%s: Port multiplier: AsyncNotify cannot be "
378 "enabled\n", PORTNAME(ap));
379 } else if (ahci_pm_write(ap, 15, SATA_PMREG_EEENA, serr_bits)) {
380 kprintf("%s: Port mulltiplier: AsyncNotify unable "
381 "to enable error info bits\n", PORTNAME(ap));
383 kprintf("%s: Port multiplier: AsyncNotify enabled\n",
390 kprintf("%s: Port multiplier cannot be identified\n", PORTNAME(ap));
395 * Do a COMRESET sequence on the target behind a port multiplier.
397 * If hard is 2 we also cycle the phy on the target.
399 * This must be done prior to any softreset or probe attempts on
400 * targets behind the port multiplier.
402 * Returns 0 on success or an error.
405 ahci_pm_hardreset(struct ahci_port *ap, int target, int hard)
412 at = ap->ap_ata[target];
415 * Turn off power management and kill the phy on the target
416 * if requested. Hold state for 10ms.
418 data = AHCI_PREG_SCTL_IPM_DISABLED;
420 data |= AHCI_PREG_SCTL_DET_DISABLE;
421 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1))
423 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
428 * Start transmitting COMRESET. COMRESET must be sent for at
431 at->at_probe = ATA_PROBE_FAILED;
432 at->at_type = ATA_PORT_T_NONE;
433 data = AHCI_PREG_SCTL_IPM_DISABLED | AHCI_PREG_SCTL_DET_INIT;
434 switch(AhciForceGen) {
436 data |= AHCI_PREG_SCTL_SPD_ANY;
439 data |= AHCI_PREG_SCTL_SPD_GEN1;
442 data |= AHCI_PREG_SCTL_SPD_GEN2;
445 data |= AHCI_PREG_SCTL_SPD_GEN3;
448 data |= AHCI_PREG_SCTL_SPD_GEN3;
451 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
455 * It takes about 100ms for the DET logic to settle down,
456 * from trial and error testing. If this is too short
457 * the softreset code will fail.
461 if (ahci_pm_phy_status(ap, target, &data)) {
462 kprintf("%s: (A)Cannot clear phy status\n",
467 * Flush any status, then clear DET to initiate negotiation.
469 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
470 data = AHCI_PREG_SCTL_IPM_DISABLED | AHCI_PREG_SCTL_DET_NONE;
471 if (ahci_pm_write(ap, target, SATA_PMREG_SCTL, data))
475 * Try to determine if there is a device on the port.
477 * Give the device 3/10 second to at least be detected.
478 * If we fail clear any pending status since we may have
479 * cycled the phy and probably caused another PRCS interrupt.
481 for (loop = 3; loop; --loop) {
482 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data))
484 if (data & AHCI_PREG_SSTS_DET)
489 kprintf("%s.%d: Port appears to be unplugged\n",
490 PORTNAME(ap), target);
496 * There is something on the port. Give the device 3 seconds
497 * to fully negotiate.
499 for (loop = 30; loop; --loop) {
500 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data))
502 if ((data & AHCI_PREG_SSTS_DET) == AHCI_PREG_SSTS_DET_DEV)
508 * Device not detected
511 kprintf("%s: Device may be powered down\n",
520 kprintf("%s.%d: Device detected data=%08x\n",
521 PORTNAME(ap), target, data);
523 * Clear SERR on the target so we get a new NOTIFY event if a hot-plug
524 * or hot-unplug occurs. Clear any spurious IFS that may have
525 * occured during the probe.
527 * WARNING! 100ms seems to work in most cases but
530 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
531 ahci_pwrite(ap, AHCI_PREG_SERR, -1);
532 ahci_pwrite(ap, AHCI_PREG_IS, AHCI_PREG_IS_IFS);
536 at->at_probe = error ? ATA_PROBE_FAILED : ATA_PROBE_NEED_SOFT_RESET;
541 * AHCI soft reset through port multiplier.
543 * This function keeps port communications intact and attempts to generate
544 * a reset to the connected device using device commands. Unlike
545 * hard-port operations we can't do fancy stop/starts or stuff like
546 * that without messing up other commands that might be running or
550 ahci_pm_softreset(struct ahci_port *ap, int target)
553 struct ahci_ccb *ccb;
554 struct ahci_cmd_hdr *cmd_slot;
561 at = ap->ap_ata[target];
563 DPRINTF(AHCI_D_VERBOSE, "%s: soft reset\n", PORTNAME(ap));
568 * Try to clear the phy so we get a good signature, otherwise
569 * the PM may not latch a new signature.
571 * NOTE: This cannot be safely done between the first and second
572 * softreset FISs. It's now or never.
574 if (ahci_pm_phy_status(ap, target, &data)) {
575 kprintf("%s: (B)Cannot clear phy status\n",
578 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
581 * Prep first D2H command with SRST feature & clear busy/reset flags
583 * It is unclear which other fields in the FIS are used. Just zero
586 * When soft-resetting a port behind a multiplier at will be
587 * non-NULL, assigning it to the ccb prevents the port interrupt
588 * from hard-resetting the port if a problem crops up.
590 ccb = ahci_get_err_ccb(ap);
591 ccb->ccb_xa.flags = ATA_F_POLL | ATA_F_EXCLUSIVE | ATA_F_AUTOSENSE;
592 ccb->ccb_xa.complete = ahci_pm_dummy_done;
595 fis = ccb->ccb_cmd_table->cfis;
596 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
597 fis[0] = ATA_FIS_TYPE_H2D;
598 fis[1] = at->at_target;
599 fis[15] = ATA_FIS_CONTROL_SRST|ATA_FIS_CONTROL_4BIT;
601 cmd_slot = ccb->ccb_cmd_hdr;
603 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
604 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_C); /* Clear busy on OK */
605 cmd_slot->flags |= htole16(AHCI_CMD_LIST_FLAG_R); /* Reset */
606 cmd_slot->flags |= htole16(at->at_target <<
607 AHCI_CMD_LIST_FLAG_PMP_SHIFT);
609 ccb->ccb_xa.state = ATA_S_PENDING;
612 * This soft reset of the AP target can cause a stream of IFS
613 * errors to occur. Setting AP_F_IGNORE_IFS prevents the port
614 * from being hard reset (because its the target behind the
615 * port that isn't happy).
617 * The act of sending the soft reset can cause the target to
618 * blow the port up and generate IFS errors.
620 ap->ap_flags |= AP_F_IGNORE_IFS;
621 ap->ap_flags &= ~AP_F_IFS_IGNORED;
623 if (ahci_poll(ccb, 1000, ahci_ata_cmd_timeout) != ATA_S_COMPLETE) {
624 kprintf("%s: Soft-reset through PM failed, %s\n",
626 (count > 1 ? "retrying" : "giving up"));
627 ahci_put_err_ccb(ccb);
629 if (ap->ap_flags & AP_F_IFS_IGNORED)
633 ahci_pwrite(ap, AHCI_PREG_SERR, -1);
634 ahci_pwrite(ap, AHCI_PREG_IS, AHCI_PREG_IS_IFS);
641 * WARNING! SENSITIVE TIME PERIOD! WARNING!
643 * The first and second FISes are supposed to be back-to-back,
644 * I think the idea is to get the second sent and then after
645 * the device resets it will send a signature. Do not delay
646 * here and most definitely do not issue any commands to other
651 * Prep second D2H command to read status and complete reset sequence
652 * AHCI 10.4.1 and "Serial ATA Revision 2.6". I can't find the ATA
653 * Rev 2.6 and it is unclear how the second FIS should be set up
654 * from the AHCI document.
656 * Give the device 3ms before sending the second FIS.
658 * It is unclear which other fields in the FIS are used. Just zero
661 bzero(fis, sizeof(ccb->ccb_cmd_table->cfis));
662 fis[0] = ATA_FIS_TYPE_H2D;
663 fis[1] = at->at_target;
664 fis[15] = ATA_FIS_CONTROL_4BIT;
667 cmd_slot->flags = htole16(5); /* FIS length: 5 DWORDS */
668 cmd_slot->flags |= htole16(at->at_target <<
669 AHCI_CMD_LIST_FLAG_PMP_SHIFT);
671 ccb->ccb_xa.state = ATA_S_PENDING;
672 ccb->ccb_xa.flags = ATA_F_POLL | ATA_F_EXCLUSIVE | ATA_F_AUTOSENSE;
674 ap->ap_flags &= ~AP_F_IFS_IGNORED;
676 if (ahci_poll(ccb, 1000, ahci_ata_cmd_timeout) != ATA_S_COMPLETE) {
677 kprintf("%s: Soft-reset(2) through PM failed, %s\n",
679 (count > 1 ? "retrying" : "giving up"));
682 ahci_put_err_ccb(ccb);
683 ahci_pwrite(ap, AHCI_PREG_SERR, -1);
684 ahci_pwrite(ap, AHCI_PREG_IS, AHCI_PREG_IS_IFS);
690 ahci_put_err_ccb(ccb);
692 ahci_pwrite(ap, AHCI_PREG_SERR, -1);
693 ahci_pwrite(ap, AHCI_PREG_IS, AHCI_PREG_IS_IFS);
695 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
696 if (ahci_pm_phy_status(ap, target, &data)) {
697 kprintf("%s: (C)Cannot clear phy status\n",
700 ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
703 * Do it again, even if we think we got a good result
711 * If the softreset is trying to clear a BSY condition after a
712 * normal portreset we assign the port type.
714 * If the softreset is being run first as part of the ccb error
715 * processing code then report if the device signature changed
718 if (at->at_type == ATA_PORT_T_NONE) {
719 at->at_type = ahci_port_signature_detect(ap, at);
721 if (ahci_port_signature_detect(ap, at) != at->at_type) {
722 kprintf("%s: device signature unexpectedly "
723 "changed\n", ATANAME(ap, at));
724 error = EBUSY; /* XXX */
730 * Who knows what kind of mess occured. We have exclusive access
731 * to the port so try to clean up potential problems.
737 * Clear error status so we can detect removal.
739 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1)) {
740 kprintf("%s: ahci_pm_softreset unable to clear SERR\n",
743 ahci_pwrite(ap, AHCI_PREG_SERR, -1);
744 ahci_pwrite(ap, AHCI_PREG_IS, AHCI_PREG_IS_IFS);
745 ap->ap_flags &= ~(AP_F_IGNORE_IFS | AP_F_IFS_IGNORED);
747 at->at_probe = error ? ATA_PROBE_FAILED : ATA_PROBE_NEED_IDENT;
753 * Return the phy status for a target behind a port multiplier and
754 * reset SATA_PMREG_SERR.
756 * Returned bits follow AHCI_PREG_SSTS bits. The AHCI_PREG_SSTS_SPD
757 * bits can be used to determine the link speed and will be 0 if there
760 * 0 is returned if any communications error occurs.
763 ahci_pm_phy_status(struct ahci_port *ap, int target, u_int32_t *datap)
767 error = ahci_pm_read(ap, target, SATA_PMREG_SSTS, datap);
769 error = ahci_pm_write(ap, target, SATA_PMREG_SERR, -1);
776 * Check that a target is still good.
779 ahci_pm_check_good(struct ahci_port *ap, int target)
785 * It looks like we might have to read the EINFO register
786 * to allow the PM to generate a new event.
788 if (ahci_pm_read(ap, 15, SATA_PMREG_EINFO, &data)) {
789 kprintf("%s: Port multiplier EINFO could not be read\n",
793 if (ahci_pm_write(ap, target, SATA_PMREG_SERR, -1)) {
794 kprintf("%s: Port multiplier: SERR could not be cleared\n",
798 if (target == CAM_TARGET_WILDCARD || target >= ap->ap_pmcount)
800 at = ap->ap_ata[target];
803 * If the device needs an init or hard reset also make sure the
806 if (at->at_probe <= ATA_PROBE_NEED_HARD_RESET) {
807 /*kprintf("%s DOHARD\n", ATANAME(ap, at));*/
808 ahci_pm_hardreset(ap, target, 1);
812 * Read the detect status
814 if (ahci_pm_read(ap, target, SATA_PMREG_SSTS, &data)) {
815 kprintf("%s: Unable to access PM SSTS register target %d\n",
816 PORTNAME(ap), target);
819 if ((data & AHCI_PREG_SSTS_DET) != AHCI_PREG_SSTS_DET_DEV) {
820 /*kprintf("%s: DETECT %08x\n", ATANAME(ap, at), data);*/
821 if (at->at_probe != ATA_PROBE_FAILED) {
822 at->at_probe = ATA_PROBE_FAILED;
823 at->at_type = ATA_PORT_T_NONE;
824 at->at_features |= ATA_PORT_F_RESCAN;
825 kprintf("%s: HOTPLUG (PM) - Device removed\n",
829 if (at->at_probe == ATA_PROBE_FAILED) {
830 at->at_probe = ATA_PROBE_NEED_HARD_RESET;
831 at->at_features |= ATA_PORT_F_RESCAN;
832 kprintf("%s: HOTPLUG (PM) - Device inserted\n",
842 ahci_pm_read(struct ahci_port *ap, int target, int which, u_int32_t *datap)
847 xa = ahci_ata_get_xfer(ap, ap->ap_ata[15]);
849 xa->fis->type = ATA_FIS_TYPE_H2D;
850 xa->fis->flags = ATA_H2D_FLAGS_CMD | 15;
851 xa->fis->command = ATA_C_READ_PM;
852 xa->fis->features = which;
853 xa->fis->device = target | ATA_H2D_DEVICE_LBA;
854 xa->fis->control = ATA_FIS_CONTROL_4BIT;
856 xa->complete = ahci_pm_dummy_done;
858 xa->flags = ATA_F_POLL | ATA_F_AUTOSENSE;
861 if (ahci_ata_cmd(xa) == ATA_S_COMPLETE) {
862 *datap = xa->rfis.sector_count | (xa->rfis.lba_low << 8) |
863 (xa->rfis.lba_mid << 16) | (xa->rfis.lba_high << 24);
866 kprintf("%s.%d pm_read SCA[%d] failed\n",
867 PORTNAME(ap), target, which);
871 ahci_ata_put_xfer(xa);
876 * Write a PM register
879 ahci_pm_write(struct ahci_port *ap, int target, int which, u_int32_t data)
884 xa = ahci_ata_get_xfer(ap, ap->ap_ata[15]);
886 xa->fis->type = ATA_FIS_TYPE_H2D;
887 xa->fis->flags = ATA_H2D_FLAGS_CMD | 15;
888 xa->fis->command = ATA_C_WRITE_PM;
889 xa->fis->features = which;
890 xa->fis->device = target | ATA_H2D_DEVICE_LBA;
891 xa->fis->sector_count = (u_int8_t)data;
892 xa->fis->lba_low = (u_int8_t)(data >> 8);
893 xa->fis->lba_mid = (u_int8_t)(data >> 16);
894 xa->fis->lba_high = (u_int8_t)(data >> 24);
895 xa->fis->control = ATA_FIS_CONTROL_4BIT;
897 xa->complete = ahci_pm_dummy_done;
899 xa->flags = ATA_F_POLL;
902 if (ahci_ata_cmd(xa) == ATA_S_COMPLETE)
906 ahci_ata_put_xfer(xa);
911 * Dummy done callback for xa.
914 ahci_pm_dummy_done(struct ata_xfer *xa)