2018-06-22 00:52:15 +03:00
|
|
|
/* $NetBSD: sata_subr.c,v 1.24 2018/06/21 21:52:15 jdolecek Exp $ */
|
2004-05-29 03:26:27 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2004 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of Wasabi Systems, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common functions for Serial ATA.
|
|
|
|
*/
|
2007-12-11 14:38:15 +03:00
|
|
|
#include <sys/cdefs.h>
|
2018-06-22 00:52:15 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sata_subr.c,v 1.24 2018/06/21 21:52:15 jdolecek Exp $");
|
2004-05-29 03:26:27 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2006-11-21 02:42:21 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
2004-05-29 03:26:27 +04:00
|
|
|
|
|
|
|
#include <dev/ata/satareg.h>
|
|
|
|
#include <dev/ata/satavar.h>
|
2012-07-31 19:50:31 +04:00
|
|
|
#include <dev/ata/satapmpreg.h>
|
2004-05-29 03:26:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sata_speed:
|
|
|
|
*
|
|
|
|
* Return a string describing the port speed reported by
|
|
|
|
* the port's SStatus register.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
sata_speed(uint32_t sstatus)
|
|
|
|
{
|
2010-12-12 01:45:31 +03:00
|
|
|
static const char * const sata_speedtab[] = {
|
2004-05-29 03:26:27 +04:00
|
|
|
"no negotiated speed",
|
|
|
|
"1.5Gb/s",
|
2006-12-01 02:07:31 +03:00
|
|
|
"3.0Gb/s",
|
2008-11-18 12:52:10 +03:00
|
|
|
"6.0Gb/s",
|
2004-05-29 03:26:27 +04:00
|
|
|
"<unknown 4>",
|
|
|
|
"<unknown 5>",
|
|
|
|
"<unknown 6>",
|
|
|
|
"<unknown 7>",
|
|
|
|
"<unknown 8>",
|
|
|
|
"<unknown 9>",
|
|
|
|
"<unknown 10>",
|
|
|
|
"<unknown 11>",
|
|
|
|
"<unknown 12>",
|
|
|
|
"<unknown 13>",
|
|
|
|
"<unknown 14>",
|
|
|
|
"<unknown 15>",
|
|
|
|
};
|
|
|
|
|
|
|
|
return (sata_speedtab[(sstatus & SStatus_SPD_mask) >>
|
|
|
|
SStatus_SPD_shift]);
|
|
|
|
}
|
2006-11-21 02:42:21 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* reset the PHY and bring it online
|
|
|
|
*/
|
|
|
|
uint32_t
|
|
|
|
sata_reset_interface(struct ata_channel *chp, bus_space_tag_t sata_t,
|
2013-04-03 21:15:07 +04:00
|
|
|
bus_space_handle_t scontrol_r, bus_space_handle_t sstatus_r, int flags)
|
2006-11-21 02:42:21 +03:00
|
|
|
{
|
|
|
|
uint32_t scontrol, sstatus;
|
|
|
|
int i;
|
|
|
|
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
ata_channel_lock_owned(chp);
|
|
|
|
|
|
|
|
/* bring the PHYs online.
|
2010-12-12 03:38:07 +03:00
|
|
|
* The work-around for errata #1 of the Intel GD31244 says that we must
|
2006-11-21 02:42:21 +03:00
|
|
|
* write 0 to the port first to be sure of correctly initializing
|
|
|
|
* the device. It doesn't hurt for other devices.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(sata_t, scontrol_r, 0, 0);
|
|
|
|
scontrol = SControl_IPM_NONE | SControl_SPD_ANY | SControl_DET_INIT;
|
2017-05-10 11:46:39 +03:00
|
|
|
bus_space_write_4(sata_t, scontrol_r, 0, scontrol);
|
2006-11-21 02:42:21 +03:00
|
|
|
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
ata_delay(chp, 50, "sataup", flags);
|
2006-11-21 02:42:21 +03:00
|
|
|
scontrol &= ~SControl_DET_INIT;
|
|
|
|
bus_space_write_4(sata_t, scontrol_r, 0, scontrol);
|
|
|
|
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
ata_delay(chp, 50, "sataup", flags);
|
2006-11-21 02:42:21 +03:00
|
|
|
/* wait up to 1s for device to come up */
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
|
|
sstatus = bus_space_read_4(sata_t, sstatus_r, 0);
|
|
|
|
if ((sstatus & SStatus_DET_mask) == SStatus_DET_DEV)
|
|
|
|
break;
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
ata_delay(chp, 10, "sataup", flags);
|
2006-11-21 02:42:21 +03:00
|
|
|
}
|
2012-05-15 23:01:10 +04:00
|
|
|
/*
|
|
|
|
* if we have a link up without device, wait a few more seconds
|
|
|
|
* for connection to establish
|
|
|
|
*/
|
|
|
|
if ((sstatus & SStatus_DET_mask) == SStatus_DET_DEV_NE) {
|
|
|
|
for (i = 0; i < 500; i++) {
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
ata_delay(chp, 10, "sataup", flags);
|
2012-05-15 23:01:10 +04:00
|
|
|
sstatus = bus_space_read_4(sata_t, sstatus_r, 0);
|
|
|
|
if ((sstatus & SStatus_DET_mask) == SStatus_DET_DEV)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-21 02:42:21 +03:00
|
|
|
|
2018-06-22 00:52:15 +03:00
|
|
|
sata_interpret_det(chp, sstatus);
|
|
|
|
|
|
|
|
return (sstatus & SStatus_DET_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sata_interpret_det(struct ata_channel *chp, uint32_t sstatus)
|
|
|
|
{
|
2006-11-21 02:42:21 +03:00
|
|
|
switch (sstatus & SStatus_DET_mask) {
|
|
|
|
case SStatus_DET_NODEV:
|
|
|
|
/* No Device; be silent. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SStatus_DET_DEV_NE:
|
2006-11-22 20:51:02 +03:00
|
|
|
aprint_error("%s port %d: device connected, but "
|
2006-11-21 02:42:21 +03:00
|
|
|
"communication not established\n",
|
2008-03-18 23:46:35 +03:00
|
|
|
device_xname(chp->ch_atac->atac_dev), chp->ch_channel);
|
2006-11-21 02:42:21 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SStatus_DET_OFFLINE:
|
2018-06-22 00:52:15 +03:00
|
|
|
aprint_normal("%s port %d: PHY offline\n",
|
2008-03-18 23:46:35 +03:00
|
|
|
device_xname(chp->ch_atac->atac_dev), chp->ch_channel);
|
2006-11-21 02:42:21 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SStatus_DET_DEV:
|
2006-11-22 20:51:02 +03:00
|
|
|
aprint_normal("%s port %d: device present, speed: %s\n",
|
2008-03-18 23:46:35 +03:00
|
|
|
device_xname(chp->ch_atac->atac_dev), chp->ch_channel,
|
2006-11-21 02:42:21 +03:00
|
|
|
sata_speed(sstatus));
|
|
|
|
break;
|
|
|
|
default:
|
2006-11-22 20:51:02 +03:00
|
|
|
aprint_error("%s port %d: unknown SStatus: 0x%08x\n",
|
2008-03-18 23:46:35 +03:00
|
|
|
device_xname(chp->ch_atac->atac_dev), chp->ch_channel,
|
2006-11-21 02:42:21 +03:00
|
|
|
sstatus);
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 19:50:31 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
sata_interpret_sig(struct ata_channel *chp, int port, uint32_t sig)
|
|
|
|
{
|
|
|
|
int err;
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
|
|
|
|
ata_channel_lock_owned(chp);
|
2012-07-31 19:50:31 +04:00
|
|
|
|
|
|
|
/* some ATAPI devices have bogus lower two bytes, sigh */
|
|
|
|
if ((sig & 0xffff0000) == 0xeb140000) {
|
|
|
|
sig &= 0xffff0000;
|
|
|
|
sig |= 0x00000101;
|
|
|
|
}
|
|
|
|
if (chp->ch_drive == NULL) {
|
|
|
|
if (sig == 0x96690101)
|
|
|
|
err = atabus_alloc_drives(chp, PMP_MAX_DRIVES);
|
|
|
|
else
|
|
|
|
err = atabus_alloc_drives(chp, 1);
|
|
|
|
if (err)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
KASSERT(port < chp->ch_ndrives);
|
|
|
|
|
|
|
|
switch(sig) {
|
|
|
|
case 0x96690101:
|
|
|
|
KASSERT(port == 0 || port == PMP_PORT_CTL);
|
|
|
|
chp->ch_drive[PMP_PORT_CTL].drive_type = ATA_DRIVET_PM;
|
|
|
|
break;
|
|
|
|
case 0xc33c0101:
|
|
|
|
aprint_verbose_dev(chp->atabus, "port %d is SEMB, ignored\n",
|
|
|
|
port);
|
|
|
|
break;
|
|
|
|
case 0xeb140101:
|
|
|
|
chp->ch_drive[port].drive_type = ATA_DRIVET_ATAPI;
|
|
|
|
break;
|
|
|
|
case 0x00000101:
|
|
|
|
chp->ch_drive[port].drive_type = ATA_DRIVET_ATA;
|
|
|
|
break;
|
|
|
|
case 0xffffffff:
|
|
|
|
/* COMRESET time out */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
chp->ch_drive[port].drive_type = ATA_DRIVET_ATA;
|
|
|
|
aprint_verbose_dev(chp->atabus,
|
|
|
|
"Unrecognized signature 0x%08x on port %d. "
|
|
|
|
"Assuming it's a disk.\n", sig, port);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|