1dd48af36SAlexander Motin /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4dd48af36SAlexander Motin * Copyright (c) 2010 Alexander Motin <mav@FreeBSD.org> 5dd48af36SAlexander Motin * All rights reserved. 6dd48af36SAlexander Motin * 7dd48af36SAlexander Motin * Redistribution and use in source and binary forms, with or without 8dd48af36SAlexander Motin * modification, are permitted provided that the following conditions 9dd48af36SAlexander Motin * are met: 10dd48af36SAlexander Motin * 1. Redistributions of source code must retain the above copyright 11dd48af36SAlexander Motin * notice, this list of conditions and the following disclaimer, 12dd48af36SAlexander Motin * without modification, immediately at the beginning of the file. 13dd48af36SAlexander Motin * 2. Redistributions in binary form must reproduce the above copyright 14dd48af36SAlexander Motin * notice, this list of conditions and the following disclaimer in the 15dd48af36SAlexander Motin * documentation and/or other materials provided with the distribution. 16dd48af36SAlexander Motin * 17dd48af36SAlexander Motin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18dd48af36SAlexander Motin * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19dd48af36SAlexander Motin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20dd48af36SAlexander Motin * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21dd48af36SAlexander Motin * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22dd48af36SAlexander Motin * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23dd48af36SAlexander Motin * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24dd48af36SAlexander Motin * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25dd48af36SAlexander Motin * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26dd48af36SAlexander Motin * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27dd48af36SAlexander Motin */ 28dd48af36SAlexander Motin 29dd48af36SAlexander Motin #include "mvs_if.h" 30dd48af36SAlexander Motin 31dd48af36SAlexander Motin /* Chip registers */ 32dd48af36SAlexander Motin #define CHIP_PCIEIC 0x1900 /* PCIe Interrupt Cause */ 33dd48af36SAlexander Motin #define CHIP_PCIEIM 0x1910 /* PCIe Interrupt Mask */ 34dd48af36SAlexander Motin #define CHIP_PCIIC 0x1d58 /* PCI Interrupt Cause */ 35dd48af36SAlexander Motin #define CHIP_PCIIM 0x1d5c /* PCI Interrupt Mask */ 36dd48af36SAlexander Motin #define CHIP_MIC 0x1d60 /* Main Interrupt Cause */ 37dd48af36SAlexander Motin #define CHIP_MIM 0x1d64 /* Main Interrupt Mask */ 38dd48af36SAlexander Motin #define CHIP_SOC_MIC 0x20 /* SoC Main Interrupt Cause */ 39dd48af36SAlexander Motin #define CHIP_SOC_MIM 0x24 /* SoC Main Interrupt Mask */ 40dd48af36SAlexander Motin #define IC_ERR_IRQ (1 << 0) /* shift by (2 * port #) */ 41dd48af36SAlexander Motin #define IC_DONE_IRQ (1 << 1) /* shift by (2 * port #) */ 42dd48af36SAlexander Motin #define IC_HC0 0x000001ff /* bits 0-8 = HC0 */ 43dd48af36SAlexander Motin #define IC_HC_SHIFT 9 /* HC1 shift */ 44dd48af36SAlexander Motin #define IC_HC1 (IC_HC0 << IC_HC_SHIFT) /* 9-17 = HC1 */ 45dd48af36SAlexander Motin #define IC_ERR_HC0 0x00000055 /* HC0 ERR_IRQ */ 46dd48af36SAlexander Motin #define IC_DONE_HC0 0x000000aa /* HC0 DONE_IRQ */ 47dd48af36SAlexander Motin #define IC_ERR_HC1 (IC_ERR_HC0 << IC_HC_SHIFT) /* HC1 ERR_IRQ */ 48dd48af36SAlexander Motin #define IC_DONE_HC1 (IC_DONE_HC0 << IC_HC_SHIFT) /* HC1 DONE_IRQ */ 49dd48af36SAlexander Motin #define IC_HC0_COAL_DONE (1 << 8) /* HC0 IRQ coalescing */ 50dd48af36SAlexander Motin #define IC_HC1_COAL_DONE (1 << 17) /* HC1 IRQ coalescing */ 51dd48af36SAlexander Motin #define IC_PCI_ERR (1 << 18) 52dd48af36SAlexander Motin #define IC_TRAN_COAL_LO_DONE (1 << 19) /* transaction coalescing */ 53dd48af36SAlexander Motin #define IC_TRAN_COAL_HI_DONE (1 << 20) /* transaction coalescing */ 54dd48af36SAlexander Motin #define IC_ALL_PORTS_COAL_DONE (1 << 21) /* GEN_II(E) IRQ coalescing */ 55dd48af36SAlexander Motin #define IC_GPIO_INT (1 << 22) 56dd48af36SAlexander Motin #define IC_SELF_INT (1 << 23) 57dd48af36SAlexander Motin #define IC_TWSI_INT (1 << 24) 58dd48af36SAlexander Motin #define IC_MAIN_RSVD (0xfe000000) /* bits 31-25 */ 59dd48af36SAlexander Motin #define IC_MAIN_RSVD_5 (0xfff10000) /* bits 31-19 */ 60dd48af36SAlexander Motin #define IC_MAIN_RSVD_SOC (0xfffffec0) /* bits 31-9, 7-6 */ 61dd48af36SAlexander Motin 62dd48af36SAlexander Motin #define CHIP_SOC_LED 0x2C /* SoC LED Configuration */ 63dd48af36SAlexander Motin 64c72ef339SRafal Jaworowski /* Additional mask for SoC devices with less than 4 channels */ 65c72ef339SRafal Jaworowski #define CHIP_SOC_HC0_MASK(num) (0xff >> ((4 - (num)) * 2)) 66c72ef339SRafal Jaworowski 67dd48af36SAlexander Motin /* Chip CCC registers */ 68dd48af36SAlexander Motin #define CHIP_ICC 0x18008 69dd48af36SAlexander Motin #define CHIP_ICC_ALL_PORTS (1 << 4) /* all ports irq event */ 70dd48af36SAlexander Motin #define CHIP_ICT 0x180cc 71dd48af36SAlexander Motin #define CHIP_ITT 0x180d0 72dd48af36SAlexander Motin #define CHIP_TRAN_COAL_CAUSE_LO 0x18088 73dd48af36SAlexander Motin #define CHIP_TRAN_COAL_CAUSE_HI 0x1808c 74dd48af36SAlexander Motin 75dd48af36SAlexander Motin /* Host Controller registers */ 76dd48af36SAlexander Motin #define HC_SIZE 0x10000 77dd48af36SAlexander Motin #define HC_OFFSET 0x20000 78dd48af36SAlexander Motin #define HC_BASE(hc) ((hc) * HC_SIZE + HC_OFFSET) 79dd48af36SAlexander Motin 80dd48af36SAlexander Motin #define HC_CFG 0x0 /* Configuration */ 81dd48af36SAlexander Motin #define HC_CFG_TIMEOUT_MASK (0xff << 0) 82dd48af36SAlexander Motin #define HC_CFG_NODMABS (1 << 8) 83dd48af36SAlexander Motin #define HC_CFG_NOEDMABS (1 << 9) 84dd48af36SAlexander Motin #define HC_CFG_NOPRDBS (1 << 10) 85dd48af36SAlexander Motin #define HC_CFG_TIMEOUTEN (1 << 16) /* Timer Enable */ 86dd48af36SAlexander Motin #define HC_CFG_COALDIS(p) (1 << ((p) + 24))/* Coalescing Disable*/ 87dd48af36SAlexander Motin #define HC_RQOP 0x4 /* Request Queue Out-Pointer */ 88dd48af36SAlexander Motin #define HC_RQIP 0x8 /* Response Queue In-Pointer */ 89dd48af36SAlexander Motin #define HC_ICT 0xc /* Interrupt Coalescing Threshold */ 90dd48af36SAlexander Motin #define HC_ICT_SAICOALT_MASK 0x000000ff 91dd48af36SAlexander Motin #define HC_ITT 0x10 /* Interrupt Time Threshold */ 92dd48af36SAlexander Motin #define HC_ITT_SAITMTH_MASK 0x00ffffff 93dd48af36SAlexander Motin #define HC_IC 0x14 /* Interrupt Cause */ 94dd48af36SAlexander Motin #define HC_IC_DONE(p) (1 << (p)) /* SaCrpb/DMA Done */ 95dd48af36SAlexander Motin #define HC_IC_COAL (1 << 4) /* Intr Coalescing */ 96dd48af36SAlexander Motin #define HC_IC_DEV(p) (1 << ((p) + 8)) /* Device Intr */ 97dd48af36SAlexander Motin 98dd48af36SAlexander Motin /* Port registers */ 99dd48af36SAlexander Motin #define PORT_SIZE 0x2000 100dd48af36SAlexander Motin #define PORT_OFFSET 0x2000 101dd48af36SAlexander Motin #define PORT_BASE(hc) ((hc) * PORT_SIZE + PORT_OFFSET) 102dd48af36SAlexander Motin 103dd48af36SAlexander Motin #define EDMA_CFG 0x0 /* Configuration */ 104dd48af36SAlexander Motin #define EDMA_CFG_RESERVED (0x1f << 0) /* Queue len ? */ 105dd48af36SAlexander Motin #define EDMA_CFG_ESATANATVCMDQUE (1 << 5) 106dd48af36SAlexander Motin #define EDMA_CFG_ERDBSZ (1 << 8) 107dd48af36SAlexander Motin #define EDMA_CFG_EQUE (1 << 9) 108dd48af36SAlexander Motin #define EDMA_CFG_ERDBSZEXT (1 << 11) 109dd48af36SAlexander Motin #define EDMA_CFG_RESERVED2 (1 << 12) 110dd48af36SAlexander Motin #define EDMA_CFG_EWRBUFFERLEN (1 << 13) 111dd48af36SAlexander Motin #define EDMA_CFG_EDEVERR (1 << 14) 112dd48af36SAlexander Motin #define EDMA_CFG_EEDMAFBS (1 << 16) 113dd48af36SAlexander Motin #define EDMA_CFG_ECUTTHROUGHEN (1 << 17) 114dd48af36SAlexander Motin #define EDMA_CFG_EEARLYCOMPLETIONEN (1 << 18) 115dd48af36SAlexander Motin #define EDMA_CFG_EEDMAQUELEN (1 << 19) 116dd48af36SAlexander Motin #define EDMA_CFG_EHOSTQUEUECACHEEN (1 << 22) 117dd48af36SAlexander Motin #define EDMA_CFG_EMASKRXPM (1 << 23) 118dd48af36SAlexander Motin #define EDMA_CFG_RESUMEDIS (1 << 24) 119dd48af36SAlexander Motin #define EDMA_CFG_EDMAFBS (1 << 26) 120dd48af36SAlexander Motin #define EDMA_T 0x4 /* Timer */ 121dd48af36SAlexander Motin #define EDMA_IEC 0x8 /* Interrupt Error Cause */ 122dd48af36SAlexander Motin #define EDMA_IEM 0xc /* Interrupt Error Mask */ 123dd48af36SAlexander Motin #define EDMA_IE_EDEVERR (1 << 2) /* EDMA Device Error */ 124dd48af36SAlexander Motin #define EDMA_IE_EDEVDIS (1 << 3) /* EDMA Dev Disconn */ 125dd48af36SAlexander Motin #define EDMA_IE_EDEVCON (1 << 4) /* EDMA Dev Conn */ 126dd48af36SAlexander Motin #define EDMA_IE_SERRINT (1 << 5) 127dd48af36SAlexander Motin #define EDMA_IE_ESELFDIS (1 << 7) /* EDMA Self Disable */ 128dd48af36SAlexander Motin #define EDMA_IE_ETRANSINT (1 << 8) /* Transport Layer */ 129dd48af36SAlexander Motin #define EDMA_IE_EIORDYERR (1 << 12) /* EDMA IORdy Error */ 130dd48af36SAlexander Motin #define EDMA_IE_LINKXERR_SATACRC (1 << 0) /* SATA CRC error */ 131dd48af36SAlexander Motin #define EDMA_IE_LINKXERR_INTERNALFIFO (1 << 1) /* internal FIFO err */ 132dd48af36SAlexander Motin #define EDMA_IE_LINKXERR_LINKLAYERRESET (1 << 2) 133dd48af36SAlexander Motin /* Link Layer is reset by the reception of SYNC primitive from device */ 134dd48af36SAlexander Motin #define EDMA_IE_LINKXERR_OTHERERRORS (1 << 3) 135dd48af36SAlexander Motin /* 136dd48af36SAlexander Motin * Link state errors, coding errors, or running disparity errors occur 137dd48af36SAlexander Motin * during FIS reception. 138dd48af36SAlexander Motin */ 139dd48af36SAlexander Motin #define EDMA_IE_LINKTXERR_FISTXABORTED (1 << 4) /* FIS Tx is aborted */ 140dd48af36SAlexander Motin #define EDMA_IE_LINKCTLRXERR(x) ((x) << 13) /* Link Ctrl Recv Err */ 141dd48af36SAlexander Motin #define EDMA_IE_LINKDATARXERR(x) ((x) << 17) /* Link Data Recv Err */ 142dd48af36SAlexander Motin #define EDMA_IE_LINKCTLTXERR(x) ((x) << 21) /* Link Ctrl Tx Error */ 143dd48af36SAlexander Motin #define EDMA_IE_LINKDATATXERR(x) ((x) << 26) /* Link Data Tx Error */ 1447a22215cSEitan Adler #define EDMA_IE_TRANSPROTERR (1U << 31) /* Transport Proto E */ 145dd48af36SAlexander Motin #define EDMA_IE_TRANSIENT (EDMA_IE_LINKCTLRXERR(0x0b) | \ 146dd48af36SAlexander Motin EDMA_IE_LINKCTLTXERR(0x1f)) 147dd48af36SAlexander Motin /* Non-fatal Errors */ 148dd48af36SAlexander Motin #define EDMA_REQQBAH 0x10 /* Request Queue Base Address High */ 149dd48af36SAlexander Motin #define EDMA_REQQIP 0x14 /* Request Queue In-Pointer */ 150dd48af36SAlexander Motin #define EDMA_REQQOP 0x18 /* Request Queue Out-Pointer */ 151dd48af36SAlexander Motin #define EDMA_REQQP_ERQQP_SHIFT 5 152dd48af36SAlexander Motin #define EDMA_REQQP_ERQQP_MASK 0x000003e0 153dd48af36SAlexander Motin #define EDMA_REQQP_ERQQBAP_MASK 0x00000c00 154dd48af36SAlexander Motin #define EDMA_REQQP_ERQQBA_MASK 0xfffff000 155dd48af36SAlexander Motin #define EDMA_RESQBAH 0x1c /* Response Queue Base Address High */ 156dd48af36SAlexander Motin #define EDMA_RESQIP 0x20 /* Response Queue In-Pointer */ 157dd48af36SAlexander Motin #define EDMA_RESQOP 0x24 /* Response Queue Out-Pointer */ 158dd48af36SAlexander Motin #define EDMA_RESQP_ERPQP_SHIFT 3 159dd48af36SAlexander Motin #define EDMA_RESQP_ERPQP_MASK 0x000000f8 160dd48af36SAlexander Motin #define EDMA_RESQP_ERPQBAP_MASK 0x00000300 161dd48af36SAlexander Motin #define EDMA_RESQP_ERPQBA_MASK 0xfffffc00 162dd48af36SAlexander Motin #define EDMA_CMD 0x28 /* Command */ 163dd48af36SAlexander Motin #define EDMA_CMD_EENEDMA (1 << 0) /* Enable EDMA */ 164dd48af36SAlexander Motin #define EDMA_CMD_EDSEDMA (1 << 1) /* Disable EDMA */ 165dd48af36SAlexander Motin #define EDMA_CMD_EATARST (1 << 2) /* ATA Device Reset */ 166dd48af36SAlexander Motin #define EDMA_CMD_EEDMAFRZ (1 << 4) /* EDMA Freeze */ 167dd48af36SAlexander Motin #define EDMA_TC 0x2c /* Test Control */ 168dd48af36SAlexander Motin #define EDMA_S 0x30 /* Status */ 169dd48af36SAlexander Motin #define EDMA_S_EDEVQUETAG(s) ((s) & 0x0000001f) 170dd48af36SAlexander Motin #define EDMA_S_EDEVDIR_WRITE (0 << 5) 171dd48af36SAlexander Motin #define EDMA_S_EDEVDIR_READ (1 << 5) 172dd48af36SAlexander Motin #define EDMA_S_ECACHEEMPTY (1 << 6) 173dd48af36SAlexander Motin #define EDMA_S_EDMAIDLE (1 << 7) 174dd48af36SAlexander Motin #define EDMA_S_ESTATE(s) (((s) & 0x0000ff00) >> 8) 175dd48af36SAlexander Motin #define EDMA_S_EIOID(s) (((s) & 0x003f0000) >> 16) 176dd48af36SAlexander Motin #define EDMA_IORT 0x34 /* IORdy Timeout */ 177dd48af36SAlexander Motin #define EDMA_CDT 0x40 /* Command Delay Threshold */ 178dd48af36SAlexander Motin #define EDMA_HC 0x60 /* Halt Condition */ 179dd48af36SAlexander Motin #define EDMA_UNKN_RESD 0x6C /* Unknown register */ 180dd48af36SAlexander Motin #define EDMA_CQDCQOS(x) (0x90 + ((x) << 2) 181dd48af36SAlexander Motin /* NCQ Done/TCQ Outstanding Status */ 182dd48af36SAlexander Motin 183dd48af36SAlexander Motin /* ATA register defines */ 184dd48af36SAlexander Motin #define ATA_DATA 0x100 /* (RW) data */ 185dd48af36SAlexander Motin #define ATA_FEATURE 0x104 /* (W) feature */ 186dd48af36SAlexander Motin #define ATA_F_DMA 0x01 /* enable DMA */ 187dd48af36SAlexander Motin #define ATA_F_OVL 0x02 /* enable overlap */ 188dd48af36SAlexander Motin #define ATA_ERROR 0x104 /* (R) error */ 189dd48af36SAlexander Motin #define ATA_E_ILI 0x01 /* illegal length */ 190dd48af36SAlexander Motin #define ATA_E_NM 0x02 /* no media */ 191dd48af36SAlexander Motin #define ATA_E_ABORT 0x04 /* command aborted */ 192dd48af36SAlexander Motin #define ATA_E_MCR 0x08 /* media change request */ 193dd48af36SAlexander Motin #define ATA_E_IDNF 0x10 /* ID not found */ 194dd48af36SAlexander Motin #define ATA_E_MC 0x20 /* media changed */ 195dd48af36SAlexander Motin #define ATA_E_UNC 0x40 /* uncorrectable data */ 196dd48af36SAlexander Motin #define ATA_E_ICRC 0x80 /* UDMA crc error */ 197dd48af36SAlexander Motin #define ATA_E_ATAPI_SENSE_MASK 0xf0 /* ATAPI sense key mask */ 198dd48af36SAlexander Motin #define ATA_COUNT 0x108 /* (W) sector count */ 199dd48af36SAlexander Motin #define ATA_IREASON 0x108 /* (R) interrupt reason */ 200dd48af36SAlexander Motin #define ATA_I_CMD 0x01 /* cmd (1) | data (0) */ 201dd48af36SAlexander Motin #define ATA_I_IN 0x02 /* read (1) | write (0) */ 202dd48af36SAlexander Motin #define ATA_I_RELEASE 0x04 /* released bus (1) */ 203dd48af36SAlexander Motin #define ATA_I_TAGMASK 0xf8 /* tag mask */ 204dd48af36SAlexander Motin #define ATA_SECTOR 0x10c /* (RW) sector # */ 205dd48af36SAlexander Motin #define ATA_CYL_LSB 0x110 /* (RW) cylinder# LSB */ 206dd48af36SAlexander Motin #define ATA_CYL_MSB 0x114 /* (RW) cylinder# MSB */ 207dd48af36SAlexander Motin #define ATA_DRIVE 0x118 /* (W) Sector/Drive/Head */ 208dd48af36SAlexander Motin #define ATA_D_LBA 0x40 /* use LBA addressing */ 209dd48af36SAlexander Motin #define ATA_D_IBM 0xa0 /* 512 byte sectors, ECC */ 210dd48af36SAlexander Motin #define ATA_COMMAND 0x11c /* (W) command */ 211dd48af36SAlexander Motin #define ATA_STATUS 0x11c /* (R) status */ 212dd48af36SAlexander Motin #define ATA_S_ERROR 0x01 /* error */ 213dd48af36SAlexander Motin #define ATA_S_INDEX 0x02 /* index */ 214dd48af36SAlexander Motin #define ATA_S_CORR 0x04 /* data corrected */ 215dd48af36SAlexander Motin #define ATA_S_DRQ 0x08 /* data request */ 216dd48af36SAlexander Motin #define ATA_S_DSC 0x10 /* drive seek completed */ 217dd48af36SAlexander Motin #define ATA_S_SERVICE 0x10 /* drive needs service */ 218dd48af36SAlexander Motin #define ATA_S_DWF 0x20 /* drive write fault */ 219dd48af36SAlexander Motin #define ATA_S_DMA 0x20 /* DMA ready */ 220dd48af36SAlexander Motin #define ATA_S_READY 0x40 /* drive ready */ 221dd48af36SAlexander Motin #define ATA_S_BUSY 0x80 /* busy */ 222dd48af36SAlexander Motin #define ATA_CONTROL 0x120 /* (W) control */ 223dd48af36SAlexander Motin #define ATA_A_IDS 0x02 /* disable interrupts */ 224dd48af36SAlexander Motin #define ATA_A_RESET 0x04 /* RESET controller */ 225dd48af36SAlexander Motin #define ATA_A_4BIT 0x08 /* 4 head bits */ 226dd48af36SAlexander Motin #define ATA_A_HOB 0x80 /* High Order Byte enable */ 227dd48af36SAlexander Motin #define ATA_ALTSTAT 0x120 /* (R) alternate status */ 228dd48af36SAlexander Motin #define ATAPI_P_READ (ATA_S_DRQ | ATA_I_IN) 229dd48af36SAlexander Motin #define ATAPI_P_WRITE (ATA_S_DRQ) 230dd48af36SAlexander Motin #define ATAPI_P_CMDOUT (ATA_S_DRQ | ATA_I_CMD) 231dd48af36SAlexander Motin #define ATAPI_P_DONEDRQ (ATA_S_DRQ | ATA_I_CMD | ATA_I_IN) 232dd48af36SAlexander Motin #define ATAPI_P_DONE (ATA_I_CMD | ATA_I_IN) 233dd48af36SAlexander Motin #define ATAPI_P_ABORT 0 234dd48af36SAlexander Motin 235dd48af36SAlexander Motin /* Basic DMA Registers */ 236dd48af36SAlexander Motin #define DMA_C 0x224 /* Basic DMA Command */ 237dd48af36SAlexander Motin #define DMA_C_START (1 << 0) 238dd48af36SAlexander Motin #define DMA_C_READ (1 << 3) 239dd48af36SAlexander Motin #define DMA_C_DREGIONVALID (1 << 8) 240dd48af36SAlexander Motin #define DMA_C_DREGIONLAST (1 << 9) 241dd48af36SAlexander Motin #define DMA_C_CONTFROMPREV (1 << 10) 242dd48af36SAlexander Motin #define DMA_C_DRBC(n) (((n) & 0xffff) << 16) 243dd48af36SAlexander Motin #define DMA_S 0x228 /* Basic DMA Status */ 244dd48af36SAlexander Motin #define DMA_S_ACT (1 << 0) /* Active */ 245dd48af36SAlexander Motin #define DMA_S_ERR (1 << 1) /* Error */ 246dd48af36SAlexander Motin #define DMA_S_PAUSED (1 << 2) /* Paused */ 247dd48af36SAlexander Motin #define DMA_S_LAST (1 << 3) /* Last */ 248dd48af36SAlexander Motin #define DMA_DTLBA 0x22c /* Descriptor Table Low Base Address */ 249dd48af36SAlexander Motin #define DMA_DTLBA_MASK 0xfffffff0 250dd48af36SAlexander Motin #define DMA_DTHBA 0x230 /* Descriptor Table High Base Address */ 251dd48af36SAlexander Motin #define DMA_DRLA 0x234 /* Data Region Low Address */ 252dd48af36SAlexander Motin #define DMA_DRHA 0x238 /* Data Region High Address */ 253dd48af36SAlexander Motin 254dd48af36SAlexander Motin /* Serial-ATA Registers */ 255dd48af36SAlexander Motin #define SATA_SS 0x300 /* SStatus */ 256dd48af36SAlexander Motin #define SATA_SS_DET_MASK 0x0000000f 257dd48af36SAlexander Motin #define SATA_SS_DET_NO_DEVICE 0x00000000 258dd48af36SAlexander Motin #define SATA_SS_DET_DEV_PRESENT 0x00000001 259dd48af36SAlexander Motin #define SATA_SS_DET_PHY_ONLINE 0x00000003 260dd48af36SAlexander Motin #define SATA_SS_DET_PHY_OFFLINE 0x00000004 261dd48af36SAlexander Motin 262dd48af36SAlexander Motin #define SATA_SS_SPD_MASK 0x000000f0 263dd48af36SAlexander Motin #define SATA_SS_SPD_NO_SPEED 0x00000000 264dd48af36SAlexander Motin #define SATA_SS_SPD_GEN1 0x00000010 265dd48af36SAlexander Motin #define SATA_SS_SPD_GEN2 0x00000020 266c21b342bSAlexander Motin #define SATA_SS_SPD_GEN3 0x00000030 267dd48af36SAlexander Motin 268dd48af36SAlexander Motin #define SATA_SS_IPM_MASK 0x00000f00 269dd48af36SAlexander Motin #define SATA_SS_IPM_NO_DEVICE 0x00000000 270dd48af36SAlexander Motin #define SATA_SS_IPM_ACTIVE 0x00000100 271dd48af36SAlexander Motin #define SATA_SS_IPM_PARTIAL 0x00000200 272dd48af36SAlexander Motin #define SATA_SS_IPM_SLUMBER 0x00000600 273dd48af36SAlexander Motin #define SATA_SE 0x304 /* SError */ 274dd48af36SAlexander Motin #define SATA_SEIM 0x340 /* SError Interrupt Mask */ 275dd48af36SAlexander Motin #define SATA_SE_DATA_CORRECTED 0x00000001 276dd48af36SAlexander Motin #define SATA_SE_COMM_CORRECTED 0x00000002 277dd48af36SAlexander Motin #define SATA_SE_DATA_ERR 0x00000100 278dd48af36SAlexander Motin #define SATA_SE_COMM_ERR 0x00000200 279dd48af36SAlexander Motin #define SATA_SE_PROT_ERR 0x00000400 280dd48af36SAlexander Motin #define SATA_SE_HOST_ERR 0x00000800 281dd48af36SAlexander Motin #define SATA_SE_PHY_CHANGED 0x00010000 282dd48af36SAlexander Motin #define SATA_SE_PHY_IERROR 0x00020000 283dd48af36SAlexander Motin #define SATA_SE_COMM_WAKE 0x00040000 284dd48af36SAlexander Motin #define SATA_SE_DECODE_ERR 0x00080000 285dd48af36SAlexander Motin #define SATA_SE_PARITY_ERR 0x00100000 286dd48af36SAlexander Motin #define SATA_SE_CRC_ERR 0x00200000 287dd48af36SAlexander Motin #define SATA_SE_HANDSHAKE_ERR 0x00400000 288dd48af36SAlexander Motin #define SATA_SE_LINKSEQ_ERR 0x00800000 289dd48af36SAlexander Motin #define SATA_SE_TRANSPORT_ERR 0x01000000 290dd48af36SAlexander Motin #define SATA_SE_UNKNOWN_FIS 0x02000000 291dd48af36SAlexander Motin #define SATA_SC 0x308 /* SControl */ 292dd48af36SAlexander Motin #define SATA_SC_DET_MASK 0x0000000f 293dd48af36SAlexander Motin #define SATA_SC_DET_IDLE 0x00000000 294dd48af36SAlexander Motin #define SATA_SC_DET_RESET 0x00000001 295dd48af36SAlexander Motin #define SATA_SC_DET_DISABLE 0x00000004 296dd48af36SAlexander Motin 297dd48af36SAlexander Motin #define SATA_SC_SPD_MASK 0x000000f0 298dd48af36SAlexander Motin #define SATA_SC_SPD_NO_SPEED 0x00000000 299dd48af36SAlexander Motin #define SATA_SC_SPD_SPEED_GEN1 0x00000010 300dd48af36SAlexander Motin #define SATA_SC_SPD_SPEED_GEN2 0x00000020 301c21b342bSAlexander Motin #define SATA_SC_SPD_SPEED_GEN3 0x00000030 302dd48af36SAlexander Motin 303dd48af36SAlexander Motin #define SATA_SC_IPM_MASK 0x00000f00 304dd48af36SAlexander Motin #define SATA_SC_IPM_NONE 0x00000000 305dd48af36SAlexander Motin #define SATA_SC_IPM_DIS_PARTIAL 0x00000100 306dd48af36SAlexander Motin #define SATA_SC_IPM_DIS_SLUMBER 0x00000200 307dd48af36SAlexander Motin 308dd48af36SAlexander Motin #define SATA_SC_SPM_MASK 0x0000f000 309dd48af36SAlexander Motin #define SATA_SC_SPM_NONE 0x00000000 310dd48af36SAlexander Motin #define SATA_SC_SPM_PARTIAL 0x00001000 311dd48af36SAlexander Motin #define SATA_SC_SPM_SLUMBER 0x00002000 312dd48af36SAlexander Motin #define SATA_SC_SPM_ACTIVE 0x00004000 313dd48af36SAlexander Motin #define SATA_LTM 0x30c /* LTMode */ 314dd48af36SAlexander Motin #define SATA_PHYM3 0x310 /* PHY Mode 3 */ 315dd48af36SAlexander Motin #define SATA_PHYM4 0x314 /* PHY Mode 4 */ 316dd48af36SAlexander Motin #define SATA_PHYM1 0x32c /* PHY Mode 1 */ 317dd48af36SAlexander Motin #define SATA_PHYM2 0x330 /* PHY Mode 2 */ 318dd48af36SAlexander Motin #define SATA_BISTC 0x334 /* BIST Control */ 319dd48af36SAlexander Motin #define SATA_BISTDW1 0x338 /* BIST DW1 */ 320dd48af36SAlexander Motin #define SATA_BISTDW2 0x33c /* BIST DW2 */ 321dd48af36SAlexander Motin #define SATA_SATAICFG 0x050 /* Serial-ATA Interface Configuration */ 322dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKCNF_20MHZ (0 << 0) 323dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKCNF_25MHZ (1 << 0) 324dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKCNF_30MHZ (2 << 0) 325dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKCNF_40MHZ (3 << 0) 326dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKCNF_MASK (3 << 0) 327dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKDIV_1 (0 << 2) 328dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKDIV_2 (1 << 2) /* Used 20 or 25MHz */ 329dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKDIV_4 (2 << 2) /* Used 40MHz */ 330dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKDIV_3 (3 << 2) /* Used 30MHz */ 331dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKDIV_MASK (3 << 2) 332dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKFEEDDIV_50 (0 << 4) /* or 100, when Gen2En is 1 */ 333dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKFEEDDIV_60 (1 << 4) /* or 120. Used 25MHz */ 334dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKFEEDDIV_75 (2 << 4) /* or 150. Used 20MHz */ 335dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKFEEDDIV_90 (3 << 4) /* or 180 */ 336dd48af36SAlexander Motin #define SATA_SATAICFG_REFCLKFEEDDIV_MASK (3 << 4) 337dd48af36SAlexander Motin #define SATA_SATAICFG_PHYSSCEN (1 << 6) 338dd48af36SAlexander Motin #define SATA_SATAICFG_GEN2EN (1 << 7) 339dd48af36SAlexander Motin #define SATA_SATAICFG_COMMEN (1 << 8) 340dd48af36SAlexander Motin #define SATA_SATAICFG_PHYSHUTDOWN (1 << 9) 341dd48af36SAlexander Motin #define SATA_SATAICFG_TARGETMODE (1 << 10) /* 1 = Initiator */ 342dd48af36SAlexander Motin #define SATA_SATAICFG_COMCHANNEL (1 << 11) 343dd48af36SAlexander Motin #define SATA_SATAICFG_IGNOREBSY (1 << 24) 344dd48af36SAlexander Motin #define SATA_SATAICFG_LINKRSTEN (1 << 25) 345dd48af36SAlexander Motin #define SATA_SATAICFG_CMDRETXDS (1 << 26) 346dd48af36SAlexander Motin #define SATA_SATAICTL 0x344 /* Serial-ATA Interface Control */ 347dd48af36SAlexander Motin #define SATA_SATAICTL_PMPTX_MASK 0x0000000f 348dd48af36SAlexander Motin #define SATA_SATAICTL_PMPTX_SHIFT 0 349dd48af36SAlexander Motin #define SATA_SATAICTL_VUM (1 << 8) 350dd48af36SAlexander Motin #define SATA_SATAICTL_VUS (1 << 9) 351dd48af36SAlexander Motin #define SATA_SATAICTL_EDMAACT (1 << 16) 352dd48af36SAlexander Motin #define SATA_SATAICTL_CLEARSTAT (1 << 24) 353dd48af36SAlexander Motin #define SATA_SATAICTL_SRST (1 << 25) 354dd48af36SAlexander Motin #define SATA_SATAITC 0x348 /* Serial-ATA Interface Test Control */ 355dd48af36SAlexander Motin #define SATA_SATAIS 0x34c /* Serial-ATA Interface Status */ 356dd48af36SAlexander Motin #define SATA_VU 0x35c /* Vendor Unique */ 357dd48af36SAlexander Motin #define SATA_FISC 0x360 /* FIS Configuration */ 358dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4RDYEN_B0 (1 << 0) /* Device to Host FIS */ 359dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4RDYEN_B1 (1 << 1) /* SDB FIS rcv with <N>bit 0 */ 360dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4RDYEN_B2 (1 << 2) /* DMA Activate FIS */ 361dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4RDYEN_B3 (1 << 3) /* DMA Setup FIS */ 362dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4RDYEN_B4 (1 << 4) /* Data FIS first DW */ 363dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4RDYEN_B5 (1 << 5) /* Data FIS entire FIS */ 364dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4HOSTRDYEN_B0 (1 << 8) 365dd48af36SAlexander Motin /* Device to Host FIS with <ERR> or <DF> */ 366dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4HOSTRDYEN_B1 (1 << 9) /* SDB FIS rcv with <N>bit */ 367dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4HOSTRDYEN_B2 (1 << 10) /* SDB FIS rcv with <ERR> */ 368dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4HOSTRDYEN_B3 (1 << 11) /* BIST Acivate FIS */ 369dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4HOSTRDYEN_B4 (1 << 12) /* PIO Setup FIS */ 370dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4HOSTRDYEN_B5 (1 << 13) /* Data FIS with Link error */ 371dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4HOSTRDYEN_B6 (1 << 14) /* Unrecognized FIS type */ 372dd48af36SAlexander Motin #define SATA_FISC_FISWAIT4HOSTRDYEN_B7 (1 << 15) /* Any FIS */ 373dd48af36SAlexander Motin #define SATA_FISC_FISDMAACTIVATESYNCRESP (1 << 16) 374dd48af36SAlexander Motin #define SATA_FISC_FISUNRECTYPECONT (1 << 17) 375dd48af36SAlexander Motin #define SATA_FISIC 0x364 /* FIS Interrupt Cause */ 376dd48af36SAlexander Motin #define SATA_FISIM 0x368 /* FIS Interrupt Mask */ 377dd48af36SAlexander Motin #define SATA_FISDW0 0x370 /* FIS DW0 */ 378dd48af36SAlexander Motin #define SATA_FISDW1 0x374 /* FIS DW1 */ 379dd48af36SAlexander Motin #define SATA_FISDW2 0x378 /* FIS DW2 */ 380dd48af36SAlexander Motin #define SATA_FISDW3 0x37c /* FIS DW3 */ 381dd48af36SAlexander Motin #define SATA_FISDW4 0x380 /* FIS DW4 */ 382dd48af36SAlexander Motin #define SATA_FISDW5 0x384 /* FIS DW5 */ 383dd48af36SAlexander Motin #define SATA_FISDW6 0x388 /* FIS DW6 */ 384dd48af36SAlexander Motin 385b30c7d51SAlexander Motin #define SATA_PHYM9_GEN2 0x398 386b30c7d51SAlexander Motin #define SATA_PHYM9_GEN1 0x39c 387b30c7d51SAlexander Motin #define SATA_PHYCFG_OFS 0x3a0 /* 65nm SoCs only */ 388b30c7d51SAlexander Motin 389dd48af36SAlexander Motin #define MVS_MAX_PORTS 8 390dd48af36SAlexander Motin #define MVS_MAX_SLOTS 32 391dd48af36SAlexander Motin 392dd48af36SAlexander Motin /* Pessimistic prognosis on number of required S/G entries */ 393cd853791SKonstantin Belousov #define MVS_SG_ENTRIES (btoc(maxphys) + 1) 394dd48af36SAlexander Motin 395dd48af36SAlexander Motin /* EDMA Command Request Block (CRQB) Data */ 396dd48af36SAlexander Motin struct mvs_crqb { 397dd48af36SAlexander Motin uint32_t cprdbl; /* cPRD Desriptor Table Base Low Address */ 398dd48af36SAlexander Motin uint32_t cprdbh; /* cPRD Desriptor Table Base High Address */ 399dd48af36SAlexander Motin uint16_t ctrlflg; /* Control Flags */ 400dd48af36SAlexander Motin #define MVS_CRQB_READ 0x0001 401dd48af36SAlexander Motin #define MVS_CRQB_TAG_MASK 0x003e 402dd48af36SAlexander Motin #define MVS_CRQB_TAG_SHIFT 1 403dd48af36SAlexander Motin #define MVS_CRQB_PMP_MASK 0xf000 404dd48af36SAlexander Motin #define MVS_CRQB_PMP_SHIFT 12 405dd48af36SAlexander Motin uint8_t cmd[22]; 406dd48af36SAlexander Motin } __packed; 407dd48af36SAlexander Motin 408dd48af36SAlexander Motin struct mvs_crqb_gen2e { 409dd48af36SAlexander Motin uint32_t cprdbl; /* cPRD Desriptor Table Base Low Address */ 410dd48af36SAlexander Motin uint32_t cprdbh; /* cPRD Desriptor Table Base High Address */ 411dd48af36SAlexander Motin uint32_t ctrlflg; /* Control Flags */ 412dd48af36SAlexander Motin #define MVS_CRQB2E_READ 0x00000001 413dd48af36SAlexander Motin #define MVS_CRQB2E_DTAG_MASK 0x0000003e 414dd48af36SAlexander Motin #define MVS_CRQB2E_DTAG_SHIFT 1 415dd48af36SAlexander Motin #define MVS_CRQB2E_PMP_MASK 0x0000f000 416dd48af36SAlexander Motin #define MVS_CRQB2E_PMP_SHIFT 12 417dd48af36SAlexander Motin #define MVS_CRQB2E_CPRD 0x00010000 418dd48af36SAlexander Motin #define MVS_CRQB2E_HTAG_MASK 0x003e0000 419dd48af36SAlexander Motin #define MVS_CRQB2E_HTAG_SHIFT 17 420dd48af36SAlexander Motin uint32_t drbc; /* Data Region Byte Count */ 421dd48af36SAlexander Motin uint8_t cmd[16]; 422dd48af36SAlexander Motin } __packed; 423dd48af36SAlexander Motin 424dd48af36SAlexander Motin /* EDMA Phisical Region Descriptors (ePRD) Table Data Structure */ 425dd48af36SAlexander Motin struct mvs_eprd { 426dd48af36SAlexander Motin uint32_t prdbal; /* Address bits[31:1] */ 427dd48af36SAlexander Motin uint32_t bytecount; /* Byte Count */ 428dd48af36SAlexander Motin #define MVS_EPRD_MASK 0x0000ffff /* max 64KB */ 429dd48af36SAlexander Motin #define MVS_EPRD_MAX (MVS_EPRD_MASK + 1) 430dd48af36SAlexander Motin #define MVS_EPRD_EOF 0x80000000 431dd48af36SAlexander Motin uint32_t prdbah; /* Address bits[63:32] */ 432dd48af36SAlexander Motin uint32_t resv; 433dd48af36SAlexander Motin } __packed; 434dd48af36SAlexander Motin 435dd48af36SAlexander Motin /* Command request blocks. 32 commands. First 1Kbyte aligned. */ 436dd48af36SAlexander Motin #define MVS_CRQB_OFFSET 0 437dd48af36SAlexander Motin #define MVS_CRQB_SIZE 32 /* sizeof(struct mvs_crqb) */ 438dd48af36SAlexander Motin #define MVS_CRQB_MASK 0x000003e0 439dd48af36SAlexander Motin #define MVS_CRQB_SHIFT 5 440dd48af36SAlexander Motin #define MVS_CRQB_TO_ADDR(slot) ((slot) << MVS_CRQB_SHIFT) 441dd48af36SAlexander Motin #define MVS_ADDR_TO_CRQB(addr) (((addr) & MVS_CRQB_MASK) >> MVS_CRQB_SHIFT) 442dd48af36SAlexander Motin /* ePRD blocks. Up to 32 commands, Each 16byte aligned. */ 443dd48af36SAlexander Motin #define MVS_EPRD_OFFSET (MVS_CRQB_OFFSET + MVS_CRQB_SIZE * MVS_MAX_SLOTS) 444dd48af36SAlexander Motin #define MVS_EPRD_SIZE (MVS_SG_ENTRIES * 16) /* sizeof(struct mvs_eprd) */ 445dd48af36SAlexander Motin /* Request work area. */ 446dd48af36SAlexander Motin #define MVS_WORKRQ_SIZE (MVS_EPRD_OFFSET + MVS_EPRD_SIZE * MVS_MAX_SLOTS) 447dd48af36SAlexander Motin 448dd48af36SAlexander Motin /* EDMA Command Response Block (CRPB) Data */ 449dd48af36SAlexander Motin struct mvs_crpb { 450dd48af36SAlexander Motin uint16_t id; /* CRPB ID */ 451dd48af36SAlexander Motin #define MVS_CRPB_TAG_MASK 0x001F 452dd48af36SAlexander Motin #define MVS_CRPB_TAG_SHIFT 0 453dd48af36SAlexander Motin uint16_t rspflg; /* CPRB Response Flags */ 454dd48af36SAlexander Motin #define MVS_CRPB_EDMASTS_MASK 0x007F 455dd48af36SAlexander Motin #define MVS_CRPB_EDMASTS_SHIFT 0 456dd48af36SAlexander Motin #define MVS_CRPB_ATASTS_MASK 0xFF00 457dd48af36SAlexander Motin #define MVS_CRPB_ATASTS_SHIFT 8 458dd48af36SAlexander Motin uint32_t ts; /* CPRB Time Stamp */ 459dd48af36SAlexander Motin } __packed; 460dd48af36SAlexander Motin 461dd48af36SAlexander Motin /* Command response blocks. 32 commands. First 256byte aligned. */ 462dd48af36SAlexander Motin #define MVS_CRPB_OFFSET 0 463dd48af36SAlexander Motin #define MVS_CRPB_SIZE sizeof(struct mvs_crpb) 464dd48af36SAlexander Motin #define MVS_CRPB_MASK 0x000000f8 465dd48af36SAlexander Motin #define MVS_CRPB_SHIFT 3 466dd48af36SAlexander Motin #define MVS_CRPB_TO_ADDR(slot) ((slot) << MVS_CRPB_SHIFT) 467dd48af36SAlexander Motin #define MVS_ADDR_TO_CRPB(addr) (((addr) & MVS_CRPB_MASK) >> MVS_CRPB_SHIFT) 468dd48af36SAlexander Motin /* Request work area. */ 469dd48af36SAlexander Motin #define MVS_WORKRP_SIZE (MVS_CRPB_OFFSET + MVS_CRPB_SIZE * MVS_MAX_SLOTS) 470dd48af36SAlexander Motin 471dd48af36SAlexander Motin /* misc defines */ 472dd48af36SAlexander Motin #define ATA_IRQ_RID 0 473dd48af36SAlexander Motin #define ATA_INTR_FLAGS (INTR_MPSAFE|INTR_TYPE_BIO|INTR_ENTROPY) 474dd48af36SAlexander Motin 475dd48af36SAlexander Motin struct ata_dmaslot { 476dd48af36SAlexander Motin bus_dmamap_t data_map; /* Data DMA map */ 477dd48af36SAlexander Motin bus_addr_t addr; /* Data address */ 478dd48af36SAlexander Motin uint16_t len; /* Data size */ 479dd48af36SAlexander Motin }; 480dd48af36SAlexander Motin 481dd48af36SAlexander Motin /* structure holding DMA related information */ 482dd48af36SAlexander Motin struct mvs_dma { 483dd48af36SAlexander Motin bus_dma_tag_t workrq_tag; /* Request workspace DMA tag */ 484dd48af36SAlexander Motin bus_dmamap_t workrq_map; /* Request workspace DMA map */ 485dd48af36SAlexander Motin uint8_t *workrq; /* Request workspace */ 486dd48af36SAlexander Motin bus_addr_t workrq_bus; /* Request bus address */ 487dd48af36SAlexander Motin bus_dma_tag_t workrp_tag; /* Reply workspace DMA tag */ 488dd48af36SAlexander Motin bus_dmamap_t workrp_map; /* Reply workspace DMA map */ 489dd48af36SAlexander Motin uint8_t *workrp; /* Reply workspace */ 490dd48af36SAlexander Motin bus_addr_t workrp_bus; /* Reply bus address */ 491dd48af36SAlexander Motin bus_dma_tag_t data_tag; /* Data DMA tag */ 492dd48af36SAlexander Motin }; 493dd48af36SAlexander Motin 494dd48af36SAlexander Motin enum mvs_slot_states { 495dd48af36SAlexander Motin MVS_SLOT_EMPTY, 496dd48af36SAlexander Motin MVS_SLOT_LOADING, 497dd48af36SAlexander Motin MVS_SLOT_RUNNING, 498dd48af36SAlexander Motin MVS_SLOT_EXECUTING 499dd48af36SAlexander Motin }; 500dd48af36SAlexander Motin 501dd48af36SAlexander Motin struct mvs_slot { 502dd48af36SAlexander Motin device_t dev; /* Device handle */ 503dd48af36SAlexander Motin int slot; /* Number of this slot */ 504dd48af36SAlexander Motin int tag; /* Used command tag */ 505dd48af36SAlexander Motin enum mvs_slot_states state; /* Slot state */ 506cd853791SKonstantin Belousov u_int eprd_offset; /* EPRD offset */ 507dd48af36SAlexander Motin union ccb *ccb; /* CCB occupying slot */ 508dd48af36SAlexander Motin struct ata_dmaslot dma; /* DMA data of this slot */ 509dd48af36SAlexander Motin struct callout timeout; /* Execution timeout */ 510dd48af36SAlexander Motin }; 511dd48af36SAlexander Motin 512dd48af36SAlexander Motin struct mvs_device { 513dd48af36SAlexander Motin int revision; 514dd48af36SAlexander Motin int mode; 515dd48af36SAlexander Motin u_int bytecount; 516dd48af36SAlexander Motin u_int atapi; 517dd48af36SAlexander Motin u_int tags; 518dd48af36SAlexander Motin u_int caps; 519dd48af36SAlexander Motin }; 520dd48af36SAlexander Motin 521dd48af36SAlexander Motin enum mvs_edma_mode { 522dd48af36SAlexander Motin MVS_EDMA_UNKNOWN, 523dd48af36SAlexander Motin MVS_EDMA_OFF, 524dd48af36SAlexander Motin MVS_EDMA_ON, 525dd48af36SAlexander Motin MVS_EDMA_QUEUED, 526dd48af36SAlexander Motin MVS_EDMA_NCQ, 527dd48af36SAlexander Motin }; 528dd48af36SAlexander Motin 529dd48af36SAlexander Motin /* structure describing an ATA channel */ 530dd48af36SAlexander Motin struct mvs_channel { 531dd48af36SAlexander Motin device_t dev; /* Device handle */ 532dd48af36SAlexander Motin int unit; /* Physical channel */ 533dd48af36SAlexander Motin struct resource *r_mem; /* Memory of this channel */ 534dd48af36SAlexander Motin struct resource *r_irq; /* Interrupt of this channel */ 535dd48af36SAlexander Motin void *ih; /* Interrupt handle */ 536dd48af36SAlexander Motin struct mvs_dma dma; /* DMA data */ 537dd48af36SAlexander Motin struct cam_sim *sim; 538dd48af36SAlexander Motin struct cam_path *path; 539dd48af36SAlexander Motin int quirks; 540dd48af36SAlexander Motin #define MVS_Q_GENI 1 541dd48af36SAlexander Motin #define MVS_Q_GENII 2 542dd48af36SAlexander Motin #define MVS_Q_GENIIE 4 543dd48af36SAlexander Motin #define MVS_Q_SOC 8 544dd48af36SAlexander Motin #define MVS_Q_CT 16 545b30c7d51SAlexander Motin #define MVS_Q_SOC65 32 546dd48af36SAlexander Motin int pm_level; /* power management level */ 547dd48af36SAlexander Motin 548dd48af36SAlexander Motin struct mvs_slot slot[MVS_MAX_SLOTS]; 549dd48af36SAlexander Motin union ccb *hold[MVS_MAX_SLOTS]; 5507bcc5957SAlexander Motin int holdtag[MVS_MAX_SLOTS]; /* Tags used for held commands. */ 551dd48af36SAlexander Motin struct mtx mtx; /* state lock */ 552dd48af36SAlexander Motin int devices; /* What is present */ 553dd48af36SAlexander Motin int pm_present; /* PM presence reported */ 554dd48af36SAlexander Motin enum mvs_edma_mode curr_mode; /* Current EDMA mode */ 555dd48af36SAlexander Motin int fbs_enabled; /* FIS-based switching enabled */ 556dd48af36SAlexander Motin uint32_t oslots; /* Occupied slots */ 557dd48af36SAlexander Motin uint32_t otagspd[16]; /* Occupied device tags */ 558dd48af36SAlexander Motin uint32_t rslots; /* Running slots */ 559dd48af36SAlexander Motin uint32_t aslots; /* Slots with atomic commands */ 560dd48af36SAlexander Motin uint32_t eslots; /* Slots in error */ 561dd48af36SAlexander Motin uint32_t toslots; /* Slots in timeout */ 562dd48af36SAlexander Motin int numrslots; /* Number of running slots */ 563dd48af36SAlexander Motin int numrslotspd[16];/* Number of running slots per dev */ 564dd48af36SAlexander Motin int numpslots; /* Number of PIO slots */ 565dd48af36SAlexander Motin int numdslots; /* Number of DMA slots */ 566dd48af36SAlexander Motin int numtslots; /* Number of NCQ slots */ 567dd48af36SAlexander Motin int numtslotspd[16];/* Number of NCQ slots per dev */ 5687bcc5957SAlexander Motin int numhslots; /* Number of held slots */ 56997fd3ac6SAlexander Motin int recoverycmd; /* Our READ LOG active */ 570453130d9SPedro F. Giffuni int fatalerr; /* Fatal error happened */ 571dd48af36SAlexander Motin int lastslot; /* Last used slot */ 572dd48af36SAlexander Motin int taggedtarget; /* Last tagged target */ 57370b7af2bSAlexander Motin int resetting; /* Hard-reset in progress. */ 57470b7af2bSAlexander Motin int resetpolldiv; /* Hard-reset poll divider. */ 575dd48af36SAlexander Motin int out_idx; /* Next written CRQB */ 576dd48af36SAlexander Motin int in_idx; /* Next read CRPB */ 577dd48af36SAlexander Motin u_int transfersize; /* PIO transfer size */ 578dd48af36SAlexander Motin u_int donecount; /* PIO bytes sent/received */ 579dd48af36SAlexander Motin u_int basic_dma; /* Basic DMA used for ATAPI */ 580dd48af36SAlexander Motin u_int fake_busy; /* Fake busy bit after command submission */ 581dd48af36SAlexander Motin union ccb *frozen; /* Frozen command */ 582dd48af36SAlexander Motin struct callout pm_timer; /* Power management events */ 58370b7af2bSAlexander Motin struct callout reset_timer; /* Hard-reset timeout */ 584dd48af36SAlexander Motin 585dd48af36SAlexander Motin struct mvs_device user[16]; /* User-specified settings */ 586dd48af36SAlexander Motin struct mvs_device curr[16]; /* Current settings */ 587dd48af36SAlexander Motin }; 588dd48af36SAlexander Motin 589dd48af36SAlexander Motin /* structure describing a MVS controller */ 590dd48af36SAlexander Motin struct mvs_controller { 591dd48af36SAlexander Motin device_t dev; 592dd48af36SAlexander Motin int r_rid; 593dd48af36SAlexander Motin struct resource *r_mem; 594dd48af36SAlexander Motin struct rman sc_iomem; 595dd48af36SAlexander Motin struct mvs_controller_irq { 596dd48af36SAlexander Motin struct resource *r_irq; 597dd48af36SAlexander Motin void *handle; 598dd48af36SAlexander Motin int r_irq_rid; 599dd48af36SAlexander Motin } irq; 600dd48af36SAlexander Motin int quirks; 601dd48af36SAlexander Motin int channels; 602dd48af36SAlexander Motin int ccc; /* CCC timeout */ 603dd48af36SAlexander Motin int cccc; /* CCC commands */ 604dd48af36SAlexander Motin struct mtx mtx; /* MIM access lock */ 605dd48af36SAlexander Motin int gmim; /* Globally wanted MIM bits */ 606dd48af36SAlexander Motin int pmim; /* Port wanted MIM bits */ 607dd48af36SAlexander Motin int mim; /* Current MIM bits */ 608dd48af36SAlexander Motin int msi; /* MSI enabled */ 609dd48af36SAlexander Motin int msia; /* MSI active */ 610dd48af36SAlexander Motin struct { 611dd48af36SAlexander Motin void (*function)(void *); 612dd48af36SAlexander Motin void *argument; 613dd48af36SAlexander Motin } interrupt[MVS_MAX_PORTS]; 614dd48af36SAlexander Motin }; 615dd48af36SAlexander Motin 616dd48af36SAlexander Motin enum mvs_err_type { 617dd48af36SAlexander Motin MVS_ERR_NONE, /* No error */ 618dd48af36SAlexander Motin MVS_ERR_INVALID, /* Error detected by us before submitting. */ 619dd48af36SAlexander Motin MVS_ERR_INNOCENT, /* Innocent victim. */ 620dd48af36SAlexander Motin MVS_ERR_TFE, /* Task File Error. */ 621dd48af36SAlexander Motin MVS_ERR_SATA, /* SATA error. */ 622dd48af36SAlexander Motin MVS_ERR_TIMEOUT, /* Command execution timeout. */ 623dd48af36SAlexander Motin MVS_ERR_NCQ, /* NCQ command error. CCB should be put on hold 624dd48af36SAlexander Motin * until READ LOG executed to reveal error. */ 625dd48af36SAlexander Motin }; 626dd48af36SAlexander Motin 627dd48af36SAlexander Motin struct mvs_intr_arg { 628dd48af36SAlexander Motin void *arg; 629dd48af36SAlexander Motin u_int cause; 630dd48af36SAlexander Motin }; 631dd48af36SAlexander Motin 632dd48af36SAlexander Motin /* macros to hide busspace uglyness */ 633dd48af36SAlexander Motin #define ATA_INB(res, offset) \ 634dd48af36SAlexander Motin bus_read_1((res), (offset)) 635dd48af36SAlexander Motin #define ATA_INW(res, offset) \ 636dd48af36SAlexander Motin bus_read_2((res), (offset)) 637dd48af36SAlexander Motin #define ATA_INL(res, offset) \ 638dd48af36SAlexander Motin bus_read_4((res), (offset)) 639dd48af36SAlexander Motin #define ATA_INSW(res, offset, addr, count) \ 640dd48af36SAlexander Motin bus_read_multi_2((res), (offset), (addr), (count)) 641dd48af36SAlexander Motin #define ATA_INSW_STRM(res, offset, addr, count) \ 642dd48af36SAlexander Motin bus_read_multi_stream_2((res), (offset), (addr), (count)) 643dd48af36SAlexander Motin #define ATA_INSL(res, offset, addr, count) \ 644dd48af36SAlexander Motin bus_read_multi_4((res), (offset), (addr), (count)) 645dd48af36SAlexander Motin #define ATA_INSL_STRM(res, offset, addr, count) \ 646dd48af36SAlexander Motin bus_read_multi_stream_4((res), (offset), (addr), (count)) 647dd48af36SAlexander Motin #define ATA_OUTB(res, offset, value) \ 648dd48af36SAlexander Motin bus_write_1((res), (offset), (value)) 649dd48af36SAlexander Motin #define ATA_OUTW(res, offset, value) \ 650dd48af36SAlexander Motin bus_write_2((res), (offset), (value)) 651dd48af36SAlexander Motin #define ATA_OUTL(res, offset, value) \ 652dd48af36SAlexander Motin bus_write_4((res), (offset), (value)); 653dd48af36SAlexander Motin #define ATA_OUTSW(res, offset, addr, count) \ 654dd48af36SAlexander Motin bus_write_multi_2((res), (offset), (addr), (count)) 655dd48af36SAlexander Motin #define ATA_OUTSW_STRM(res, offset, addr, count) \ 656dd48af36SAlexander Motin bus_write_multi_stream_2((res), (offset), (addr), (count)) 657dd48af36SAlexander Motin #define ATA_OUTSL(res, offset, addr, count) \ 658dd48af36SAlexander Motin bus_write_multi_4((res), (offset), (addr), (count)) 659dd48af36SAlexander Motin #define ATA_OUTSL_STRM(res, offset, addr, count) \ 660dd48af36SAlexander Motin bus_write_multi_stream_4((res), (offset), (addr), (count)) 661