xref: /illumos-gate/usr/src/uts/common/io/aac/aac.h (revision 0749e8de8370b977962d1cbaa31a8ebbaf755a01)
17c478bd9Sstevel@tonic-gate /*
21ee13a44SXinChen  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
5830d82f7Spl 
67c478bd9Sstevel@tonic-gate /*
7830d82f7Spl  * Copyright 2005-06 Adaptec, Inc.
8830d82f7Spl  * Copyright (c) 2005-06 Adaptec Inc., Achim Leubner
97c478bd9Sstevel@tonic-gate  * Copyright (c) 2000 Michael Smith
107c478bd9Sstevel@tonic-gate  * Copyright (c) 2001 Scott Long
117c478bd9Sstevel@tonic-gate  * Copyright (c) 2000 BSDi
127c478bd9Sstevel@tonic-gate  * All rights reserved.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
157c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
167c478bd9Sstevel@tonic-gate  * are met:
177c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
187c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
197c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
207c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
217c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
227c478bd9Sstevel@tonic-gate  *
237c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
247c478bd9Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
257c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
267c478bd9Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
277c478bd9Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
287c478bd9Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
297c478bd9Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
307c478bd9Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
317c478bd9Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
327c478bd9Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
337c478bd9Sstevel@tonic-gate  * SUCH DAMAGE.
347c478bd9Sstevel@tonic-gate  *
35830d82f7Spl  *    $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.47 2005/10/08 15:55:09 scottl Exp $
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifndef	_AAC_H_
397c478bd9Sstevel@tonic-gate #define	_AAC_H_
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
45830d82f7Spl #define	AAC_ROUNDUP(x, y)		(((x) + (y) - 1) / (y) * (y))
46830d82f7Spl 
47830d82f7Spl #define	AAC_TYPE_DEVO			1
48830d82f7Spl #define	AAC_TYPE_ALPHA			2
49830d82f7Spl #define	AAC_TYPE_BETA			3
50830d82f7Spl #define	AAC_TYPE_RELEASE		4
51830d82f7Spl 
52830d82f7Spl #ifndef	AAC_DRIVER_BUILD
53830d82f7Spl #define	AAC_DRIVER_BUILD		1
54830d82f7Spl #endif
55830d82f7Spl 
56830d82f7Spl #define	AAC_DRIVER_MAJOR_VERSION	2
57942c5e3cSpl #define	AAC_DRIVER_MINOR_VERSION	2
58*0749e8deSXin Chen - Sun Microsystems - Beijing China #define	AAC_DRIVER_BUGFIX_LEVEL		10
59830d82f7Spl #define	AAC_DRIVER_TYPE			AAC_TYPE_RELEASE
607c478bd9Sstevel@tonic-gate 
61832e0b5aSpl #define	STR(s)				# s
62832e0b5aSpl #define	AAC_VERSION(a, b, c)		STR(a.b.c)
63832e0b5aSpl #define	AAC_DRIVER_VERSION		AAC_VERSION(AAC_DRIVER_MAJOR_VERSION, \
64832e0b5aSpl 					AAC_DRIVER_MINOR_VERSION, \
65832e0b5aSpl 					AAC_DRIVER_BUGFIX_LEVEL)
66832e0b5aSpl 
67830d82f7Spl #define	AACOK				0
68830d82f7Spl #define	AACERR				-1
69830d82f7Spl 
70830d82f7Spl #define	AAC_MAX_ADAPTERS		64
71830d82f7Spl 
72830d82f7Spl /* Definitions for mode sense */
737c478bd9Sstevel@tonic-gate #ifndef	SD_MODE_SENSE_PAGE3_CODE
74830d82f7Spl #define	SD_MODE_SENSE_PAGE3_CODE	0x03
757c478bd9Sstevel@tonic-gate #endif
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #ifndef	SD_MODE_SENSE_PAGE4_CODE
78830d82f7Spl #define	SD_MODE_SENSE_PAGE4_CODE	0x04
797c478bd9Sstevel@tonic-gate #endif
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #ifndef	SCMD_SYNCHRONIZE_CACHE
82830d82f7Spl #define	SCMD_SYNCHRONIZE_CACHE		0x35
837c478bd9Sstevel@tonic-gate #endif
847c478bd9Sstevel@tonic-gate 
85830d82f7Spl /*
86830d82f7Spl  * The controller reports status events in AIFs. We hang on to a number of
87830d82f7Spl  * these in order to pass them out to user-space management tools.
88830d82f7Spl  */
89830d82f7Spl #define	AAC_AIFQ_LENGTH			64
90830d82f7Spl 
91942c5e3cSpl #ifdef __x86
92830d82f7Spl #define	AAC_IMMEDIATE_TIMEOUT		30	/* seconds */
93942c5e3cSpl #else
94942c5e3cSpl #define	AAC_IMMEDIATE_TIMEOUT		60	/* seconds */
95942c5e3cSpl #endif
96830d82f7Spl #define	AAC_FWUP_TIMEOUT		180	/* wait up to 3 minutes */
9758bc78c7SXin Chen #define	AAC_IOCTL_TIMEOUT		900	/* wait up to 15 minutes */
98f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_SYNC_TIMEOUT		900	/* wait up to 15 minutes */
997c478bd9Sstevel@tonic-gate 
100830d82f7Spl /* Adapter hardware interface types */
101830d82f7Spl #define	AAC_HWIF_UNKNOWN		0
102830d82f7Spl #define	AAC_HWIF_I960RX			1
103830d82f7Spl #define	AAC_HWIF_RKT			2
104830d82f7Spl 
105830d82f7Spl #define	AAC_TYPE_UNKNOWN		0
106830d82f7Spl #define	AAC_TYPE_SCSI			1
107830d82f7Spl #define	AAC_TYPE_SATA			2
108830d82f7Spl #define	AAC_TYPE_SAS			3
109fd4ae32fSyf 
110942c5e3cSpl #define	AAC_LS32(d)			((uint32_t)((d) & 0xffffffffull))
111942c5e3cSpl #define	AAC_MS32(d)			((uint32_t)((d) >> 32))
112942c5e3cSpl #define	AAC_LO32(p64)			((uint32_t *)(p64))
113942c5e3cSpl #define	AAC_HI32(p64)			((uint32_t *)(p64) + 1)
114942c5e3cSpl 
115*0749e8deSXin Chen - Sun Microsystems - Beijing China /*
116*0749e8deSXin Chen - Sun Microsystems - Beijing China  * Internal events that will be handled serially by aac_event_thread()
117*0749e8deSXin Chen - Sun Microsystems - Beijing China  */
118*0749e8deSXin Chen - Sun Microsystems - Beijing China #define	AAC_EVENT_AIF			(1 << 0)
119*0749e8deSXin Chen - Sun Microsystems - Beijing China #define	AAC_EVENT_TIMEOUT		(1 << 1)
120*0749e8deSXin Chen - Sun Microsystems - Beijing China #define	AAC_EVENT_SYNCTICK		(1 << 2)
121*0749e8deSXin Chen - Sun Microsystems - Beijing China 
122382c8bcaSpl /*
123382c8bcaSpl  * AAC_CMDQ_SYNC should be 0 and AAC_CMDQ_ASYNC be 1 for Sync FIB io
124382c8bcaSpl  * to be served before async FIB io, see aac_start_waiting_io().
125382c8bcaSpl  * So that io requests sent by interactive userland commands get
126382c8bcaSpl  * responded asap.
127382c8bcaSpl  */
128382c8bcaSpl enum aac_cmdq {
129382c8bcaSpl 	AAC_CMDQ_SYNC,	/* sync FIB queue */
130382c8bcaSpl 	AAC_CMDQ_ASYNC,	/* async FIB queue */
131382c8bcaSpl 	AAC_CMDQ_NUM
132382c8bcaSpl };
133382c8bcaSpl 
134382c8bcaSpl /*
135382c8bcaSpl  * IO command flags
136382c8bcaSpl  */
137382c8bcaSpl #define	AAC_IOCMD_SYNC		(1 << AAC_CMDQ_SYNC)
138382c8bcaSpl #define	AAC_IOCMD_ASYNC		(1 << AAC_CMDQ_ASYNC)
139382c8bcaSpl #define	AAC_IOCMD_OUTSTANDING	(1 << AAC_CMDQ_NUM)
140382c8bcaSpl #define	AAC_IOCMD_ALL		(AAC_IOCMD_SYNC | AAC_IOCMD_ASYNC | \
141382c8bcaSpl 				AAC_IOCMD_OUTSTANDING)
142382c8bcaSpl 
143382c8bcaSpl struct aac_cmd_queue {
144382c8bcaSpl 	struct aac_cmd *q_head; /* also as the header of aac_cmd */
145382c8bcaSpl 	struct aac_cmd *q_tail;
146382c8bcaSpl };
147382c8bcaSpl 
1487c478bd9Sstevel@tonic-gate struct aac_card_type {
149830d82f7Spl 	uint16_t vendor;	/* PCI Vendor ID */
150830d82f7Spl 	uint16_t device;	/* PCI Device ID */
151830d82f7Spl 	uint16_t subvendor;	/* PCI Subsystem Vendor ID */
152830d82f7Spl 	uint16_t subsys;	/* PCI Subsystem ID */
153830d82f7Spl 	uint16_t hwif;		/* card chip type: i960 or Rocket */
154830d82f7Spl 	uint16_t quirks;	/* card odd limits */
155830d82f7Spl 	uint16_t type;		/* hard drive type */
156830d82f7Spl 	char *vid;		/* ASCII data for INQUIRY command vendor id */
157830d82f7Spl 	char *desc;		/* ASCII data for INQUIRY command product id */
1587c478bd9Sstevel@tonic-gate };
1597c478bd9Sstevel@tonic-gate 
16058bc78c7SXin Chen /* Device types */
16158bc78c7SXin Chen #define	AAC_DEV_LD		0	/* logical device */
16258bc78c7SXin Chen #define	AAC_DEV_PD		1	/* physical device */
16358bc78c7SXin Chen 
16458bc78c7SXin Chen /* Device flags */
16558bc78c7SXin Chen #define	AAC_DFLAG_VALID		(1 << 0)
16658bc78c7SXin Chen #define	AAC_DFLAG_CONFIGURING	(1 << 1)
16758bc78c7SXin Chen 
16858bc78c7SXin Chen #define	AAC_DEV_IS_VALID(dvp)	((dvp)->flags & AAC_DFLAG_VALID)
16958bc78c7SXin Chen 
170*0749e8deSXin Chen - Sun Microsystems - Beijing China /*
171*0749e8deSXin Chen - Sun Microsystems - Beijing China  * Device config change events
172*0749e8deSXin Chen - Sun Microsystems - Beijing China  */
173*0749e8deSXin Chen - Sun Microsystems - Beijing China enum aac_cfg_event {
174*0749e8deSXin Chen - Sun Microsystems - Beijing China 	AAC_CFG_NULL_NOEXIST = 0,	/* No change with no device */
175*0749e8deSXin Chen - Sun Microsystems - Beijing China 	AAC_CFG_NULL_EXIST,		/* No change but have device */
176*0749e8deSXin Chen - Sun Microsystems - Beijing China 	AAC_CFG_ADD,			/* Device added */
177*0749e8deSXin Chen - Sun Microsystems - Beijing China 	AAC_CFG_DELETE,			/* Device deleted */
178*0749e8deSXin Chen - Sun Microsystems - Beijing China 	AAC_CFG_CHANGE			/* Device changed */
179*0749e8deSXin Chen - Sun Microsystems - Beijing China };
180*0749e8deSXin Chen - Sun Microsystems - Beijing China 
18158bc78c7SXin Chen struct aac_device {
18258bc78c7SXin Chen 	int flags;
18358bc78c7SXin Chen 
18458bc78c7SXin Chen 	uint8_t type;
18558bc78c7SXin Chen 	dev_info_t *dip;
18658bc78c7SXin Chen 	int ncmds[AAC_CMDQ_NUM];	/* outstanding cmds of the device */
18758bc78c7SXin Chen 	int throttle[AAC_CMDQ_NUM];	/* hold IO cmds for the device */
18858bc78c7SXin Chen };
18958bc78c7SXin Chen 
190d937e6ebSpl /* Array description */
1917c478bd9Sstevel@tonic-gate struct aac_container {
19258bc78c7SXin Chen 	struct aac_device dev;
19358bc78c7SXin Chen 
194830d82f7Spl 	uint32_t cid;		/* container id */
195830d82f7Spl 	uint32_t uid;		/* container uid */
196382c8bcaSpl 	uint64_t size;		/* in block */
197382c8bcaSpl 	uint8_t locked;
198382c8bcaSpl 	uint8_t deleted;
19958bc78c7SXin Chen 	uint8_t reset;		/* container is being reseted */
20058bc78c7SXin Chen };
20158bc78c7SXin Chen 
20258bc78c7SXin Chen /* Non-DASD phys. device descrption, eg. CDROM or tape */
20358bc78c7SXin Chen struct aac_nondasd {
20458bc78c7SXin Chen 	struct aac_device dev;
20558bc78c7SXin Chen 
20658bc78c7SXin Chen 	uint32_t bus;
20758bc78c7SXin Chen 	uint32_t tid;
2087c478bd9Sstevel@tonic-gate };
2097c478bd9Sstevel@tonic-gate 
210830d82f7Spl /*
211830d82f7Spl  * The firmware can support a lot of outstanding commands. Each aac_slot
212830d82f7Spl  * is corresponding to one of such commands. It records the command and
213830d82f7Spl  * associated DMA resource for FIB command.
214830d82f7Spl  */
2157c478bd9Sstevel@tonic-gate struct aac_slot {
216382c8bcaSpl 	struct aac_slot *next;	/* next slot in the free slot list */
217382c8bcaSpl 	int index;		/* index of this slot */
2187c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t fib_acc_handle;
2197c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t fib_dma_handle;
220830d82f7Spl 	uint64_t fib_phyaddr;	/* physical address of FIB memory */
221830d82f7Spl 	struct aac_cmd *acp;	/* command using this slot */
222830d82f7Spl 	struct aac_fib *fibp;	/* virtual address of FIB memory */
2237c478bd9Sstevel@tonic-gate };
2247c478bd9Sstevel@tonic-gate 
225f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /*
226f42c2f53Szhongyan gu - Sun Microsystems - Beijing China  * Scatter-gather list structure defined by HBA hardware
227f42c2f53Szhongyan gu - Sun Microsystems - Beijing China  */
228f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_sge {
229f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	uint32_t bcount;	/* byte count */
230f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	union {
231f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 		uint32_t ad32;	/* 32 bit address */
232f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 		struct {
233f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 			uint32_t lo;
234f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 			uint32_t hi;
235f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 		} ad64;		/* 64 bit address */
236f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	} addr;
237f42c2f53Szhongyan gu - Sun Microsystems - Beijing China };
238f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
239f42c2f53Szhongyan gu - Sun Microsystems - Beijing China /* aac_cmd flags */
240f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_CONSISTENT		(1 << 0)
241f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_DMA_PARTIAL		(1 << 1)
242f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_DMA_VALID		(1 << 2)
243f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_BUF_READ		(1 << 3)
244f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_BUF_WRITE		(1 << 4)
245f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_SYNC			(1 << 5) /* use sync FIB */
246f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_NO_INTR			(1 << 6) /* poll IO, no intr */
247f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_NO_CB			(1 << 7) /* sync IO, no callback */
248f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_NTAG			(1 << 8)
249f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_CMPLT			(1 << 9) /* cmd exec'ed by driver/fw */
250f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_ABORT			(1 << 10)
251f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_TIMEOUT			(1 << 11)
252f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_ERR			(1 << 12)
253f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_CMD_IN_SYNC_SLOT		(1 << 13)
254f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
255f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_softstate;
256f42c2f53Szhongyan gu - Sun Microsystems - Beijing China typedef void (*aac_cmd_fib_t)(struct aac_softstate *, struct aac_cmd *);
257f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
258f42c2f53Szhongyan gu - Sun Microsystems - Beijing China struct aac_cmd {
259f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	/*
260f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	 * Note: should be the first member for aac_cmd_queue to work
261f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	 * correctly.
262f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	 */
263f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	struct aac_cmd *next;
264f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	struct aac_cmd *prev;
265f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
266f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	struct scsi_pkt *pkt;
267f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	int cmdlen;
268f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	int flags;
269f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	uint32_t timeout; /* time when the cmd should have completed */
270f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	struct buf *bp;
271f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	ddi_dma_handle_t buf_dma_handle;
272f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
273f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	/* For non-aligned buffer and SRB */
274f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	caddr_t abp;
275f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	ddi_acc_handle_t abh;
276f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
277f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	/* Data transfer state */
278f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	ddi_dma_cookie_t cookie;
279f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	uint_t left_cookien;
280f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	uint_t cur_win;
281f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	uint_t total_nwin;
282f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	size_t total_xfer;
283f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	uint64_t blkno;
284f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	uint32_t bcount;	/* buffer size in byte */
285f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	struct aac_sge *sgt;	/* sg table */
286f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
287f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	/* FIB construct function */
288f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	aac_cmd_fib_t aac_cmd_fib;
289f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	/* Call back function for completed command */
290f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	void (*ac_comp)(struct aac_softstate *, struct aac_cmd *);
291f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
292f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	struct aac_slot *slotp;	/* slot used by this command */
293f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	struct aac_device *dvp;	/* target device */
294f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
295f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	/* FIB for this IO command */
296f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	int fib_size; /* size of the FIB xferred to/from the card */
297f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	struct aac_fib *fibp;
298f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
299f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #ifdef DEBUG
300f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	uint32_t fib_flags;
301f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #endif
302f42c2f53Szhongyan gu - Sun Microsystems - Beijing China };
303f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 
304382c8bcaSpl /* Flags for attach tracking */
305830d82f7Spl #define	AAC_ATTACH_SOFTSTATE_ALLOCED	(1 << 0)
306830d82f7Spl #define	AAC_ATTACH_CARD_DETECTED	(1 << 1)
307830d82f7Spl #define	AAC_ATTACH_PCI_MEM_MAPPED	(1 << 2)
308830d82f7Spl #define	AAC_ATTACH_KMUTEX_INITED	(1 << 3)
309f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_ATTACH_SCSI_TRAN_SETUP	(1 << 4)
310f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_ATTACH_COMM_SPACE_SETUP	(1 << 5)
311f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_ATTACH_CREATE_DEVCTL	(1 << 6)
312f42c2f53Szhongyan gu - Sun Microsystems - Beijing China #define	AAC_ATTACH_CREATE_SCSI		(1 << 7)
313830d82f7Spl 
314382c8bcaSpl /* Driver running states */
315382c8bcaSpl #define	AAC_STATE_STOPPED	0
316382c8bcaSpl #define	AAC_STATE_RUN		(1 << 0)
317382c8bcaSpl #define	AAC_STATE_RESET		(1 << 1)
318382c8bcaSpl #define	AAC_STATE_QUIESCED	(1 << 2)
319382c8bcaSpl #define	AAC_STATE_DEAD		(1 << 3)
3201ee13a44SXinChen #define	AAC_STATE_INTR		(1 << 4)
321830d82f7Spl 
322382c8bcaSpl /*
323382c8bcaSpl  * Flags for aac firmware
324382c8bcaSpl  * Note: Quirks are only valid for the older cards. These cards only supported
325382c8bcaSpl  * old comm. Thus they are not valid for any cards that support new comm.
326382c8bcaSpl  */
327830d82f7Spl #define	AAC_FLAGS_SG_64BIT	(1 << 0) /* Use 64-bit S/G addresses */
328830d82f7Spl #define	AAC_FLAGS_4GB_WINDOW	(1 << 1) /* Can access host mem 2-4GB range */
329382c8bcaSpl #define	AAC_FLAGS_NO4GB	(1 << 2)	/* quirk: FIB addresses must reside */
330382c8bcaSpl 					/*	  between 0x2000 & 0x7FFFFFFF */
331382c8bcaSpl #define	AAC_FLAGS_256FIBS	(1 << 3) /* quirk: Can only do 256 commands */
332830d82f7Spl #define	AAC_FLAGS_NEW_COMM	(1 << 4) /* New comm. interface supported */
333830d82f7Spl #define	AAC_FLAGS_RAW_IO	(1 << 5) /* Raw I/O interface */
334830d82f7Spl #define	AAC_FLAGS_ARRAY_64BIT	(1 << 6) /* 64-bit array size */
335830d82f7Spl #define	AAC_FLAGS_LBA_64BIT	(1 << 7) /* 64-bit LBA supported */
336382c8bcaSpl #define	AAC_FLAGS_17SG		(1 << 8) /* quirk: 17 scatter gather maximum */
337382c8bcaSpl #define	AAC_FLAGS_34SG		(1 << 9) /* quirk: 34 scatter gather maximum */
33858bc78c7SXin Chen #define	AAC_FLAGS_NONDASD	(1 << 10) /* non-DASD device supported */
33972888e72Speng liu - Sun Microsystems - Beijing China #define	AAC_FLAGS_BRKUP		(1 << 11) /* pkt breakup support */
340830d82f7Spl 
341830d82f7Spl struct aac_softstate;
342830d82f7Spl struct aac_interface {
343830d82f7Spl 	int (*aif_get_fwstatus)(struct aac_softstate *);
344d937e6ebSpl 	int (*aif_get_mailbox)(struct aac_softstate *, int);
345d937e6ebSpl 	void (*aif_set_mailbox)(struct aac_softstate *, uint32_t,
346c9487164Spl 	    uint32_t, uint32_t, uint32_t, uint32_t);
347830d82f7Spl };
348830d82f7Spl 
349*0749e8deSXin Chen - Sun Microsystems - Beijing China #define	AAC_CTXFLAG_FILLED	0x01	/* aifq's full for this ctx */
350*0749e8deSXin Chen - Sun Microsystems - Beijing China #define	AAC_CTXFLAG_RESETED	0x02
351*0749e8deSXin Chen - Sun Microsystems - Beijing China 
352830d82f7Spl struct aac_fib_context {
353830d82f7Spl 	uint32_t unique;
354830d82f7Spl 	int ctx_idx;
355c4219f59Sxc 	int ctx_filled;		/* aifq is full for this fib context */
356*0749e8deSXin Chen - Sun Microsystems - Beijing China 	int ctx_flags;
357*0749e8deSXin Chen - Sun Microsystems - Beijing China 	int ctx_overrun;
358830d82f7Spl 	struct aac_fib_context *next, *prev;
359830d82f7Spl };
3607c478bd9Sstevel@tonic-gate 
361d937e6ebSpl #define	AAC_VENDOR_LEN		8
362d937e6ebSpl #define	AAC_PRODUCT_LEN		16
363d937e6ebSpl 
3647c478bd9Sstevel@tonic-gate struct aac_softstate {
365830d82f7Spl 	int card;		/* index to aac_cards */
366d937e6ebSpl 	uint16_t hwif;		/* card chip type: i960 or Rocket */
3671cea6be9Sxc 	uint16_t vendid;	/* vendor id */
3681cea6be9Sxc 	uint16_t subvendid;	/* sub vendor id */
3691cea6be9Sxc 	uint16_t devid;		/* device id */
3701cea6be9Sxc 	uint16_t subsysid;	/* sub system id */
371d937e6ebSpl 	char vendor_name[AAC_VENDOR_LEN + 1];
372d937e6ebSpl 	char product_name[AAC_PRODUCT_LEN + 1];
373830d82f7Spl 	uint32_t support_opt;	/* firmware features */
374b40e8a89Szhongyan gu - Sun Microsystems - Beijing China 	uint32_t support_opt2;
375b40e8a89Szhongyan gu - Sun Microsystems - Beijing China 	uint32_t feature_bits;
376830d82f7Spl 	uint32_t atu_size;	/* actual size of PCI mem space */
377830d82f7Spl 	uint32_t map_size;	/* mapped PCI mem space size */
378830d82f7Spl 	uint32_t map_size_min;	/* minimum size of PCI mem that must be */
379830d82f7Spl 				/* mapped to address the card */
380c9487164Spl 	int flags;		/* firmware features enabled */
3811dd0a2dbSpl 	int instance;
3827c478bd9Sstevel@tonic-gate 	dev_info_t *devinfo_p;
38358bc78c7SXin Chen 	scsi_hba_tran_t *hba_tran;
384d7c5bf88Spl 	int slen;
38558bc78c7SXin Chen 	int legacy;		/* legacy device naming */
38672888e72Speng liu - Sun Microsystems - Beijing China 	uint32_t dma_max;	/* for buf breakup */
387830d82f7Spl 
388c9487164Spl 	/* DMA attributes */
389830d82f7Spl 	ddi_dma_attr_t buf_dma_attr;
390830d82f7Spl 	ddi_dma_attr_t addr_dma_attr;
3917c478bd9Sstevel@tonic-gate 
392c9487164Spl 	/* PCI spaces */
39358bc78c7SXin Chen 	ddi_device_acc_attr_t acc_attr;
394837c1ac4SStephen Hanson 	ddi_device_acc_attr_t reg_attr;
3957c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t pci_mem_handle;
396a74f7440Spl 	uint8_t *pci_mem_base_vaddr;
3971dd0a2dbSpl 	uint32_t pci_mem_base_paddr;
3987c478bd9Sstevel@tonic-gate 
399c9487164Spl 	struct aac_interface aac_if;	/* adapter hardware interface */
4007c478bd9Sstevel@tonic-gate 
401f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	struct aac_cmd sync_ac;		/* sync FIB */
4027c478bd9Sstevel@tonic-gate 
403c9487164Spl 	/* Communication space */
4047c478bd9Sstevel@tonic-gate 	struct aac_comm_space *comm_space;
4057c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t comm_space_acc_handle;
4067c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t comm_space_dma_handle;
407830d82f7Spl 	uint32_t comm_space_phyaddr;
4087c478bd9Sstevel@tonic-gate 
409c9487164Spl 	/* Old Comm. interface: message queues */
4107c478bd9Sstevel@tonic-gate 	struct aac_queue_table *qtablep;
4117c478bd9Sstevel@tonic-gate 	struct aac_queue_entry *qentries[AAC_QUEUE_COUNT];
4127c478bd9Sstevel@tonic-gate 
413c9487164Spl 	/* New Comm. interface */
414c9487164Spl 	uint32_t aac_max_fibs;		/* max. FIB count */
415c9487164Spl 	uint32_t aac_max_fib_size;	/* max. FIB size */
416c9487164Spl 	uint32_t aac_sg_tablesize;	/* max. sg count from host */
417c9487164Spl 	uint32_t aac_max_sectors;	/* max. I/O size from host (blocks) */
418c9487164Spl 
419d7c5bf88Spl 	aac_cmd_fib_t aac_cmd_fib;	/* IO cmd FIB construct function */
420942c5e3cSpl 	aac_cmd_fib_t aac_cmd_fib_scsi;	/* SRB construct function */
421d7c5bf88Spl 
422c9487164Spl 	ddi_softintr_t softint_id;	/* soft intr */
423c9487164Spl 
424382c8bcaSpl 	kmutex_t io_lock;
425c9487164Spl 	int state;			/* driver state */
426c9487164Spl 
427942c5e3cSpl 	struct aac_container containers[AAC_MAX_LD];
428c9487164Spl 	int container_count;		/* max container id + 1 */
42958bc78c7SXin Chen 	struct aac_nondasd *nondasds;
43058bc78c7SXin Chen 	uint32_t bus_max;		/* max FW buses exposed */
43158bc78c7SXin Chen 	uint32_t tgt_max;		/* max FW target per bus */
4327c478bd9Sstevel@tonic-gate 
433830d82f7Spl 	/*
434830d82f7Spl 	 * Command queues
435830d82f7Spl 	 * Each aac command flows through wait(or wait_sync) queue,
436382c8bcaSpl 	 * busy queue, and complete queue sequentially.
437830d82f7Spl 	 */
438382c8bcaSpl 	struct aac_cmd_queue q_wait[AAC_CMDQ_NUM];
439382c8bcaSpl 	struct aac_cmd_queue q_busy;	/* outstanding cmd queue */
440382c8bcaSpl 	kmutex_t q_comp_mutex;
441c9487164Spl 	struct aac_cmd_queue q_comp;	/* completed io requests */
442830d82f7Spl 
443d937e6ebSpl 	/* I/O slots and FIBs */
444830d82f7Spl 	int total_slots;		/* total slots allocated */
445830d82f7Spl 	int total_fibs;			/* total FIBs allocated */
446830d82f7Spl 	struct aac_slot *io_slot;	/* static list for allocated slots */
447382c8bcaSpl 	struct aac_slot *free_io_slot_head;
4487c478bd9Sstevel@tonic-gate 
449382c8bcaSpl 	kcondvar_t event;		/* for ioctl_send_fib() and sync IO */
4501ee13a44SXinChen 	kcondvar_t sync_fib_cv;		/* for sync_fib_slot_bind/release */
451382c8bcaSpl 
452382c8bcaSpl 	int bus_ncmds[AAC_CMDQ_NUM];	/* total outstanding async cmds */
453382c8bcaSpl 	int bus_throttle[AAC_CMDQ_NUM];	/* hold IO cmds for the bus */
454382c8bcaSpl 	int ndrains;			/* number of draining threads */
455382c8bcaSpl 	timeout_id_t drain_timeid;	/* for outstanding cmd drain */
456382c8bcaSpl 	kcondvar_t drain_cv;		/* for quiesce drain */
457830d82f7Spl 
458*0749e8deSXin Chen - Sun Microsystems - Beijing China 	/* Internal timer */
459*0749e8deSXin Chen - Sun Microsystems - Beijing China 	kmutex_t time_mutex;
460*0749e8deSXin Chen - Sun Microsystems - Beijing China 	timeout_id_t timeout_id;	/* for timeout daemon */
461*0749e8deSXin Chen - Sun Microsystems - Beijing China 	uint32_t timebase;		/* internal timer in seconds */
462*0749e8deSXin Chen - Sun Microsystems - Beijing China 	uint32_t time_sync;		/* next time to sync with firmware */
463*0749e8deSXin Chen - Sun Microsystems - Beijing China 	uint32_t time_out;		/* next time to check timeout */
464*0749e8deSXin Chen - Sun Microsystems - Beijing China 	uint32_t time_throttle;		/* next time to restore throttle */
465*0749e8deSXin Chen - Sun Microsystems - Beijing China 
466*0749e8deSXin Chen - Sun Microsystems - Beijing China 	/* Internal events handling */
467*0749e8deSXin Chen - Sun Microsystems - Beijing China 	kmutex_t ev_lock;
468*0749e8deSXin Chen - Sun Microsystems - Beijing China 	int events;
469*0749e8deSXin Chen - Sun Microsystems - Beijing China 	kthread_t *event_thread;	/* for AIF & timeout */
470*0749e8deSXin Chen - Sun Microsystems - Beijing China 	kcondvar_t event_wait_cv;
471*0749e8deSXin Chen - Sun Microsystems - Beijing China 	kcondvar_t event_disp_cv;
472*0749e8deSXin Chen - Sun Microsystems - Beijing China 
473830d82f7Spl 	/* AIF */
474830d82f7Spl 	kmutex_t aifq_mutex;		/* for AIF queue aifq */
475*0749e8deSXin Chen - Sun Microsystems - Beijing China 	kcondvar_t aifq_cv;
476942c5e3cSpl 	union aac_fib_align aifq[AAC_AIFQ_LENGTH];
477c4219f59Sxc 	int aifq_idx;			/* slot for next new AIF */
478c4219f59Sxc 	int aifq_wrap;			/* AIF queue has ever been wrapped */
479*0749e8deSXin Chen - Sun Microsystems - Beijing China 	struct aac_fib_context aifctx;	/* sys aif ctx */
480*0749e8deSXin Chen - Sun Microsystems - Beijing China 	struct aac_fib_context *fibctx_p;
481830d82f7Spl 	int devcfg_wait_on;		/* AIF event waited for rescan */
4821dd0a2dbSpl 
4837675db54Syw 	int fm_capabilities;
4847675db54Syw 
485b6094a86Sjd 	/* MSI specific fields */
486b6094a86Sjd 	ddi_intr_handle_t *htable;	/* For array of interrupts */
487b6094a86Sjd 	int intr_type;			/* What type of interrupt */
488b6094a86Sjd 	int intr_cnt;			/* # of intrs count returned */
489f42c2f53Szhongyan gu - Sun Microsystems - Beijing China 	int intr_size;
490b6094a86Sjd 	uint_t intr_pri;		/* Interrupt priority   */
491b6094a86Sjd 	int intr_cap;			/* Interrupt capabilities */
492b6094a86Sjd 
4931dd0a2dbSpl #ifdef DEBUG
4941dd0a2dbSpl 	/* UART trace printf variables */
4951dd0a2dbSpl 	uint32_t debug_flags;		/* debug print flags bitmap */
49658bc78c7SXin Chen 	uint32_t debug_fib_flags;	/* debug FIB print flags bitmap */
4971dd0a2dbSpl 	uint32_t debug_fw_flags;	/* FW debug flags */
4981dd0a2dbSpl 	uint32_t debug_buf_offset;	/* offset from DPMEM start */
4991dd0a2dbSpl 	uint32_t debug_buf_size;	/* FW debug buffer size in bytes */
5001dd0a2dbSpl 	uint32_t debug_header_size;	/* size of debug header */
5011dd0a2dbSpl #endif
5027c478bd9Sstevel@tonic-gate };
5037c478bd9Sstevel@tonic-gate 
504942c5e3cSpl /*
505942c5e3cSpl  * The following data are kept stable because they are only written at driver
506942c5e3cSpl  * initialization, and we do not allow them changed otherwise even at driver
507942c5e3cSpl  * re-initialization.
508942c5e3cSpl  */
509382c8bcaSpl _NOTE(SCHEME_PROTECTS_DATA("stable data", aac_softstate::{flags slen \
510942c5e3cSpl     buf_dma_attr pci_mem_handle pci_mem_base_vaddr \
511382c8bcaSpl     comm_space_acc_handle comm_space_dma_handle aac_max_fib_size \
51258bc78c7SXin Chen     aac_sg_tablesize aac_cmd_fib aac_cmd_fib_scsi debug_flags bus_max tgt_max}))
513942c5e3cSpl 
5141dd0a2dbSpl #ifdef DEBUG
5151dd0a2dbSpl 
5161dd0a2dbSpl #define	AACDB_FLAGS_MASK		0x0000ffff
5171dd0a2dbSpl #define	AACDB_FLAGS_KERNEL_PRINT	0x00000001
5181dd0a2dbSpl #define	AACDB_FLAGS_FW_PRINT		0x00000002
519942c5e3cSpl #define	AACDB_FLAGS_NO_HEADERS		0x00000004
520942c5e3cSpl 
521942c5e3cSpl #define	AACDB_FLAGS_MISC		0x00000010
522942c5e3cSpl #define	AACDB_FLAGS_FUNC1		0x00000020
523942c5e3cSpl #define	AACDB_FLAGS_FUNC2		0x00000040
524942c5e3cSpl #define	AACDB_FLAGS_SCMD		0x00000080
525942c5e3cSpl #define	AACDB_FLAGS_AIF			0x00000100
526942c5e3cSpl #define	AACDB_FLAGS_FIB			0x00000200
527942c5e3cSpl #define	AACDB_FLAGS_IOCTL		0x00000400
5281dd0a2dbSpl 
52958bc78c7SXin Chen /*
53058bc78c7SXin Chen  * Flags for FIB print
53158bc78c7SXin Chen  */
53258bc78c7SXin Chen /* FIB sources */
53358bc78c7SXin Chen #define	AACDB_FLAGS_FIB_SCMD		0x00000001
53458bc78c7SXin Chen #define	AACDB_FLAGS_FIB_IOCTL		0x00000002
53558bc78c7SXin Chen #define	AACDB_FLAGS_FIB_SRB		0x00000004
53658bc78c7SXin Chen #define	AACDB_FLAGS_FIB_SYNC		0x00000008
53758bc78c7SXin Chen /* FIB components */
53858bc78c7SXin Chen #define	AACDB_FLAGS_FIB_HEADER		0x00000010
53958bc78c7SXin Chen /* FIB states */
54058bc78c7SXin Chen #define	AACDB_FLAGS_FIB_TIMEOUT		0x00000100
54158bc78c7SXin Chen 
5421dd0a2dbSpl extern uint32_t aac_debug_flags;
5431dd0a2dbSpl extern int aac_dbflag_on(struct aac_softstate *, int);
5441dd0a2dbSpl extern void aac_printf(struct aac_softstate *, uint_t, const char *, ...);
54558bc78c7SXin Chen extern void aac_print_fib(struct aac_softstate *, struct aac_slot *);
5461dd0a2dbSpl 
5471dd0a2dbSpl #define	AACDB_PRINT(s, lev, ...) { \
5481dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_MISC)) \
5491dd0a2dbSpl 		aac_printf((s), (lev), __VA_ARGS__); }
5501dd0a2dbSpl 
5511dd0a2dbSpl #define	AACDB_PRINT_IOCTL(s, ...) { \
5521dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_IOCTL)) \
5531dd0a2dbSpl 		aac_printf((s), CE_NOTE, __VA_ARGS__); }
5541dd0a2dbSpl 
5551dd0a2dbSpl #define	AACDB_PRINT_TRAN(s, ...) { \
5561dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) \
5571dd0a2dbSpl 		aac_printf((s), CE_NOTE, __VA_ARGS__); }
5581dd0a2dbSpl 
5591dd0a2dbSpl #define	DBCALLED(s, n) { \
5601dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_FUNC ## n)) \
5611dd0a2dbSpl 		aac_printf((s), CE_NOTE, "--- %s() called ---", __func__); }
5621dd0a2dbSpl 
5631dd0a2dbSpl #define	AACDB_PRINT_SCMD(s, x) { \
5641dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) aac_print_scmd((s), (x)); }
5651dd0a2dbSpl 
5661dd0a2dbSpl #define	AACDB_PRINT_AIF(s, x) { \
5671dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_AIF)) aac_print_aif((s), (x)); }
5681dd0a2dbSpl 
5691dd0a2dbSpl #define	AACDB_PRINT_FIB(s, x) { \
5701dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_FIB)) aac_print_fib((s), (x)); }
5711dd0a2dbSpl 
5721dd0a2dbSpl #else /* DEBUG */
5731dd0a2dbSpl 
5741dd0a2dbSpl #define	AACDB_PRINT(s, lev, ...)
5751dd0a2dbSpl #define	AACDB_PRINT_IOCTL(s, ...)
5761dd0a2dbSpl #define	AACDB_PRINT_TRAN(s, ...)
5771dd0a2dbSpl #define	AACDB_PRINT_FIB(s, x)
5781dd0a2dbSpl #define	AACDB_PRINT_SCMD(s, x)
5791dd0a2dbSpl #define	AACDB_PRINT_AIF(s, x)
5801dd0a2dbSpl #define	DBCALLED(s, n)
5811dd0a2dbSpl 
5821dd0a2dbSpl #endif /* DEBUG */
5831dd0a2dbSpl 
5847c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
5857c478bd9Sstevel@tonic-gate }
5867c478bd9Sstevel@tonic-gate #endif
5877c478bd9Sstevel@tonic-gate 
5887c478bd9Sstevel@tonic-gate #endif /* _AAC_H_ */
589