source: trunk/src/os2ahci/ahci.h@ 196

Last change on this file since 196 was 196, checked in by David Azarewicz, 7 years ago

Changes to debug output for debug versions.
Removed interrupt requirement on init.

File size: 16.0 KB
Line 
1/******************************************************************************
2 * ahci.h - AHCI-specific constants for os2ahci.h
3 *
4 * Copyright (c) 2011 thi.guten Software Development
5 * Copyright (c) 2011 Mensys B.V.
6 * Copyright (c) 2013-2018 David Azarewicz
7 *
8 * Authors: Christian Mueller, Markus Thielen
9 *
10 * Parts copied from/inspired by the Linux AHCI driver;
11 * those parts are (c) Linux AHCI/ATA maintainers
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 */
27
28/* ----------------------------- include files ----------------------------- */
29
30/* -------------------------- macros and constants ------------------------- */
31
32/******************************************************************************
33 * device prefix strings for Resource Manager
34 */
35#define RM_HD_PREFIX "HD_(%d,%d) "
36#define RM_HD_PREFIX_LEN (sizeof(RM_HD_PREFIX) - 1)
37#define RM_CD_PREFIX "CD_(%d,%d) "
38#define RM_CD_PREFIX_LEN (sizeof(RM_CD_PREFIX) - 1)
39#define RM_TAPE_PREFIX "TAPE_(%d,%d) "
40#define RM_TAPE_PREFIX_LEN (sizeof(RM_TAPE_PREFIX) - 1)
41#define RM_MAX_PREFIX_LEN RM_TAPE_PREFIX_LEN
42
43/******************************************************************************
44 * AHCI flags and constants; those were initially copied from the Linux AHCI
45 * driver but converted to macros because enums are 16 bits for OS/2 drivers
46 * (unless we use KEE and a 32-bit compiler, which we don't)
47 *
48 * Changes from the Linux source:
49 *
50 * - reduced AHCI_MAX_SG from 168 to 48 because the port-specific DMA scratch
51 * buffer needs to be less than 64K to allow mapping the whole DMA area to a
52 * 16-bit memory segment
53 *
54 * - added AHCI_MAX_SG_ELEMENT_LEN constant
55 *
56 * - replaced much of the top-level size/offset math with real structs and
57 * corresponding sizeof() directives.
58 */
59#define AHCI_PCI_BAR 5
60#define AHCI_MAX_PORTS 16 /* Spec says 32, but we only support 16 */
61#define AHCI_MAX_DEVS 1 /* was 8. we only support 1 drive per port */
62#define AHCI_MAX_SG 48 /* hardware max is 64K */
63#define AHCI_MAX_SG_ELEMENT_LEN (1UL << 22)
64#define AHCI_MAX_CMDS 32
65#define AHCI_RX_FIS_SZ 256
66#define AHCI_DEV_NAME_LEN 40
67
68/* port-specific DMA scratch buffer aligned to 1024 bytes */
69//DAZ #define AHCI_PORT_PRIV_DMA_SZ (((sizeof(AHCI_PORT_DMA) + 1023U) / 1024U) * 1024U)
70#define AHCI_PORT_PRIV_DMA_SZ sizeof(AHCI_PORT_DMA)
71
72#define AHCI_IRQ_ON_SG (1UL << 31)
73#define AHCI_CMD_ATAPI (1UL << 5)
74#define AHCI_CMD_WRITE (1UL << 6)
75#define AHCI_CMD_PREFETCH (1UL << 7)
76#define AHCI_CMD_RESET (1UL << 8)
77#define AHCI_CMD_CLR_BUSY (1UL << 10)
78
79#define RX_FIS_D2H_REG 0x40 /* offset of D2H Register FIS data */
80#define RX_FIS_SDB 0x58 /* offset of SDB FIS data */
81#define RX_FIS_UNK 0x60 /* offset of Unknown FIS data */
82
83#define board_ahci 0
84#define board_ahci_vt8251 1
85#define board_ahci_ign_iferr 2
86#define board_ahci_sb600 3
87#define board_ahci_mv 4
88#define board_ahci_sb700 5 /* for SB700 and SB800 */
89#define board_ahci_mcp65 6
90#define board_ahci_nopmp 7
91#define board_ahci_yesncq 8
92#define board_ahci_nosntf 9
93
94/* global controller registers */
95#define HOST_CAP 0x00 /* host capabilities */
96#define HOST_CTL 0x04 /* global host control */
97#define HOST_IRQ_STAT 0x08 /* interrupt status */
98#define HOST_PORTS_IMPL 0x0c /* bitmap of implemented ports */
99#define HOST_VERSION 0x10 /* AHCI spec. version compliancy */
100#define HOST_CCC 0x14 /* Command Completion Coalescing Control */
101#define HOST_CCC_PORTS 0x18 /* CCC ports */
102#define HOST_EM_LOC 0x1c /* Enclosure Management location */
103#define HOST_EM_CTL 0x20 /* Enclosure Management Control */
104#define HOST_CAP2 0x24 /* host capabilities, extended */
105#define HOST_BOHC 0x28 /* BIOS hand off control and status */
106
107/* HOST_CTL bits */
108#define HOST_RESET (1UL << 0) /* reset controller; self-clear */
109#define HOST_IRQ_EN (1UL << 1) /* global IRQ enable */
110#define HOST_AHCI_EN (1UL << 31) /* AHCI enabled */
111
112/* HOST_CAP bits */
113#define HOST_CAP_SXS (1UL << 5) /* Supports External SATA */
114#define HOST_CAP_EMS (1UL << 6) /* Enclosure Management support */
115#define HOST_CAP_CCC (1UL << 7) /* Command Completion Coalescing */
116#define HOST_CAP_PART (1UL << 13) /* Partial state capable */
117#define HOST_CAP_SSC (1UL << 14) /* Slumber state capable */
118#define HOST_CAP_PIO_MULTI (1UL << 15) /* PIO multiple DRQ support */
119#define HOST_CAP_FBS (1UL << 16) /* FIS-based switching support */
120#define HOST_CAP_PMP (1UL << 17) /* Port Multiplier support */
121#define HOST_CAP_ONLY (1UL << 18) /* Supports AHCI mode only */
122#define HOST_CAP_CLO (1UL << 24) /* Command List Override support */
123#define HOST_CAP_LED (1UL << 25) /* Supports activity LED */
124#define HOST_CAP_ALPM (1UL << 26) /* Aggressive Link PM support */
125#define HOST_CAP_SSS (1UL << 27) /* Staggered Spin-up */
126#define HOST_CAP_MPS (1UL << 28) /* Mechanical presence switch */
127#define HOST_CAP_SNTF (1UL << 29) /* SNotification register */
128#define HOST_CAP_NCQ (1UL << 30) /* Native Command Queueing */
129#define HOST_CAP_64 (1UL << 31) /* PCI DAC (64-bit DMA) support */
130
131/* HOST_CAP2 bits */
132#define HOST_CAP2_BOH (1UL << 0) /* BIOS/OS handoff supported */
133#define HOST_CAP2_NVMHCI (1UL << 1) /* NVMHCI supported */
134#define HOST_CAP2_APST (1UL << 2) /* Automatic partial to slumber */
135
136/* HOST_BOHC bits */
137#define HOST_BOHC_BOS (1UL << 0) /* BIOS owned (semaphore bit) */
138#define HOST_BOHC_OOS (1UL << 1) /* OS owned (semaphore bit) */
139#define HOST_BOHC_SOOE (1UL << 2) /* SMI on ownership change enable */
140#define HOST_BOHC_OOC (1UL << 3) /* OS ownership change */
141#define HOST_BOHC_BB (1UL << 4) /* BIOS is busy changing ownership */
142
143/* registers for each SATA port */
144#define PORT_LST_ADDR 0x00 /* command list DMA addr */
145#define PORT_LST_ADDR_HI 0x04 /* command list DMA addr hi */
146#define PORT_FIS_ADDR 0x08 /* FIS rx buf addr */
147#define PORT_FIS_ADDR_HI 0x0c /* FIS rx buf addr hi */
148#define PORT_IRQ_STAT 0x10 /* interrupt status */
149#define PORT_IRQ_MASK 0x14 /* interrupt enable/disable mask */
150#define PORT_CMD 0x18 /* port command */
151#define PORT_TFDATA 0x20 /* taskfile data */
152#define PORT_SIG 0x24 /* device TF signature */
153#define PORT_CMD_ISSUE 0x38 /* command issue */
154#define PORT_SCR_STAT 0x28 /* SATA phy register: SStatus */
155#define PORT_SCR_CTL 0x2c /* SATA phy register: SControl */
156#define PORT_SCR_ERR 0x30 /* SATA phy register: SError */
157#define PORT_SCR_ACT 0x34 /* SATA phy register: SActive */
158#define PORT_SCR_NTF 0x3c /* SATA phy register: SNotification */
159
160/* PORT_IRQ_{STAT,MASK} bits */
161#define PORT_IRQ_COLD_PRES (1UL << 31) /* cold presence detect */
162#define PORT_IRQ_TF_ERR (1UL << 30) /* task file error */
163#define PORT_IRQ_HBUS_ERR (1UL << 29) /* host bus fatal error */
164#define PORT_IRQ_HBUS_DATA_ERR (1UL << 28) /* host bus data error */
165#define PORT_IRQ_IF_ERR (1UL << 27) /* interface fatal error */
166#define PORT_IRQ_IF_NONFATAL (1UL << 26) /* interface non-fatal error */
167#define PORT_IRQ_OVERFLOW (1UL << 24) /* xfer exhausted available S/G */
168#define PORT_IRQ_BAD_PMP (1UL << 23) /* incorrect port multiplier */
169#define PORT_IRQ_PHYRDY (1UL << 22) /* PhyRdy changed */
170#define PORT_IRQ_DEV_ILCK (1UL << 7) /* device interlock */
171#define PORT_IRQ_CONNECT (1UL << 6) /* port connect change status */
172#define PORT_IRQ_SG_DONE (1UL << 5) /* descriptor processed */
173#define PORT_IRQ_UNK_FIS (1UL << 4) /* unknown FIS rx'd */
174#define PORT_IRQ_SDB_FIS (1UL << 3) /* Set Device Bits FIS rx'd */
175#define PORT_IRQ_DMAS_FIS (1UL << 2) /* DMA Setup FIS rx'd */
176#define PORT_IRQ_PIOS_FIS (1UL << 1) /* PIO Setup FIS rx'd */
177#define PORT_IRQ_D2H_REG_FIS (1UL << 0) /* D2H Register FIS rx'd */
178#define PORT_IRQ_FREEZE (PORT_IRQ_HBUS_ERR | PORT_IRQ_IF_ERR | \
179 PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY | \
180 PORT_IRQ_UNK_FIS | PORT_IRQ_BAD_PMP)
181#define PORT_IRQ_ERROR (PORT_IRQ_FREEZE | PORT_IRQ_TF_ERR | \
182 PORT_IRQ_OVERFLOW | PORT_IRQ_HBUS_DATA_ERR)
183#define DEF_PORT_IRQ (PORT_IRQ_ERROR | PORT_IRQ_SG_DONE | \
184 PORT_IRQ_SDB_FIS | PORT_IRQ_DMAS_FIS | \
185 PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FIS)
186
187#define PORT_ERR_X (1UL << 26) /* Exchanged */
188#define PORT_ERR_FIS (1UL << 25) /* Unknown FIS type */
189#define PORT_ERR_TP (1UL << 24) /* Transport State Transition Error */
190#define PORT_ERR_S (1UL << 23) /* Link Sequence Error */
191#define PORT_ERR_H (1UL << 22) /* Handshake Error */
192#define PORT_ERR_CRC (1UL << 21) /* CRC Error */
193#define PORT_ERR_D (1UL << 20) /* Disparity Error */
194#define PORT_ERR_B (1UL << 19) /* 10B to 8B Decode Error */
195#define PORT_ERR_W (1UL << 18) /* Comm Wake */
196#define PORT_ERR_PI (1UL << 17) /* Phy Internal Error */
197#define PORT_ERR_N (1UL << 16) /* PhyRdy Change */
198#define PORT_ERR_IE (1UL << 11) /* Internal Error */
199#define PORT_ERR_P (1UL << 10) /* Protocol Error */
200#define PORT_ERR_C (1UL << 9) /* Persistent Communication or Data Integrity Error */
201#define PORT_ERR_TD (1UL << 8) /* Transient Data Integrity Error */
202#define PORT_ERR_M (1UL << 1) /* Recovered Communications Error */
203#define PORT_ERR_DI (1UL << 0) /* Recoverred Data Integrity Error */
204#define PORT_ERR_FAIL_BITS (PORT_ERR_X | PORT_ERR_FIS | PORT_ERR_TP | PORT_ERR_S | PORT_ERR_H | PORT_ERR_CRC | \
205 PORT_ERR_D | PORT_ERR_B | PORT_ERR_W | PORT_ERR_PI | PORT_ERR_IE | PORT_ERR_P | \
206 PORT_ERR_C | PORT_ERR_TD)
207
208/* PORT_CMD bits */
209#define PORT_CMD_ASP (1UL << 27) /* Aggressive Slumber/Partial */
210#define PORT_CMD_ALPE (1UL << 26) /* Aggressive Link PM enable */
211#define PORT_CMD_ATAPI (1UL << 24) /* Device is ATAPI */
212#define PORT_CMD_PMP (1UL << 17) /* PMP attached */
213#define PORT_CMD_LIST_ON (1UL << 15) /* cmd list DMA engine running */
214#define PORT_CMD_FIS_ON (1UL << 14) /* FIS DMA engine running */
215#define PORT_CMD_FIS_RX (1UL << 4) /* Enable FIS receive DMA engine */
216#define PORT_CMD_CLO (1UL << 3) /* Command list override */
217#define PORT_CMD_POWER_ON (1UL << 2) /* Power up device */
218#define PORT_CMD_SPIN_UP (1UL << 1) /* Spin up device */
219#define PORT_CMD_START (1UL << 0) /* Enable port DMA engine */
220
221#define PORT_CMD_ICC_MASK (0xfUL << 28) /* i/f ICC state mask */
222#define PORT_CMD_ICC_ACTIVE (0x1UL << 28) /* Put i/f in active state */
223#define PORT_CMD_ICC_PARTIAL (0x2UL << 28) /* Put i/f in partial state */
224#define PORT_CMD_ICC_SLUMBER (0x6UL << 28) /* Put i/f in slumber state */
225
226/* driver status bits */
227#define AHCI_HFLAG_NO_NCQ (1UL << 0) /* no native cmd queuing */
228#define AHCI_HFLAG_IGN_IRQ_IF_ERR (1UL << 1) /* ignore IRQ_IF_ERR */
229#define AHCI_HFLAG_IGN_SERR_INTERNAL (1UL << 2) /* ignore SERR_INTERNAL */
230#define AHCI_HFLAG_32BIT_ONLY (1UL << 3) /* force 32bit */
231#define AHCI_HFLAG_MV_PATA (1UL << 4) /* PATA port */
232#define AHCI_HFLAG_NO_MSI (1UL << 5) /* no PCI MSI */
233#define AHCI_HFLAG_NO_PMP (1UL << 6) /* no PMP */
234#define AHCI_HFLAG_NO_HOTPLUG (1UL << 7) /* ignore PxSERR.DIAG.N */
235#define AHCI_HFLAG_SECT255 (1UL << 8) /* max 255 sectors */
236#define AHCI_HFLAG_YES_NCQ (1UL << 9) /* force NCQ cap on */
237#define AHCI_HFLAG_NO_SUSPEND (1UL << 10) /* don't suspend */
238#define AHCI_HFLAG_SRST_TOUT_IS_OFFLINE (1UL << 11) /* treat SRST timeout as
239 link offline */
240#define AHCI_HFLAG_NO_SNTF (1UL << 12) /* no sntf */
241
242#define ICH_MAP 0x90 /* ICH MAP register */
243
244/* em constants */
245#define EM_MAX_SLOTS 8
246#define EM_MAX_RETRY 5
247
248/* em_ctl bits */
249#define EM_CTL_RST (1UL << 9) /* Reset */
250#define EM_CTL_TM (1UL << 8) /* Transmit Message */
251#define EM_CTL_ALHD (1UL << 26) /* Activity LED */
252
253/* ------------------------ typedefs and structures ------------------------ */
254
255/* Primitive types
256 *
257 * Note: Since OS/2 is essentially an x86 OS and this driver, as well as the
258 * interface it's developed for, is based on x86 design patterns, we're
259 * not even going to start making a difference between little and big
260 * endian architectures. PCI is little endian, AHCI is little endian,
261 * x86 is little endian, and that's it.
262 */
263typedef unsigned char u8;
264typedef unsigned short u16;
265typedef unsigned long u32;
266
267/* AHCI S/G structure */
268typedef struct {
269 u32 addr; /* address of S/G element */
270 u32 addr_hi; /* address of S/G element (upper 32 bits) */
271 u32 reserved;
272 u32 size; /* size of S/G element - 1; the high 10 bits are flags:
273 * 31 : interrupt on completion of this S/G
274 * 30-22 : reserved */
275} AHCI_SG;
276
277/* AHCI command header */
278typedef struct {
279 u32 options; /* command options */
280 u32 status; /* command status */
281 u32 tbl_addr; /* command table address */
282 u32 tbl_addr_high; /* command table address (upper 32 bits) */
283 u32 reserved[4];
284} AHCI_CMD_HDR;
285
286/* AHCI command table */
287typedef struct {
288 u8 cmd_fis[64]; /* ATA command FIS */
289 u8 atapi_cmd[16]; /* ATAPI command */
290 u8 reserved[48];
291 AHCI_SG sg_list[AHCI_MAX_SG]; /* AHCI S/G list */
292} AHCI_CMD_TBL;
293
294/* AHCI port DMA scratch area */
295typedef struct {
296 AHCI_CMD_HDR cmd_hdr[AHCI_MAX_CMDS]; /* command headers */
297 u8 rx_fis[AHCI_RX_FIS_SZ]; /* FIS RX area */
298 AHCI_CMD_TBL cmd_tbl[AHCI_MAX_CMDS]; /* command table */
299} AHCI_PORT_DMA;
300
301/* AHCI port BIOS configuration save area */
302typedef struct {
303 u32 cmd_list; /* cmd list base address */
304 u32 cmd_list_h; /* cmd list base address high */
305 u32 fis_rx; /* FIS receive buffer */
306 u32 fis_rx_h; /* FIS receive bufffer high */
307 u32 irq_mask; /* IRQ mask */
308 u32 port_cmd; /* port engine status */
309} AHCI_PORT_CFG;
310
Note: See TracBrowser for help on using the repository browser.