1*507c3241Smlf /* 2*507c3241Smlf * CDDL HEADER START 3*507c3241Smlf * 4*507c3241Smlf * The contents of this file are subject to the terms of the 5*507c3241Smlf * Common Development and Distribution License (the "License"). 6*507c3241Smlf * You may not use this file except in compliance with the License. 7*507c3241Smlf * 8*507c3241Smlf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*507c3241Smlf * or http://www.opensolaris.org/os/licensing. 10*507c3241Smlf * See the License for the specific language governing permissions 11*507c3241Smlf * and limitations under the License. 12*507c3241Smlf * 13*507c3241Smlf * When distributing Covered Code, include this CDDL HEADER in each 14*507c3241Smlf * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*507c3241Smlf * If applicable, add the following below this CDDL HEADER, with the 16*507c3241Smlf * fields enclosed by brackets "[]" replaced with your own identifying 17*507c3241Smlf * information: Portions Copyright [yyyy] [name of copyright owner] 18*507c3241Smlf * 19*507c3241Smlf * CDDL HEADER END 20*507c3241Smlf */ 21*507c3241Smlf 22*507c3241Smlf /* 23*507c3241Smlf * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24*507c3241Smlf * Use is subject to license terms. 25*507c3241Smlf */ 26*507c3241Smlf 27*507c3241Smlf #ifndef _ATA_COMMON_H 28*507c3241Smlf #define _ATA_COMMON_H 29*507c3241Smlf 30*507c3241Smlf #pragma ident "%Z%%M% %I% %E% SMI" 31*507c3241Smlf 32*507c3241Smlf #ifdef __cplusplus 33*507c3241Smlf extern "C" { 34*507c3241Smlf #endif 35*507c3241Smlf 36*507c3241Smlf #include <sys/varargs.h> 37*507c3241Smlf 38*507c3241Smlf #include <sys/scsi/scsi.h> 39*507c3241Smlf #include <sys/dktp/dadkio.h> 40*507c3241Smlf #include <sys/dktp/dadev.h> 41*507c3241Smlf #include <sys/dkio.h> 42*507c3241Smlf #include <sys/dktp/tgdk.h> 43*507c3241Smlf 44*507c3241Smlf #include <sys/ddi.h> 45*507c3241Smlf #include <sys/sunddi.h> 46*507c3241Smlf 47*507c3241Smlf #include "ghd.h" 48*507c3241Smlf 49*507c3241Smlf #include "pciide.h" 50*507c3241Smlf #include "ata_cmd.h" 51*507c3241Smlf #include "ata_fsm.h" 52*507c3241Smlf #include "ata_debug.h" 53*507c3241Smlf 54*507c3241Smlf 55*507c3241Smlf /* 56*507c3241Smlf * device types 57*507c3241Smlf */ 58*507c3241Smlf #define ATA_DEV_NONE 0 59*507c3241Smlf #define ATA_DEV_DISK 1 60*507c3241Smlf #define ATA_DEV_ATAPI 2 61*507c3241Smlf 62*507c3241Smlf /* 63*507c3241Smlf * Largest sector allowed in 28 bit mode 64*507c3241Smlf */ 65*507c3241Smlf #define MAX_28BIT_CAPACITY 0xfffffff 66*507c3241Smlf 67*507c3241Smlf 68*507c3241Smlf 69*507c3241Smlf /* 70*507c3241Smlf * ata-options property configuration bits 71*507c3241Smlf */ 72*507c3241Smlf 73*507c3241Smlf #define ATA_OPTIONS_DMA 0x01 74*507c3241Smlf 75*507c3241Smlf 76*507c3241Smlf 77*507c3241Smlf /* ad_flags (per-drive) */ 78*507c3241Smlf 79*507c3241Smlf #define AD_ATAPI 0x01 /* is an ATAPI drive */ 80*507c3241Smlf #define AD_DISK 0x02 81*507c3241Smlf #define AD_MUTEX_INIT 0x04 82*507c3241Smlf #define AD_NO_CDB_INTR 0x20 83*507c3241Smlf #define AD_1SECTOR 0x40 84*507c3241Smlf #define AD_INT13LBA 0x80 /* supports LBA at Int13 interface */ 85*507c3241Smlf #define AD_NORVRT 0x100 /* block revert-to-defaults */ 86*507c3241Smlf #define AD_EXT48 0x200 /* 48 bit (extended) LBA */ 87*507c3241Smlf #define ATAPIDRV(X) ((X)->ad_flags & AD_ATAPI) 88*507c3241Smlf 89*507c3241Smlf 90*507c3241Smlf /* max targets and luns */ 91*507c3241Smlf 92*507c3241Smlf #define ATA_MAXTARG 2 93*507c3241Smlf #define ATA_MAXLUN 16 94*507c3241Smlf 95*507c3241Smlf /* 96*507c3241Smlf * PCI-IDE Bus Mastering Scatter/Gather list size 97*507c3241Smlf */ 98*507c3241Smlf #define ATA_DMA_NSEGS 17 /* enough for at least 64K */ 99*507c3241Smlf 100*507c3241Smlf /* 101*507c3241Smlf * Controller port address defaults 102*507c3241Smlf */ 103*507c3241Smlf #define ATA_BASE0 0x1f0 104*507c3241Smlf #define ATA_BASE1 0x170 105*507c3241Smlf 106*507c3241Smlf /* 107*507c3241Smlf * port offsets from base address ioaddr1 108*507c3241Smlf */ 109*507c3241Smlf #define AT_DATA 0x00 /* data register */ 110*507c3241Smlf #define AT_ERROR 0x01 /* error register (read) */ 111*507c3241Smlf #define AT_FEATURE 0x01 /* features (write) */ 112*507c3241Smlf #define AT_COUNT 0x02 /* sector count */ 113*507c3241Smlf #define AT_SECT 0x03 /* sector number */ 114*507c3241Smlf #define AT_LCYL 0x04 /* cylinder low byte */ 115*507c3241Smlf #define AT_HCYL 0x05 /* cylinder high byte */ 116*507c3241Smlf #define AT_DRVHD 0x06 /* drive/head register */ 117*507c3241Smlf #define AT_STATUS 0x07 /* status/command register */ 118*507c3241Smlf #define AT_CMD 0x07 /* status/command register */ 119*507c3241Smlf 120*507c3241Smlf /* 121*507c3241Smlf * port offsets from base address ioaddr2 122*507c3241Smlf */ 123*507c3241Smlf #define AT_ALTSTATUS 0x00 /* alternate status (read) */ 124*507c3241Smlf #define AT_DEVCTL 0x00 /* device control (write) */ 125*507c3241Smlf 126*507c3241Smlf /* Device control register */ 127*507c3241Smlf #define ATDC_NIEN 0x02 /* disable interrupts */ 128*507c3241Smlf #define ATDC_SRST 0x04 /* controller reset */ 129*507c3241Smlf #define ATDC_D3 0x08 /* Mysterious bit, must be set */ 130*507c3241Smlf /* 131*507c3241Smlf * ATA-6 spec 132*507c3241Smlf * In 48-bit addressing, reading the LBA location and count 133*507c3241Smlf * registers when the high-order bit is set reads the "previous 134*507c3241Smlf * content" (LBA bits 47:24, count bits 15:8) instead of the 135*507c3241Smlf * "most recent" values (LBA bits 23:0, count bits 7:0). 136*507c3241Smlf */ 137*507c3241Smlf #define ATDC_HOB 0x80 /* High order bit */ 138*507c3241Smlf 139*507c3241Smlf /* 140*507c3241Smlf * Status bits from AT_STATUS register 141*507c3241Smlf */ 142*507c3241Smlf #define ATS_BSY 0x80 /* controller busy */ 143*507c3241Smlf #define ATS_DRDY 0x40 /* drive ready */ 144*507c3241Smlf #define ATS_DF 0x20 /* device fault */ 145*507c3241Smlf #define ATS_DSC 0x10 /* seek operation complete */ 146*507c3241Smlf #define ATS_DRQ 0x08 /* data request */ 147*507c3241Smlf #define ATS_CORR 0x04 /* ECC correction applied */ 148*507c3241Smlf #define ATS_IDX 0x02 /* disk revolution index */ 149*507c3241Smlf #define ATS_ERR 0x01 /* error flag */ 150*507c3241Smlf 151*507c3241Smlf /* 152*507c3241Smlf * Status bits from AT_ERROR register 153*507c3241Smlf */ 154*507c3241Smlf #define ATE_BBK_ICRC 0x80 /* bad block detected in ATA-1 */ 155*507c3241Smlf /* ICRC error in ATA-4 and newer */ 156*507c3241Smlf #define ATE_UNC 0x40 /* uncorrectable data error */ 157*507c3241Smlf #define ATE_MC 0x20 /* Media change */ 158*507c3241Smlf #define ATE_IDNF 0x10 /* ID not found */ 159*507c3241Smlf #define ATE_MCR 0x08 /* media change request */ 160*507c3241Smlf #define ATE_ABORT 0x04 /* aborted command */ 161*507c3241Smlf #define ATE_TKONF 0x02 /* track 0 not found */ 162*507c3241Smlf #define ATE_AMNF 0x01 /* address mark not found */ 163*507c3241Smlf 164*507c3241Smlf #define ATE_NM 0x02 /* no media */ 165*507c3241Smlf 166*507c3241Smlf /* 167*507c3241Smlf * Drive selectors for AT_DRVHD register 168*507c3241Smlf */ 169*507c3241Smlf #define ATDH_LBA 0x40 /* addressing in LBA mode not chs */ 170*507c3241Smlf #define ATDH_DRIVE0 0xa0 /* or into AT_DRVHD to select drive 0 */ 171*507c3241Smlf #define ATDH_DRIVE1 0xb0 /* or into AT_DRVHD to select drive 1 */ 172*507c3241Smlf 173*507c3241Smlf /* 174*507c3241Smlf * Feature register bits 175*507c3241Smlf */ 176*507c3241Smlf #define ATF_ATAPI_DMA 0x01 /* ATAPI DMA enable bit */ 177*507c3241Smlf 178*507c3241Smlf /* 179*507c3241Smlf * common bits and options for set features (ATC_SET_FEAT) 180*507c3241Smlf */ 181*507c3241Smlf #define FC_WRITE_CACHE_ON 0x02 182*507c3241Smlf #define FC_WRITE_CACHE_OFF 0x82 183*507c3241Smlf 184*507c3241Smlf /* Test which version of ATA is supported */ 185*507c3241Smlf #define IS_ATA_VERSION_SUPPORTED(idp, n) \ 186*507c3241Smlf ((idp->ai_majorversion != 0xffff) && \ 187*507c3241Smlf (idp->ai_majorversion & (1<<n))) 188*507c3241Smlf 189*507c3241Smlf /* Test if supported version >= ATA-n */ 190*507c3241Smlf #define IS_ATA_VERSION_GE(idp, n) \ 191*507c3241Smlf ((idp->ai_majorversion != 0xffff) && \ 192*507c3241Smlf (idp->ai_majorversion != 0) && \ 193*507c3241Smlf (idp->ai_majorversion >= (1<<n))) 194*507c3241Smlf 195*507c3241Smlf /* Test whether a device is a CD drive */ 196*507c3241Smlf #define IS_CDROM(dp) \ 197*507c3241Smlf ((dp->ad_flags & AD_ATAPI) && \ 198*507c3241Smlf ((dp->ad_id.ai_config >> 8) & DTYPE_MASK) == \ 199*507c3241Smlf DTYPE_RODIRECT) 200*507c3241Smlf 201*507c3241Smlf /* macros from old common hba code */ 202*507c3241Smlf 203*507c3241Smlf #define ATA_INTPROP(devi, pname, pval, plen) \ 204*507c3241Smlf (ddi_prop_op(DDI_DEV_T_ANY, (devi), PROP_LEN_AND_VAL_BUF, \ 205*507c3241Smlf DDI_PROP_DONTPASS, (pname), (caddr_t)(pval), (plen))) 206*507c3241Smlf 207*507c3241Smlf #define ATA_LONGPROP(devi, pname, pval, plen) \ 208*507c3241Smlf (ddi_getlongprop(DDI_DEV_T_ANY, (devi), DDI_PROP_DONTPASS, \ 209*507c3241Smlf (pname), (caddr_t)(pval), (plen))) 210*507c3241Smlf 211*507c3241Smlf /* 212*507c3241Smlf * 213*507c3241Smlf * per-controller soft-state data structure 214*507c3241Smlf * 215*507c3241Smlf */ 216*507c3241Smlf 217*507c3241Smlf #define CTL2DRV(cp, t, l) (cp->ac_drvp[t][l]) 218*507c3241Smlf 219*507c3241Smlf typedef struct ata_ctl { 220*507c3241Smlf 221*507c3241Smlf dev_info_t *ac_dip; 222*507c3241Smlf uint_t ac_flags; 223*507c3241Smlf uint_t ac_timing_flags; 224*507c3241Smlf struct ata_drv *ac_drvp[ATA_MAXTARG][ATA_MAXLUN]; 225*507c3241Smlf int ac_max_transfer; /* max transfer in sectors */ 226*507c3241Smlf uint_t ac_standby_time; /* timer value seconds */ 227*507c3241Smlf 228*507c3241Smlf ccc_t ac_ccc; /* for GHD module */ 229*507c3241Smlf struct ata_drv *ac_active_drvp; /* active drive, if any */ 230*507c3241Smlf struct ata_pkt *ac_active_pktp; /* active packet, if any */ 231*507c3241Smlf uchar_t ac_state; 232*507c3241Smlf 233*507c3241Smlf scsi_hba_tran_t *ac_atapi_tran; /* for atapi module */ 234*507c3241Smlf 235*507c3241Smlf /* 236*507c3241Smlf * port addresses associated with ioaddr1 237*507c3241Smlf */ 238*507c3241Smlf ddi_acc_handle_t ac_iohandle1; /* DDI I/O handle */ 239*507c3241Smlf caddr_t ac_ioaddr1; 240*507c3241Smlf ushort_t *ac_data; /* data register */ 241*507c3241Smlf uchar_t *ac_error; /* error register (read) */ 242*507c3241Smlf uchar_t *ac_feature; /* features (write) */ 243*507c3241Smlf uchar_t *ac_count; /* sector count */ 244*507c3241Smlf uchar_t *ac_sect; /* sector number */ 245*507c3241Smlf uchar_t *ac_lcyl; /* cylinder low byte */ 246*507c3241Smlf uchar_t *ac_hcyl; /* cylinder high byte */ 247*507c3241Smlf uchar_t *ac_drvhd; /* drive/head register */ 248*507c3241Smlf uchar_t *ac_status; /* status/command register */ 249*507c3241Smlf uchar_t *ac_cmd; /* status/command register */ 250*507c3241Smlf 251*507c3241Smlf /* 252*507c3241Smlf * port addresses associated with ioaddr2 253*507c3241Smlf */ 254*507c3241Smlf ddi_acc_handle_t ac_iohandle2; /* DDI I/O handle */ 255*507c3241Smlf caddr_t ac_ioaddr2; 256*507c3241Smlf uchar_t *ac_altstatus; /* alternate status (read) */ 257*507c3241Smlf uchar_t *ac_devctl; /* device control (write) */ 258*507c3241Smlf 259*507c3241Smlf /* 260*507c3241Smlf * handle and port addresss for PCI-IDE Bus Master controller 261*507c3241Smlf */ 262*507c3241Smlf ddi_acc_handle_t ac_bmhandle; /* DDI I/O handle */ 263*507c3241Smlf caddr_t ac_bmaddr; /* base addr of Bus Master Regs */ 264*507c3241Smlf uchar_t ac_pciide; /* PCI-IDE device */ 265*507c3241Smlf uchar_t ac_pciide_bm; /* Bus Mastering PCI-IDE device */ 266*507c3241Smlf 267*507c3241Smlf /* 268*507c3241Smlf * Scatter/Gather list for PCI-IDE Bus Mastering controllers 269*507c3241Smlf */ 270*507c3241Smlf caddr_t ac_sg_list; /* virtual addr of S/G list */ 271*507c3241Smlf paddr_t ac_sg_paddr; /* phys addr of S/G list */ 272*507c3241Smlf ddi_acc_handle_t ac_sg_acc_handle; 273*507c3241Smlf ddi_dma_handle_t ac_sg_handle; 274*507c3241Smlf 275*507c3241Smlf /* 276*507c3241Smlf * data for managing ARQ on ATAPI devices 277*507c3241Smlf */ 278*507c3241Smlf struct ata_pkt *ac_arq_pktp; /* pkt for performing ATAPI ARQ */ 279*507c3241Smlf struct ata_pkt *ac_fault_pktp; /* pkt that caused ARQ */ 280*507c3241Smlf uchar_t ac_arq_cdb[6]; 281*507c3241Smlf } ata_ctl_t; 282*507c3241Smlf 283*507c3241Smlf /* ac_flags (per-controller) */ 284*507c3241Smlf 285*507c3241Smlf #define AC_GHD_INIT 0x02 286*507c3241Smlf #define AC_ATAPI_INIT 0x04 287*507c3241Smlf #define AC_DISK_INIT 0x08 288*507c3241Smlf #define AC_ATTACHED 0x10 289*507c3241Smlf #define AC_SCSI_HBA_TRAN_ALLOC 0x1000 290*507c3241Smlf #define AC_SCSI_HBA_ATTACH 0x2000 291*507c3241Smlf 292*507c3241Smlf #define AC_BMSTATREG_PIO_BROKEN 0x80000000 293*507c3241Smlf 294*507c3241Smlf /* 295*507c3241Smlf * Bug 1256489: 296*507c3241Smlf * 297*507c3241Smlf * If AC_BSY_WAIT needs to be set for laptops that do 298*507c3241Smlf * suspend/resume but do not correctly wait for the busy bit to 299*507c3241Smlf * drop after a resume. 300*507c3241Smlf */ 301*507c3241Smlf 302*507c3241Smlf /* ac_timing_flags (per-controller) */ 303*507c3241Smlf #define AC_BSY_WAIT 0x1 /* tweak timing in ata_start & atapi_start */ 304*507c3241Smlf 305*507c3241Smlf 306*507c3241Smlf 307*507c3241Smlf /* Identify drive data */ 308*507c3241Smlf struct ata_id { 309*507c3241Smlf /* WORD */ 310*507c3241Smlf /* OFFSET COMMENT */ 311*507c3241Smlf ushort_t ai_config; /* 0 general configuration bits */ 312*507c3241Smlf ushort_t ai_fixcyls; /* 1 # of fixed cylinders */ 313*507c3241Smlf ushort_t ai_resv0; /* 2 # reserved */ 314*507c3241Smlf ushort_t ai_heads; /* 3 # of heads */ 315*507c3241Smlf ushort_t ai_trksiz; /* 4 # of unformatted bytes/track */ 316*507c3241Smlf ushort_t ai_secsiz; /* 5 # of unformatted bytes/sector */ 317*507c3241Smlf ushort_t ai_sectors; /* 6 # of sectors/track */ 318*507c3241Smlf ushort_t ai_resv1[3]; /* 7 "Vendor Unique" */ 319*507c3241Smlf char ai_drvser[20]; /* 10 Serial number */ 320*507c3241Smlf ushort_t ai_buftype; /* 20 Buffer type */ 321*507c3241Smlf ushort_t ai_bufsz; /* 21 Buffer size in 512 byte incr */ 322*507c3241Smlf ushort_t ai_ecc; /* 22 # of ecc bytes avail on rd/wr */ 323*507c3241Smlf char ai_fw[8]; /* 23 Firmware revision */ 324*507c3241Smlf char ai_model[40]; /* 27 Model # */ 325*507c3241Smlf ushort_t ai_mult1; /* 47 Multiple command flags */ 326*507c3241Smlf ushort_t ai_dwcap; /* 48 Doubleword capabilities */ 327*507c3241Smlf ushort_t ai_cap; /* 49 Capabilities */ 328*507c3241Smlf ushort_t ai_resv2; /* 50 Reserved */ 329*507c3241Smlf ushort_t ai_piomode; /* 51 PIO timing mode */ 330*507c3241Smlf ushort_t ai_dmamode; /* 52 DMA timing mode */ 331*507c3241Smlf ushort_t ai_validinfo; /* 53 bit0: wds 54-58, bit1: 64-70 */ 332*507c3241Smlf ushort_t ai_curcyls; /* 54 # of current cylinders */ 333*507c3241Smlf ushort_t ai_curheads; /* 55 # of current heads */ 334*507c3241Smlf ushort_t ai_cursectrk; /* 56 # of current sectors/track */ 335*507c3241Smlf ushort_t ai_cursccp[2]; /* 57 current sectors capacity */ 336*507c3241Smlf ushort_t ai_mult2; /* 59 multiple sectors info */ 337*507c3241Smlf ushort_t ai_addrsec[2]; /* 60 LBA only: no of addr secs */ 338*507c3241Smlf ushort_t ai_sworddma; /* 62 single word dma modes */ 339*507c3241Smlf ushort_t ai_dworddma; /* 63 double word dma modes */ 340*507c3241Smlf ushort_t ai_advpiomode; /* 64 advanced PIO modes supported */ 341*507c3241Smlf ushort_t ai_minmwdma; /* 65 min multi-word dma cycle info */ 342*507c3241Smlf ushort_t ai_recmwdma; /* 66 rec multi-word dma cycle info */ 343*507c3241Smlf ushort_t ai_minpio; /* 67 min PIO cycle info */ 344*507c3241Smlf ushort_t ai_minpioflow; /* 68 min PIO cycle info w/flow ctl */ 345*507c3241Smlf ushort_t ai_resv3[2]; /* 69,70 reserved */ 346*507c3241Smlf ushort_t ai_resv4[4]; /* 71-74 reserved */ 347*507c3241Smlf ushort_t ai_qdepth; /* 75 queue depth */ 348*507c3241Smlf ushort_t ai_resv5[4]; /* 76-79 reserved */ 349*507c3241Smlf ushort_t ai_majorversion; /* 80 major versions supported */ 350*507c3241Smlf ushort_t ai_minorversion; /* 81 minor version number supported */ 351*507c3241Smlf ushort_t ai_cmdset82; /* 82 command set supported */ 352*507c3241Smlf ushort_t ai_cmdset83; /* 83 more command sets supported */ 353*507c3241Smlf ushort_t ai_cmdset84; /* 84 more command sets supported */ 354*507c3241Smlf ushort_t ai_features85; /* 85 enabled features */ 355*507c3241Smlf ushort_t ai_features86; /* 86 enabled features */ 356*507c3241Smlf ushort_t ai_features87; /* 87 enabled features */ 357*507c3241Smlf ushort_t ai_ultradma; /* 88 Ultra DMA mode */ 358*507c3241Smlf ushort_t ai_erasetime; /* 89 security erase time */ 359*507c3241Smlf ushort_t ai_erasetimex; /* 90 enhanced security erase time */ 360*507c3241Smlf ushort_t ai_padding1[9]; /* pad through 99 */ 361*507c3241Smlf ushort_t ai_addrsecxt[4]; /* 100 extended max LBA sector */ 362*507c3241Smlf ushort_t ai_padding2[22]; /* pad to 126 */ 363*507c3241Smlf ushort_t ai_lastlun; /* 126 last LUN, as per SFF-8070i */ 364*507c3241Smlf ushort_t ai_resv6; /* 127 reserved */ 365*507c3241Smlf ushort_t ai_securestatus; /* 128 security status */ 366*507c3241Smlf ushort_t ai_vendor[31]; /* 129-159 vendor specific */ 367*507c3241Smlf ushort_t ai_padding3[16]; /* 160 pad to 176 */ 368*507c3241Smlf ushort_t ai_curmedser[30]; /* 176-205 current media serial number */ 369*507c3241Smlf ushort_t ai_padding4[49]; /* 206 pad to 255 */ 370*507c3241Smlf ushort_t ai_integrity; /* 255 integrity word */ 371*507c3241Smlf }; 372*507c3241Smlf 373*507c3241Smlf /* Identify Drive: general config bits - word 0 */ 374*507c3241Smlf 375*507c3241Smlf #define ATA_ID_REM_DRV 0x80 376*507c3241Smlf #define ATA_ID_COMPACT_FLASH 0x848a 377*507c3241Smlf #define ATA_ID_CF_TO_ATA 0x040a 378*507c3241Smlf 379*507c3241Smlf /* Identify Drive: common capability bits - word 49 */ 380*507c3241Smlf 381*507c3241Smlf #define ATAC_DMA_SUPPORT 0x0100 382*507c3241Smlf #define ATAC_LBA_SUPPORT 0x0200 383*507c3241Smlf #define ATAC_IORDY_DISABLE 0x0400 384*507c3241Smlf #define ATAC_IORDY_SUPPORT 0x0800 385*507c3241Smlf #define ATAC_RESERVED_IDPKT 0x1000 /* rsrvd for identify pkt dev */ 386*507c3241Smlf #define ATAC_STANDBYTIMER 0x2000 387*507c3241Smlf #define ATAC_ATA_TYPE_MASK 0x8001 388*507c3241Smlf #define ATAC_ATA_TYPE 0x0000 389*507c3241Smlf #define ATAC_ATAPI_TYPE_MASK 0xc000 390*507c3241Smlf #define ATAC_ATAPI_TYPE 0x8000 391*507c3241Smlf 392*507c3241Smlf /* Identify Driver ai_validinfo (word 53) */ 393*507c3241Smlf 394*507c3241Smlf #define ATAC_VALIDINFO_83 0x0004 /* word 83 supported fields valid */ 395*507c3241Smlf #define ATAC_VALIDINFO_70_64 0x0002 /* word 70:64 sup. fields valid */ 396*507c3241Smlf 397*507c3241Smlf /* Identify Drive: ai_dworddma (word 63) */ 398*507c3241Smlf 399*507c3241Smlf #define ATAC_MDMA_SEL_MASK 0x0700 /* Multiword DMA selected */ 400*507c3241Smlf #define ATAC_MDMA_2_SEL 0x0400 /* Multiword DMA mode 2 selected */ 401*507c3241Smlf #define ATAC_MDMA_1_SEL 0x0200 /* Multiword DMA mode 1 selected */ 402*507c3241Smlf #define ATAC_MDMA_0_SEL 0x0100 /* Multiword DMA mode 0 selected */ 403*507c3241Smlf #define ATAC_MDMA_2_SUP 0x0004 /* Multiword DMA mode 2 supported */ 404*507c3241Smlf #define ATAC_MDMA_1_SUP 0x0002 /* Multiword DMA mode 1 supported */ 405*507c3241Smlf #define ATAC_MDMA_0_SUP 0x0001 /* Multiword DMA mode 0 supported */ 406*507c3241Smlf 407*507c3241Smlf /* Identify Drive: ai_advpiomode (word 64) */ 408*507c3241Smlf 409*507c3241Smlf #define ATAC_ADVPIO_4_SUP 0x0002 /* PIO mode 4 supported */ 410*507c3241Smlf #define ATAC_ADVPIO_3_SUP 0x0001 /* PIO mode 3 supported */ 411*507c3241Smlf #define ATAC_ADVPIO_SERIAL 0x0003 /* Serial interface */ 412*507c3241Smlf 413*507c3241Smlf /* Identify Drive: ai_majorversion (word 80) */ 414*507c3241Smlf 415*507c3241Smlf #define ATAC_MAJVER_6 0x0040 /* ATA/ATAPI-6 version supported */ 416*507c3241Smlf #define ATAC_MAJVER_4 0x0010 /* ATA/ATAPI-4 version supported */ 417*507c3241Smlf 418*507c3241Smlf /* Identify Drive: command set supported/enabled bits - words 83 and 86 */ 419*507c3241Smlf 420*507c3241Smlf #define ATACS_EXT48 0x0400 /* 48 bit address feature */ 421*507c3241Smlf 422*507c3241Smlf /* Identify Drive: ai_features85 (word 85) */ 423*507c3241Smlf #define ATAC_FEATURES85_WCE 0x0020 /* write cache enabled */ 424*507c3241Smlf 425*507c3241Smlf /* per-drive data struct */ 426*507c3241Smlf 427*507c3241Smlf typedef struct ata_drv { 428*507c3241Smlf ata_ctl_t *ad_ctlp; /* pointer back to ctlr */ 429*507c3241Smlf struct ata_id ad_id; /* IDENTIFY DRIVE data */ 430*507c3241Smlf 431*507c3241Smlf uint_t ad_flags; 432*507c3241Smlf uchar_t ad_pciide_dma; /* PCIIDE DMA supported */ 433*507c3241Smlf uchar_t ad_targ; /* target */ 434*507c3241Smlf uchar_t ad_lun; /* lun */ 435*507c3241Smlf uchar_t ad_drive_bits; 436*507c3241Smlf 437*507c3241Smlf /* Used by atapi side only */ 438*507c3241Smlf 439*507c3241Smlf uchar_t ad_state; /* state of ATAPI FSM */ 440*507c3241Smlf uchar_t ad_cdb_len; /* Size of ATAPI CDBs */ 441*507c3241Smlf 442*507c3241Smlf uchar_t ad_bogus_drq; 443*507c3241Smlf uchar_t ad_nec_bad_status; 444*507c3241Smlf 445*507c3241Smlf /* Used by disk side only */ 446*507c3241Smlf 447*507c3241Smlf struct scsi_device ad_device; 448*507c3241Smlf struct scsi_inquiry ad_inquiry; 449*507c3241Smlf struct ctl_obj ad_ctl_obj; 450*507c3241Smlf uchar_t ad_rd_cmd; 451*507c3241Smlf uchar_t ad_wr_cmd; 452*507c3241Smlf ushort_t ad_acyl; 453*507c3241Smlf 454*507c3241Smlf /* 455*507c3241Smlf * Geometry note: The following three values are the geometry 456*507c3241Smlf * that the driver will use. They may differ from the 457*507c3241Smlf * geometry reported by the controller and/or BIOS. See note 458*507c3241Smlf * on ata_fix_large_disk_geometry in ata_disk.c for more 459*507c3241Smlf * details. 460*507c3241Smlf */ 461*507c3241Smlf uint32_t ad_drvrcyl; /* number of cyls */ 462*507c3241Smlf uint32_t ad_drvrhd; /* number of heads */ 463*507c3241Smlf uint32_t ad_drvrsec; /* number of sectors */ 464*507c3241Smlf ushort_t ad_phhd; /* number of phys heads */ 465*507c3241Smlf ushort_t ad_phsec; /* number of phys sectors */ 466*507c3241Smlf short ad_block_factor; 467*507c3241Smlf short ad_bytes_per_block; 468*507c3241Smlf 469*507c3241Smlf /* 470*507c3241Smlf * Support for 48-bit LBA (ATA-6) 471*507c3241Smlf */ 472*507c3241Smlf uint64_t ad_capacity; /* Total sectors on disk */ 473*507c3241Smlf } ata_drv_t; 474*507c3241Smlf 475*507c3241Smlf typedef struct ata_tgt { 476*507c3241Smlf ata_drv_t *at_drvp; 477*507c3241Smlf int at_arq; 478*507c3241Smlf ulong_t at_total_sectors; 479*507c3241Smlf ddi_dma_attr_t at_dma_attr; 480*507c3241Smlf } ata_tgt_t; 481*507c3241Smlf 482*507c3241Smlf /* values for ad_pciide_dma */ 483*507c3241Smlf #define ATA_DMA_OFF 0x0 484*507c3241Smlf #define ATA_DMA_ON 0x1 485*507c3241Smlf 486*507c3241Smlf /* 487*507c3241Smlf * (ata_pkt_t *) to (gcmd_t *) 488*507c3241Smlf */ 489*507c3241Smlf #define APKT2GCMD(apktp) (apktp->ap_gcmdp) 490*507c3241Smlf 491*507c3241Smlf /* 492*507c3241Smlf * (gcmd_t *) to (ata_pkt_t *) 493*507c3241Smlf */ 494*507c3241Smlf #define GCMD2APKT(gcmdp) ((ata_pkt_t *)gcmdp->cmd_private) 495*507c3241Smlf 496*507c3241Smlf /* 497*507c3241Smlf * (gtgt_t *) to (ata_ctl_t *) 498*507c3241Smlf */ 499*507c3241Smlf #define GTGTP2ATAP(gtgtp) ((ata_ctl_t *)GTGTP2HBA(gtgtp)) 500*507c3241Smlf 501*507c3241Smlf /* 502*507c3241Smlf * (gtgt_t *) to (ata_tgt_t *) 503*507c3241Smlf */ 504*507c3241Smlf #define GTGTP2ATATGTP(gtgtp) ((ata_tgt_t *)GTGTP2TARGET(gtgtp)) 505*507c3241Smlf 506*507c3241Smlf /* 507*507c3241Smlf * (gtgt_t *) to (ata_drv_t *) 508*507c3241Smlf */ 509*507c3241Smlf #define GTGTP2ATADRVP(gtgtp) (GTGTP2ATATGTP(gtgtp)->at_drvp) 510*507c3241Smlf 511*507c3241Smlf /* 512*507c3241Smlf * (gcmd_t *) to (ata_tgt_t *) 513*507c3241Smlf */ 514*507c3241Smlf #define GCMD2TGT(gcmdp) GTGTP2ATATGTP(GCMDP2GTGTP(gcmdp)) 515*507c3241Smlf 516*507c3241Smlf /* 517*507c3241Smlf * (gcmd_t *) to (ata_drv_t *) 518*507c3241Smlf */ 519*507c3241Smlf #define GCMD2DRV(gcmdp) GTGTP2ATADRVP(GCMDP2GTGTP(gcmdp)) 520*507c3241Smlf 521*507c3241Smlf /* 522*507c3241Smlf * (ata_pkt_t *) to (ata_drv_t *) 523*507c3241Smlf */ 524*507c3241Smlf #define APKT2DRV(apktp) GCMD2DRV(APKT2GCMD(apktp)) 525*507c3241Smlf 526*507c3241Smlf 527*507c3241Smlf /* 528*507c3241Smlf * (struct hba_tran *) to (ata_ctl_t *) 529*507c3241Smlf */ 530*507c3241Smlf #define TRAN2ATAP(tranp) ((ata_ctl_t *)TRAN2HBA(tranp)) 531*507c3241Smlf 532*507c3241Smlf 533*507c3241Smlf /* 534*507c3241Smlf * ata common packet structure 535*507c3241Smlf */ 536*507c3241Smlf typedef struct ata_pkt { 537*507c3241Smlf 538*507c3241Smlf gcmd_t *ap_gcmdp; /* GHD command struct */ 539*507c3241Smlf 540*507c3241Smlf uint_t ap_flags; /* packet flags */ 541*507c3241Smlf 542*507c3241Smlf caddr_t ap_baddr; /* I/O buffer base address */ 543*507c3241Smlf size_t ap_boffset; /* current offset into I/O buffer */ 544*507c3241Smlf size_t ap_bcount; /* # bytes in this request */ 545*507c3241Smlf 546*507c3241Smlf caddr_t ap_v_addr; /* I/O buffer address */ 547*507c3241Smlf size_t ap_resid; /* # bytes left to read/write */ 548*507c3241Smlf 549*507c3241Smlf uchar_t ap_pciide_dma; /* This pkt uses DMA transfer mode */ 550*507c3241Smlf prde_t ap_sg_list[ATA_DMA_NSEGS]; /* Scatter/Gather list */ 551*507c3241Smlf int ap_sg_cnt; /* number of entries in S/G list */ 552*507c3241Smlf 553*507c3241Smlf /* command, starting sector number, sector count */ 554*507c3241Smlf 555*507c3241Smlf daddr_t ap_startsec; /* starting sector number */ 556*507c3241Smlf ushort_t ap_count; /* sector count */ 557*507c3241Smlf uchar_t ap_sec; 558*507c3241Smlf uchar_t ap_lwcyl; 559*507c3241Smlf uchar_t ap_hicyl; 560*507c3241Smlf uchar_t ap_hd; 561*507c3241Smlf uchar_t ap_cmd; 562*507c3241Smlf 563*507c3241Smlf /* saved status and error registers for error case */ 564*507c3241Smlf 565*507c3241Smlf uchar_t ap_status; 566*507c3241Smlf uchar_t ap_error; 567*507c3241Smlf 568*507c3241Smlf /* disk/atapi callback routines */ 569*507c3241Smlf 570*507c3241Smlf int (*ap_start)(ata_ctl_t *ata_ctlp, ata_drv_t *ata_drvp, 571*507c3241Smlf struct ata_pkt *ata_pktp); 572*507c3241Smlf int (*ap_intr)(ata_ctl_t *ata_ctlp, ata_drv_t *ata_drvp, 573*507c3241Smlf struct ata_pkt *ata_pktp); 574*507c3241Smlf void (*ap_complete)(ata_drv_t *ata_drvp, 575*507c3241Smlf struct ata_pkt *ata_pktp, int do_callback); 576*507c3241Smlf 577*507c3241Smlf /* Used by disk side */ 578*507c3241Smlf 579*507c3241Smlf char ap_cdb; /* disk command */ 580*507c3241Smlf char ap_scb; /* status after disk cmd */ 581*507c3241Smlf uint_t ap_bytes_per_block; /* blk mode factor */ 582*507c3241Smlf uint_t ap_wrt_count; /* size of last write */ 583*507c3241Smlf caddr_t ap_v_addr_sav; /* Original I/O buffer address. */ 584*507c3241Smlf size_t ap_resid_sav; /* Original # of bytes */ 585*507c3241Smlf /* left to read/write. */ 586*507c3241Smlf 587*507c3241Smlf /* Used by atapi side */ 588*507c3241Smlf 589*507c3241Smlf uchar_t *ap_cdbp; /* ptr to SCSI CDB */ 590*507c3241Smlf uchar_t ap_cdb_len; /* length of SCSI CDB (in bytes) */ 591*507c3241Smlf uchar_t ap_cdb_pad; /* padding after SCSI CDB (in shorts) */ 592*507c3241Smlf 593*507c3241Smlf struct scsi_arq_status *ap_scbp; /* ptr to SCSI status block */ 594*507c3241Smlf uchar_t ap_statuslen; /* length of SCSI status block */ 595*507c3241Smlf } ata_pkt_t; 596*507c3241Smlf 597*507c3241Smlf 598*507c3241Smlf /* 599*507c3241Smlf * defines for ap_flags 600*507c3241Smlf */ 601*507c3241Smlf #define AP_ATAPI 0x0001 /* device is atapi */ 602*507c3241Smlf #define AP_ERROR 0x0002 /* normal error */ 603*507c3241Smlf #define AP_TRAN_ERROR 0x0004 /* transport error */ 604*507c3241Smlf #define AP_READ 0x0008 /* read data */ 605*507c3241Smlf #define AP_WRITE 0x0010 /* write data */ 606*507c3241Smlf #define AP_ABORT 0x0020 /* packet aborted */ 607*507c3241Smlf #define AP_TIMEOUT 0x0040 /* packet timed out */ 608*507c3241Smlf #define AP_BUS_RESET 0x0080 /* bus reset */ 609*507c3241Smlf #define AP_DEV_RESET 0x0100 /* device reset */ 610*507c3241Smlf 611*507c3241Smlf #define AP_SENT_CMD 0x0200 /* atapi: cdb sent */ 612*507c3241Smlf #define AP_XFERRED_DATA 0x0400 /* atapi: data transferred */ 613*507c3241Smlf #define AP_GOT_STATUS 0x0800 /* atapi: status received */ 614*507c3241Smlf #define AP_ARQ_ON_ERROR 0x1000 /* atapi: do ARQ on error */ 615*507c3241Smlf #define AP_ARQ_OKAY 0x2000 616*507c3241Smlf #define AP_ARQ_ERROR 0x4000 617*507c3241Smlf 618*507c3241Smlf #define AP_FREE 0x80000000u /* packet is free! */ 619*507c3241Smlf 620*507c3241Smlf 621*507c3241Smlf /* 622*507c3241Smlf * public function prototypes 623*507c3241Smlf */ 624*507c3241Smlf 625*507c3241Smlf int ata_check_drive_blacklist(struct ata_id *aidp, uint_t flags); 626*507c3241Smlf int ata_command(ata_ctl_t *ata_ctlp, ata_drv_t *ata_drvp, int expect_drdy, 627*507c3241Smlf int silent, uint_t busy_wait, uchar_t cmd, uchar_t feature, 628*507c3241Smlf uchar_t count, uchar_t sector, uchar_t head, uchar_t cyl_low, 629*507c3241Smlf uchar_t cyl_hi); 630*507c3241Smlf int ata_get_status_clear_intr(ata_ctl_t *ata_ctlp, ata_pkt_t *ata_pktp); 631*507c3241Smlf int ata_id_common(uchar_t id_cmd, int drdy_expected, 632*507c3241Smlf ddi_acc_handle_t io_hdl1, caddr_t ioaddr1, 633*507c3241Smlf ddi_acc_handle_t io_hdl2, caddr_t ioaddr2, 634*507c3241Smlf struct ata_id *ata_idp); 635*507c3241Smlf int ata_prop_create(dev_info_t *tgt_dip, ata_drv_t *ata_drvp, char *name); 636*507c3241Smlf int ata_queue_cmd(int (*func)(ata_ctl_t *, ata_drv_t *, ata_pkt_t *), 637*507c3241Smlf void *arg, ata_ctl_t *ata_ctlp, ata_drv_t *ata_drvp, 638*507c3241Smlf gtgt_t *gtgtp); 639*507c3241Smlf int ata_set_feature(ata_ctl_t *ata_ctlp, ata_drv_t *ata_drvp, 640*507c3241Smlf uchar_t feature, uchar_t value); 641*507c3241Smlf int ata_wait(ddi_acc_handle_t io_hdl, caddr_t ioaddr, uchar_t onbits, 642*507c3241Smlf uchar_t offbits, uint_t timeout_usec); 643*507c3241Smlf int ata_wait3(ddi_acc_handle_t io_hdl, caddr_t ioaddr, uchar_t onbits1, 644*507c3241Smlf uchar_t offbits1, uchar_t failure_onbits2, 645*507c3241Smlf uchar_t failure_offbits2, uchar_t failure_onbits3, 646*507c3241Smlf uchar_t failure_offbits3, uint_t timeout_usec); 647*507c3241Smlf int ata_test_lba_support(struct ata_id *aidp); 648*507c3241Smlf 649*507c3241Smlf /* 650*507c3241Smlf * It's not clear to which of the two following delay mechanisms is 651*507c3241Smlf * better. 652*507c3241Smlf * 653*507c3241Smlf * We really need something better than drv_usecwait(). The 654*507c3241Smlf * granularity for drv_usecwait() currently is 10 usec. This means that 655*507c3241Smlf * the ATA_DELAY_400NSEC macro delays 25 timers longer than necessary. 656*507c3241Smlf * 657*507c3241Smlf * Doing 4 inb()'s from the alternate status register is guaranteed 658*507c3241Smlf * to take at least 400 nsecs (it may take as long as 4 usecs. 659*507c3241Smlf * The problem with inb() is that on an x86 platform it also causes 660*507c3241Smlf * a CPU synchronization, CPU write buffer flush, cache flush, and 661*507c3241Smlf * flushes posted writes in any PCI bridge devices between the CPU 662*507c3241Smlf * and the ATA controller. 663*507c3241Smlf */ 664*507c3241Smlf #if 1 665*507c3241Smlf #define ATA_DELAY_400NSEC(H, A) \ 666*507c3241Smlf ((void) ddi_get8((H), (uint8_t *)(A) + AT_ALTSTATUS), \ 667*507c3241Smlf (void) ddi_get8((H), (uint8_t *)(A) + AT_ALTSTATUS), \ 668*507c3241Smlf (void) ddi_get8((H), (uint8_t *)(A) + AT_ALTSTATUS), \ 669*507c3241Smlf (void) ddi_get8((H), (uint8_t *)(A) + AT_ALTSTATUS)) 670*507c3241Smlf #else 671*507c3241Smlf #define ATA_DELAY_400NSEC(H, A) ((void) drv_usecwait(1)) 672*507c3241Smlf #endif 673*507c3241Smlf 674*507c3241Smlf 675*507c3241Smlf /* 676*507c3241Smlf * PCIIDE DMA (Bus Mastering) functions and data in ata_dma.c 677*507c3241Smlf */ 678*507c3241Smlf extern ddi_dma_attr_t ata_pciide_dma_attr; 679*507c3241Smlf extern int ata_dma_disabled; 680*507c3241Smlf 681*507c3241Smlf int ata_pciide_alloc(dev_info_t *dip, ata_ctl_t *ata_ctlp); 682*507c3241Smlf void ata_pciide_free(ata_ctl_t *ata_ctlp); 683*507c3241Smlf 684*507c3241Smlf void ata_pciide_dma_sg_func(gcmd_t *gcmdp, ddi_dma_cookie_t *dmackp, 685*507c3241Smlf int single_segment, int seg_index); 686*507c3241Smlf void ata_pciide_dma_setup(ata_ctl_t *ata_ctlp, prde_t *srcp, int sg_cnt); 687*507c3241Smlf void ata_pciide_dma_start(ata_ctl_t *ata_ctlp, uchar_t direction); 688*507c3241Smlf void ata_pciide_dma_stop(ata_ctl_t *ata_ctlp); 689*507c3241Smlf int ata_pciide_status_clear(ata_ctl_t *ata_ctlp); 690*507c3241Smlf int ata_pciide_status_dmacheck_clear(ata_ctl_t *ata_ctlp); 691*507c3241Smlf int ata_pciide_status_pending(ata_ctl_t *ata_ctlp); 692*507c3241Smlf 693*507c3241Smlf #ifdef __cplusplus 694*507c3241Smlf } 695*507c3241Smlf #endif 696*507c3241Smlf 697*507c3241Smlf #endif /* _ATA_COMMON_H */ 698