History log of /openbsd-current/sys/dev/ic/ahci.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.41 28-May-2024 jsg

Move ccb access before ccb_done to avoid a potential use-after-free
if pages can be freed from interrupt context. ok dlg@


# 1.40 23-Apr-2024 jsg

use 1U << 31 to avoid undefined behaviour
ok miod@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.39 03-Feb-2023 miod

Remove redundant DIAGNOSTIC wrappers around KASSERT macros.
From Crystal Kolipe.


Revision tags: OPENBSD_7_2_BASE
# 1.38 09-Apr-2022 naddy

atascsi: constify method tables

ok miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.37 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


Revision tags: OPENBSD_6_7_BASE
# 1.36 14-Mar-2020 krw

ahci_get_pmp_ccb() returns a non-NULL pointer, fails a
KASSERT(), or has already blown up by dereferencing the
pointer.

Two of the four invocations of ahci_get_pmp_ccb() check for
NULL. Save a couple of bytes by not bothering. Add comments
to the invocations to docuement the assumption.


# 1.35 14-Mar-2020 krw

Trailing whitespace, long lines, incorrect function names in
printf()'s.


Revision tags: OPENBSD_6_6_BASE
# 1.34 08-Jul-2019 mlarkin

Remove some "set but not used" variables in ahci(4)'s hibernate code.

ok jmatthew


# 1.33 25-Jun-2019 patrick

Turn off the code which waits for AHCI_PREG_CMD_CR to be set by the
HBA after ahci_default_port_start() sets AHCI_PREG_CMD_ST. The AHCI
spec. rev. 1.3 only requires the inverse to be true, i. e. that a
HBA clears AHCI_PREG_CMD_CR when AHCI_PREG_CMD_ST gets cleared by
software/driver. In fact, some HBAs will not raise AHCI_PREG_CMD_CR
as an immediate consequence of AHCI_PREG_CMD_ST being set. Actually
neither the FreeBSD, Linux nor NetBSD counterpart of ahci(4) has an
analogous check. Disabling that wait fixes "failed to start command
DMA on port N, disabling" bails during attach.

From Marius Strobl
ok deraadt@ jmatthew@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 21-Aug-2017 jmatthew

Split up ahci_port_portreset into a few smaller bits, and also slightly
adjust port multiplier detection so it doesn't call ahci_port_portreset
again directly, but instead restarts the loop for the current call.

During attach, poll for device detection across all ports until either all
ports have detected a device, or one second has passed, rather than doing
them sequentially. Devices are still attached in order of port number,
so disk unit numbers won't change.

ok visa@


# 1.31 13-Aug-2017 mlarkin

improve AHCI hibernate writeout performance by doing smaller delay()s
between each I/O.

ok kettenis@, jmatthew@


# 1.30 30-May-2017 jmatthew

Remove comments about implementing FIS-based switching with port multipliers,
which we can safely assume isn't going to happen now. No code changes.


Revision tags: OPENBSD_6_1_BASE
# 1.29 05-Mar-2017 jmatthew

When we're unable to determine which NCQ command failed, fail all active
commands rather than proceeding to an assertion failure. This matches
how we handle the same condition with non-queued commands, and the
behaviour of every other ahci driver I can find. Add a printf there so
we might get some idea of how often this condition arises and what happens
afterwards.

ok dlg@


# 1.28 02-Oct-2016 patrick

Some HABs reset parts of AHCI_PREG_CMD when AHCI_PREG_SCTL_DET_INIT
gets set. Therefore, ahci_port_softreset() restores the sate of the
former register once the device detection sequence is finished. The
device detection code in ahci_pmp_port_portreset() does not restore
AHCI_PREG_CMD afterwards, so let it catch up. Apparently, this part
was an oversight as ahci_pmp_port_portreset() did not otherwise use
"cmd".

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.27 02-Oct-2016 patrick

Some HBAs report NCQ capability despite only supporting one command
slot. Thus, extend the check whether NCQ actually should be enabled
accordingly.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.26 02-Oct-2016 patrick

Given that ahci_port_alloc() grabs one CCB for use during NCQ error
recovery from the CCB pool sized based on the NCS capability, i. e.
number of command slots reported by the controller, it is necessary
to pretend at least 2 slots in sc->sc_ncmds for devices without NCQ
support. That way, also at least 1 available slot is made available
for atascsi(4). Otherwise, controllers having only a single command
slot will trigger "no free xfers on a new port" in atascsi(4).
Note that pretending 2 command slots is also fine with the abuse of
the NCQ error recovery CCB in ahci_port_softreset().

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.25 02-Oct-2016 patrick

Contrary to e. g. the xHCI specification, the AHCI rev. 1.3 spec
does not say anything about which type (snoopable/uncached etc.) of
bus transactions are issued by HBAs on accesses to the descriptors.
Thus, the right assumption would be "classical" concurrent accesses
by both CPU/driver as well as hardware to the descriptors and their
DMA memory backings respectively, which is also confirmed by actual
testing. Consequently, switch to BUS_DMA_COHERENT mappings for said
DMA memory as otherwise corruption of descriptors is seen.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


Revision tags: OPENBSD_6_0_BASE
# 1.24 10-Mar-2016 krw

Enforce some naming sanity. Stop using 'sc_link' to mean two different
things by renaming the field 'SLIST_HEAD(, scsi_link) sc_link' to
'sc_link_list' in struct scsibus_softc. Use 'sb' as the short name
for scsibus_softc variables.

Impetus from & ok bluhm@


Revision tags: OPENBSD_5_9_BASE
# 1.23 04-Oct-2015 jmatthew

Fix memory leak in error path.
From Benjamin Baier, found by llvm/scan-build.


# 1.22 27-Aug-2015 deraadt

sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.21 21-Mar-2015 mpi

Print speeds consistently.

ok brynet@, miod@


# 1.20 12-Mar-2015 brynet

Print the current link speed for SATA devices attached on ahci(4).

The port numbers correspond to scsibus(4) targets:

ahci0: port 0, at 6Gbps
ahci0: port 2, at 3Gbps
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 ..
sd1 at scsibus1 targ 2 ..

ok deraadt@, tested by bmercer@


Revision tags: OPENBSD_5_7_BASE
# 1.19 11-Feb-2015 jmatthew

include extended capabilities in ahci debug output
ok dlg@


# 1.18 11-Feb-2015 jmatthew

recognise ahci 1.3.1
ok dlg@


# 1.17 03-Dec-2014 jsg

Turn ahci port start into a callback so sxiahci can do some magic to
setup dma. Modified version of a patch from Edwin Amsler which was
based on changes made in Bitrig by Artturi Alm.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.16 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 26-Jun-2014 jmatthew

Work around compatibility problems with Intel ahci and Intel SSDs by retrying
device detection if the port is still busy after our normal timeout.

based on a diff by chris@, based on a change in dragonflybsd
tested by Peter J Philipp
ok dlg@


# 1.13 14-Apr-2014 dlg

move the hardware structures into ahcireg.h.


# 1.12 31-Mar-2014 dlg

move the last htoleXX things to htolemXX where possible.

ok jmatthew@


# 1.11 31-Mar-2014 dlg

ahci dva things are 64bit and surprisingly aligned nicely to 64bit too.

ok jmatthew@


# 1.10 31-Mar-2014 dlg

replace bzero with memset


# 1.9 31-Mar-2014 dlg

massage the prdt (what an sgl is on every other chip) loading with
better ops and alignment.

ok jmatthew@ who was cruel and made me test hibernate before he oked it.


# 1.8 28-Mar-2014 mpi

Reduce uvm include madness. Use <uvm/uvm_extern.h> instead of
<uvm/uvm.h> if possible and remove double inclusions.

ok beck@, mlarkin@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.7 13-Feb-2014 pelikan

fix previous errorneous constants (compiled against the old header)


# 1.6 13-Feb-2014 pelikan

Recognize SATA-III ports in dmesg.

ok millert


# 1.5 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.4 06-Nov-2013 deraadt

teach the side-effect free drivers about the partition they are dealing
by passing a start/length in the HIB_INIT op. Then rebase all
hibernate-time block offsets to be relative to the start of that partition.
This simplifies things a lot.
ok mlarkin


Revision tags: OPENBSD_5_4_BASE
# 1.3 09-Jul-2013 deraadt

pay attention to the #ifdef


# 1.2 09-Jul-2013 jmatthew

move AHCI_DEBUG stuff into ahci.c so we can build with it enabled again

ok dlg@


Revision tags: OPENBSD_5_3_BASE
# 1.1 21-Jan-2013 patrick

Split AHCI in order to support devices which are not attached via pci.
Tested on a few machines, including JMicron and Intel AHCIs.

ok dlg@ jmatthew@


# 1.40 23-Apr-2024 jsg

use 1U << 31 to avoid undefined behaviour
ok miod@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.39 03-Feb-2023 miod

Remove redundant DIAGNOSTIC wrappers around KASSERT macros.
From Crystal Kolipe.


Revision tags: OPENBSD_7_2_BASE
# 1.38 09-Apr-2022 naddy

atascsi: constify method tables

ok miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.37 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


Revision tags: OPENBSD_6_7_BASE
# 1.36 14-Mar-2020 krw

ahci_get_pmp_ccb() returns a non-NULL pointer, fails a
KASSERT(), or has already blown up by dereferencing the
pointer.

Two of the four invocations of ahci_get_pmp_ccb() check for
NULL. Save a couple of bytes by not bothering. Add comments
to the invocations to docuement the assumption.


# 1.35 14-Mar-2020 krw

Trailing whitespace, long lines, incorrect function names in
printf()'s.


Revision tags: OPENBSD_6_6_BASE
# 1.34 08-Jul-2019 mlarkin

Remove some "set but not used" variables in ahci(4)'s hibernate code.

ok jmatthew


# 1.33 25-Jun-2019 patrick

Turn off the code which waits for AHCI_PREG_CMD_CR to be set by the
HBA after ahci_default_port_start() sets AHCI_PREG_CMD_ST. The AHCI
spec. rev. 1.3 only requires the inverse to be true, i. e. that a
HBA clears AHCI_PREG_CMD_CR when AHCI_PREG_CMD_ST gets cleared by
software/driver. In fact, some HBAs will not raise AHCI_PREG_CMD_CR
as an immediate consequence of AHCI_PREG_CMD_ST being set. Actually
neither the FreeBSD, Linux nor NetBSD counterpart of ahci(4) has an
analogous check. Disabling that wait fixes "failed to start command
DMA on port N, disabling" bails during attach.

From Marius Strobl
ok deraadt@ jmatthew@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 21-Aug-2017 jmatthew

Split up ahci_port_portreset into a few smaller bits, and also slightly
adjust port multiplier detection so it doesn't call ahci_port_portreset
again directly, but instead restarts the loop for the current call.

During attach, poll for device detection across all ports until either all
ports have detected a device, or one second has passed, rather than doing
them sequentially. Devices are still attached in order of port number,
so disk unit numbers won't change.

ok visa@


# 1.31 13-Aug-2017 mlarkin

improve AHCI hibernate writeout performance by doing smaller delay()s
between each I/O.

ok kettenis@, jmatthew@


# 1.30 30-May-2017 jmatthew

Remove comments about implementing FIS-based switching with port multipliers,
which we can safely assume isn't going to happen now. No code changes.


Revision tags: OPENBSD_6_1_BASE
# 1.29 05-Mar-2017 jmatthew

When we're unable to determine which NCQ command failed, fail all active
commands rather than proceeding to an assertion failure. This matches
how we handle the same condition with non-queued commands, and the
behaviour of every other ahci driver I can find. Add a printf there so
we might get some idea of how often this condition arises and what happens
afterwards.

ok dlg@


# 1.28 02-Oct-2016 patrick

Some HABs reset parts of AHCI_PREG_CMD when AHCI_PREG_SCTL_DET_INIT
gets set. Therefore, ahci_port_softreset() restores the sate of the
former register once the device detection sequence is finished. The
device detection code in ahci_pmp_port_portreset() does not restore
AHCI_PREG_CMD afterwards, so let it catch up. Apparently, this part
was an oversight as ahci_pmp_port_portreset() did not otherwise use
"cmd".

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.27 02-Oct-2016 patrick

Some HBAs report NCQ capability despite only supporting one command
slot. Thus, extend the check whether NCQ actually should be enabled
accordingly.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.26 02-Oct-2016 patrick

Given that ahci_port_alloc() grabs one CCB for use during NCQ error
recovery from the CCB pool sized based on the NCS capability, i. e.
number of command slots reported by the controller, it is necessary
to pretend at least 2 slots in sc->sc_ncmds for devices without NCQ
support. That way, also at least 1 available slot is made available
for atascsi(4). Otherwise, controllers having only a single command
slot will trigger "no free xfers on a new port" in atascsi(4).
Note that pretending 2 command slots is also fine with the abuse of
the NCQ error recovery CCB in ahci_port_softreset().

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.25 02-Oct-2016 patrick

Contrary to e. g. the xHCI specification, the AHCI rev. 1.3 spec
does not say anything about which type (snoopable/uncached etc.) of
bus transactions are issued by HBAs on accesses to the descriptors.
Thus, the right assumption would be "classical" concurrent accesses
by both CPU/driver as well as hardware to the descriptors and their
DMA memory backings respectively, which is also confirmed by actual
testing. Consequently, switch to BUS_DMA_COHERENT mappings for said
DMA memory as otherwise corruption of descriptors is seen.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


Revision tags: OPENBSD_6_0_BASE
# 1.24 10-Mar-2016 krw

Enforce some naming sanity. Stop using 'sc_link' to mean two different
things by renaming the field 'SLIST_HEAD(, scsi_link) sc_link' to
'sc_link_list' in struct scsibus_softc. Use 'sb' as the short name
for scsibus_softc variables.

Impetus from & ok bluhm@


Revision tags: OPENBSD_5_9_BASE
# 1.23 04-Oct-2015 jmatthew

Fix memory leak in error path.
From Benjamin Baier, found by llvm/scan-build.


# 1.22 27-Aug-2015 deraadt

sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.21 21-Mar-2015 mpi

Print speeds consistently.

ok brynet@, miod@


# 1.20 12-Mar-2015 brynet

Print the current link speed for SATA devices attached on ahci(4).

The port numbers correspond to scsibus(4) targets:

ahci0: port 0, at 6Gbps
ahci0: port 2, at 3Gbps
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 ..
sd1 at scsibus1 targ 2 ..

ok deraadt@, tested by bmercer@


Revision tags: OPENBSD_5_7_BASE
# 1.19 11-Feb-2015 jmatthew

include extended capabilities in ahci debug output
ok dlg@


# 1.18 11-Feb-2015 jmatthew

recognise ahci 1.3.1
ok dlg@


# 1.17 03-Dec-2014 jsg

Turn ahci port start into a callback so sxiahci can do some magic to
setup dma. Modified version of a patch from Edwin Amsler which was
based on changes made in Bitrig by Artturi Alm.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.16 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 26-Jun-2014 jmatthew

Work around compatibility problems with Intel ahci and Intel SSDs by retrying
device detection if the port is still busy after our normal timeout.

based on a diff by chris@, based on a change in dragonflybsd
tested by Peter J Philipp
ok dlg@


# 1.13 14-Apr-2014 dlg

move the hardware structures into ahcireg.h.


# 1.12 31-Mar-2014 dlg

move the last htoleXX things to htolemXX where possible.

ok jmatthew@


# 1.11 31-Mar-2014 dlg

ahci dva things are 64bit and surprisingly aligned nicely to 64bit too.

ok jmatthew@


# 1.10 31-Mar-2014 dlg

replace bzero with memset


# 1.9 31-Mar-2014 dlg

massage the prdt (what an sgl is on every other chip) loading with
better ops and alignment.

ok jmatthew@ who was cruel and made me test hibernate before he oked it.


# 1.8 28-Mar-2014 mpi

Reduce uvm include madness. Use <uvm/uvm_extern.h> instead of
<uvm/uvm.h> if possible and remove double inclusions.

ok beck@, mlarkin@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.7 13-Feb-2014 pelikan

fix previous errorneous constants (compiled against the old header)


# 1.6 13-Feb-2014 pelikan

Recognize SATA-III ports in dmesg.

ok millert


# 1.5 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.4 06-Nov-2013 deraadt

teach the side-effect free drivers about the partition they are dealing
by passing a start/length in the HIB_INIT op. Then rebase all
hibernate-time block offsets to be relative to the start of that partition.
This simplifies things a lot.
ok mlarkin


Revision tags: OPENBSD_5_4_BASE
# 1.3 09-Jul-2013 deraadt

pay attention to the #ifdef


# 1.2 09-Jul-2013 jmatthew

move AHCI_DEBUG stuff into ahci.c so we can build with it enabled again

ok dlg@


Revision tags: OPENBSD_5_3_BASE
# 1.1 21-Jan-2013 patrick

Split AHCI in order to support devices which are not attached via pci.
Tested on a few machines, including JMicron and Intel AHCIs.

ok dlg@ jmatthew@


# 1.39 03-Feb-2023 miod

Remove redundant DIAGNOSTIC wrappers around KASSERT macros.
From Crystal Kolipe.


Revision tags: OPENBSD_7_2_BASE
# 1.38 09-Apr-2022 naddy

atascsi: constify method tables

ok miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.37 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


Revision tags: OPENBSD_6_7_BASE
# 1.36 14-Mar-2020 krw

ahci_get_pmp_ccb() returns a non-NULL pointer, fails a
KASSERT(), or has already blown up by dereferencing the
pointer.

Two of the four invocations of ahci_get_pmp_ccb() check for
NULL. Save a couple of bytes by not bothering. Add comments
to the invocations to docuement the assumption.


# 1.35 14-Mar-2020 krw

Trailing whitespace, long lines, incorrect function names in
printf()'s.


Revision tags: OPENBSD_6_6_BASE
# 1.34 08-Jul-2019 mlarkin

Remove some "set but not used" variables in ahci(4)'s hibernate code.

ok jmatthew


# 1.33 25-Jun-2019 patrick

Turn off the code which waits for AHCI_PREG_CMD_CR to be set by the
HBA after ahci_default_port_start() sets AHCI_PREG_CMD_ST. The AHCI
spec. rev. 1.3 only requires the inverse to be true, i. e. that a
HBA clears AHCI_PREG_CMD_CR when AHCI_PREG_CMD_ST gets cleared by
software/driver. In fact, some HBAs will not raise AHCI_PREG_CMD_CR
as an immediate consequence of AHCI_PREG_CMD_ST being set. Actually
neither the FreeBSD, Linux nor NetBSD counterpart of ahci(4) has an
analogous check. Disabling that wait fixes "failed to start command
DMA on port N, disabling" bails during attach.

From Marius Strobl
ok deraadt@ jmatthew@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 21-Aug-2017 jmatthew

Split up ahci_port_portreset into a few smaller bits, and also slightly
adjust port multiplier detection so it doesn't call ahci_port_portreset
again directly, but instead restarts the loop for the current call.

During attach, poll for device detection across all ports until either all
ports have detected a device, or one second has passed, rather than doing
them sequentially. Devices are still attached in order of port number,
so disk unit numbers won't change.

ok visa@


# 1.31 13-Aug-2017 mlarkin

improve AHCI hibernate writeout performance by doing smaller delay()s
between each I/O.

ok kettenis@, jmatthew@


# 1.30 30-May-2017 jmatthew

Remove comments about implementing FIS-based switching with port multipliers,
which we can safely assume isn't going to happen now. No code changes.


Revision tags: OPENBSD_6_1_BASE
# 1.29 05-Mar-2017 jmatthew

When we're unable to determine which NCQ command failed, fail all active
commands rather than proceeding to an assertion failure. This matches
how we handle the same condition with non-queued commands, and the
behaviour of every other ahci driver I can find. Add a printf there so
we might get some idea of how often this condition arises and what happens
afterwards.

ok dlg@


# 1.28 02-Oct-2016 patrick

Some HABs reset parts of AHCI_PREG_CMD when AHCI_PREG_SCTL_DET_INIT
gets set. Therefore, ahci_port_softreset() restores the sate of the
former register once the device detection sequence is finished. The
device detection code in ahci_pmp_port_portreset() does not restore
AHCI_PREG_CMD afterwards, so let it catch up. Apparently, this part
was an oversight as ahci_pmp_port_portreset() did not otherwise use
"cmd".

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.27 02-Oct-2016 patrick

Some HBAs report NCQ capability despite only supporting one command
slot. Thus, extend the check whether NCQ actually should be enabled
accordingly.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.26 02-Oct-2016 patrick

Given that ahci_port_alloc() grabs one CCB for use during NCQ error
recovery from the CCB pool sized based on the NCS capability, i. e.
number of command slots reported by the controller, it is necessary
to pretend at least 2 slots in sc->sc_ncmds for devices without NCQ
support. That way, also at least 1 available slot is made available
for atascsi(4). Otherwise, controllers having only a single command
slot will trigger "no free xfers on a new port" in atascsi(4).
Note that pretending 2 command slots is also fine with the abuse of
the NCQ error recovery CCB in ahci_port_softreset().

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.25 02-Oct-2016 patrick

Contrary to e. g. the xHCI specification, the AHCI rev. 1.3 spec
does not say anything about which type (snoopable/uncached etc.) of
bus transactions are issued by HBAs on accesses to the descriptors.
Thus, the right assumption would be "classical" concurrent accesses
by both CPU/driver as well as hardware to the descriptors and their
DMA memory backings respectively, which is also confirmed by actual
testing. Consequently, switch to BUS_DMA_COHERENT mappings for said
DMA memory as otherwise corruption of descriptors is seen.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


Revision tags: OPENBSD_6_0_BASE
# 1.24 10-Mar-2016 krw

Enforce some naming sanity. Stop using 'sc_link' to mean two different
things by renaming the field 'SLIST_HEAD(, scsi_link) sc_link' to
'sc_link_list' in struct scsibus_softc. Use 'sb' as the short name
for scsibus_softc variables.

Impetus from & ok bluhm@


Revision tags: OPENBSD_5_9_BASE
# 1.23 04-Oct-2015 jmatthew

Fix memory leak in error path.
From Benjamin Baier, found by llvm/scan-build.


# 1.22 27-Aug-2015 deraadt

sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.21 21-Mar-2015 mpi

Print speeds consistently.

ok brynet@, miod@


# 1.20 12-Mar-2015 brynet

Print the current link speed for SATA devices attached on ahci(4).

The port numbers correspond to scsibus(4) targets:

ahci0: port 0, at 6Gbps
ahci0: port 2, at 3Gbps
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 ..
sd1 at scsibus1 targ 2 ..

ok deraadt@, tested by bmercer@


Revision tags: OPENBSD_5_7_BASE
# 1.19 11-Feb-2015 jmatthew

include extended capabilities in ahci debug output
ok dlg@


# 1.18 11-Feb-2015 jmatthew

recognise ahci 1.3.1
ok dlg@


# 1.17 03-Dec-2014 jsg

Turn ahci port start into a callback so sxiahci can do some magic to
setup dma. Modified version of a patch from Edwin Amsler which was
based on changes made in Bitrig by Artturi Alm.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.16 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 26-Jun-2014 jmatthew

Work around compatibility problems with Intel ahci and Intel SSDs by retrying
device detection if the port is still busy after our normal timeout.

based on a diff by chris@, based on a change in dragonflybsd
tested by Peter J Philipp
ok dlg@


# 1.13 14-Apr-2014 dlg

move the hardware structures into ahcireg.h.


# 1.12 31-Mar-2014 dlg

move the last htoleXX things to htolemXX where possible.

ok jmatthew@


# 1.11 31-Mar-2014 dlg

ahci dva things are 64bit and surprisingly aligned nicely to 64bit too.

ok jmatthew@


# 1.10 31-Mar-2014 dlg

replace bzero with memset


# 1.9 31-Mar-2014 dlg

massage the prdt (what an sgl is on every other chip) loading with
better ops and alignment.

ok jmatthew@ who was cruel and made me test hibernate before he oked it.


# 1.8 28-Mar-2014 mpi

Reduce uvm include madness. Use <uvm/uvm_extern.h> instead of
<uvm/uvm.h> if possible and remove double inclusions.

ok beck@, mlarkin@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.7 13-Feb-2014 pelikan

fix previous errorneous constants (compiled against the old header)


# 1.6 13-Feb-2014 pelikan

Recognize SATA-III ports in dmesg.

ok millert


# 1.5 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.4 06-Nov-2013 deraadt

teach the side-effect free drivers about the partition they are dealing
by passing a start/length in the HIB_INIT op. Then rebase all
hibernate-time block offsets to be relative to the start of that partition.
This simplifies things a lot.
ok mlarkin


Revision tags: OPENBSD_5_4_BASE
# 1.3 09-Jul-2013 deraadt

pay attention to the #ifdef


# 1.2 09-Jul-2013 jmatthew

move AHCI_DEBUG stuff into ahci.c so we can build with it enabled again

ok dlg@


Revision tags: OPENBSD_5_3_BASE
# 1.1 21-Jan-2013 patrick

Split AHCI in order to support devices which are not attached via pci.
Tested on a few machines, including JMicron and Intel AHCIs.

ok dlg@ jmatthew@


# 1.38 09-Apr-2022 naddy

atascsi: constify method tables

ok miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.37 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


Revision tags: OPENBSD_6_7_BASE
# 1.36 14-Mar-2020 krw

ahci_get_pmp_ccb() returns a non-NULL pointer, fails a
KASSERT(), or has already blown up by dereferencing the
pointer.

Two of the four invocations of ahci_get_pmp_ccb() check for
NULL. Save a couple of bytes by not bothering. Add comments
to the invocations to docuement the assumption.


# 1.35 14-Mar-2020 krw

Trailing whitespace, long lines, incorrect function names in
printf()'s.


Revision tags: OPENBSD_6_6_BASE
# 1.34 08-Jul-2019 mlarkin

Remove some "set but not used" variables in ahci(4)'s hibernate code.

ok jmatthew


# 1.33 25-Jun-2019 patrick

Turn off the code which waits for AHCI_PREG_CMD_CR to be set by the
HBA after ahci_default_port_start() sets AHCI_PREG_CMD_ST. The AHCI
spec. rev. 1.3 only requires the inverse to be true, i. e. that a
HBA clears AHCI_PREG_CMD_CR when AHCI_PREG_CMD_ST gets cleared by
software/driver. In fact, some HBAs will not raise AHCI_PREG_CMD_CR
as an immediate consequence of AHCI_PREG_CMD_ST being set. Actually
neither the FreeBSD, Linux nor NetBSD counterpart of ahci(4) has an
analogous check. Disabling that wait fixes "failed to start command
DMA on port N, disabling" bails during attach.

From Marius Strobl
ok deraadt@ jmatthew@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 21-Aug-2017 jmatthew

Split up ahci_port_portreset into a few smaller bits, and also slightly
adjust port multiplier detection so it doesn't call ahci_port_portreset
again directly, but instead restarts the loop for the current call.

During attach, poll for device detection across all ports until either all
ports have detected a device, or one second has passed, rather than doing
them sequentially. Devices are still attached in order of port number,
so disk unit numbers won't change.

ok visa@


# 1.31 13-Aug-2017 mlarkin

improve AHCI hibernate writeout performance by doing smaller delay()s
between each I/O.

ok kettenis@, jmatthew@


# 1.30 30-May-2017 jmatthew

Remove comments about implementing FIS-based switching with port multipliers,
which we can safely assume isn't going to happen now. No code changes.


Revision tags: OPENBSD_6_1_BASE
# 1.29 05-Mar-2017 jmatthew

When we're unable to determine which NCQ command failed, fail all active
commands rather than proceeding to an assertion failure. This matches
how we handle the same condition with non-queued commands, and the
behaviour of every other ahci driver I can find. Add a printf there so
we might get some idea of how often this condition arises and what happens
afterwards.

ok dlg@


# 1.28 02-Oct-2016 patrick

Some HABs reset parts of AHCI_PREG_CMD when AHCI_PREG_SCTL_DET_INIT
gets set. Therefore, ahci_port_softreset() restores the sate of the
former register once the device detection sequence is finished. The
device detection code in ahci_pmp_port_portreset() does not restore
AHCI_PREG_CMD afterwards, so let it catch up. Apparently, this part
was an oversight as ahci_pmp_port_portreset() did not otherwise use
"cmd".

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.27 02-Oct-2016 patrick

Some HBAs report NCQ capability despite only supporting one command
slot. Thus, extend the check whether NCQ actually should be enabled
accordingly.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.26 02-Oct-2016 patrick

Given that ahci_port_alloc() grabs one CCB for use during NCQ error
recovery from the CCB pool sized based on the NCS capability, i. e.
number of command slots reported by the controller, it is necessary
to pretend at least 2 slots in sc->sc_ncmds for devices without NCQ
support. That way, also at least 1 available slot is made available
for atascsi(4). Otherwise, controllers having only a single command
slot will trigger "no free xfers on a new port" in atascsi(4).
Note that pretending 2 command slots is also fine with the abuse of
the NCQ error recovery CCB in ahci_port_softreset().

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.25 02-Oct-2016 patrick

Contrary to e. g. the xHCI specification, the AHCI rev. 1.3 spec
does not say anything about which type (snoopable/uncached etc.) of
bus transactions are issued by HBAs on accesses to the descriptors.
Thus, the right assumption would be "classical" concurrent accesses
by both CPU/driver as well as hardware to the descriptors and their
DMA memory backings respectively, which is also confirmed by actual
testing. Consequently, switch to BUS_DMA_COHERENT mappings for said
DMA memory as otherwise corruption of descriptors is seen.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


Revision tags: OPENBSD_6_0_BASE
# 1.24 10-Mar-2016 krw

Enforce some naming sanity. Stop using 'sc_link' to mean two different
things by renaming the field 'SLIST_HEAD(, scsi_link) sc_link' to
'sc_link_list' in struct scsibus_softc. Use 'sb' as the short name
for scsibus_softc variables.

Impetus from & ok bluhm@


Revision tags: OPENBSD_5_9_BASE
# 1.23 04-Oct-2015 jmatthew

Fix memory leak in error path.
From Benjamin Baier, found by llvm/scan-build.


# 1.22 27-Aug-2015 deraadt

sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.21 21-Mar-2015 mpi

Print speeds consistently.

ok brynet@, miod@


# 1.20 12-Mar-2015 brynet

Print the current link speed for SATA devices attached on ahci(4).

The port numbers correspond to scsibus(4) targets:

ahci0: port 0, at 6Gbps
ahci0: port 2, at 3Gbps
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 ..
sd1 at scsibus1 targ 2 ..

ok deraadt@, tested by bmercer@


Revision tags: OPENBSD_5_7_BASE
# 1.19 11-Feb-2015 jmatthew

include extended capabilities in ahci debug output
ok dlg@


# 1.18 11-Feb-2015 jmatthew

recognise ahci 1.3.1
ok dlg@


# 1.17 03-Dec-2014 jsg

Turn ahci port start into a callback so sxiahci can do some magic to
setup dma. Modified version of a patch from Edwin Amsler which was
based on changes made in Bitrig by Artturi Alm.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.16 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 26-Jun-2014 jmatthew

Work around compatibility problems with Intel ahci and Intel SSDs by retrying
device detection if the port is still busy after our normal timeout.

based on a diff by chris@, based on a change in dragonflybsd
tested by Peter J Philipp
ok dlg@


# 1.13 14-Apr-2014 dlg

move the hardware structures into ahcireg.h.


# 1.12 31-Mar-2014 dlg

move the last htoleXX things to htolemXX where possible.

ok jmatthew@


# 1.11 31-Mar-2014 dlg

ahci dva things are 64bit and surprisingly aligned nicely to 64bit too.

ok jmatthew@


# 1.10 31-Mar-2014 dlg

replace bzero with memset


# 1.9 31-Mar-2014 dlg

massage the prdt (what an sgl is on every other chip) loading with
better ops and alignment.

ok jmatthew@ who was cruel and made me test hibernate before he oked it.


# 1.8 28-Mar-2014 mpi

Reduce uvm include madness. Use <uvm/uvm_extern.h> instead of
<uvm/uvm.h> if possible and remove double inclusions.

ok beck@, mlarkin@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.7 13-Feb-2014 pelikan

fix previous errorneous constants (compiled against the old header)


# 1.6 13-Feb-2014 pelikan

Recognize SATA-III ports in dmesg.

ok millert


# 1.5 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.4 06-Nov-2013 deraadt

teach the side-effect free drivers about the partition they are dealing
by passing a start/length in the HIB_INIT op. Then rebase all
hibernate-time block offsets to be relative to the start of that partition.
This simplifies things a lot.
ok mlarkin


Revision tags: OPENBSD_5_4_BASE
# 1.3 09-Jul-2013 deraadt

pay attention to the #ifdef


# 1.2 09-Jul-2013 jmatthew

move AHCI_DEBUG stuff into ahci.c so we can build with it enabled again

ok dlg@


Revision tags: OPENBSD_5_3_BASE
# 1.1 21-Jan-2013 patrick

Split AHCI in order to support devices which are not attached via pci.
Tested on a few machines, including JMicron and Intel AHCIs.

ok dlg@ jmatthew@


# 1.37 16-Jul-2020 krw

Access adapter softc via link->bus->sb_adapter_softc.

In sparc64 autoconf access 'luns' via sb_luns and 'adapter_buswidth'
via sb_adapter_buswidth.

Removes last post-config uses of the copies of bus related
information in scsi_link.


Revision tags: OPENBSD_6_7_BASE
# 1.36 14-Mar-2020 krw

ahci_get_pmp_ccb() returns a non-NULL pointer, fails a
KASSERT(), or has already blown up by dereferencing the
pointer.

Two of the four invocations of ahci_get_pmp_ccb() check for
NULL. Save a couple of bytes by not bothering. Add comments
to the invocations to docuement the assumption.


# 1.35 14-Mar-2020 krw

Trailing whitespace, long lines, incorrect function names in
printf()'s.


Revision tags: OPENBSD_6_6_BASE
# 1.34 08-Jul-2019 mlarkin

Remove some "set but not used" variables in ahci(4)'s hibernate code.

ok jmatthew


# 1.33 25-Jun-2019 patrick

Turn off the code which waits for AHCI_PREG_CMD_CR to be set by the
HBA after ahci_default_port_start() sets AHCI_PREG_CMD_ST. The AHCI
spec. rev. 1.3 only requires the inverse to be true, i. e. that a
HBA clears AHCI_PREG_CMD_CR when AHCI_PREG_CMD_ST gets cleared by
software/driver. In fact, some HBAs will not raise AHCI_PREG_CMD_CR
as an immediate consequence of AHCI_PREG_CMD_ST being set. Actually
neither the FreeBSD, Linux nor NetBSD counterpart of ahci(4) has an
analogous check. Disabling that wait fixes "failed to start command
DMA on port N, disabling" bails during attach.

From Marius Strobl
ok deraadt@ jmatthew@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 21-Aug-2017 jmatthew

Split up ahci_port_portreset into a few smaller bits, and also slightly
adjust port multiplier detection so it doesn't call ahci_port_portreset
again directly, but instead restarts the loop for the current call.

During attach, poll for device detection across all ports until either all
ports have detected a device, or one second has passed, rather than doing
them sequentially. Devices are still attached in order of port number,
so disk unit numbers won't change.

ok visa@


# 1.31 13-Aug-2017 mlarkin

improve AHCI hibernate writeout performance by doing smaller delay()s
between each I/O.

ok kettenis@, jmatthew@


# 1.30 30-May-2017 jmatthew

Remove comments about implementing FIS-based switching with port multipliers,
which we can safely assume isn't going to happen now. No code changes.


Revision tags: OPENBSD_6_1_BASE
# 1.29 05-Mar-2017 jmatthew

When we're unable to determine which NCQ command failed, fail all active
commands rather than proceeding to an assertion failure. This matches
how we handle the same condition with non-queued commands, and the
behaviour of every other ahci driver I can find. Add a printf there so
we might get some idea of how often this condition arises and what happens
afterwards.

ok dlg@


# 1.28 02-Oct-2016 patrick

Some HABs reset parts of AHCI_PREG_CMD when AHCI_PREG_SCTL_DET_INIT
gets set. Therefore, ahci_port_softreset() restores the sate of the
former register once the device detection sequence is finished. The
device detection code in ahci_pmp_port_portreset() does not restore
AHCI_PREG_CMD afterwards, so let it catch up. Apparently, this part
was an oversight as ahci_pmp_port_portreset() did not otherwise use
"cmd".

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.27 02-Oct-2016 patrick

Some HBAs report NCQ capability despite only supporting one command
slot. Thus, extend the check whether NCQ actually should be enabled
accordingly.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.26 02-Oct-2016 patrick

Given that ahci_port_alloc() grabs one CCB for use during NCQ error
recovery from the CCB pool sized based on the NCS capability, i. e.
number of command slots reported by the controller, it is necessary
to pretend at least 2 slots in sc->sc_ncmds for devices without NCQ
support. That way, also at least 1 available slot is made available
for atascsi(4). Otherwise, controllers having only a single command
slot will trigger "no free xfers on a new port" in atascsi(4).
Note that pretending 2 command slots is also fine with the abuse of
the NCQ error recovery CCB in ahci_port_softreset().

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.25 02-Oct-2016 patrick

Contrary to e. g. the xHCI specification, the AHCI rev. 1.3 spec
does not say anything about which type (snoopable/uncached etc.) of
bus transactions are issued by HBAs on accesses to the descriptors.
Thus, the right assumption would be "classical" concurrent accesses
by both CPU/driver as well as hardware to the descriptors and their
DMA memory backings respectively, which is also confirmed by actual
testing. Consequently, switch to BUS_DMA_COHERENT mappings for said
DMA memory as otherwise corruption of descriptors is seen.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


Revision tags: OPENBSD_6_0_BASE
# 1.24 10-Mar-2016 krw

Enforce some naming sanity. Stop using 'sc_link' to mean two different
things by renaming the field 'SLIST_HEAD(, scsi_link) sc_link' to
'sc_link_list' in struct scsibus_softc. Use 'sb' as the short name
for scsibus_softc variables.

Impetus from & ok bluhm@


Revision tags: OPENBSD_5_9_BASE
# 1.23 04-Oct-2015 jmatthew

Fix memory leak in error path.
From Benjamin Baier, found by llvm/scan-build.


# 1.22 27-Aug-2015 deraadt

sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.21 21-Mar-2015 mpi

Print speeds consistently.

ok brynet@, miod@


# 1.20 12-Mar-2015 brynet

Print the current link speed for SATA devices attached on ahci(4).

The port numbers correspond to scsibus(4) targets:

ahci0: port 0, at 6Gbps
ahci0: port 2, at 3Gbps
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 ..
sd1 at scsibus1 targ 2 ..

ok deraadt@, tested by bmercer@


Revision tags: OPENBSD_5_7_BASE
# 1.19 11-Feb-2015 jmatthew

include extended capabilities in ahci debug output
ok dlg@


# 1.18 11-Feb-2015 jmatthew

recognise ahci 1.3.1
ok dlg@


# 1.17 03-Dec-2014 jsg

Turn ahci port start into a callback so sxiahci can do some magic to
setup dma. Modified version of a patch from Edwin Amsler which was
based on changes made in Bitrig by Artturi Alm.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.16 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 26-Jun-2014 jmatthew

Work around compatibility problems with Intel ahci and Intel SSDs by retrying
device detection if the port is still busy after our normal timeout.

based on a diff by chris@, based on a change in dragonflybsd
tested by Peter J Philipp
ok dlg@


# 1.13 14-Apr-2014 dlg

move the hardware structures into ahcireg.h.


# 1.12 31-Mar-2014 dlg

move the last htoleXX things to htolemXX where possible.

ok jmatthew@


# 1.11 31-Mar-2014 dlg

ahci dva things are 64bit and surprisingly aligned nicely to 64bit too.

ok jmatthew@


# 1.10 31-Mar-2014 dlg

replace bzero with memset


# 1.9 31-Mar-2014 dlg

massage the prdt (what an sgl is on every other chip) loading with
better ops and alignment.

ok jmatthew@ who was cruel and made me test hibernate before he oked it.


# 1.8 28-Mar-2014 mpi

Reduce uvm include madness. Use <uvm/uvm_extern.h> instead of
<uvm/uvm.h> if possible and remove double inclusions.

ok beck@, mlarkin@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.7 13-Feb-2014 pelikan

fix previous errorneous constants (compiled against the old header)


# 1.6 13-Feb-2014 pelikan

Recognize SATA-III ports in dmesg.

ok millert


# 1.5 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.4 06-Nov-2013 deraadt

teach the side-effect free drivers about the partition they are dealing
by passing a start/length in the HIB_INIT op. Then rebase all
hibernate-time block offsets to be relative to the start of that partition.
This simplifies things a lot.
ok mlarkin


Revision tags: OPENBSD_5_4_BASE
# 1.3 09-Jul-2013 deraadt

pay attention to the #ifdef


# 1.2 09-Jul-2013 jmatthew

move AHCI_DEBUG stuff into ahci.c so we can build with it enabled again

ok dlg@


Revision tags: OPENBSD_5_3_BASE
# 1.1 21-Jan-2013 patrick

Split AHCI in order to support devices which are not attached via pci.
Tested on a few machines, including JMicron and Intel AHCIs.

ok dlg@ jmatthew@


# 1.36 14-Mar-2020 krw

ahci_get_pmp_ccb() returns a non-NULL pointer, fails a
KASSERT(), or has already blown up by dereferencing the
pointer.

Two of the four invocations of ahci_get_pmp_ccb() check for
NULL. Save a couple of bytes by not bothering. Add comments
to the invocations to docuement the assumption.


# 1.35 14-Mar-2020 krw

Trailing whitespace, long lines, incorrect function names in
printf()'s.


Revision tags: OPENBSD_6_6_BASE
# 1.34 08-Jul-2019 mlarkin

Remove some "set but not used" variables in ahci(4)'s hibernate code.

ok jmatthew


# 1.33 25-Jun-2019 patrick

Turn off the code which waits for AHCI_PREG_CMD_CR to be set by the
HBA after ahci_default_port_start() sets AHCI_PREG_CMD_ST. The AHCI
spec. rev. 1.3 only requires the inverse to be true, i. e. that a
HBA clears AHCI_PREG_CMD_CR when AHCI_PREG_CMD_ST gets cleared by
software/driver. In fact, some HBAs will not raise AHCI_PREG_CMD_CR
as an immediate consequence of AHCI_PREG_CMD_ST being set. Actually
neither the FreeBSD, Linux nor NetBSD counterpart of ahci(4) has an
analogous check. Disabling that wait fixes "failed to start command
DMA on port N, disabling" bails during attach.

From Marius Strobl
ok deraadt@ jmatthew@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 21-Aug-2017 jmatthew

Split up ahci_port_portreset into a few smaller bits, and also slightly
adjust port multiplier detection so it doesn't call ahci_port_portreset
again directly, but instead restarts the loop for the current call.

During attach, poll for device detection across all ports until either all
ports have detected a device, or one second has passed, rather than doing
them sequentially. Devices are still attached in order of port number,
so disk unit numbers won't change.

ok visa@


# 1.31 13-Aug-2017 mlarkin

improve AHCI hibernate writeout performance by doing smaller delay()s
between each I/O.

ok kettenis@, jmatthew@


# 1.30 30-May-2017 jmatthew

Remove comments about implementing FIS-based switching with port multipliers,
which we can safely assume isn't going to happen now. No code changes.


Revision tags: OPENBSD_6_1_BASE
# 1.29 05-Mar-2017 jmatthew

When we're unable to determine which NCQ command failed, fail all active
commands rather than proceeding to an assertion failure. This matches
how we handle the same condition with non-queued commands, and the
behaviour of every other ahci driver I can find. Add a printf there so
we might get some idea of how often this condition arises and what happens
afterwards.

ok dlg@


# 1.28 02-Oct-2016 patrick

Some HABs reset parts of AHCI_PREG_CMD when AHCI_PREG_SCTL_DET_INIT
gets set. Therefore, ahci_port_softreset() restores the sate of the
former register once the device detection sequence is finished. The
device detection code in ahci_pmp_port_portreset() does not restore
AHCI_PREG_CMD afterwards, so let it catch up. Apparently, this part
was an oversight as ahci_pmp_port_portreset() did not otherwise use
"cmd".

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.27 02-Oct-2016 patrick

Some HBAs report NCQ capability despite only supporting one command
slot. Thus, extend the check whether NCQ actually should be enabled
accordingly.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.26 02-Oct-2016 patrick

Given that ahci_port_alloc() grabs one CCB for use during NCQ error
recovery from the CCB pool sized based on the NCS capability, i. e.
number of command slots reported by the controller, it is necessary
to pretend at least 2 slots in sc->sc_ncmds for devices without NCQ
support. That way, also at least 1 available slot is made available
for atascsi(4). Otherwise, controllers having only a single command
slot will trigger "no free xfers on a new port" in atascsi(4).
Note that pretending 2 command slots is also fine with the abuse of
the NCQ error recovery CCB in ahci_port_softreset().

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.25 02-Oct-2016 patrick

Contrary to e. g. the xHCI specification, the AHCI rev. 1.3 spec
does not say anything about which type (snoopable/uncached etc.) of
bus transactions are issued by HBAs on accesses to the descriptors.
Thus, the right assumption would be "classical" concurrent accesses
by both CPU/driver as well as hardware to the descriptors and their
DMA memory backings respectively, which is also confirmed by actual
testing. Consequently, switch to BUS_DMA_COHERENT mappings for said
DMA memory as otherwise corruption of descriptors is seen.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


Revision tags: OPENBSD_6_0_BASE
# 1.24 10-Mar-2016 krw

Enforce some naming sanity. Stop using 'sc_link' to mean two different
things by renaming the field 'SLIST_HEAD(, scsi_link) sc_link' to
'sc_link_list' in struct scsibus_softc. Use 'sb' as the short name
for scsibus_softc variables.

Impetus from & ok bluhm@


Revision tags: OPENBSD_5_9_BASE
# 1.23 04-Oct-2015 jmatthew

Fix memory leak in error path.
From Benjamin Baier, found by llvm/scan-build.


# 1.22 27-Aug-2015 deraadt

sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.21 21-Mar-2015 mpi

Print speeds consistently.

ok brynet@, miod@


# 1.20 12-Mar-2015 brynet

Print the current link speed for SATA devices attached on ahci(4).

The port numbers correspond to scsibus(4) targets:

ahci0: port 0, at 6Gbps
ahci0: port 2, at 3Gbps
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 ..
sd1 at scsibus1 targ 2 ..

ok deraadt@, tested by bmercer@


Revision tags: OPENBSD_5_7_BASE
# 1.19 11-Feb-2015 jmatthew

include extended capabilities in ahci debug output
ok dlg@


# 1.18 11-Feb-2015 jmatthew

recognise ahci 1.3.1
ok dlg@


# 1.17 03-Dec-2014 jsg

Turn ahci port start into a callback so sxiahci can do some magic to
setup dma. Modified version of a patch from Edwin Amsler which was
based on changes made in Bitrig by Artturi Alm.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.16 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 26-Jun-2014 jmatthew

Work around compatibility problems with Intel ahci and Intel SSDs by retrying
device detection if the port is still busy after our normal timeout.

based on a diff by chris@, based on a change in dragonflybsd
tested by Peter J Philipp
ok dlg@


# 1.13 14-Apr-2014 dlg

move the hardware structures into ahcireg.h.


# 1.12 31-Mar-2014 dlg

move the last htoleXX things to htolemXX where possible.

ok jmatthew@


# 1.11 31-Mar-2014 dlg

ahci dva things are 64bit and surprisingly aligned nicely to 64bit too.

ok jmatthew@


# 1.10 31-Mar-2014 dlg

replace bzero with memset


# 1.9 31-Mar-2014 dlg

massage the prdt (what an sgl is on every other chip) loading with
better ops and alignment.

ok jmatthew@ who was cruel and made me test hibernate before he oked it.


# 1.8 28-Mar-2014 mpi

Reduce uvm include madness. Use <uvm/uvm_extern.h> instead of
<uvm/uvm.h> if possible and remove double inclusions.

ok beck@, mlarkin@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.7 13-Feb-2014 pelikan

fix previous errorneous constants (compiled against the old header)


# 1.6 13-Feb-2014 pelikan

Recognize SATA-III ports in dmesg.

ok millert


# 1.5 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.4 06-Nov-2013 deraadt

teach the side-effect free drivers about the partition they are dealing
by passing a start/length in the HIB_INIT op. Then rebase all
hibernate-time block offsets to be relative to the start of that partition.
This simplifies things a lot.
ok mlarkin


Revision tags: OPENBSD_5_4_BASE
# 1.3 09-Jul-2013 deraadt

pay attention to the #ifdef


# 1.2 09-Jul-2013 jmatthew

move AHCI_DEBUG stuff into ahci.c so we can build with it enabled again

ok dlg@


Revision tags: OPENBSD_5_3_BASE
# 1.1 21-Jan-2013 patrick

Split AHCI in order to support devices which are not attached via pci.
Tested on a few machines, including JMicron and Intel AHCIs.

ok dlg@ jmatthew@


# 1.34 08-Jul-2019 mlarkin

Remove some "set but not used" variables in ahci(4)'s hibernate code.

ok jmatthew


# 1.33 25-Jun-2019 patrick

Turn off the code which waits for AHCI_PREG_CMD_CR to be set by the
HBA after ahci_default_port_start() sets AHCI_PREG_CMD_ST. The AHCI
spec. rev. 1.3 only requires the inverse to be true, i. e. that a
HBA clears AHCI_PREG_CMD_CR when AHCI_PREG_CMD_ST gets cleared by
software/driver. In fact, some HBAs will not raise AHCI_PREG_CMD_CR
as an immediate consequence of AHCI_PREG_CMD_ST being set. Actually
neither the FreeBSD, Linux nor NetBSD counterpart of ahci(4) has an
analogous check. Disabling that wait fixes "failed to start command
DMA on port N, disabling" bails during attach.

From Marius Strobl
ok deraadt@ jmatthew@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 21-Aug-2017 jmatthew

Split up ahci_port_portreset into a few smaller bits, and also slightly
adjust port multiplier detection so it doesn't call ahci_port_portreset
again directly, but instead restarts the loop for the current call.

During attach, poll for device detection across all ports until either all
ports have detected a device, or one second has passed, rather than doing
them sequentially. Devices are still attached in order of port number,
so disk unit numbers won't change.

ok visa@


# 1.31 13-Aug-2017 mlarkin

improve AHCI hibernate writeout performance by doing smaller delay()s
between each I/O.

ok kettenis@, jmatthew@


# 1.30 30-May-2017 jmatthew

Remove comments about implementing FIS-based switching with port multipliers,
which we can safely assume isn't going to happen now. No code changes.


Revision tags: OPENBSD_6_1_BASE
# 1.29 05-Mar-2017 jmatthew

When we're unable to determine which NCQ command failed, fail all active
commands rather than proceeding to an assertion failure. This matches
how we handle the same condition with non-queued commands, and the
behaviour of every other ahci driver I can find. Add a printf there so
we might get some idea of how often this condition arises and what happens
afterwards.

ok dlg@


# 1.28 02-Oct-2016 patrick

Some HABs reset parts of AHCI_PREG_CMD when AHCI_PREG_SCTL_DET_INIT
gets set. Therefore, ahci_port_softreset() restores the sate of the
former register once the device detection sequence is finished. The
device detection code in ahci_pmp_port_portreset() does not restore
AHCI_PREG_CMD afterwards, so let it catch up. Apparently, this part
was an oversight as ahci_pmp_port_portreset() did not otherwise use
"cmd".

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.27 02-Oct-2016 patrick

Some HBAs report NCQ capability despite only supporting one command
slot. Thus, extend the check whether NCQ actually should be enabled
accordingly.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.26 02-Oct-2016 patrick

Given that ahci_port_alloc() grabs one CCB for use during NCQ error
recovery from the CCB pool sized based on the NCS capability, i. e.
number of command slots reported by the controller, it is necessary
to pretend at least 2 slots in sc->sc_ncmds for devices without NCQ
support. That way, also at least 1 available slot is made available
for atascsi(4). Otherwise, controllers having only a single command
slot will trigger "no free xfers on a new port" in atascsi(4).
Note that pretending 2 command slots is also fine with the abuse of
the NCQ error recovery CCB in ahci_port_softreset().

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.25 02-Oct-2016 patrick

Contrary to e. g. the xHCI specification, the AHCI rev. 1.3 spec
does not say anything about which type (snoopable/uncached etc.) of
bus transactions are issued by HBAs on accesses to the descriptors.
Thus, the right assumption would be "classical" concurrent accesses
by both CPU/driver as well as hardware to the descriptors and their
DMA memory backings respectively, which is also confirmed by actual
testing. Consequently, switch to BUS_DMA_COHERENT mappings for said
DMA memory as otherwise corruption of descriptors is seen.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


Revision tags: OPENBSD_6_0_BASE
# 1.24 10-Mar-2016 krw

Enforce some naming sanity. Stop using 'sc_link' to mean two different
things by renaming the field 'SLIST_HEAD(, scsi_link) sc_link' to
'sc_link_list' in struct scsibus_softc. Use 'sb' as the short name
for scsibus_softc variables.

Impetus from & ok bluhm@


Revision tags: OPENBSD_5_9_BASE
# 1.23 04-Oct-2015 jmatthew

Fix memory leak in error path.
From Benjamin Baier, found by llvm/scan-build.


# 1.22 27-Aug-2015 deraadt

sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.21 21-Mar-2015 mpi

Print speeds consistently.

ok brynet@, miod@


# 1.20 12-Mar-2015 brynet

Print the current link speed for SATA devices attached on ahci(4).

The port numbers correspond to scsibus(4) targets:

ahci0: port 0, at 6Gbps
ahci0: port 2, at 3Gbps
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 ..
sd1 at scsibus1 targ 2 ..

ok deraadt@, tested by bmercer@


Revision tags: OPENBSD_5_7_BASE
# 1.19 11-Feb-2015 jmatthew

include extended capabilities in ahci debug output
ok dlg@


# 1.18 11-Feb-2015 jmatthew

recognise ahci 1.3.1
ok dlg@


# 1.17 03-Dec-2014 jsg

Turn ahci port start into a callback so sxiahci can do some magic to
setup dma. Modified version of a patch from Edwin Amsler which was
based on changes made in Bitrig by Artturi Alm.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.16 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 26-Jun-2014 jmatthew

Work around compatibility problems with Intel ahci and Intel SSDs by retrying
device detection if the port is still busy after our normal timeout.

based on a diff by chris@, based on a change in dragonflybsd
tested by Peter J Philipp
ok dlg@


# 1.13 14-Apr-2014 dlg

move the hardware structures into ahcireg.h.


# 1.12 31-Mar-2014 dlg

move the last htoleXX things to htolemXX where possible.

ok jmatthew@


# 1.11 31-Mar-2014 dlg

ahci dva things are 64bit and surprisingly aligned nicely to 64bit too.

ok jmatthew@


# 1.10 31-Mar-2014 dlg

replace bzero with memset


# 1.9 31-Mar-2014 dlg

massage the prdt (what an sgl is on every other chip) loading with
better ops and alignment.

ok jmatthew@ who was cruel and made me test hibernate before he oked it.


# 1.8 28-Mar-2014 mpi

Reduce uvm include madness. Use <uvm/uvm_extern.h> instead of
<uvm/uvm.h> if possible and remove double inclusions.

ok beck@, mlarkin@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.7 13-Feb-2014 pelikan

fix previous errorneous constants (compiled against the old header)


# 1.6 13-Feb-2014 pelikan

Recognize SATA-III ports in dmesg.

ok millert


# 1.5 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.4 06-Nov-2013 deraadt

teach the side-effect free drivers about the partition they are dealing
by passing a start/length in the HIB_INIT op. Then rebase all
hibernate-time block offsets to be relative to the start of that partition.
This simplifies things a lot.
ok mlarkin


Revision tags: OPENBSD_5_4_BASE
# 1.3 09-Jul-2013 deraadt

pay attention to the #ifdef


# 1.2 09-Jul-2013 jmatthew

move AHCI_DEBUG stuff into ahci.c so we can build with it enabled again

ok dlg@


Revision tags: OPENBSD_5_3_BASE
# 1.1 21-Jan-2013 patrick

Split AHCI in order to support devices which are not attached via pci.
Tested on a few machines, including JMicron and Intel AHCIs.

ok dlg@ jmatthew@


# 1.33 25-Jun-2019 patrick

Turn off the code which waits for AHCI_PREG_CMD_CR to be set by the
HBA after ahci_default_port_start() sets AHCI_PREG_CMD_ST. The AHCI
spec. rev. 1.3 only requires the inverse to be true, i. e. that a
HBA clears AHCI_PREG_CMD_CR when AHCI_PREG_CMD_ST gets cleared by
software/driver. In fact, some HBAs will not raise AHCI_PREG_CMD_CR
as an immediate consequence of AHCI_PREG_CMD_ST being set. Actually
neither the FreeBSD, Linux nor NetBSD counterpart of ahci(4) has an
analogous check. Disabling that wait fixes "failed to start command
DMA on port N, disabling" bails during attach.

From Marius Strobl
ok deraadt@ jmatthew@


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.32 21-Aug-2017 jmatthew

Split up ahci_port_portreset into a few smaller bits, and also slightly
adjust port multiplier detection so it doesn't call ahci_port_portreset
again directly, but instead restarts the loop for the current call.

During attach, poll for device detection across all ports until either all
ports have detected a device, or one second has passed, rather than doing
them sequentially. Devices are still attached in order of port number,
so disk unit numbers won't change.

ok visa@


# 1.31 13-Aug-2017 mlarkin

improve AHCI hibernate writeout performance by doing smaller delay()s
between each I/O.

ok kettenis@, jmatthew@


# 1.30 30-May-2017 jmatthew

Remove comments about implementing FIS-based switching with port multipliers,
which we can safely assume isn't going to happen now. No code changes.


Revision tags: OPENBSD_6_1_BASE
# 1.29 05-Mar-2017 jmatthew

When we're unable to determine which NCQ command failed, fail all active
commands rather than proceeding to an assertion failure. This matches
how we handle the same condition with non-queued commands, and the
behaviour of every other ahci driver I can find. Add a printf there so
we might get some idea of how often this condition arises and what happens
afterwards.

ok dlg@


# 1.28 02-Oct-2016 patrick

Some HABs reset parts of AHCI_PREG_CMD when AHCI_PREG_SCTL_DET_INIT
gets set. Therefore, ahci_port_softreset() restores the sate of the
former register once the device detection sequence is finished. The
device detection code in ahci_pmp_port_portreset() does not restore
AHCI_PREG_CMD afterwards, so let it catch up. Apparently, this part
was an oversight as ahci_pmp_port_portreset() did not otherwise use
"cmd".

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.27 02-Oct-2016 patrick

Some HBAs report NCQ capability despite only supporting one command
slot. Thus, extend the check whether NCQ actually should be enabled
accordingly.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.26 02-Oct-2016 patrick

Given that ahci_port_alloc() grabs one CCB for use during NCQ error
recovery from the CCB pool sized based on the NCS capability, i. e.
number of command slots reported by the controller, it is necessary
to pretend at least 2 slots in sc->sc_ncmds for devices without NCQ
support. That way, also at least 1 available slot is made available
for atascsi(4). Otherwise, controllers having only a single command
slot will trigger "no free xfers on a new port" in atascsi(4).
Note that pretending 2 command slots is also fine with the abuse of
the NCQ error recovery CCB in ahci_port_softreset().

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.25 02-Oct-2016 patrick

Contrary to e. g. the xHCI specification, the AHCI rev. 1.3 spec
does not say anything about which type (snoopable/uncached etc.) of
bus transactions are issued by HBAs on accesses to the descriptors.
Thus, the right assumption would be "classical" concurrent accesses
by both CPU/driver as well as hardware to the descriptors and their
DMA memory backings respectively, which is also confirmed by actual
testing. Consequently, switch to BUS_DMA_COHERENT mappings for said
DMA memory as otherwise corruption of descriptors is seen.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


Revision tags: OPENBSD_6_0_BASE
# 1.24 10-Mar-2016 krw

Enforce some naming sanity. Stop using 'sc_link' to mean two different
things by renaming the field 'SLIST_HEAD(, scsi_link) sc_link' to
'sc_link_list' in struct scsibus_softc. Use 'sb' as the short name
for scsibus_softc variables.

Impetus from & ok bluhm@


Revision tags: OPENBSD_5_9_BASE
# 1.23 04-Oct-2015 jmatthew

Fix memory leak in error path.
From Benjamin Baier, found by llvm/scan-build.


# 1.22 27-Aug-2015 deraadt

sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.21 21-Mar-2015 mpi

Print speeds consistently.

ok brynet@, miod@


# 1.20 12-Mar-2015 brynet

Print the current link speed for SATA devices attached on ahci(4).

The port numbers correspond to scsibus(4) targets:

ahci0: port 0, at 6Gbps
ahci0: port 2, at 3Gbps
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 ..
sd1 at scsibus1 targ 2 ..

ok deraadt@, tested by bmercer@


Revision tags: OPENBSD_5_7_BASE
# 1.19 11-Feb-2015 jmatthew

include extended capabilities in ahci debug output
ok dlg@


# 1.18 11-Feb-2015 jmatthew

recognise ahci 1.3.1
ok dlg@


# 1.17 03-Dec-2014 jsg

Turn ahci port start into a callback so sxiahci can do some magic to
setup dma. Modified version of a patch from Edwin Amsler which was
based on changes made in Bitrig by Artturi Alm.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.16 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 26-Jun-2014 jmatthew

Work around compatibility problems with Intel ahci and Intel SSDs by retrying
device detection if the port is still busy after our normal timeout.

based on a diff by chris@, based on a change in dragonflybsd
tested by Peter J Philipp
ok dlg@


# 1.13 14-Apr-2014 dlg

move the hardware structures into ahcireg.h.


# 1.12 31-Mar-2014 dlg

move the last htoleXX things to htolemXX where possible.

ok jmatthew@


# 1.11 31-Mar-2014 dlg

ahci dva things are 64bit and surprisingly aligned nicely to 64bit too.

ok jmatthew@


# 1.10 31-Mar-2014 dlg

replace bzero with memset


# 1.9 31-Mar-2014 dlg

massage the prdt (what an sgl is on every other chip) loading with
better ops and alignment.

ok jmatthew@ who was cruel and made me test hibernate before he oked it.


# 1.8 28-Mar-2014 mpi

Reduce uvm include madness. Use <uvm/uvm_extern.h> instead of
<uvm/uvm.h> if possible and remove double inclusions.

ok beck@, mlarkin@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.7 13-Feb-2014 pelikan

fix previous errorneous constants (compiled against the old header)


# 1.6 13-Feb-2014 pelikan

Recognize SATA-III ports in dmesg.

ok millert


# 1.5 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.4 06-Nov-2013 deraadt

teach the side-effect free drivers about the partition they are dealing
by passing a start/length in the HIB_INIT op. Then rebase all
hibernate-time block offsets to be relative to the start of that partition.
This simplifies things a lot.
ok mlarkin


Revision tags: OPENBSD_5_4_BASE
# 1.3 09-Jul-2013 deraadt

pay attention to the #ifdef


# 1.2 09-Jul-2013 jmatthew

move AHCI_DEBUG stuff into ahci.c so we can build with it enabled again

ok dlg@


Revision tags: OPENBSD_5_3_BASE
# 1.1 21-Jan-2013 patrick

Split AHCI in order to support devices which are not attached via pci.
Tested on a few machines, including JMicron and Intel AHCIs.

ok dlg@ jmatthew@


Revision tags: OPENBSD_6_2_BASE
# 1.32 21-Aug-2017 jmatthew

Split up ahci_port_portreset into a few smaller bits, and also slightly
adjust port multiplier detection so it doesn't call ahci_port_portreset
again directly, but instead restarts the loop for the current call.

During attach, poll for device detection across all ports until either all
ports have detected a device, or one second has passed, rather than doing
them sequentially. Devices are still attached in order of port number,
so disk unit numbers won't change.

ok visa@


# 1.31 13-Aug-2017 mlarkin

improve AHCI hibernate writeout performance by doing smaller delay()s
between each I/O.

ok kettenis@, jmatthew@


# 1.30 30-May-2017 jmatthew

Remove comments about implementing FIS-based switching with port multipliers,
which we can safely assume isn't going to happen now. No code changes.


Revision tags: OPENBSD_6_1_BASE
# 1.29 05-Mar-2017 jmatthew

When we're unable to determine which NCQ command failed, fail all active
commands rather than proceeding to an assertion failure. This matches
how we handle the same condition with non-queued commands, and the
behaviour of every other ahci driver I can find. Add a printf there so
we might get some idea of how often this condition arises and what happens
afterwards.

ok dlg@


# 1.28 02-Oct-2016 patrick

Some HABs reset parts of AHCI_PREG_CMD when AHCI_PREG_SCTL_DET_INIT
gets set. Therefore, ahci_port_softreset() restores the sate of the
former register once the device detection sequence is finished. The
device detection code in ahci_pmp_port_portreset() does not restore
AHCI_PREG_CMD afterwards, so let it catch up. Apparently, this part
was an oversight as ahci_pmp_port_portreset() did not otherwise use
"cmd".

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.27 02-Oct-2016 patrick

Some HBAs report NCQ capability despite only supporting one command
slot. Thus, extend the check whether NCQ actually should be enabled
accordingly.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.26 02-Oct-2016 patrick

Given that ahci_port_alloc() grabs one CCB for use during NCQ error
recovery from the CCB pool sized based on the NCS capability, i. e.
number of command slots reported by the controller, it is necessary
to pretend at least 2 slots in sc->sc_ncmds for devices without NCQ
support. That way, also at least 1 available slot is made available
for atascsi(4). Otherwise, controllers having only a single command
slot will trigger "no free xfers on a new port" in atascsi(4).
Note that pretending 2 command slots is also fine with the abuse of
the NCQ error recovery CCB in ahci_port_softreset().

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


# 1.25 02-Oct-2016 patrick

Contrary to e. g. the xHCI specification, the AHCI rev. 1.3 spec
does not say anything about which type (snoopable/uncached etc.) of
bus transactions are issued by HBAs on accesses to the descriptors.
Thus, the right assumption would be "classical" concurrent accesses
by both CPU/driver as well as hardware to the descriptors and their
DMA memory backings respectively, which is also confirmed by actual
testing. Consequently, switch to BUS_DMA_COHERENT mappings for said
DMA memory as otherwise corruption of descriptors is seen.

From Marius Strobl

tested by awolk (amd64), bluhm (amd64, i386), myself (amd64, armv7)
ok jmatthew@


Revision tags: OPENBSD_6_0_BASE
# 1.24 10-Mar-2016 krw

Enforce some naming sanity. Stop using 'sc_link' to mean two different
things by renaming the field 'SLIST_HEAD(, scsi_link) sc_link' to
'sc_link_list' in struct scsibus_softc. Use 'sb' as the short name
for scsibus_softc variables.

Impetus from & ok bluhm@


Revision tags: OPENBSD_5_9_BASE
# 1.23 04-Oct-2015 jmatthew

Fix memory leak in error path.
From Benjamin Baier, found by llvm/scan-build.


# 1.22 27-Aug-2015 deraadt

sizes for free()


Revision tags: OPENBSD_5_8_BASE
# 1.21 21-Mar-2015 mpi

Print speeds consistently.

ok brynet@, miod@


# 1.20 12-Mar-2015 brynet

Print the current link speed for SATA devices attached on ahci(4).

The port numbers correspond to scsibus(4) targets:

ahci0: port 0, at 6Gbps
ahci0: port 2, at 3Gbps
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 ..
sd1 at scsibus1 targ 2 ..

ok deraadt@, tested by bmercer@


Revision tags: OPENBSD_5_7_BASE
# 1.19 11-Feb-2015 jmatthew

include extended capabilities in ahci debug output
ok dlg@


# 1.18 11-Feb-2015 jmatthew

recognise ahci 1.3.1
ok dlg@


# 1.17 03-Dec-2014 jsg

Turn ahci port start into a callback so sxiahci can do some magic to
setup dma. Modified version of a patch from Edwin Amsler which was
based on changes made in Bitrig by Artturi Alm.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.16 13-Jul-2014 deraadt

Some reallocarray() use; review Jean-Philippe Ouellet, patrick keshishian
ok tedu


# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 26-Jun-2014 jmatthew

Work around compatibility problems with Intel ahci and Intel SSDs by retrying
device detection if the port is still busy after our normal timeout.

based on a diff by chris@, based on a change in dragonflybsd
tested by Peter J Philipp
ok dlg@


# 1.13 14-Apr-2014 dlg

move the hardware structures into ahcireg.h.


# 1.12 31-Mar-2014 dlg

move the last htoleXX things to htolemXX where possible.

ok jmatthew@


# 1.11 31-Mar-2014 dlg

ahci dva things are 64bit and surprisingly aligned nicely to 64bit too.

ok jmatthew@


# 1.10 31-Mar-2014 dlg

replace bzero with memset


# 1.9 31-Mar-2014 dlg

massage the prdt (what an sgl is on every other chip) loading with
better ops and alignment.

ok jmatthew@ who was cruel and made me test hibernate before he oked it.


# 1.8 28-Mar-2014 mpi

Reduce uvm include madness. Use <uvm/uvm_extern.h> instead of
<uvm/uvm.h> if possible and remove double inclusions.

ok beck@, mlarkin@, deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.7 13-Feb-2014 pelikan

fix previous errorneous constants (compiled against the old header)


# 1.6 13-Feb-2014 pelikan

Recognize SATA-III ports in dmesg.

ok millert


# 1.5 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.4 06-Nov-2013 deraadt

teach the side-effect free drivers about the partition they are dealing
by passing a start/length in the HIB_INIT op. Then rebase all
hibernate-time block offsets to be relative to the start of that partition.
This simplifies things a lot.
ok mlarkin


Revision tags: OPENBSD_5_4_BASE
# 1.3 09-Jul-2013 deraadt

pay attention to the #ifdef


# 1.2 09-Jul-2013 jmatthew

move AHCI_DEBUG stuff into ahci.c so we can build with it enabled again

ok dlg@


Revision tags: OPENBSD_5_3_BASE
# 1.1 21-Jan-2013 patrick

Split AHCI in order to support devices which are not attached via pci.
Tested on a few machines, including JMicron and Intel AHCIs.

ok dlg@ jmatthew@