xref: /freebsd/sys/dev/siis/siis.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
167b87e44SAlexander Motin /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
467b87e44SAlexander Motin  * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
567b87e44SAlexander Motin  * All rights reserved.
667b87e44SAlexander Motin  *
767b87e44SAlexander Motin  * Redistribution and use in source and binary forms, with or without
867b87e44SAlexander Motin  * modification, are permitted provided that the following conditions
967b87e44SAlexander Motin  * are met:
1067b87e44SAlexander Motin  * 1. Redistributions of source code must retain the above copyright
1167b87e44SAlexander Motin  *    notice, this list of conditions and the following disclaimer,
1267b87e44SAlexander Motin  *    without modification, immediately at the beginning of the file.
1367b87e44SAlexander Motin  * 2. Redistributions in binary form must reproduce the above copyright
1467b87e44SAlexander Motin  *    notice, this list of conditions and the following disclaimer in the
1567b87e44SAlexander Motin  *    documentation and/or other materials provided with the distribution.
1667b87e44SAlexander Motin  *
1767b87e44SAlexander Motin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1867b87e44SAlexander Motin  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1967b87e44SAlexander Motin  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2067b87e44SAlexander Motin  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2167b87e44SAlexander Motin  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2267b87e44SAlexander Motin  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2367b87e44SAlexander Motin  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2467b87e44SAlexander Motin  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2567b87e44SAlexander Motin  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2667b87e44SAlexander Motin  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2767b87e44SAlexander Motin  */
2867b87e44SAlexander Motin 
2967b87e44SAlexander Motin /* ATA register defines */
3067b87e44SAlexander Motin #define ATA_DATA                        0       /* (RW) data */
3167b87e44SAlexander Motin 
3267b87e44SAlexander Motin #define ATA_FEATURE                     1       /* (W) feature */
3367b87e44SAlexander Motin #define         ATA_F_DMA               0x01    /* enable DMA */
3467b87e44SAlexander Motin #define         ATA_F_OVL               0x02    /* enable overlap */
3567b87e44SAlexander Motin 
3667b87e44SAlexander Motin #define ATA_COUNT                       2       /* (W) sector count */
3767b87e44SAlexander Motin 
3867b87e44SAlexander Motin #define ATA_SECTOR                      3       /* (RW) sector # */
3967b87e44SAlexander Motin #define ATA_CYL_LSB                     4       /* (RW) cylinder# LSB */
4067b87e44SAlexander Motin #define ATA_CYL_MSB                     5       /* (RW) cylinder# MSB */
4167b87e44SAlexander Motin #define ATA_DRIVE                       6       /* (W) Sector/Drive/Head */
4267b87e44SAlexander Motin #define         ATA_D_LBA               0x40    /* use LBA addressing */
4367b87e44SAlexander Motin #define         ATA_D_IBM               0xa0    /* 512 byte sectors, ECC */
4467b87e44SAlexander Motin 
4567b87e44SAlexander Motin #define ATA_COMMAND                     7       /* (W) command */
4667b87e44SAlexander Motin 
4767b87e44SAlexander Motin #define ATA_ERROR                       8       /* (R) error */
4867b87e44SAlexander Motin #define         ATA_E_ILI               0x01    /* illegal length */
4967b87e44SAlexander Motin #define         ATA_E_NM                0x02    /* no media */
5067b87e44SAlexander Motin #define         ATA_E_ABORT             0x04    /* command aborted */
5167b87e44SAlexander Motin #define         ATA_E_MCR               0x08    /* media change request */
5267b87e44SAlexander Motin #define         ATA_E_IDNF              0x10    /* ID not found */
5367b87e44SAlexander Motin #define         ATA_E_MC                0x20    /* media changed */
5467b87e44SAlexander Motin #define         ATA_E_UNC               0x40    /* uncorrectable data */
5567b87e44SAlexander Motin #define         ATA_E_ICRC              0x80    /* UDMA crc error */
5667b87e44SAlexander Motin #define		ATA_E_ATAPI_SENSE_MASK	0xf0	/* ATAPI sense key mask */
5767b87e44SAlexander Motin 
5867b87e44SAlexander Motin #define ATA_IREASON                     9       /* (R) interrupt reason */
5967b87e44SAlexander Motin #define         ATA_I_CMD               0x01    /* cmd (1) | data (0) */
6067b87e44SAlexander Motin #define         ATA_I_IN                0x02    /* read (1) | write (0) */
6167b87e44SAlexander Motin #define         ATA_I_RELEASE           0x04    /* released bus (1) */
6267b87e44SAlexander Motin #define         ATA_I_TAGMASK           0xf8    /* tag mask */
6367b87e44SAlexander Motin 
6467b87e44SAlexander Motin #define ATA_STATUS                      10      /* (R) status */
6567b87e44SAlexander Motin #define ATA_ALTSTAT                     11      /* (R) alternate status */
6667b87e44SAlexander Motin #define         ATA_S_ERROR             0x01    /* error */
6767b87e44SAlexander Motin #define         ATA_S_INDEX             0x02    /* index */
6867b87e44SAlexander Motin #define         ATA_S_CORR              0x04    /* data corrected */
6967b87e44SAlexander Motin #define         ATA_S_DRQ               0x08    /* data request */
7067b87e44SAlexander Motin #define         ATA_S_DSC               0x10    /* drive seek completed */
7167b87e44SAlexander Motin #define         ATA_S_SERVICE           0x10    /* drive needs service */
7267b87e44SAlexander Motin #define         ATA_S_DWF               0x20    /* drive write fault */
7367b87e44SAlexander Motin #define         ATA_S_DMA               0x20    /* DMA ready */
7467b87e44SAlexander Motin #define         ATA_S_READY             0x40    /* drive ready */
7567b87e44SAlexander Motin #define         ATA_S_BUSY              0x80    /* busy */
7667b87e44SAlexander Motin 
7767b87e44SAlexander Motin #define ATA_CONTROL                     12      /* (W) control */
7867b87e44SAlexander Motin #define         ATA_A_IDS               0x02    /* disable interrupts */
7967b87e44SAlexander Motin #define         ATA_A_RESET             0x04    /* RESET controller */
8067b87e44SAlexander Motin #define         ATA_A_4BIT              0x08    /* 4 head bits */
8167b87e44SAlexander Motin #define         ATA_A_HOB               0x80    /* High Order Byte enable */
8267b87e44SAlexander Motin 
8367b87e44SAlexander Motin /* SATA register defines */
8467b87e44SAlexander Motin #define ATA_SSTATUS                     13
8567b87e44SAlexander Motin #define         ATA_SS_DET_MASK         0x0000000f
8667b87e44SAlexander Motin #define         ATA_SS_DET_NO_DEVICE    0x00000000
8767b87e44SAlexander Motin #define         ATA_SS_DET_DEV_PRESENT  0x00000001
8867b87e44SAlexander Motin #define         ATA_SS_DET_PHY_ONLINE   0x00000003
8967b87e44SAlexander Motin #define         ATA_SS_DET_PHY_OFFLINE  0x00000004
9067b87e44SAlexander Motin 
9167b87e44SAlexander Motin #define         ATA_SS_SPD_MASK         0x000000f0
9267b87e44SAlexander Motin #define         ATA_SS_SPD_NO_SPEED     0x00000000
9367b87e44SAlexander Motin #define         ATA_SS_SPD_GEN1         0x00000010
9467b87e44SAlexander Motin #define         ATA_SS_SPD_GEN2         0x00000020
95c21b342bSAlexander Motin #define         ATA_SS_SPD_GEN3         0x00000030
9667b87e44SAlexander Motin 
9767b87e44SAlexander Motin #define         ATA_SS_IPM_MASK         0x00000f00
9867b87e44SAlexander Motin #define         ATA_SS_IPM_NO_DEVICE    0x00000000
9967b87e44SAlexander Motin #define         ATA_SS_IPM_ACTIVE       0x00000100
10067b87e44SAlexander Motin #define         ATA_SS_IPM_PARTIAL      0x00000200
10167b87e44SAlexander Motin #define         ATA_SS_IPM_SLUMBER      0x00000600
10267b87e44SAlexander Motin 
10367b87e44SAlexander Motin #define ATA_SERROR                      14
10467b87e44SAlexander Motin #define         ATA_SE_DATA_CORRECTED   0x00000001
10567b87e44SAlexander Motin #define         ATA_SE_COMM_CORRECTED   0x00000002
10667b87e44SAlexander Motin #define         ATA_SE_DATA_ERR         0x00000100
10767b87e44SAlexander Motin #define         ATA_SE_COMM_ERR         0x00000200
10867b87e44SAlexander Motin #define         ATA_SE_PROT_ERR         0x00000400
10967b87e44SAlexander Motin #define         ATA_SE_HOST_ERR         0x00000800
11067b87e44SAlexander Motin #define         ATA_SE_PHY_CHANGED      0x00010000
11167b87e44SAlexander Motin #define         ATA_SE_PHY_IERROR       0x00020000
11267b87e44SAlexander Motin #define         ATA_SE_COMM_WAKE        0x00040000
11367b87e44SAlexander Motin #define         ATA_SE_DECODE_ERR       0x00080000
11467b87e44SAlexander Motin #define         ATA_SE_PARITY_ERR       0x00100000
11567b87e44SAlexander Motin #define         ATA_SE_CRC_ERR          0x00200000
11667b87e44SAlexander Motin #define         ATA_SE_HANDSHAKE_ERR    0x00400000
11767b87e44SAlexander Motin #define         ATA_SE_LINKSEQ_ERR      0x00800000
11867b87e44SAlexander Motin #define         ATA_SE_TRANSPORT_ERR    0x01000000
11967b87e44SAlexander Motin #define         ATA_SE_UNKNOWN_FIS      0x02000000
12067b87e44SAlexander Motin 
12167b87e44SAlexander Motin #define ATA_SCONTROL                    15
12267b87e44SAlexander Motin #define         ATA_SC_DET_MASK         0x0000000f
12367b87e44SAlexander Motin #define         ATA_SC_DET_IDLE         0x00000000
12467b87e44SAlexander Motin #define         ATA_SC_DET_RESET        0x00000001
12567b87e44SAlexander Motin #define         ATA_SC_DET_DISABLE      0x00000004
12667b87e44SAlexander Motin 
12767b87e44SAlexander Motin #define         ATA_SC_SPD_MASK         0x000000f0
12867b87e44SAlexander Motin #define         ATA_SC_SPD_NO_SPEED     0x00000000
12967b87e44SAlexander Motin #define         ATA_SC_SPD_SPEED_GEN1   0x00000010
13067b87e44SAlexander Motin #define         ATA_SC_SPD_SPEED_GEN2   0x00000020
131c21b342bSAlexander Motin #define         ATA_SC_SPD_SPEED_GEN3   0x00000030
13267b87e44SAlexander Motin 
13367b87e44SAlexander Motin #define         ATA_SC_IPM_MASK         0x00000f00
13467b87e44SAlexander Motin #define         ATA_SC_IPM_NONE         0x00000000
13567b87e44SAlexander Motin #define         ATA_SC_IPM_DIS_PARTIAL  0x00000100
13667b87e44SAlexander Motin #define         ATA_SC_IPM_DIS_SLUMBER  0x00000200
13767b87e44SAlexander Motin 
13867b87e44SAlexander Motin #define ATA_SACTIVE                     16
13967b87e44SAlexander Motin 
14067b87e44SAlexander Motin /*
14167b87e44SAlexander Motin  * Global registers
14267b87e44SAlexander Motin  */
14367b87e44SAlexander Motin #define SIIS_GCTL		0x0040		/* Global Control	*/
14467b87e44SAlexander Motin #define SIIS_GCTL_GRESET	  0x80000000	/* Global Reset		*/
14567b87e44SAlexander Motin #define SIIS_GCTL_MSIACK	  0x40000000	/* MSI Ack		*/
14667b87e44SAlexander Motin #define SIIS_GCTL_I2C_IE	  0x20000000	/* I2C int enable	*/
14767b87e44SAlexander Motin #define SIIS_GCTL_300CAP	  0x01000000	/* 3Gb/s capable (R)	*/
14867b87e44SAlexander Motin #define SIIS_GCTL_PIE(n)	  (1 << (n))	/* Port int enable	*/
14967b87e44SAlexander Motin #define SIIS_IS			0x0044		/* Interrupt Status	*/
15067b87e44SAlexander Motin #define SIIS_IS_I2C		  0x20000000	/* I2C Int Status	*/
15167b87e44SAlexander Motin #define SIIS_IS_PORT(n)		  (1 << (n))	/* Port interrupt stat	*/
15267b87e44SAlexander Motin #define SIIS_PHYCONF		0x0048		/* PHY Configuration */
15367b87e44SAlexander Motin #define SIIS_BIST_CTL		0x0050
15467b87e44SAlexander Motin #define SIIS_BIST_PATTERN	0x0054	/* 32 bit pattern */
15567b87e44SAlexander Motin #define SIIS_BIST_STATUS	0x0058
15667b87e44SAlexander Motin #define SIIS_I2C_CTL		0x0060
15767b87e44SAlexander Motin #define SIIS_I2C_STS		0x0064
15867b87e44SAlexander Motin #define SIIS_I2C_SADDR		0x0068
15967b87e44SAlexander Motin #define SIIS_I2C_DATA		0x006C
16067b87e44SAlexander Motin #define SIIS_FLASH_ADDR		0x0070
16167b87e44SAlexander Motin #define SIIS_GPIO		0x0074
16267b87e44SAlexander Motin 
16367b87e44SAlexander Motin /*
16467b87e44SAlexander Motin  * Port registers
16567b87e44SAlexander Motin  */
16667b87e44SAlexander Motin 
16767b87e44SAlexander Motin #define SIIS_P_LRAM		0x0000
16867b87e44SAlexander Motin #define   SIIS_P_LRAM_SLOT(i)	  (SIIS_P_LRAM + i * 128)
16967b87e44SAlexander Motin #define SIIS_P_PMPSTS(i)	(0x0F80 + i * 8)
17067b87e44SAlexander Motin #define SIIS_P_PMPQACT(i)	(0x0F80 + i * 8 + 4)
17167b87e44SAlexander Motin #define SIIS_P_STS		0x1000
17267b87e44SAlexander Motin #define SIIS_P_CTLSET		0x1000
17367b87e44SAlexander Motin #define SIIS_P_CTLCLR		0x1004
17467b87e44SAlexander Motin #define   SIIS_P_CTL_READY	  0x80000000
17567b87e44SAlexander Motin #define   SIIS_P_CTL_OOBB	  0x02000000
17667b87e44SAlexander Motin #define   SIIS_P_CTL_ACT	  0x001F0000
17767b87e44SAlexander Motin #define   SIIS_P_CTL_ACT_SHIFT	  16
17867b87e44SAlexander Motin #define   SIIS_P_CTL_LED_ON	  0x00008000
17967b87e44SAlexander Motin #define   SIIS_P_CTL_AIA	  0x00004000
18067b87e44SAlexander Motin #define   SIIS_P_CTL_PME	  0x00002000
18167b87e44SAlexander Motin #define   SIIS_P_CTL_IA		  0x00001000
18267b87e44SAlexander Motin #define   SIIS_P_CTL_IR		  0x00000800
18367b87e44SAlexander Motin #define   SIIS_P_CTL_32BIT	  0x00000400
18467b87e44SAlexander Motin #define   SIIS_P_CTL_SCR_DIS	  0x00000200
18567b87e44SAlexander Motin #define   SIIS_P_CTL_CONT_DIS	  0x00000100
18667b87e44SAlexander Motin #define   SIIS_P_CTL_TBIST	  0x00000080
18767b87e44SAlexander Motin #define   SIIS_P_CTL_RESUME	  0x00000040
18867b87e44SAlexander Motin #define   SIIS_P_CTL_PLENGTH	  0x00000020
18967b87e44SAlexander Motin #define   SIIS_P_CTL_LED_DIS	  0x00000010
19067b87e44SAlexander Motin #define   SIIS_P_CTL_INT_NCOR	  0x00000008
19167b87e44SAlexander Motin #define   SIIS_P_CTL_PORT_INIT  0x00000004
19267b87e44SAlexander Motin #define   SIIS_P_CTL_DEV_RESET  0x00000002
19367b87e44SAlexander Motin #define   SIIS_P_CTL_PORT_RESET 0x00000001
19467b87e44SAlexander Motin #define SIIS_P_IS		0x1008
19567b87e44SAlexander Motin #define   SIIS_P_IX_SDBN	  0x00000800
19667b87e44SAlexander Motin #define   SIIS_P_IX_HS_ET	  0x00000400
19767b87e44SAlexander Motin #define   SIIS_P_IX_CRC_ET	  0x00000200
19867b87e44SAlexander Motin #define   SIIS_P_IX_8_10_ET	  0x00000100
19967b87e44SAlexander Motin #define   SIIS_P_IX_DEX		  0x00000080
20067b87e44SAlexander Motin #define   SIIS_P_IX_UNRECFIS	  0x00000040
20167b87e44SAlexander Motin #define   SIIS_P_IX_COMWAKE	  0x00000020
20267b87e44SAlexander Motin #define   SIIS_P_IX_PHYRDYCHG	  0x00000010
20367b87e44SAlexander Motin #define   SIIS_P_IX_PMCHG	  0x00000008
20467b87e44SAlexander Motin #define   SIIS_P_IX_READY	  0x00000004
20567b87e44SAlexander Motin #define   SIIS_P_IX_COMMERR	  0x00000002
20667b87e44SAlexander Motin #define   SIIS_P_IX_COMMCOMP	  0x00000001
20767b87e44SAlexander Motin #define   SIIS_P_IX_ENABLED	  SIIS_P_IX_COMMCOMP | SIIS_P_IX_COMMERR | \
20867b87e44SAlexander Motin     SIIS_P_IX_PHYRDYCHG | SIIS_P_IX_SDBN
20967b87e44SAlexander Motin #define SIIS_P_IESET		0x1010
21067b87e44SAlexander Motin #define SIIS_P_IECLR		0x1014
21167b87e44SAlexander Motin #define SIIS_P_CACTU		0x101C
21267b87e44SAlexander Motin #define SIIS_P_CMDEFIFO		0x1020
21367b87e44SAlexander Motin #define SIIS_P_CMDERR		0x1024
21467b87e44SAlexander Motin #define   SIIS_P_CMDERR_DEV		1
21567b87e44SAlexander Motin #define   SIIS_P_CMDERR_SDB		2
21667b87e44SAlexander Motin #define   SIIS_P_CMDERR_DATAFIS		3
21767b87e44SAlexander Motin #define   SIIS_P_CMDERR_SENDFIS		4
21867b87e44SAlexander Motin #define   SIIS_P_CMDERR_INCSTATE	5
21967b87e44SAlexander Motin #define   SIIS_P_CMDERR_DIRECTION	6
22067b87e44SAlexander Motin #define   SIIS_P_CMDERR_UNDERRUN	7
22167b87e44SAlexander Motin #define   SIIS_P_CMDERR_OVERRUN		8
22267b87e44SAlexander Motin #define   SIIS_P_CMDERR_LLOVERRUN	9
22367b87e44SAlexander Motin #define   SIIS_P_CMDERR_PPE		11
22467b87e44SAlexander Motin #define   SIIS_P_CMDERR_SGTALIGN	16
22567b87e44SAlexander Motin #define   SIIS_P_CMDERR_PCITASGT	17
22667b87e44SAlexander Motin #define   SIIS_P_CMDERR_OCIMASGT	18
22767b87e44SAlexander Motin #define   SIIS_P_CMDERR_PCIPESGT	19
22867b87e44SAlexander Motin #define   SIIS_P_CMDERR_PRBALIGN	24
22967b87e44SAlexander Motin #define   SIIS_P_CMDERR_PCITAPRB	25
23067b87e44SAlexander Motin #define   SIIS_P_CMDERR_PCIMAPRB	26
23167b87e44SAlexander Motin #define   SIIS_P_CMDERR_PCIPEPRB	27
23267b87e44SAlexander Motin #define   SIIS_P_CMDERR_PCITADATA	33
23367b87e44SAlexander Motin #define   SIIS_P_CMDERR_PCIMADATA	34
23467b87e44SAlexander Motin #define   SIIS_P_CMDERR_PCIPEDATA	35
23567b87e44SAlexander Motin #define   SIIS_P_CMDERR_SERVICE		36
23667b87e44SAlexander Motin #define SIIS_P_FISCFG		0x1028
23767b87e44SAlexander Motin #define SIIS_P_PCIEFIFOTH	0x102C
23867b87e44SAlexander Motin #define SIIS_P_8_10_DEC_ERR	0x1040
23967b87e44SAlexander Motin #define SIIS_P_CRC_ERR		0x1044
24067b87e44SAlexander Motin #define SIIS_P_HS_ERR		0x1048
24167b87e44SAlexander Motin #define SIIS_P_PHYCFG		0x1050
24267b87e44SAlexander Motin #define SIIS_P_SS		0x1800
24367b87e44SAlexander Motin #define   SIIS_P_SS_ATTN	  0x80000000
24467b87e44SAlexander Motin #define SIIS_P_CACTL(i)		(0x1C00 + i * 8)
24567b87e44SAlexander Motin #define SIIS_P_CACTH(i)		(0x1C00 + i * 8 + 4)
24667b87e44SAlexander Motin #define SIIS_P_CTX		0x1E04
24767b87e44SAlexander Motin #define   SIIS_P_CTX_SLOT	  0x0000001F
24867b87e44SAlexander Motin #define   SIIS_P_CTX_SLOT_SHIFT	  0
24967b87e44SAlexander Motin #define   SIIS_P_CTX_PMP	  0x000001E0
25067b87e44SAlexander Motin #define   SIIS_P_CTX_PMP_SHIFT	  5
25167b87e44SAlexander Motin 
25267b87e44SAlexander Motin #define SIIS_P_SCTL		0x1F00
25367b87e44SAlexander Motin #define SIIS_P_SSTS		0x1F04
25467b87e44SAlexander Motin #define SIIS_P_SERR		0x1F08
25567b87e44SAlexander Motin #define SIIS_P_SACT		0x1F0C
25667b87e44SAlexander Motin #define SIIS_P_SNTF		0x1F10
25767b87e44SAlexander Motin 
25867b87e44SAlexander Motin #define SIIS_MAX_PORTS		4
25967b87e44SAlexander Motin #define SIIS_MAX_SLOTS		31
26067b87e44SAlexander Motin 
26167b87e44SAlexander Motin #define SIIS_OFFSET		0x100
26267b87e44SAlexander Motin #define SIIS_STEP		0x80
26367b87e44SAlexander Motin 
26467b87e44SAlexander Motin /* Pessimistic prognosis on number of required S/G entries */
265cd853791SKonstantin Belousov #define SIIS_SG_ENTRIES		(roundup(btoc(maxphys), 4) + 1)
266cd853791SKonstantin Belousov /* Port Request Block + S/G entries.  128byte aligned. */
267cd853791SKonstantin Belousov #define SIIS_PRB_SIZE		(32 + 16 + SIIS_SG_ENTRIES * 16)
26867b87e44SAlexander Motin /* Total main work area. */
269cd853791SKonstantin Belousov #define SIIS_WORK_SIZE		(SIIS_PRB_SIZE * SIIS_MAX_SLOTS)
27067b87e44SAlexander Motin 
27167b87e44SAlexander Motin struct siis_dma_prd {
27267b87e44SAlexander Motin     u_int64_t			dba;
27367b87e44SAlexander Motin     u_int32_t			dbc;
27467b87e44SAlexander Motin     u_int32_t			control;
27567b87e44SAlexander Motin #define SIIS_PRD_TRM		0x80000000
27667b87e44SAlexander Motin #define SIIS_PRD_LNK		0x40000000
27767b87e44SAlexander Motin #define SIIS_PRD_DRD		0x20000000
27867b87e44SAlexander Motin #define SIIS_PRD_XCF		0x10000000
27967b87e44SAlexander Motin } __packed;
28067b87e44SAlexander Motin 
28167b87e44SAlexander Motin struct siis_cmd_ata {
282cd853791SKonstantin Belousov     struct siis_dma_prd		prd[2];
28367b87e44SAlexander Motin } __packed;
28467b87e44SAlexander Motin 
28567b87e44SAlexander Motin struct siis_cmd_atapi {
28667b87e44SAlexander Motin     u_int8_t			ccb[16];
287cd853791SKonstantin Belousov     struct siis_dma_prd		prd[1];
28867b87e44SAlexander Motin } __packed;
28967b87e44SAlexander Motin 
29067b87e44SAlexander Motin struct siis_cmd {
29167b87e44SAlexander Motin     u_int16_t			control;
29267b87e44SAlexander Motin #define SIIS_PRB_PROTOCOL_OVERRIDE	0x0001
29367b87e44SAlexander Motin #define SIIS_PRB_RETRANSMIT		0x0002
29467b87e44SAlexander Motin #define SIIS_PRB_EXTERNAL_COMMAND	0x0004
29567b87e44SAlexander Motin #define SIIS_PRB_RECEIVE		0x0008
29667b87e44SAlexander Motin #define SIIS_PRB_PACKET_READ		0x0010
29767b87e44SAlexander Motin #define SIIS_PRB_PACKET_WRITE		0x0020
29867b87e44SAlexander Motin #define SIIS_PRB_INTERRUPT_MASK		0x0040
29967b87e44SAlexander Motin #define SIIS_PRB_SOFT_RESET		0x0080
30067b87e44SAlexander Motin     u_int16_t			protocol_override;
301723bd8c6SAlexander Motin #define SIIS_PRB_PROTO_PACKET		0x0001
302723bd8c6SAlexander Motin #define SIIS_PRB_PROTO_TCQ		0x0002
303723bd8c6SAlexander Motin #define SIIS_PRB_PROTO_NCQ		0x0004
304723bd8c6SAlexander Motin #define SIIS_PRB_PROTO_READ		0x0008
305723bd8c6SAlexander Motin #define SIIS_PRB_PROTO_WRITE		0x0010
306723bd8c6SAlexander Motin #define SIIS_PRB_PROTO_TRANSPARENT	0x0020
30767b87e44SAlexander Motin     u_int32_t			transfer_count;
30867b87e44SAlexander Motin     u_int8_t			fis[24];
30967b87e44SAlexander Motin     union {
31067b87e44SAlexander Motin 	struct siis_cmd_ata	ata;
31167b87e44SAlexander Motin 	struct siis_cmd_atapi	atapi;
31267b87e44SAlexander Motin     } u;
31367b87e44SAlexander Motin } __packed;
31467b87e44SAlexander Motin 
31567b87e44SAlexander Motin /* misc defines */
31667b87e44SAlexander Motin #define ATA_IRQ_RID                     0
31767b87e44SAlexander Motin #define ATA_INTR_FLAGS                  (INTR_MPSAFE|INTR_TYPE_BIO|INTR_ENTROPY)
31867b87e44SAlexander Motin 
31967b87e44SAlexander Motin struct ata_dmaslot {
32067b87e44SAlexander Motin     bus_dmamap_t                data_map;       /* data DMA map */
32167b87e44SAlexander Motin     int				nsegs;		/* Number of segs loaded */
32267b87e44SAlexander Motin };
32367b87e44SAlexander Motin 
32467b87e44SAlexander Motin /* structure holding DMA related information */
32567b87e44SAlexander Motin struct ata_dma {
32667b87e44SAlexander Motin     bus_dma_tag_t               work_tag;       /* workspace DMA tag */
32767b87e44SAlexander Motin     bus_dmamap_t                work_map;       /* workspace DMA map */
32867b87e44SAlexander Motin     uint8_t                     *work;          /* workspace */
32967b87e44SAlexander Motin     bus_addr_t                  work_bus;       /* bus address of work */
33067b87e44SAlexander Motin     bus_dma_tag_t               data_tag;       /* data DMA tag */
33167b87e44SAlexander Motin };
33267b87e44SAlexander Motin 
33367b87e44SAlexander Motin enum siis_slot_states {
33467b87e44SAlexander Motin 	SIIS_SLOT_EMPTY,
33567b87e44SAlexander Motin 	SIIS_SLOT_LOADING,
33667b87e44SAlexander Motin 	SIIS_SLOT_RUNNING,
33767b87e44SAlexander Motin 	SIIS_SLOT_WAITING
33867b87e44SAlexander Motin };
33967b87e44SAlexander Motin 
34067b87e44SAlexander Motin struct siis_slot {
34167b87e44SAlexander Motin     device_t                    dev;            /* Device handle */
34267b87e44SAlexander Motin     u_int8_t			slot;           /* Number of this slot */
34367b87e44SAlexander Motin     enum siis_slot_states	state;          /* Slot state */
344cd853791SKonstantin Belousov     u_int			prb_offset;	/* PRB offset */
34567b87e44SAlexander Motin     union ccb			*ccb;		/* CCB occupying slot */
34667b87e44SAlexander Motin     struct ata_dmaslot          dma;            /* DMA data of this slot */
34767b87e44SAlexander Motin     struct callout              timeout;        /* Execution timeout */
34867b87e44SAlexander Motin };
34967b87e44SAlexander Motin 
350c8039fc6SAlexander Motin struct siis_device {
351b447e682SAlexander Motin 	int			revision;
352c8039fc6SAlexander Motin 	int			mode;
353c8039fc6SAlexander Motin 	u_int			bytecount;
3544cca1530SAlexander Motin 	u_int			atapi;
355c8039fc6SAlexander Motin 	u_int			tags;
356da6808c1SAlexander Motin 	u_int			caps;
357c8039fc6SAlexander Motin };
358c8039fc6SAlexander Motin 
35967b87e44SAlexander Motin /* structure describing an ATA channel */
36067b87e44SAlexander Motin struct siis_channel {
36167b87e44SAlexander Motin 	device_t		dev;            /* Device handle */
36267b87e44SAlexander Motin 	int			unit;           /* Physical channel */
36367b87e44SAlexander Motin 	struct resource		*r_mem;		/* Memory of this channel */
36467b87e44SAlexander Motin 	struct resource		*r_irq;         /* Interrupt of this channel */
36567b87e44SAlexander Motin 	void			*ih;            /* Interrupt handle */
36667b87e44SAlexander Motin 	struct ata_dma		dma;            /* DMA data */
36767b87e44SAlexander Motin 	struct cam_sim		*sim;
36867b87e44SAlexander Motin 	struct cam_path		*path;
3697f63cad8SAlexander Motin 	struct cdev		*led;		/* Activity led led(4) cdev. */
370d095fa04SAlexander Motin 	int			quirks;
37167b87e44SAlexander Motin 	int			pm_level;	/* power management level */
37267b87e44SAlexander Motin 
37367b87e44SAlexander Motin 	struct siis_slot	slot[SIIS_MAX_SLOTS];
37467b87e44SAlexander Motin 	union ccb		*hold[SIIS_MAX_SLOTS];
37567b87e44SAlexander Motin 	struct mtx		mtx;		/* state lock */
37667b87e44SAlexander Motin 	int			devices;        /* What is present */
37767b87e44SAlexander Motin 	int			pm_present;	/* PM presence reported */
378c8039fc6SAlexander Motin 	uint32_t		oslots;		/* Occupied slots */
37967b87e44SAlexander Motin 	uint32_t		rslots;		/* Running slots */
38067b87e44SAlexander Motin 	uint32_t		aslots;		/* Slots with atomic commands */
38167b87e44SAlexander Motin 	uint32_t		eslots;		/* Slots in error */
3826f9a51c7SAlexander Motin 	uint32_t		toslots;	/* Slots in timeout */
38367b87e44SAlexander Motin 	int			numrslots;	/* Number of running slots */
38467b87e44SAlexander Motin 	int			numtslots[SIIS_MAX_SLOTS]; /* Number of tagged slots */
3857bcc5957SAlexander Motin 	int			numhslots;	/* Number of held slots */
386b8b7a902SAlexander Motin 	int			recoverycmd;	/* Our READ LOG active */
387453130d9SPedro F. Giffuni 	int			fatalerr;	/* Fatal error happened */
38867b87e44SAlexander Motin 	int			recovery;	/* Some slots are in error */
38967b87e44SAlexander Motin 	union ccb		*frozen;	/* Frozen command */
390c8039fc6SAlexander Motin 
391c8039fc6SAlexander Motin 	struct siis_device	user[16];	/* User-specified settings */
392c8039fc6SAlexander Motin 	struct siis_device	curr[16];	/* Current settings */
39367b87e44SAlexander Motin };
39467b87e44SAlexander Motin 
39567b87e44SAlexander Motin /* structure describing a SIIS controller */
39667b87e44SAlexander Motin struct siis_controller {
39767b87e44SAlexander Motin 	device_t		dev;
39867b87e44SAlexander Motin 	int			r_grid;
39967b87e44SAlexander Motin 	struct resource		*r_gmem;
40067b87e44SAlexander Motin 	int			r_rid;
40167b87e44SAlexander Motin 	struct resource		*r_mem;
40267b87e44SAlexander Motin 	struct rman		sc_iomem;
40367b87e44SAlexander Motin 	struct siis_controller_irq {
40467b87e44SAlexander Motin 		struct resource		*r_irq;
40567b87e44SAlexander Motin 		void			*handle;
40667b87e44SAlexander Motin 		int			r_irq_rid;
40767b87e44SAlexander Motin 	} irq;
408d095fa04SAlexander Motin 	int			quirks;
40967b87e44SAlexander Motin 	int			channels;
41030053681SAlexander Motin 	uint32_t		gctl;
41167b87e44SAlexander Motin 	struct {
41267b87e44SAlexander Motin 		void			(*function)(void *);
41367b87e44SAlexander Motin 		void			*argument;
41467b87e44SAlexander Motin 	} interrupt[SIIS_MAX_PORTS];
41567b87e44SAlexander Motin };
41667b87e44SAlexander Motin 
41767b87e44SAlexander Motin enum siis_err_type {
41867b87e44SAlexander Motin 	SIIS_ERR_NONE,		/* No error */
41967b87e44SAlexander Motin 	SIIS_ERR_INVALID,	/* Error detected by us before submitting. */
42067b87e44SAlexander Motin 	SIIS_ERR_INNOCENT,	/* Innocent victim. */
42167b87e44SAlexander Motin 	SIIS_ERR_TFE,		/* Task File Error. */
42267b87e44SAlexander Motin 	SIIS_ERR_SATA,		/* SATA error. */
42367b87e44SAlexander Motin 	SIIS_ERR_TIMEOUT,	/* Command execution timeout. */
42467b87e44SAlexander Motin 	SIIS_ERR_NCQ,		/* NCQ command error. CCB should be put on hold
42567b87e44SAlexander Motin 				 * until READ LOG executed to reveal error. */
42667b87e44SAlexander Motin };
42767b87e44SAlexander Motin 
42867b87e44SAlexander Motin /* macros to hide busspace uglyness */
42967b87e44SAlexander Motin #define ATA_INB(res, offset) \
43067b87e44SAlexander Motin 	bus_read_1((res), (offset))
43167b87e44SAlexander Motin #define ATA_INW(res, offset) \
43267b87e44SAlexander Motin 	bus_read_2((res), (offset))
43367b87e44SAlexander Motin #define ATA_INL(res, offset) \
43467b87e44SAlexander Motin 	bus_read_4((res), (offset))
43567b87e44SAlexander Motin #define ATA_INSW(res, offset, addr, count) \
43667b87e44SAlexander Motin 	bus_read_multi_2((res), (offset), (addr), (count))
43767b87e44SAlexander Motin #define ATA_INSW_STRM(res, offset, addr, count) \
43867b87e44SAlexander Motin 	bus_read_multi_stream_2((res), (offset), (addr), (count))
43967b87e44SAlexander Motin #define ATA_INSL(res, offset, addr, count) \
44067b87e44SAlexander Motin 	bus_read_multi_4((res), (offset), (addr), (count))
44167b87e44SAlexander Motin #define ATA_INSL_STRM(res, offset, addr, count) \
44267b87e44SAlexander Motin 	bus_read_multi_stream_4((res), (offset), (addr), (count))
44367b87e44SAlexander Motin #define ATA_OUTB(res, offset, value) \
44467b87e44SAlexander Motin 	bus_write_1((res), (offset), (value))
44567b87e44SAlexander Motin #define ATA_OUTW(res, offset, value) \
44667b87e44SAlexander Motin 	bus_write_2((res), (offset), (value))
44767b87e44SAlexander Motin #define ATA_OUTL(res, offset, value) \
44867b87e44SAlexander Motin 	bus_write_4((res), (offset), (value))
44967b87e44SAlexander Motin #define ATA_OUTSW(res, offset, addr, count) \
45067b87e44SAlexander Motin 	bus_write_multi_2((res), (offset), (addr), (count))
45167b87e44SAlexander Motin #define ATA_OUTSW_STRM(res, offset, addr, count) \
45267b87e44SAlexander Motin 	bus_write_multi_stream_2((res), (offset), (addr), (count))
45367b87e44SAlexander Motin #define ATA_OUTSL(res, offset, addr, count) \
45467b87e44SAlexander Motin 	bus_write_multi_4((res), (offset), (addr), (count))
45567b87e44SAlexander Motin #define ATA_OUTSL_STRM(res, offset, addr, count) \
45667b87e44SAlexander Motin 	bus_write_multi_stream_4((res), (offset), (addr), (count))
457