Home | History | Annotate | Line # | Download | only in ic
siisatareg.h revision 1.4
      1 /* $NetBSD: siisatareg.h,v 1.4 2009/07/04 20:57:15 jakllsch Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2007, 2008, 2009 Jonathan A. Kollasch.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  *
     27  */
     28 
     29 /* Silicon Image SATA 2 controller register defines */
     30 
     31 #include <sys/cdefs.h>
     32 
     33 /* the SiI3124 has 4 ports, all others so far have less */
     34 #define SIISATA_MAX_PORTS 4
     35 /* all parts have a full complement of slots (so far) */
     36 #define SIISATA_MAX_SLOTS 31
     37 
     38 /* structures */
     39 
     40 /* Scatter/Gather Entry */
     41 struct siisata_sge {
     42 #if 0
     43 	uint32_t sge_dal; /* data address low */
     44 	uint32_t sge_dah; /* "          " high */
     45 #else
     46 	uint64_t sge_da;
     47 #endif
     48 	uint32_t sge_dc;  /* data count (bytes) */
     49 	uint32_t sge_flags; /* */
     50 #define SGE_FLAG_TRM __BIT(31)
     51 #define SGE_FLAG_LNK __BIT(30)
     52 #define SGE_FLAG_DRD __BIT(29)
     53 #define SGE_FLAG_XCF __BIT(28)
     54 } __packed;
     55 
     56 /* Scatter/Gather Table */
     57 /* must be aligned to 64-bit boundary */
     58 struct siisata_sgt {
     59 	struct siisata_sge sgt_sge[4];
     60 } __packed;
     61 
     62 /* Port Request Block */
     63 struct siisata_prb {
     64 	uint16_t prb_control; /* Control Field */
     65 #define PRB_CF_PROTOCOL_OVERRIDE __BIT(0)
     66 #define PRB_CF_RETRANSMIT        __BIT(1)
     67 #define PRB_CF_EXTERNAL_COMMAND  __BIT(2)
     68 #define PRB_CF_RECEIVE           __BIT(3)
     69 #define PRB_CF_PACKET_READ       __BIT(4)
     70 #define PRB_CF_PACKET_WRITE      __BIT(5)
     71 #define PRB_CF_INTERRUPT_MASK    __BIT(6)
     72 #define PRB_CF_SOFT_RESET        __BIT(7)
     73 	uint16_t prb_protocol_override;
     74 #define PRB_PO_PACKET      __BIT(0)
     75 #define PRB_PO_LCQ         __BIT(1)
     76 #define PRB_PO_NCQ         __BIT(2)
     77 #define PRB_PO_READ        __BIT(3)
     78 #define PRB_PO_WRITE       __BIT(4)
     79 #define PRB_PO_TRANSPARENT __BIT(5)
     80 	uint32_t prb_transfer_count;
     81 	uint8_t prb_fis[20];
     82 	uint32_t prb_reserved_0x1C; /* "must be zero" */
     83 /* First SGE in PRB is always reserved for ATAPI in this implementation. */
     84 	uint8_t prb_atapi[16]; /* zero for non-ATAPI */
     85 	struct siisata_sge prb_sge[1]; /* extended to NSGE */
     86 } __packed;
     87 
     88 
     89 #define SIISATA_NSGE ((MAXPHYS/PAGE_SIZE) + 1)
     90 #define SIISATA_CMD_ALIGN 0x7f
     91 #define SIISATA_CMD_SIZE \
     92 ( ( sizeof(struct siisata_prb) + (SIISATA_NSGE - 1) * sizeof(struct siisata_sge) + SIISATA_CMD_ALIGN ) & ~SIISATA_CMD_ALIGN )
     93 
     94 /* PCI stuff */
     95 #define SIISATA_PCI_BAR0 0x10
     96 #define SIISATA_PCI_BAR1 0x18
     97 #define SIISATA_PCI_BAR2 0x20
     98 
     99 /* BAR 0 */
    100 
    101 /* port n slot status */
    102 #define GR_PXSS(n) (n*4)
    103 /* global control */
    104 #define GR_GC		0x40
    105 /* global interrupt status */
    106 #define GR_GIS		0x44
    107 /* phy config - don't touch */
    108 #define GR_PHYC		0x48
    109 /* BIST */
    110 #define GR_BIST_CONTROL	0x50
    111 #define GR_BIST_PATTERN	0x54
    112 #define GR_BIST_STATUS	0x58
    113 /* I2C SiI3132 */
    114 #define GR_SII3132_IICCONTROL	0x60
    115 #define GR_SII3132_IICSTATUS	0x64
    116 #define GR_SII3132_IICSLAVEADDR	0x68
    117 #define GR_SII3132_IICDATA	0x6c
    118 /* Flash */
    119 #define GR_FLSHADDR	0x70
    120 #define GR_FLSHDATA	0x74
    121 /* I2C SiI3124 */
    122 #define GR_SII3124_IICADDR	0x78
    123 #define GR_SII3124_IICDATA	0x7c
    124 
    125 
    126 /* GR_GC bits */
    127 #define GR_GC_GLBLRST		__BIT(31)
    128 #define GR_GC_MSIACK		__BIT(30)
    129 #define GR_GC_I2CINTEN		__BIT(29)
    130 #define GR_GC_PERRRPTDSBL	__BIT(28)
    131 #define GR_GC_3GBPS		__BIT(24)
    132 #define GR_GC_REQ64		__BIT(20)
    133 #define GR_GC_DEVSEL		__BIT(19)
    134 #define GR_GC_STOP		__BIT(18)
    135 #define GR_GC_TRDY		__BIT(17)
    136 #define GR_GC_M66EN		__BIT(16)
    137 #define GR_GC_PXIE_MASK		__BITS(SIISATA_MAX_PORTS - 1, 0)
    138 #define GR_GC_PXIE(n)		__SHIFTIN(__BIT(n), GR_GC_PXIE_MASK)
    139 
    140 /* GR_GIS bits */
    141 #define GR_GIS_I2C		__BIT(29)
    142 #define GR_GIS_PXIS_MASK	__BITS(SIISATA_MAX_PORTS - 1, 0)
    143 #define GR_GIS_PXIS(n)		__SHIFTIN(__BIT(n), GR_GIS_PXIS_MASK)
    144 
    145 
    146 /* BAR 1 */
    147 
    148 /* hmm, this could use a better name */
    149 #define PR_PORT_SIZE	0x2000
    150 #define PR_SLOT_SIZE	0x80
    151 /* get the register by port number and offset */
    152 #define PRO(p) (PR_PORT_SIZE * p)
    153 #define PRX(p,r) (PRO(p) + r)
    154 #define PRSX(p,s,o) (PRX(p, PR_SLOT_SIZE * s + o))
    155 
    156 #define PRSO_RTC	0x04		/* recieved transfer count */
    157 #define PRSO_FIS	0x08		/* base of FIS */
    158 
    159 #define PRO_PCS		0x1000		/* (write) port control set */
    160 #define PRO_PS		PRO_PCS		/* (read) port status */
    161 #define PRO_PCC		0x1004		/* port control clear */
    162 #define PRO_PIS		0x1008		/* port interrupt status */
    163 #define PRO_PIES	0x1010		/* port interrupt enable set */
    164 #define PRO_PIEC	0x1014		/* port interrupt enable clear */
    165 #define PRO_32BAUA	0x101c		/* 32-bit activation upper address */
    166 #define PRO_PCEF	0x1020		/* port command execution fifo */
    167 #define PRO_PCE		0x1024		/* port command error */
    168 #define PRO_PFISC	0x1028		/* port FIS config */
    169 #define PRO_PCIRFIFOT	0x102c		/* pci request fifo threshhold */
    170 #define PRO_P8B10BDEC	0x1040		/* port 8B/10B decode error counter */
    171 #define PRO_PCRCEC	0x1044		/* port crc error count */
    172 #define PRO_PHEC	0x1048		/* port handshake error count */
    173 #define PRO_PPHYC	0x1050		/* phy config */
    174 #define PRO_PSS		0x1800		/* port slot status */
    175 /* technically this is a shadow of the CAR */
    176 #define PRO_CAR		0x1c00
    177 
    178 #define PRO_CARX(p,s)     (PRX(p, PRO_CAR) + s * sizeof(uint64_t))
    179 
    180 #define PRO_PCR		0x1e04		/* port context register */
    181 #define PRO_SCONTROL	0x1f00		/* SControl */
    182 #define PRO_SSTATUS	0x1f04		/* SStatus */
    183 #define PRO_SERROR	0x1f08		/* SError */
    184 #define PRO_SACTIVE	0x1f0c		/* SActive */
    185 
    186 
    187 /* Port Command Error */
    188 #define PR_PCE_DEVICEERROR		1
    189 #define PR_PCE_SDBERROR			2
    190 #define PR_PCE_DATAFISERROR		3
    191 #define PR_PCE_SENDFISERROR		4
    192 #define PR_PCE_INCONSISTENTSTATE	5
    193 #define PR_PCE_DIRECTIONERROR		6
    194 #define PR_PCE_UNDERRUNERROR		7
    195 #define PR_PCE_OVERRUNERROR		8
    196 #define PR_PCE_LINKFIFOOVERRUN		9
    197 #define PR_PCE_PACKETPROTOCOLERROR	11
    198 #define PR_PCE_PLDSGTERRORBOUNDARY	16
    199 #define PR_PCE_PLDSGTERRORTARGETABORT	17
    200 #define PR_PCE_PLDSGTERRORMASTERABORT	18
    201 #define PR_PCE_PLDSGTERRORPCIPERR	19
    202 #define PR_PCE_PLDCMDERRORBOUNDARY	24
    203 #define PR_PCE_PLDCMDERRORTARGETABORT	25
    204 #define PR_PCE_PLDCMDERRORMASTERABORT	26
    205 #define PR_PCE_PLDCMDERRORPCIPERR	27
    206 #define PR_PCE_PSDERRORTARGETABORT	33
    207 #define PR_PCE_PSDERRORMASTERABORT	34
    208 #define PR_PCE_PSDERRORPCIPERR		35
    209 #define PR_PCE_SENDSERVICEERROROR	36
    210 
    211 
    212 #define PR_PIS_UNMASKED_SHIFT	16
    213 #define PR_PIS_CMDCMPL		__BIT(0)	/* command completion */
    214 #define PR_PIS_CMDERRR		__BIT(1)	/* command error */
    215 #define PR_PIS_PRTRDY		__BIT(2)  /* port ready */
    216 #define PR_PIS_PMCHNG		__BIT(3)  /* power management state change */
    217 #define PR_PIS_PHYRDYCHG	__BIT(4)
    218 #define PR_PIS_COMWAKE		__BIT(5)
    219 #define PR_PIS_UNRECFIS		__BIT(6)
    220 #define PR_PIS_DEVEXCHG		__BIT(7)
    221 #define PR_PIS_8B10BDET		__BIT(8)
    222 #define PR_PIS_CRCET		__BIT(9)
    223 #define PR_PIS_HET		__BIT(10)
    224 #define PR_PIS_SDBN		__BIT(11)
    225 
    226 #define PR_PC_PORT_RESET	__BIT(0)
    227 #define PR_PC_DEVICE_RESET	__BIT(1)
    228 #define PR_PC_PORT_INITIALIZE	__BIT(2)
    229 #define PR_PC_INCOR		__BIT(3)
    230 #define PR_PC_LED_DISABLE	__BIT(4)
    231 #define PR_PC_PACKET_LENGTH	__BIT(5)
    232 #define PR_PC_RESUME		__BIT(6)
    233 #define PR_PC_TXBIST		__BIT(7)
    234 #define PR_PC_CONT_DISABLE	__BIT(8)
    235 #define PR_PC_SCRAMBLER_DISABLE	__BIT(9)
    236 #define PR_PC_32BA		__BIT(10)
    237 #define PR_PC_INTERLOCK_REJECT	__BIT(11)
    238 #define PR_PC_INTERLOCK_ACCEPT	__BIT(12)
    239 #define PR_PC_PMP_ENABLE	__BIT(13)
    240 #define PR_PC_AIA		__BIT(14)
    241 #define PR_PC_LED_ON		__BIT(15)
    242 #define PR_PC_OOB_BYPASS	__BIT(25)
    243 #define PR_PS_PORT_READY	__BIT(31)
    244 
    245 #define PR_PSS_ATTENTION	__BIT(31)
    246 #define PR_PSS_SLOT_MASK	__BITS(30, 0)
    247 #define PR_PXSS(n)		__SHIFTIN(__BIT(n), PR_PSS_SLOT_MASK)
    248