1*433d6423SLionel Sambuc #ifndef _AHCI_H 2*433d6423SLionel Sambuc #define _AHCI_H 3*433d6423SLionel Sambuc 4*433d6423SLionel Sambuc #include <minix/drivers.h> 5*433d6423SLionel Sambuc 6*433d6423SLionel Sambuc #define NR_PORTS 32 /* maximum number of ports */ 7*433d6423SLionel Sambuc #define NR_CMDS 32 /* maximum number of queued commands */ 8*433d6423SLionel Sambuc 9*433d6423SLionel Sambuc /* Time values that can be set with options. */ 10*433d6423SLionel Sambuc #define SPINUP_TIMEOUT 5000 /* initial spin-up time (ms) */ 11*433d6423SLionel Sambuc #define DEVICE_TIMEOUT 30000 /* time to wait for device (ms) */ 12*433d6423SLionel Sambuc #define COMMAND_TIMEOUT 10000 /* time to wait for non-I/O cmd (ms) */ 13*433d6423SLionel Sambuc #define TRANSFER_TIMEOUT 30000 /* time to wait for I/O cmd (ms) */ 14*433d6423SLionel Sambuc #define FLUSH_TIMEOUT 60000 /* time to wait for flush cmd (ms) */ 15*433d6423SLionel Sambuc 16*433d6423SLionel Sambuc /* Time values that are defined by the standards. */ 17*433d6423SLionel Sambuc #define COMRESET_DELAY 1 /* time to assert port reset (ms) */ 18*433d6423SLionel Sambuc #define RESET_DELAY 1000 /* maximum HBA reset time (ms) */ 19*433d6423SLionel Sambuc #define PORTREG_DELAY 500 /* maximum port register update (ms) */ 20*433d6423SLionel Sambuc 21*433d6423SLionel Sambuc /* Other hardcoded time values. */ 22*433d6423SLionel Sambuc #define DEVICE_DELAY 100 /* time between device checks (ms) */ 23*433d6423SLionel Sambuc 24*433d6423SLionel Sambuc /* Generic FIS layout. */ 25*433d6423SLionel Sambuc #define ATA_FIS_TYPE 0 /* FIS Type */ 26*433d6423SLionel Sambuc #define ATA_FIS_TYPE_H2D 0x27 /* Register - Host to Device */ 27*433d6423SLionel Sambuc 28*433d6423SLionel Sambuc /* Register - Host to Device FIS layout. */ 29*433d6423SLionel Sambuc #define ATA_H2D_SIZE 20 /* byte size of H2D FIS */ 30*433d6423SLionel Sambuc #define ATA_H2D_FLAGS 1 /* C and PM Port */ 31*433d6423SLionel Sambuc #define ATA_H2D_FLAGS_C 0x80 /* update command register */ 32*433d6423SLionel Sambuc #define ATA_H2D_CMD 2 /* Command */ 33*433d6423SLionel Sambuc #define ATA_CMD_READ_DMA_EXT 0x25 /* READ DMA EXT */ 34*433d6423SLionel Sambuc #define ATA_CMD_WRITE_DMA_EXT 0x35 /* WRITE DMA EXT */ 35*433d6423SLionel Sambuc #define ATA_CMD_READ_FPDMA_QUEUED 0x60 /* READ FPDMA QUEUED */ 36*433d6423SLionel Sambuc #define ATA_CMD_WRITE_FPDMA_QUEUED 0x61 /* WRITE FPDMA QUEUED */ 37*433d6423SLionel Sambuc #define ATA_CMD_WRITE_DMA_FUA_EXT 0x3D /* WRITE DMA FUA EXT */ 38*433d6423SLionel Sambuc #define ATA_CMD_PACKET 0xA0 /* PACKET */ 39*433d6423SLionel Sambuc #define ATA_CMD_IDENTIFY_PACKET 0xA1 /* IDENTIFY PACKET DEVICE */ 40*433d6423SLionel Sambuc #define ATA_CMD_FLUSH_CACHE 0xE7 /* FLUSH CACHE */ 41*433d6423SLionel Sambuc #define ATA_CMD_IDENTIFY 0xEC /* IDENTIFY DEVICE */ 42*433d6423SLionel Sambuc #define ATA_CMD_SET_FEATURES 0xEF /* SET FEATURES */ 43*433d6423SLionel Sambuc #define ATA_H2D_FEAT 3 /* Features */ 44*433d6423SLionel Sambuc #define ATA_FEAT_PACKET_DMA 0x01 /* use DMA */ 45*433d6423SLionel Sambuc #define ATA_FEAT_PACKET_DMADIR 0x03 /* DMA is inbound */ 46*433d6423SLionel Sambuc #define ATA_H2D_LBA_LOW 4 /* LBA Low */ 47*433d6423SLionel Sambuc #define ATA_H2D_LBA_MID 5 /* LBA Mid */ 48*433d6423SLionel Sambuc #define ATA_H2D_LBA_HIGH 6 /* LBA High */ 49*433d6423SLionel Sambuc #define ATA_H2D_DEV 7 /* Device */ 50*433d6423SLionel Sambuc #define ATA_DEV_LBA 0x40 /* use LBA addressing */ 51*433d6423SLionel Sambuc #define ATA_DEV_FUA 0x80 /* Force Unit Access (FPDMA) */ 52*433d6423SLionel Sambuc #define ATA_H2D_LBA_LOW_EXP 8 /* LBA Low (exp) */ 53*433d6423SLionel Sambuc #define ATA_H2D_LBA_MID_EXP 9 /* LBA Mid (exp) */ 54*433d6423SLionel Sambuc #define ATA_H2D_LBA_HIGH_EXP 10 /* LBA High (exp) */ 55*433d6423SLionel Sambuc #define ATA_H2D_FEAT_EXP 11 /* Features (exp) */ 56*433d6423SLionel Sambuc #define ATA_H2D_SEC 12 /* Sector Count */ 57*433d6423SLionel Sambuc #define ATA_SEC_TAG_SHIFT 3 /* NCQ command tag */ 58*433d6423SLionel Sambuc #define ATA_H2D_SEC_EXP 13 /* Sector Count (exp) */ 59*433d6423SLionel Sambuc #define ATA_H2D_CTL 15 /* Control */ 60*433d6423SLionel Sambuc 61*433d6423SLionel Sambuc #define ATA_IS_FPDMA_CMD(c) \ 62*433d6423SLionel Sambuc ((c) == ATA_CMD_READ_FPDMA_QUEUED || \ 63*433d6423SLionel Sambuc (c) == ATA_CMD_WRITE_FPDMA_QUEUED) 64*433d6423SLionel Sambuc 65*433d6423SLionel Sambuc /* ATA constants. */ 66*433d6423SLionel Sambuc #define ATA_SECTOR_SIZE 512 /* default sector size */ 67*433d6423SLionel Sambuc #define ATA_MAX_SECTORS 0x10000 /* max sectors per transfer */ 68*433d6423SLionel Sambuc 69*433d6423SLionel Sambuc #define ATA_ID_SIZE (256 * sizeof(u16_t)) /* IDENTIFY result size */ 70*433d6423SLionel Sambuc 71*433d6423SLionel Sambuc #define ATA_ID_GCAP 0 /* General capabililties */ 72*433d6423SLionel Sambuc #define ATA_ID_GCAP_ATAPI_MASK 0xC000 /* ATAPI device mask */ 73*433d6423SLionel Sambuc #define ATA_ID_GCAP_ATAPI 0x8000 /* ATAPI device */ 74*433d6423SLionel Sambuc #define ATA_ID_GCAP_ATA_MASK 0x8000 /* ATA device mask */ 75*433d6423SLionel Sambuc #define ATA_ID_GCAP_ATA 0x0000 /* ATA device */ 76*433d6423SLionel Sambuc #define ATA_ID_GCAP_TYPE_MASK 0x1F00 /* ATAPI device type */ 77*433d6423SLionel Sambuc #define ATA_ID_GCAP_TYPE_SHIFT 8 /* (one of ATAPI_TYPE_*) */ 78*433d6423SLionel Sambuc #define ATA_ID_GCAP_REMOVABLE 0x0080 /* Removable media device */ 79*433d6423SLionel Sambuc #define ATA_ID_GCAP_INCOMPLETE 0x0004 /* Incomplete response */ 80*433d6423SLionel Sambuc #define ATA_ID_CAP 49 /* Capabilities */ 81*433d6423SLionel Sambuc #define ATA_ID_CAP_DMA 0x0100 /* DMA supported (no DMADIR) */ 82*433d6423SLionel Sambuc #define ATA_ID_CAP_LBA 0x0200 /* LBA supported */ 83*433d6423SLionel Sambuc #define ATA_ID_DMADIR 62 /* DMADIR */ 84*433d6423SLionel Sambuc #define ATA_ID_DMADIR_DMADIR 0x8000 /* DMADIR required */ 85*433d6423SLionel Sambuc #define ATA_ID_DMADIR_DMA 0x0400 /* DMA supported (DMADIR) */ 86*433d6423SLionel Sambuc #define ATA_ID_QDEPTH 75 /* NCQ queue depth */ 87*433d6423SLionel Sambuc #define ATA_ID_QDEPTH_MASK 0x000F /* NCQ queue depth mask */ 88*433d6423SLionel Sambuc #define ATA_ID_SATA_CAP 76 /* SATA capabilities */ 89*433d6423SLionel Sambuc #define ATA_ID_SATA_CAP_NCQ 0x0100 /* NCQ support */ 90*433d6423SLionel Sambuc #define ATA_ID_SUP0 82 /* Features supported (1/3) */ 91*433d6423SLionel Sambuc #define ATA_ID_SUP0_WCACHE 0x0020 /* Write cache supported */ 92*433d6423SLionel Sambuc #define ATA_ID_SUP1 83 /* Features supported (2/3) */ 93*433d6423SLionel Sambuc #define ATA_ID_SUP1_VALID_MASK 0xC000 /* Word validity mask */ 94*433d6423SLionel Sambuc #define ATA_ID_SUP1_VALID 0x4000 /* Word contents are valid */ 95*433d6423SLionel Sambuc #define ATA_ID_SUP1_FLUSH 0x1000 /* FLUSH CACHE supported */ 96*433d6423SLionel Sambuc #define ATA_ID_SUP1_LBA48 0x0400 /* 48-bit LBA supported */ 97*433d6423SLionel Sambuc #define ATA_ID_ENA0 85 /* Features enabled (1/3) */ 98*433d6423SLionel Sambuc #define ATA_ID_ENA0_WCACHE 0x0020 /* Write cache enabled */ 99*433d6423SLionel Sambuc #define ATA_ID_ENA2 87 /* Features enabled (3/3) */ 100*433d6423SLionel Sambuc #define ATA_ID_ENA2_VALID_MASK 0xC000 /* Word validity mask */ 101*433d6423SLionel Sambuc #define ATA_ID_ENA2_VALID 0x4000 /* Word contents are valid */ 102*433d6423SLionel Sambuc #define ATA_ID_ENA2_FUA 0x0040 /* Forced Unit Access sup. */ 103*433d6423SLionel Sambuc #define ATA_ID_LBA0 100 /* Max. LBA48 address (LSW) */ 104*433d6423SLionel Sambuc #define ATA_ID_LBA1 101 /* Max. LBA48 address */ 105*433d6423SLionel Sambuc #define ATA_ID_LBA2 102 /* Max. LBA48 address */ 106*433d6423SLionel Sambuc #define ATA_ID_LBA3 103 /* Max. LBA48 address (MSW) */ 107*433d6423SLionel Sambuc #define ATA_ID_PLSS 106 /* Phys./logical sector size */ 108*433d6423SLionel Sambuc #define ATA_ID_PLSS_VALID_MASK 0xC000 /* Word validity mask */ 109*433d6423SLionel Sambuc #define ATA_ID_PLSS_VALID 0x4000 /* Word contents are valid */ 110*433d6423SLionel Sambuc #define ATA_ID_PLSS_LLS 0x1000 /* Long logical sectors */ 111*433d6423SLionel Sambuc #define ATA_ID_LSS0 118 /* Logical sector size (LSW) */ 112*433d6423SLionel Sambuc #define ATA_ID_LSS1 119 /* Logical sector size (MSW) */ 113*433d6423SLionel Sambuc 114*433d6423SLionel Sambuc #define ATA_SF_EN_WCACHE 0x02 /* Enable write cache */ 115*433d6423SLionel Sambuc #define ATA_SF_DI_WCACHE 0x82 /* Disable write cache */ 116*433d6423SLionel Sambuc 117*433d6423SLionel Sambuc /* ATAPI constants. */ 118*433d6423SLionel Sambuc #define ATAPI_PACKET_SIZE 16 /* ATAPI packet size */ 119*433d6423SLionel Sambuc 120*433d6423SLionel Sambuc #define ATAPI_TYPE_CDROM 5 /* CD-ROM device */ 121*433d6423SLionel Sambuc 122*433d6423SLionel Sambuc #define ATAPI_CMD_TEST_UNIT 0x00 /* Test Unit Ready */ 123*433d6423SLionel Sambuc #define ATAPI_CMD_REQUEST_SENSE 0x03 /* Request Sense */ 124*433d6423SLionel Sambuc #define ATAPI_REQUEST_SENSE_LEN 18 /* result length */ 125*433d6423SLionel Sambuc #define ATAPI_SENSE_UNIT_ATT 6 /* Unit Attention */ 126*433d6423SLionel Sambuc #define ATAPI_CMD_START_STOP 0x1B /* Start/Stop Unit */ 127*433d6423SLionel Sambuc #define ATAPI_START_STOP_EJECT 0x02 /* eject the medium */ 128*433d6423SLionel Sambuc #define ATAPI_START_STOP_LOAD 0x03 /* load the medium */ 129*433d6423SLionel Sambuc #define ATAPI_CMD_READ_CAPACITY 0x25 /* Read Capacity */ 130*433d6423SLionel Sambuc #define ATAPI_READ_CAPACITY_LEN 8 /* result length */ 131*433d6423SLionel Sambuc #define ATAPI_CMD_READ 0xA8 /* Read (12) */ 132*433d6423SLionel Sambuc #define ATAPI_CMD_WRITE 0xAA /* Write (12) */ 133*433d6423SLionel Sambuc 134*433d6423SLionel Sambuc /* Command List constants. */ 135*433d6423SLionel Sambuc #define AHCI_CL_ENTRY_SIZE 32 /* Command List header size */ 136*433d6423SLionel Sambuc #define AHCI_CL_ENTRY_DWORDS (AHCI_CL_ENTRY_SIZE / sizeof(u32_t)) 137*433d6423SLionel Sambuc 138*433d6423SLionel Sambuc #define AHCI_CL_PRDTL_SHIFT 16 /* PRD Table Length */ 139*433d6423SLionel Sambuc #define AHCI_CL_PREFETCHABLE (1L << 7) /* Prefetchable */ 140*433d6423SLionel Sambuc #define AHCI_CL_WRITE (1L << 6) /* Write */ 141*433d6423SLionel Sambuc #define AHCI_CL_ATAPI (1L << 5) /* ATAPI */ 142*433d6423SLionel Sambuc #define AHCI_CL_CFL_SHIFT 0 /* Command FIS Length */ 143*433d6423SLionel Sambuc 144*433d6423SLionel Sambuc /* Command Table offsets. */ 145*433d6423SLionel Sambuc #define AHCI_CT_PACKET_OFF 0x40 /* CT offset to ATAPI packet */ 146*433d6423SLionel Sambuc #define AHCI_CT_PRDT_OFF 0x80 /* CT offset to PRD table */ 147*433d6423SLionel Sambuc 148*433d6423SLionel Sambuc /* Host Bus Adapter (HBA) constants. */ 149*433d6423SLionel Sambuc #define AHCI_HBA_CAP 0 /* Host Capabilities */ 150*433d6423SLionel Sambuc #define AHCI_HBA_CAP_SNCQ (1L << 30) /* Native Cmd Queuing */ 151*433d6423SLionel Sambuc #define AHCI_HBA_CAP_SCLO (1L << 24) /* Cmd List Override */ 152*433d6423SLionel Sambuc #define AHCI_HBA_CAP_NCS_SHIFT 8 /* Nr of Cmd Slots */ 153*433d6423SLionel Sambuc #define AHCI_HBA_CAP_NCS_MASK 0x1FL 154*433d6423SLionel Sambuc #define AHCI_HBA_CAP_NP_SHIFT 0 /* Nr of Ports */ 155*433d6423SLionel Sambuc #define AHCI_HBA_CAP_NP_MASK 0x1FL 156*433d6423SLionel Sambuc #define AHCI_HBA_GHC 1 /* Global Host Control */ 157*433d6423SLionel Sambuc #define AHCI_HBA_GHC_AE (1L << 31) /* AHCI Enable */ 158*433d6423SLionel Sambuc #define AHCI_HBA_GHC_IE (1L << 1) /* Interrupt Enable */ 159*433d6423SLionel Sambuc #define AHCI_HBA_GHC_HR (1L << 0) /* HBA Reset */ 160*433d6423SLionel Sambuc #define AHCI_HBA_IS 2 /* Interrupt Status */ 161*433d6423SLionel Sambuc #define AHCI_HBA_PI 3 /* Ports Implemented */ 162*433d6423SLionel Sambuc #define AHCI_HBA_VS 4 /* Version */ 163*433d6423SLionel Sambuc #define AHCI_HBA_CAP2 9 /* Host Capabilities Extended */ 164*433d6423SLionel Sambuc 165*433d6423SLionel Sambuc /* Port constants. */ 166*433d6423SLionel Sambuc #define AHCI_PORT_CLB 0 /* Command List Base */ 167*433d6423SLionel Sambuc #define AHCI_PORT_CLBU 1 /* Command List Base, Upper 32 bits */ 168*433d6423SLionel Sambuc #define AHCI_PORT_FB 2 /* FIS Base */ 169*433d6423SLionel Sambuc #define AHCI_PORT_FBU 3 /* FIS Base, Upper 32 bits */ 170*433d6423SLionel Sambuc #define AHCI_PORT_IS 4 /* Interrupt Status */ 171*433d6423SLionel Sambuc #define AHCI_PORT_IS_TFES (1L << 30) /* Task File Error */ 172*433d6423SLionel Sambuc #define AHCI_PORT_IS_HBFS (1L << 29) /* Host Bus Fatal */ 173*433d6423SLionel Sambuc #define AHCI_PORT_IS_HBDS (1L << 28) /* Host Bus Data */ 174*433d6423SLionel Sambuc #define AHCI_PORT_IS_IFS (1L << 27) /* Interface Fatal */ 175*433d6423SLionel Sambuc #define AHCI_PORT_IS_PRCS (1L << 22) /* PhyRdy Change */ 176*433d6423SLionel Sambuc #define AHCI_PORT_IS_PCS (1L << 6) /* Port Conn Change */ 177*433d6423SLionel Sambuc #define AHCI_PORT_IS_SDBS (1L << 3) /* Set Dev Bits FIS */ 178*433d6423SLionel Sambuc #define AHCI_PORT_IS_PSS (1L << 1) /* PIO Setup FIS */ 179*433d6423SLionel Sambuc #define AHCI_PORT_IS_DHRS (1L << 0) /* D2H Register FIS */ 180*433d6423SLionel Sambuc #define AHCI_PORT_IS_RESTART \ 181*433d6423SLionel Sambuc (AHCI_PORT_IS_TFES | AHCI_PORT_IS_HBFS | AHCI_PORT_IS_HBDS | \ 182*433d6423SLionel Sambuc AHCI_PORT_IS_IFS) 183*433d6423SLionel Sambuc #define AHCI_PORT_IS_MASK \ 184*433d6423SLionel Sambuc (AHCI_PORT_IS_RESTART | AHCI_PORT_IS_PRCS | AHCI_PORT_IS_DHRS | \ 185*433d6423SLionel Sambuc AHCI_PORT_IS_PSS | AHCI_PORT_IS_SDBS) 186*433d6423SLionel Sambuc #define AHCI_PORT_IE 5 /* Interrupt Enable */ 187*433d6423SLionel Sambuc #define AHCI_PORT_IE_MASK AHCI_PORT_IS_MASK 188*433d6423SLionel Sambuc #define AHCI_PORT_IE_PRCE AHCI_PORT_IS_PRCS 189*433d6423SLionel Sambuc #define AHCI_PORT_IE_PCE AHCI_PORT_IS_PCS 190*433d6423SLionel Sambuc #define AHCI_PORT_IE_NONE 0L 191*433d6423SLionel Sambuc #define AHCI_PORT_CMD 6 /* Command and Status */ 192*433d6423SLionel Sambuc #define AHCI_PORT_CMD_CR (1L << 15) /* Cmd List Running */ 193*433d6423SLionel Sambuc #define AHCI_PORT_CMD_FR (1L << 14) /* FIS Recv Running */ 194*433d6423SLionel Sambuc #define AHCI_PORT_CMD_FRE (1L << 4) /* FIS Recv Enabled */ 195*433d6423SLionel Sambuc #define AHCI_PORT_CMD_CLO (1L << 3) /* Cmd List Override */ 196*433d6423SLionel Sambuc #define AHCI_PORT_CMD_SUD (1L << 1) /* Spin-Up Device */ 197*433d6423SLionel Sambuc #define AHCI_PORT_CMD_ST (1L << 0) /* Start */ 198*433d6423SLionel Sambuc #define AHCI_PORT_TFD 8 /* Task File Data */ 199*433d6423SLionel Sambuc #define AHCI_PORT_TFD_STS_BSY (1L << 7) /* Busy */ 200*433d6423SLionel Sambuc #define AHCI_PORT_TFD_STS_DF (1L << 5) /* Device Fault */ 201*433d6423SLionel Sambuc #define AHCI_PORT_TFD_STS_DRQ (1L << 3) /* Data Xfer Req'd */ 202*433d6423SLionel Sambuc #define AHCI_PORT_TFD_STS_ERR (1L << 0) /* Error */ 203*433d6423SLionel Sambuc #define AHCI_PORT_TFD_STS_INIT 0x7F /* Initial state */ 204*433d6423SLionel Sambuc #define AHCI_PORT_SIG 9 /* Signature */ 205*433d6423SLionel Sambuc #define ATA_SIG_ATA 0x00000101L /* ATA interface */ 206*433d6423SLionel Sambuc #define ATA_SIG_ATAPI 0xEB140101L /* ATAPI interface */ 207*433d6423SLionel Sambuc #define AHCI_PORT_SSTS 10 /* Serial ATA Status */ 208*433d6423SLionel Sambuc #define AHCI_PORT_SSTS_DET_MASK 0x00000007L /* Detection Mask */ 209*433d6423SLionel Sambuc #define AHCI_PORT_SSTS_DET_DET 0x00000001L /* Device Detected */ 210*433d6423SLionel Sambuc #define AHCI_PORT_SSTS_DET_PHY 0x00000003L /* PHY Comm Establ */ 211*433d6423SLionel Sambuc #define AHCI_PORT_SCTL 11 /* Serial ATA Control */ 212*433d6423SLionel Sambuc #define AHCI_PORT_SCTL_DET_INIT 0x00000001L /* Perform Init Seq */ 213*433d6423SLionel Sambuc #define AHCI_PORT_SCTL_DET_NONE 0x00000000L /* No Action Req'd */ 214*433d6423SLionel Sambuc #define AHCI_PORT_SERR 12 /* Serial ATA Error */ 215*433d6423SLionel Sambuc #define AHCI_PORT_SERR_DIAG_X (1L << 26) /* Exchanged */ 216*433d6423SLionel Sambuc #define AHCI_PORT_SERR_DIAG_N (1L << 16) /* PhyRdy Change */ 217*433d6423SLionel Sambuc #define AHCI_PORT_SACT 13 /* Serial ATA Active */ 218*433d6423SLionel Sambuc #define AHCI_PORT_CI 14 /* Command Issue */ 219*433d6423SLionel Sambuc 220*433d6423SLionel Sambuc /* Number of Physical Region Descriptors (PRDs). Must be at least NR_IOREQS+2, 221*433d6423SLionel Sambuc * and at most 1024. There is currently no reason to use more than the minimum. 222*433d6423SLionel Sambuc */ 223*433d6423SLionel Sambuc #define NR_PRDS (NR_IOREQS + 2) 224*433d6423SLionel Sambuc 225*433d6423SLionel Sambuc /* Various size constants. */ 226*433d6423SLionel Sambuc #define AHCI_MEM_BASE_SIZE 0x100 /* memory-mapped base region size */ 227*433d6423SLionel Sambuc #define AHCI_MEM_PORT_SIZE 0x80 /* memory-mapped port region size */ 228*433d6423SLionel Sambuc 229*433d6423SLionel Sambuc #define AHCI_FIS_SIZE 256 /* size of FIS receive buffer */ 230*433d6423SLionel Sambuc #define AHCI_CL_SIZE 1024 /* size of command list buffer */ 231*433d6423SLionel Sambuc #define AHCI_TMP_SIZE ATA_ID_SIZE /* size of temporary storage buffer */ 232*433d6423SLionel Sambuc #define AHCI_TMP_ALIGN 2 /* required alignment for temp buf */ 233*433d6423SLionel Sambuc #define AHCI_CT_SIZE (128 + NR_PRDS * sizeof(u32_t) * 4) 234*433d6423SLionel Sambuc /* size of command table buffer */ 235*433d6423SLionel Sambuc #define AHCI_CT_ALIGN 128 /* required alignment for CT buffer */ 236*433d6423SLionel Sambuc 237*433d6423SLionel Sambuc #define MAX_PRD_BYTES (1L << 22) /* maximum number of bytes per PRD */ 238*433d6423SLionel Sambuc #define MAX_TRANSFER MAX_PRD_BYTES /* maximum size of a single transfer */ 239*433d6423SLionel Sambuc 240*433d6423SLionel Sambuc /* Command Frame Information Structure (FIS). For internal use only; 241*433d6423SLionel Sambuc * the contents of this structure are later converted to an actual FIS. 242*433d6423SLionel Sambuc */ 243*433d6423SLionel Sambuc typedef struct { 244*433d6423SLionel Sambuc u8_t cf_cmd; /* Command */ 245*433d6423SLionel Sambuc u8_t cf_feat; /* Features */ 246*433d6423SLionel Sambuc u32_t cf_lba; /* LBA (24-bit) */ 247*433d6423SLionel Sambuc u8_t cf_dev; /* Device */ 248*433d6423SLionel Sambuc u32_t cf_lba_exp; /* LBA (exp) (24-bit) */ 249*433d6423SLionel Sambuc u8_t cf_feat_exp; /* Features (exp) */ 250*433d6423SLionel Sambuc u8_t cf_sec; /* Sector Count */ 251*433d6423SLionel Sambuc u8_t cf_sec_exp; /* Sector Count (exp) */ 252*433d6423SLionel Sambuc u8_t cf_ctl; /* Control */ 253*433d6423SLionel Sambuc } cmd_fis_t; 254*433d6423SLionel Sambuc 255*433d6423SLionel Sambuc /* Physical Region Descriptor (PRD). For internal and sys_vumap() use only; 256*433d6423SLionel Sambuc * the contents of this structure are later converted to an actual PRD. 257*433d6423SLionel Sambuc */ 258*433d6423SLionel Sambuc typedef struct vumap_phys prd_t; 259*433d6423SLionel Sambuc 260*433d6423SLionel Sambuc /* These are from at_wini, as this driver is a drop-in replacement for at_wini. 261*433d6423SLionel Sambuc * Practically speaking this is already the upper limit with 256 minor device 262*433d6423SLionel Sambuc * numbers per driver, even though it means we can only ever expose 8 devices 263*433d6423SLionel Sambuc * out of potentially 32. 264*433d6423SLionel Sambuc */ 265*433d6423SLionel Sambuc #define MAX_DRIVES 8 266*433d6423SLionel Sambuc #define NR_MINORS (MAX_DRIVES * DEV_PER_DRIVE) 267*433d6423SLionel Sambuc #define NR_SUBDEVS (MAX_DRIVES * SUB_PER_DRIVE) 268*433d6423SLionel Sambuc 269*433d6423SLionel Sambuc /* Port states. */ 270*433d6423SLionel Sambuc enum { 271*433d6423SLionel Sambuc STATE_NO_PORT, /* this port is not present */ 272*433d6423SLionel Sambuc STATE_SPIN_UP, /* waiting for device or timeout after reset */ 273*433d6423SLionel Sambuc STATE_NO_DEV, /* no device has been detected on this port */ 274*433d6423SLionel Sambuc STATE_WAIT_DEV, /* waiting for functioning device to appear */ 275*433d6423SLionel Sambuc STATE_WAIT_ID, /* waiting for device identification */ 276*433d6423SLionel Sambuc STATE_BAD_DEV, /* an unusable device has been detected */ 277*433d6423SLionel Sambuc STATE_GOOD_DEV /* a usable device has been detected */ 278*433d6423SLionel Sambuc }; 279*433d6423SLionel Sambuc 280*433d6423SLionel Sambuc /* Command results. */ 281*433d6423SLionel Sambuc enum { 282*433d6423SLionel Sambuc RESULT_FAILURE, 283*433d6423SLionel Sambuc RESULT_SUCCESS 284*433d6423SLionel Sambuc }; 285*433d6423SLionel Sambuc 286*433d6423SLionel Sambuc /* Port flags. */ 287*433d6423SLionel Sambuc #define FLAG_ATAPI 0x00000001 /* is this an ATAPI device? */ 288*433d6423SLionel Sambuc #define FLAG_HAS_MEDIUM 0x00000002 /* is a medium present? */ 289*433d6423SLionel Sambuc #define FLAG_USE_DMADIR 0x00000004 /* use ATAPI DMADIR flag? */ 290*433d6423SLionel Sambuc #define FLAG_READONLY 0x00000008 /* is the device read-only? */ 291*433d6423SLionel Sambuc #define FLAG_BUSY 0x00000010 /* is an operation ongoing? */ 292*433d6423SLionel Sambuc #define FLAG_FAILURE 0x00000020 /* did the operation fail? */ 293*433d6423SLionel Sambuc #define FLAG_BARRIER 0x00000040 /* no access until unset */ 294*433d6423SLionel Sambuc #define FLAG_HAS_WCACHE 0x00000080 /* is a write cache present? */ 295*433d6423SLionel Sambuc #define FLAG_HAS_FLUSH 0x00000100 /* is FLUSH CACHE supported? */ 296*433d6423SLionel Sambuc #define FLAG_SUSPENDED 0x00000200 /* is the thread suspended? */ 297*433d6423SLionel Sambuc #define FLAG_HAS_FUA 0x00000400 /* is WRITE DMA FUA EX sup.? */ 298*433d6423SLionel Sambuc #define FLAG_HAS_NCQ 0x00000800 /* is NCQ supported? */ 299*433d6423SLionel Sambuc #define FLAG_NCQ_MODE 0x00001000 /* issuing NCQ commands? */ 300*433d6423SLionel Sambuc 301*433d6423SLionel Sambuc /* Mapping between devices and ports. */ 302*433d6423SLionel Sambuc #define NO_PORT -1 /* this device maps to no port */ 303*433d6423SLionel Sambuc #define NO_DEVICE -1 /* this port maps to no device */ 304*433d6423SLionel Sambuc 305*433d6423SLionel Sambuc /* Output verbosity levels. */ 306*433d6423SLionel Sambuc enum { 307*433d6423SLionel Sambuc V_NONE, /* no output at all; keep silent */ 308*433d6423SLionel Sambuc V_ERR, /* important error information only (the default) */ 309*433d6423SLionel Sambuc V_INFO, /* general information about the driver and devices */ 310*433d6423SLionel Sambuc V_DEV, /* device details, to help with detection problems */ 311*433d6423SLionel Sambuc V_REQ /* detailed information about requests */ 312*433d6423SLionel Sambuc }; 313*433d6423SLionel Sambuc 314*433d6423SLionel Sambuc #endif /* _AHCI_H */ 315