2020-01-18 14:26:11 +03:00
|
|
|
/* $NetBSD: ahcisatavar.h,v 1.24 2020/01/18 11:26:11 simonb Exp $ */
|
2007-05-12 15:04:58 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2006 Manuel Bouyer.
|
|
|
|
*
|
|
|
|
* 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 AUTHOR ``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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dev/ic/ahcisatareg.h>
|
|
|
|
|
|
|
|
#define AHCI_DEBUG
|
|
|
|
|
|
|
|
#define DEBUG_INTR 0x01
|
|
|
|
#define DEBUG_XFERS 0x02
|
|
|
|
#define DEBUG_FUNCS 0x08
|
|
|
|
#define DEBUG_PROBE 0x10
|
|
|
|
#define DEBUG_DETACH 0x20
|
|
|
|
#ifdef AHCI_DEBUG
|
|
|
|
extern int ahcidebug_mask;
|
|
|
|
#define AHCIDEBUG_PRINT(args, level) \
|
|
|
|
if (ahcidebug_mask & (level)) \
|
|
|
|
printf args
|
|
|
|
#else
|
|
|
|
#define AHCIDEBUG_PRINT(args, level)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct ahci_softc {
|
|
|
|
struct atac_softc sc_atac;
|
|
|
|
bus_space_tag_t sc_ahcit; /* ahci registers mapping */
|
|
|
|
bus_space_handle_t sc_ahcih;
|
2010-07-28 02:07:50 +04:00
|
|
|
bus_size_t sc_ahcis;
|
2007-05-12 15:04:58 +04:00
|
|
|
bus_dma_tag_t sc_dmat; /* DMA memory mappings: */
|
|
|
|
void *sc_cmd_hdr; /* command tables and received FIS */
|
|
|
|
bus_dmamap_t sc_cmd_hdrd;
|
2010-07-28 02:07:50 +04:00
|
|
|
bus_dma_segment_t sc_cmd_hdr_seg;
|
|
|
|
int sc_cmd_hdr_nseg;
|
2008-02-11 11:23:48 +03:00
|
|
|
int sc_atac_capflags;
|
2012-08-20 16:48:47 +04:00
|
|
|
int sc_ahci_quirks;
|
2012-08-10 20:35:00 +04:00
|
|
|
#define AHCI_PCI_QUIRK_FORCE __BIT(0) /* force attach */
|
|
|
|
#define AHCI_PCI_QUIRK_BAD64 __BIT(1) /* broken 64-bit DMA */
|
|
|
|
#define AHCI_QUIRK_BADPMP __BIT(2) /* broken PMP support, ignore */
|
2015-05-25 01:30:05 +03:00
|
|
|
#define AHCI_QUIRK_SKIP_RESET __BIT(4) /* skip drive reset sequence */
|
2020-01-18 14:26:11 +03:00
|
|
|
#define AHCI_QUIRK_BADNCQ __BIT(5) /* possibly broken NCQ support, ignore */
|
2007-05-12 15:04:58 +04:00
|
|
|
|
2012-09-20 21:53:48 +04:00
|
|
|
uint32_t sc_ahci_cap; /* copy of AHCI_CAP */
|
2007-05-12 15:04:58 +04:00
|
|
|
int sc_ncmds; /* number of command slots */
|
2013-09-08 15:47:16 +04:00
|
|
|
uint32_t sc_ahci_ports;
|
2007-05-12 15:04:58 +04:00
|
|
|
struct ata_channel *sc_chanarray[AHCI_MAX_PORTS];
|
|
|
|
struct ahci_channel {
|
|
|
|
struct ata_channel ata_channel; /* generic part */
|
|
|
|
bus_space_handle_t ahcic_scontrol;
|
|
|
|
bus_space_handle_t ahcic_sstatus;
|
|
|
|
bus_space_handle_t ahcic_serror;
|
|
|
|
/* pointers allocated from sc_cmd_hdrd */
|
|
|
|
struct ahci_r_fis *ahcic_rfis; /* received FIS */
|
|
|
|
bus_addr_t ahcic_bus_rfis;
|
|
|
|
struct ahci_cmd_header *ahcic_cmdh; /* command headers */
|
|
|
|
bus_addr_t ahcic_bus_cmdh;
|
|
|
|
/* command tables (allocated per-channel) */
|
|
|
|
bus_dmamap_t ahcic_cmd_tbld;
|
2010-07-28 02:07:50 +04:00
|
|
|
bus_dma_segment_t ahcic_cmd_tbl_seg;
|
|
|
|
int ahcic_cmd_tbl_nseg;
|
2007-05-12 15:04:58 +04:00
|
|
|
struct ahci_cmd_tbl *ahcic_cmd_tbl[AHCI_MAX_CMDS];
|
|
|
|
bus_addr_t ahcic_bus_cmd_tbl[AHCI_MAX_CMDS];
|
|
|
|
bus_dmamap_t ahcic_datad[AHCI_MAX_CMDS];
|
|
|
|
} sc_channels[AHCI_MAX_PORTS];
|
2014-02-24 16:19:05 +04:00
|
|
|
|
|
|
|
void (*sc_channel_start)(struct ahci_softc *, struct ata_channel *);
|
|
|
|
void (*sc_channel_stop)(struct ahci_softc *, struct ata_channel *);
|
2018-12-08 01:22:12 +03:00
|
|
|
int (*sc_intr_establish)(struct ahci_softc *, int);
|
2014-02-24 16:19:05 +04:00
|
|
|
|
2018-12-08 01:22:12 +03:00
|
|
|
bool sc_ghc_mrsm;
|
2014-02-24 16:19:05 +04:00
|
|
|
bool sc_save_init_data;
|
|
|
|
struct {
|
|
|
|
uint32_t cap;
|
|
|
|
uint32_t cap2;
|
|
|
|
uint32_t ports;
|
|
|
|
} sc_init_data;
|
2007-05-12 15:04:58 +04:00
|
|
|
};
|
|
|
|
|
2008-03-18 23:46:35 +03:00
|
|
|
#define AHCINAME(sc) (device_xname((sc)->sc_atac.atac_dev))
|
2007-05-12 15:04:58 +04:00
|
|
|
|
|
|
|
#define AHCI_CMDH_SYNC(sc, achp, cmd, op) bus_dmamap_sync((sc)->sc_dmat, \
|
|
|
|
(sc)->sc_cmd_hdrd, \
|
|
|
|
(char *)(&(achp)->ahcic_cmdh[(cmd)]) - (char *)(sc)->sc_cmd_hdr, \
|
|
|
|
sizeof(struct ahci_cmd_header), (op))
|
|
|
|
#define AHCI_RFIS_SYNC(sc, achp, op) bus_dmamap_sync((sc)->sc_dmat, \
|
2019-09-30 00:16:14 +03:00
|
|
|
(sc)->sc_cmd_hdrd, \
|
|
|
|
(char *)(achp)->ahcic_rfis - (char *)(sc)->sc_cmd_hdr, \
|
2007-05-12 15:04:58 +04:00
|
|
|
AHCI_RFIS_SIZE, (op))
|
|
|
|
#define AHCI_CMDTBL_SYNC(sc, achp, cmd, op) bus_dmamap_sync((sc)->sc_dmat, \
|
|
|
|
(achp)->ahcic_cmd_tbld, AHCI_CMDTBL_SIZE * (cmd), \
|
|
|
|
AHCI_CMDTBL_SIZE, (op))
|
|
|
|
|
|
|
|
#define AHCI_READ(sc, reg) bus_space_read_4((sc)->sc_ahcit, \
|
|
|
|
(sc)->sc_ahcih, (reg))
|
|
|
|
#define AHCI_WRITE(sc, reg, val) bus_space_write_4((sc)->sc_ahcit, \
|
|
|
|
(sc)->sc_ahcih, (reg), (val))
|
|
|
|
|
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
|
|
|
#define AHCI_CH2SC(chp) (struct ahci_softc *)((chp)->ch_atac)
|
2007-05-12 15:04:58 +04:00
|
|
|
|
|
|
|
void ahci_attach(struct ahci_softc *);
|
2010-07-28 02:07:50 +04:00
|
|
|
int ahci_detach(struct ahci_softc *, int);
|
2018-10-24 22:38:00 +03:00
|
|
|
void ahci_childdetached(struct ahci_softc *, device_t);
|
2010-07-28 02:07:50 +04:00
|
|
|
void ahci_resume(struct ahci_softc *);
|
2007-05-12 15:04:58 +04:00
|
|
|
|
|
|
|
int ahci_intr(void *);
|
2018-12-08 01:22:12 +03:00
|
|
|
int ahci_intr_port(void *);
|
2007-11-12 23:10:32 +03:00
|
|
|
|