17c478bdstevel@tonic-gate/*
23fced43zhongyan gu - Sun Microsystems - Beijing China * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
37c478bdstevel@tonic-gate */
4830d82fpl
57c478bdstevel@tonic-gate/*
6830d82fpl * Copyright 2005-06 Adaptec, Inc.
7830d82fpl * Copyright (c) 2005-06 Adaptec Inc., Achim Leubner
87c478bdstevel@tonic-gate * Copyright (c) 2000 Michael Smith
97c478bdstevel@tonic-gate * Copyright (c) 2001 Scott Long
107c478bdstevel@tonic-gate * Copyright (c) 2000 BSDi
117c478bdstevel@tonic-gate * All rights reserved.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
147c478bdstevel@tonic-gate * modification, are permitted provided that the following conditions
157c478bdstevel@tonic-gate * are met:
167c478bdstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
177c478bdstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
187c478bdstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
197c478bdstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
207c478bdstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
217c478bdstevel@tonic-gate *
227c478bdstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
237c478bdstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
247c478bdstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
257c478bdstevel@tonic-gate * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
267c478bdstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
277c478bdstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
287c478bdstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
297c478bdstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
307c478bdstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
317c478bdstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
327c478bdstevel@tonic-gate * SUCH DAMAGE.
337c478bdstevel@tonic-gate *
34830d82fpl *    $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.47 2005/10/08 15:55:09 scottl Exp $
357c478bdstevel@tonic-gate */
367c478bdstevel@tonic-gate
377c478bdstevel@tonic-gate#ifndef	_AAC_H_
387c478bdstevel@tonic-gate#define	_AAC_H_
397c478bdstevel@tonic-gate
407c478bdstevel@tonic-gate#ifdef	__cplusplus
417c478bdstevel@tonic-gateextern "C" {
427c478bdstevel@tonic-gate#endif
437c478bdstevel@tonic-gate
44830d82fpl#define	AAC_ROUNDUP(x, y)		(((x) + (y) - 1) / (y) * (y))
45830d82fpl
46830d82fpl#define	AAC_TYPE_DEVO			1
47830d82fpl#define	AAC_TYPE_ALPHA			2
48830d82fpl#define	AAC_TYPE_BETA			3
49830d82fpl#define	AAC_TYPE_RELEASE		4
50830d82fpl
51830d82fpl#ifndef	AAC_DRIVER_BUILD
52830d82fpl#define	AAC_DRIVER_BUILD		1
53830d82fpl#endif
54830d82fpl
55830d82fpl#define	AAC_DRIVER_MAJOR_VERSION	2
56942c5e3pl#define	AAC_DRIVER_MINOR_VERSION	2
573fced43zhongyan gu - Sun Microsystems - Beijing China#define	AAC_DRIVER_BUGFIX_LEVEL		11
58830d82fpl#define	AAC_DRIVER_TYPE			AAC_TYPE_RELEASE
597c478bdstevel@tonic-gate
60832e0b5pl#define	STR(s)				# s
61832e0b5pl#define	AAC_VERSION(a, b, c)		STR(a.b.c)
62832e0b5pl#define	AAC_DRIVER_VERSION		AAC_VERSION(AAC_DRIVER_MAJOR_VERSION, \
63832e0b5pl					AAC_DRIVER_MINOR_VERSION, \
64832e0b5pl					AAC_DRIVER_BUGFIX_LEVEL)
65832e0b5pl
66830d82fpl#define	AACOK				0
67830d82fpl#define	AACERR				-1
68830d82fpl
69830d82fpl#define	AAC_MAX_ADAPTERS		64
70830d82fpl
71830d82fpl/* Definitions for mode sense */
727c478bdstevel@tonic-gate#ifndef	SD_MODE_SENSE_PAGE3_CODE
73830d82fpl#define	SD_MODE_SENSE_PAGE3_CODE	0x03
747c478bdstevel@tonic-gate#endif
757c478bdstevel@tonic-gate
767c478bdstevel@tonic-gate#ifndef	SD_MODE_SENSE_PAGE4_CODE
77830d82fpl#define	SD_MODE_SENSE_PAGE4_CODE	0x04
787c478bdstevel@tonic-gate#endif
797c478bdstevel@tonic-gate
807c478bdstevel@tonic-gate#ifndef	SCMD_SYNCHRONIZE_CACHE
81830d82fpl#define	SCMD_SYNCHRONIZE_CACHE		0x35
827c478bdstevel@tonic-gate#endif
837c478bdstevel@tonic-gate
84830d82fpl/*
85830d82fpl * The controller reports status events in AIFs. We hang on to a number of
86830d82fpl * these in order to pass them out to user-space management tools.
87830d82fpl */
88830d82fpl#define	AAC_AIFQ_LENGTH			64
89830d82fpl
90942c5e3pl#ifdef __x86
91830d82fpl#define	AAC_IMMEDIATE_TIMEOUT		30	/* seconds */
92942c5e3pl#else
93942c5e3pl#define	AAC_IMMEDIATE_TIMEOUT		60	/* seconds */
94942c5e3pl#endif
95830d82fpl#define	AAC_FWUP_TIMEOUT		180	/* wait up to 3 minutes */
9658bc78cXin Chen<Xin.Chen@Sun.COM>#define	AAC_IOCTL_TIMEOUT		900	/* wait up to 15 minutes */
97f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_SYNC_TIMEOUT		900	/* wait up to 15 minutes */
987c478bdstevel@tonic-gate
99830d82fpl/* Adapter hardware interface types */
100830d82fpl#define	AAC_HWIF_UNKNOWN		0
101830d82fpl#define	AAC_HWIF_I960RX			1
102830d82fpl#define	AAC_HWIF_RKT			2
103830d82fpl
104830d82fpl#define	AAC_TYPE_UNKNOWN		0
105830d82fpl#define	AAC_TYPE_SCSI			1
106830d82fpl#define	AAC_TYPE_SATA			2
107830d82fpl#define	AAC_TYPE_SAS			3
108fd4ae32yf
109942c5e3pl#define	AAC_LS32(d)			((uint32_t)((d) & 0xffffffffull))
110942c5e3pl#define	AAC_MS32(d)			((uint32_t)((d) >> 32))
111942c5e3pl#define	AAC_LO32(p64)			((uint32_t *)(p64))
112942c5e3pl#define	AAC_HI32(p64)			((uint32_t *)(p64) + 1)
113942c5e3pl
114382c8bcpl/*
1150749e8dXin Chen - Sun Microsystems - Beijing China * Internal events that will be handled serially by aac_event_thread()
1160749e8dXin Chen - Sun Microsystems - Beijing China */
1170749e8dXin Chen - Sun Microsystems - Beijing China#define	AAC_EVENT_AIF			(1 << 0)
1180749e8dXin Chen - Sun Microsystems - Beijing China#define	AAC_EVENT_TIMEOUT		(1 << 1)
1190749e8dXin Chen - Sun Microsystems - Beijing China#define	AAC_EVENT_SYNCTICK		(1 << 2)
1200749e8dXin Chen - Sun Microsystems - Beijing China
1210749e8dXin Chen - Sun Microsystems - Beijing China/*
122382c8bcpl * AAC_CMDQ_SYNC should be 0 and AAC_CMDQ_ASYNC be 1 for Sync FIB io
123382c8bcpl * to be served before async FIB io, see aac_start_waiting_io().
124382c8bcpl * So that io requests sent by interactive userland commands get
125382c8bcpl * responded asap.
126382c8bcpl */
127382c8bcplenum aac_cmdq {
128382c8bcpl	AAC_CMDQ_SYNC,	/* sync FIB queue */
129382c8bcpl	AAC_CMDQ_ASYNC,	/* async FIB queue */
130382c8bcpl	AAC_CMDQ_NUM
131382c8bcpl};
132382c8bcpl
133382c8bcpl/*
134382c8bcpl * IO command flags
135382c8bcpl */
136382c8bcpl#define	AAC_IOCMD_SYNC		(1 << AAC_CMDQ_SYNC)
137382c8bcpl#define	AAC_IOCMD_ASYNC		(1 << AAC_CMDQ_ASYNC)
138382c8bcpl#define	AAC_IOCMD_OUTSTANDING	(1 << AAC_CMDQ_NUM)
139382c8bcpl#define	AAC_IOCMD_ALL		(AAC_IOCMD_SYNC | AAC_IOCMD_ASYNC | \
140382c8bcpl				AAC_IOCMD_OUTSTANDING)
141382c8bcpl
142382c8bcplstruct aac_cmd_queue {
143382c8bcpl	struct aac_cmd *q_head; /* also as the header of aac_cmd */
144382c8bcpl	struct aac_cmd *q_tail;
145382c8bcpl};
146382c8bcpl
1477c478bdstevel@tonic-gatestruct aac_card_type {
148830d82fpl	uint16_t vendor;	/* PCI Vendor ID */
149830d82fpl	uint16_t device;	/* PCI Device ID */
150830d82fpl	uint16_t subvendor;	/* PCI Subsystem Vendor ID */
151830d82fpl	uint16_t subsys;	/* PCI Subsystem ID */
152830d82fpl	uint16_t hwif;		/* card chip type: i960 or Rocket */
153830d82fpl	uint16_t quirks;	/* card odd limits */
154830d82fpl	uint16_t type;		/* hard drive type */
155830d82fpl	char *vid;		/* ASCII data for INQUIRY command vendor id */
156830d82fpl	char *desc;		/* ASCII data for INQUIRY command product id */
1577c478bdstevel@tonic-gate};
1587c478bdstevel@tonic-gate
15958bc78cXin Chen<Xin.Chen@Sun.COM>/* Device types */
16058bc78cXin Chen<Xin.Chen@Sun.COM>#define	AAC_DEV_LD		0	/* logical device */
16158bc78cXin Chen<Xin.Chen@Sun.COM>#define	AAC_DEV_PD		1	/* physical device */
16258bc78cXin Chen<Xin.Chen@Sun.COM>
16358bc78cXin Chen<Xin.Chen@Sun.COM>/* Device flags */
16458bc78cXin Chen<Xin.Chen@Sun.COM>#define	AAC_DFLAG_VALID		(1 << 0)
16558bc78cXin Chen<Xin.Chen@Sun.COM>#define	AAC_DFLAG_CONFIGURING	(1 << 1)
16658bc78cXin Chen<Xin.Chen@Sun.COM>
16758bc78cXin Chen<Xin.Chen@Sun.COM>#define	AAC_DEV_IS_VALID(dvp)	((dvp)->flags & AAC_DFLAG_VALID)
1683fced43zhongyan gu - Sun Microsystems - Beijing China#define	AAC_P2VTGT(softs, bus, tgt) \
1693fced43zhongyan gu - Sun Microsystems - Beijing China		((softs)->tgt_max * (bus) + (tgt) + AAC_MAX_LD)
17058bc78cXin Chen<Xin.Chen@Sun.COM>
1710749e8dXin Chen - Sun Microsystems - Beijing China/*
1720749e8dXin Chen - Sun Microsystems - Beijing China * Device config change events
1730749e8dXin Chen - Sun Microsystems - Beijing China */
1740749e8dXin Chen - Sun Microsystems - Beijing Chinaenum aac_cfg_event {
1750749e8dXin Chen - Sun Microsystems - Beijing China	AAC_CFG_NULL_NOEXIST = 0,	/* No change with no device */
1760749e8dXin Chen - Sun Microsystems - Beijing China	AAC_CFG_NULL_EXIST,		/* No change but have device */
1770749e8dXin Chen - Sun Microsystems - Beijing China	AAC_CFG_ADD,			/* Device added */
1780749e8dXin Chen - Sun Microsystems - Beijing China	AAC_CFG_DELETE,			/* Device deleted */
1790749e8dXin Chen - Sun Microsystems - Beijing China	AAC_CFG_CHANGE			/* Device changed */
1800749e8dXin Chen - Sun Microsystems - Beijing China};
1810749e8dXin Chen - Sun Microsystems - Beijing China
18258bc78cXin Chen<Xin.Chen@Sun.COM>struct aac_device {
18358bc78cXin Chen<Xin.Chen@Sun.COM>	int flags;
18458bc78cXin Chen<Xin.Chen@Sun.COM>
18558bc78cXin Chen<Xin.Chen@Sun.COM>	uint8_t type;
18658bc78cXin Chen<Xin.Chen@Sun.COM>	dev_info_t *dip;
18758bc78cXin Chen<Xin.Chen@Sun.COM>	int ncmds[AAC_CMDQ_NUM];	/* outstanding cmds of the device */
18858bc78cXin Chen<Xin.Chen@Sun.COM>	int throttle[AAC_CMDQ_NUM];	/* hold IO cmds for the device */
18958bc78cXin Chen<Xin.Chen@Sun.COM>};
19058bc78cXin Chen<Xin.Chen@Sun.COM>
191d937e6epl/* Array description */
1927c478bdstevel@tonic-gatestruct aac_container {
19358bc78cXin Chen<Xin.Chen@Sun.COM>	struct aac_device dev;
19458bc78cXin Chen<Xin.Chen@Sun.COM>
195830d82fpl	uint32_t cid;		/* container id */
196830d82fpl	uint32_t uid;		/* container uid */
197382c8bcpl	uint64_t size;		/* in block */
198382c8bcpl	uint8_t locked;
199382c8bcpl	uint8_t deleted;
20058bc78cXin Chen<Xin.Chen@Sun.COM>	uint8_t reset;		/* container is being reseted */
20158bc78cXin Chen<Xin.Chen@Sun.COM>};
20258bc78cXin Chen<Xin.Chen@Sun.COM>
20358bc78cXin Chen<Xin.Chen@Sun.COM>/* Non-DASD phys. device descrption, eg. CDROM or tape */
20458bc78cXin Chen<Xin.Chen@Sun.COM>struct aac_nondasd {
20558bc78cXin Chen<Xin.Chen@Sun.COM>	struct aac_device dev;
20658bc78cXin Chen<Xin.Chen@Sun.COM>
20758bc78cXin Chen<Xin.Chen@Sun.COM>	uint32_t bus;
20858bc78cXin Chen<Xin.Chen@Sun.COM>	uint32_t tid;
2097c478bdstevel@tonic-gate};
2107c478bdstevel@tonic-gate
211830d82fpl/*
212830d82fpl * The firmware can support a lot of outstanding commands. Each aac_slot
213830d82fpl * is corresponding to one of such commands. It records the command and
214830d82fpl * associated DMA resource for FIB command.
215830d82fpl */
2167c478bdstevel@tonic-gatestruct aac_slot {
217382c8bcpl	struct aac_slot *next;	/* next slot in the free slot list */
218382c8bcpl	int index;		/* index of this slot */
2197c478bdstevel@tonic-gate	ddi_acc_handle_t fib_acc_handle;
2207c478bdstevel@tonic-gate	ddi_dma_handle_t fib_dma_handle;
221830d82fpl	uint64_t fib_phyaddr;	/* physical address of FIB memory */
222830d82fpl	struct aac_cmd *acp;	/* command using this slot */
223830d82fpl	struct aac_fib *fibp;	/* virtual address of FIB memory */
2247c478bdstevel@tonic-gate};
2257c478bdstevel@tonic-gate
226f42c2f5zhongyan gu - Sun Microsystems - Beijing China/*
227f42c2f5zhongyan gu - Sun Microsystems - Beijing China * Scatter-gather list structure defined by HBA hardware
228f42c2f5zhongyan gu - Sun Microsystems - Beijing China */
229f42c2f5zhongyan gu - Sun Microsystems - Beijing Chinastruct aac_sge {
230f42c2f5zhongyan gu - Sun Microsystems - Beijing China	uint32_t bcount;	/* byte count */
231f42c2f5zhongyan gu - Sun Microsystems - Beijing China	union {
232f42c2f5zhongyan gu - Sun Microsystems - Beijing China		uint32_t ad32;	/* 32 bit address */
233f42c2f5zhongyan gu - Sun Microsystems - Beijing China		struct {
234f42c2f5zhongyan gu - Sun Microsystems - Beijing China			uint32_t lo;
235f42c2f5zhongyan gu - Sun Microsystems - Beijing China			uint32_t hi;
236f42c2f5zhongyan gu - Sun Microsystems - Beijing China		} ad64;		/* 64 bit address */
237f42c2f5zhongyan gu - Sun Microsystems - Beijing China	} addr;
238f42c2f5zhongyan gu - Sun Microsystems - Beijing China};
239f42c2f5zhongyan gu - Sun Microsystems - Beijing China
240f42c2f5zhongyan gu - Sun Microsystems - Beijing China/* aac_cmd flags */
241f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_CONSISTENT		(1 << 0)
242f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_DMA_PARTIAL		(1 << 1)
243f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_DMA_VALID		(1 << 2)
244f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_BUF_READ		(1 << 3)
245f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_BUF_WRITE		(1 << 4)
246f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_SYNC			(1 << 5) /* use sync FIB */
247f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_NO_INTR			(1 << 6) /* poll IO, no intr */
248f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_NO_CB			(1 << 7) /* sync IO, no callback */
249f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_NTAG			(1 << 8)
250f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_CMPLT			(1 << 9) /* cmd exec'ed by driver/fw */
251f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_ABORT			(1 << 10)
252f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_TIMEOUT			(1 << 11)
253f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_ERR			(1 << 12)
254f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_CMD_IN_SYNC_SLOT		(1 << 13)
255f42c2f5zhongyan gu - Sun Microsystems - Beijing China
256f42c2f5zhongyan gu - Sun Microsystems - Beijing Chinastruct aac_softstate;
257f42c2f5zhongyan gu - Sun Microsystems - Beijing Chinatypedef void (*aac_cmd_fib_t)(struct aac_softstate *, struct aac_cmd *);
258f42c2f5zhongyan gu - Sun Microsystems - Beijing China
259f42c2f5zhongyan gu - Sun Microsystems - Beijing Chinastruct aac_cmd {
260f42c2f5zhongyan gu - Sun Microsystems - Beijing China	/*
261f42c2f5zhongyan gu - Sun Microsystems - Beijing China	 * Note: should be the first member for aac_cmd_queue to work
262f42c2f5zhongyan gu - Sun Microsystems - Beijing China	 * correctly.
263f42c2f5zhongyan gu - Sun Microsystems - Beijing China	 */
264f42c2f5zhongyan gu - Sun Microsystems - Beijing China	struct aac_cmd *next;
265f42c2f5zhongyan gu - Sun Microsystems - Beijing China	struct aac_cmd *prev;
266f42c2f5zhongyan gu - Sun Microsystems - Beijing China
267f42c2f5zhongyan gu - Sun Microsystems - Beijing China	struct scsi_pkt *pkt;
268f42c2f5zhongyan gu - Sun Microsystems - Beijing China	int cmdlen;
269f42c2f5zhongyan gu - Sun Microsystems - Beijing China	int flags;
270f42c2f5zhongyan gu - Sun Microsystems - Beijing China	uint32_t timeout; /* time when the cmd should have completed */
271f42c2f5zhongyan gu - Sun Microsystems - Beijing China	struct buf *bp;
272f42c2f5zhongyan gu - Sun Microsystems - Beijing China	ddi_dma_handle_t buf_dma_handle;
273f42c2f5zhongyan gu - Sun Microsystems - Beijing China
274f42c2f5zhongyan gu - Sun Microsystems - Beijing China	/* For non-aligned buffer and SRB */
275f42c2f5zhongyan gu - Sun Microsystems - Beijing China	caddr_t abp;
276f42c2f5zhongyan gu - Sun Microsystems - Beijing China	ddi_acc_handle_t abh;
277f42c2f5zhongyan gu - Sun Microsystems - Beijing China
278f42c2f5zhongyan gu - Sun Microsystems - Beijing China	/* Data transfer state */
279f42c2f5zhongyan gu - Sun Microsystems - Beijing China	ddi_dma_cookie_t cookie;
280f42c2f5zhongyan gu - Sun Microsystems - Beijing China	uint_t left_cookien;
281f42c2f5zhongyan gu - Sun Microsystems - Beijing China	uint_t cur_win;
282f42c2f5zhongyan gu - Sun Microsystems - Beijing China	uint_t total_nwin;
283f42c2f5zhongyan gu - Sun Microsystems - Beijing China	size_t total_xfer;
284f42c2f5zhongyan gu - Sun Microsystems - Beijing China	uint64_t blkno;
285f42c2f5zhongyan gu - Sun Microsystems - Beijing China	uint32_t bcount;	/* buffer size in byte */
286f42c2f5zhongyan gu - Sun Microsystems - Beijing China	struct aac_sge *sgt;	/* sg table */
287f42c2f5zhongyan gu - Sun Microsystems - Beijing China
288f42c2f5zhongyan gu - Sun Microsystems - Beijing China	/* FIB construct function */
289f42c2f5zhongyan gu - Sun Microsystems - Beijing China	aac_cmd_fib_t aac_cmd_fib;
290f42c2f5zhongyan gu - Sun Microsystems - Beijing China	/* Call back function for completed command */
291f42c2f5zhongyan gu - Sun Microsystems - Beijing China	void (*ac_comp)(struct aac_softstate *, struct aac_cmd *);
292f42c2f5zhongyan gu - Sun Microsystems - Beijing China
293f42c2f5zhongyan gu - Sun Microsystems - Beijing China	struct aac_slot *slotp;	/* slot used by this command */
294f42c2f5zhongyan gu - Sun Microsystems - Beijing China	struct aac_device *dvp;	/* target device */
295f42c2f5zhongyan gu - Sun Microsystems - Beijing China
296f42c2f5zhongyan gu - Sun Microsystems - Beijing China	/* FIB for this IO command */
297f42c2f5zhongyan gu - Sun Microsystems - Beijing China	int fib_size; /* size of the FIB xferred to/from the card */
298f42c2f5zhongyan gu - Sun Microsystems - Beijing China	struct aac_fib *fibp;
299f42c2f5zhongyan gu - Sun Microsystems - Beijing China
300f42c2f5zhongyan gu - Sun Microsystems - Beijing China#ifdef DEBUG
301f42c2f5zhongyan gu - Sun Microsystems - Beijing China	uint32_t fib_flags;
302f42c2f5zhongyan gu - Sun Microsystems - Beijing China#endif
303f42c2f5zhongyan gu - Sun Microsystems - Beijing China};
304f42c2f5zhongyan gu - Sun Microsystems - Beijing China
305382c8bcpl/* Flags for attach tracking */
306830d82fpl#define	AAC_ATTACH_SOFTSTATE_ALLOCED	(1 << 0)
307830d82fpl#define	AAC_ATTACH_CARD_DETECTED	(1 << 1)
308830d82fpl#define	AAC_ATTACH_PCI_MEM_MAPPED	(1 << 2)
309830d82fpl#define	AAC_ATTACH_KMUTEX_INITED	(1 << 3)
310f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_ATTACH_SCSI_TRAN_SETUP	(1 << 4)
311f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_ATTACH_COMM_SPACE_SETUP	(1 << 5)
312f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_ATTACH_CREATE_DEVCTL	(1 << 6)
313f42c2f5zhongyan gu - Sun Microsystems - Beijing China#define	AAC_ATTACH_CREATE_SCSI		(1 << 7)
314830d82fpl
315382c8bcpl/* Driver running states */
316382c8bcpl#define	AAC_STATE_STOPPED	0
317382c8bcpl#define	AAC_STATE_RUN		(1 << 0)
318382c8bcpl#define	AAC_STATE_RESET		(1 << 1)
319382c8bcpl#define	AAC_STATE_QUIESCED	(1 << 2)
320382c8bcpl#define	AAC_STATE_DEAD		(1 << 3)
3211ee13a4XinChen#define	AAC_STATE_INTR		(1 << 4)
322830d82fpl
323382c8bcpl/*
324382c8bcpl * Flags for aac firmware
325382c8bcpl * Note: Quirks are only valid for the older cards. These cards only supported
326382c8bcpl * old comm. Thus they are not valid for any cards that support new comm.
327382c8bcpl */
328830d82fpl#define	AAC_FLAGS_SG_64BIT	(1 << 0) /* Use 64-bit S/G addresses */
329830d82fpl#define	AAC_FLAGS_4GB_WINDOW	(1 << 1) /* Can access host mem 2-4GB range */
330382c8bcpl#define	AAC_FLAGS_NO4GB	(1 << 2)	/* quirk: FIB addresses must reside */
331382c8bcpl					/*	  between 0x2000 & 0x7FFFFFFF */
332382c8bcpl#define	AAC_FLAGS_256FIBS	(1 << 3) /* quirk: Can only do 256 commands */
333830d82fpl#define	AAC_FLAGS_NEW_COMM	(1 << 4) /* New comm. interface supported */
334830d82fpl#define	AAC_FLAGS_RAW_IO	(1 << 5) /* Raw I/O interface */
335830d82fpl#define	AAC_FLAGS_ARRAY_64BIT	(1 << 6) /* 64-bit array size */
336830d82fpl#define	AAC_FLAGS_LBA_64BIT	(1 << 7) /* 64-bit LBA supported */
337382c8bcpl#define	AAC_FLAGS_17SG		(1 << 8) /* quirk: 17 scatter gather maximum */
338382c8bcpl#define	AAC_FLAGS_34SG		(1 << 9) /* quirk: 34 scatter gather maximum */
33958bc78cXin Chen<Xin.Chen@Sun.COM>#define	AAC_FLAGS_NONDASD	(1 << 10) /* non-DASD device supported */
34072888e7peng liu - Sun Microsystems - Beijing China#define	AAC_FLAGS_BRKUP		(1 << 11) /* pkt breakup support */
3413fced43zhongyan gu - Sun Microsystems - Beijing China#define	AAC_FLAGS_JBOD		(1 << 12) /* JBOD mode support */
342830d82fpl
343830d82fplstruct aac_softstate;
344830d82fplstruct aac_interface {
345830d82fpl	int (*aif_get_fwstatus)(struct aac_softstate *);
346d937e6epl	int (*aif_get_mailbox)(struct aac_softstate *, int);
347d937e6epl	void (*aif_set_mailbox)(struct aac_softstate *, uint32_t,
348c948716pl	    uint32_t, uint32_t, uint32_t, uint32_t);
349830d82fpl};
350830d82fpl
3510749e8dXin Chen - Sun Microsystems - Beijing China#define	AAC_CTXFLAG_FILLED	0x01	/* aifq's full for this ctx */
3520749e8dXin Chen - Sun Microsystems - Beijing China#define	AAC_CTXFLAG_RESETED	0x02
3530749e8dXin Chen - Sun Microsystems - Beijing China
354830d82fplstruct aac_fib_context {
355830d82fpl	uint32_t unique;
356830d82fpl	int ctx_idx;
357c4219f5xc	int ctx_filled;		/* aifq is full for this fib context */
3580749e8dXin Chen - Sun Microsystems - Beijing China	int ctx_flags;
3590749e8dXin Chen - Sun Microsystems - Beijing China	int ctx_overrun;
360830d82fpl	struct aac_fib_context *next, *prev;
361830d82fpl};
3627c478bdstevel@tonic-gate
363d937e6epl#define	AAC_VENDOR_LEN		8
364d937e6epl#define	AAC_PRODUCT_LEN		16
365d937e6epl
3667c478bdstevel@tonic-gatestruct aac_softstate {
367830d82fpl	int card;		/* index to aac_cards */
368d937e6epl	uint16_t hwif;		/* card chip type: i960 or Rocket */
3691cea6bexc	uint16_t vendid;	/* vendor id */
3701cea6bexc	uint16_t subvendid;	/* sub vendor id */
3711cea6bexc	uint16_t devid;		/* device id */
3721cea6bexc	uint16_t subsysid;	/* sub system id */
373d937e6epl	char vendor_name[AAC_VENDOR_LEN + 1];
374d937e6epl	char product_name[AAC_PRODUCT_LEN + 1];
375830d82fpl	uint32_t support_opt;	/* firmware features */
376b40e8a8zhongyan gu - Sun Microsystems - Beijing China	uint32_t support_opt2;
377b40e8a8zhongyan gu - Sun Microsystems - Beijing China	uint32_t feature_bits;
378830d82fpl	uint32_t atu_size;	/* actual size of PCI mem space */
379830d82fpl	uint32_t map_size;	/* mapped PCI mem space size */
380830d82fpl	uint32_t map_size_min;	/* minimum size of PCI mem that must be */
381830d82fpl				/* mapped to address the card */
382c948716pl	int flags;		/* firmware features enabled */
3831dd0a2dpl	int instance;
3847c478bdstevel@tonic-gate	dev_info_t *devinfo_p;
38558bc78cXin Chen<Xin.Chen@Sun.COM>	scsi_hba_tran_t *hba_tran;
386d7c5bf8pl	int slen;
38758bc78cXin Chen<Xin.Chen@Sun.COM>	int legacy;		/* legacy device naming */
38872888e7peng liu - Sun Microsystems - Beijing China	uint32_t dma_max;	/* for buf breakup */
389830d82fpl
390c948716pl	/* DMA attributes */
391830d82fpl	ddi_dma_attr_t buf_dma_attr;
392830d82fpl	ddi_dma_attr_t addr_dma_attr;
3937c478bdstevel@tonic-gate
394c948716pl	/* PCI spaces */
39558bc78cXin Chen<Xin.Chen@Sun.COM>	ddi_device_acc_attr_t acc_attr;
396837c1acStephen Hanson	ddi_device_acc_attr_t reg_attr;
3977c478bdstevel@tonic-gate	ddi_acc_handle_t pci_mem_handle;
398a74f744pl	uint8_t *pci_mem_base_vaddr;
3991dd0a2dpl	uint32_t pci_mem_base_paddr;
4007c478bdstevel@tonic-gate
401c948716pl	struct aac_interface aac_if;	/* adapter hardware interface */
4027c478bdstevel@tonic-gate
403f42c2f5zhongyan gu - Sun Microsystems - Beijing China	struct aac_cmd sync_ac;		/* sync FIB */
4047c478bdstevel@tonic-gate
405c948716pl	/* Communication space */
4067c478bdstevel@tonic-gate	struct aac_comm_space *comm_space;
4077c478bdstevel@tonic-gate	ddi_acc_handle_t comm_space_acc_handle;
4087c478bdstevel@tonic-gate	ddi_dma_handle_t comm_space_dma_handle;
409830d82fpl	uint32_t comm_space_phyaddr;
4107c478bdstevel@tonic-gate
411c948716pl	/* Old Comm. interface: message queues */
4127c478bdstevel@tonic-gate	struct aac_queue_table *qtablep;
4137c478bdstevel@tonic-gate	struct aac_queue_entry *qentries[AAC_QUEUE_COUNT];
4147c478bdstevel@tonic-gate
415c948716pl	/* New Comm. interface */
416c948716pl	uint32_t aac_max_fibs;		/* max. FIB count */
417c948716pl	uint32_t aac_max_fib_size;	/* max. FIB size */
418c948716pl	uint32_t aac_sg_tablesize;	/* max. sg count from host */
419c948716pl	uint32_t aac_max_sectors;	/* max. I/O size from host (blocks) */
420c948716pl
421d7c5bf8pl	aac_cmd_fib_t aac_cmd_fib;	/* IO cmd FIB construct function */
422942c5e3pl	aac_cmd_fib_t aac_cmd_fib_scsi;	/* SRB construct function */
423d7c5bf8pl
424c948716pl	ddi_softintr_t softint_id;	/* soft intr */
425c948716pl
426382c8bcpl	kmutex_t io_lock;
427c948716pl	int state;			/* driver state */
428c948716pl
429942c5e3pl	struct aac_container containers[AAC_MAX_LD];
430c948716pl	int container_count;		/* max container id + 1 */
43158bc78cXin Chen<Xin.Chen@Sun.COM>	struct aac_nondasd *nondasds;
43258bc78cXin Chen<Xin.Chen@Sun.COM>	uint32_t bus_max;		/* max FW buses exposed */
43358bc78cXin Chen<Xin.Chen@Sun.COM>	uint32_t tgt_max;		/* max FW target per bus */
4347c478bdstevel@tonic-gate
435830d82fpl	/*
436830d82fpl	 * Command queues
437830d82fpl	 * Each aac command flows through wait(or wait_sync) queue,
438382c8bcpl	 * busy queue, and complete queue sequentially.
439830d82fpl	 */
440382c8bcpl	struct aac_cmd_queue q_wait[AAC_CMDQ_NUM];
441382c8bcpl	struct aac_cmd_queue q_busy;	/* outstanding cmd queue */
442382c8bcpl	kmutex_t q_comp_mutex;
443c948716pl	struct aac_cmd_queue q_comp;	/* completed io requests */
444830d82fpl
445d937e6epl	/* I/O slots and FIBs */
446830d82fpl	int total_slots;		/* total slots allocated */
447830d82fpl	int total_fibs;			/* total FIBs allocated */
448830d82fpl	struct aac_slot *io_slot;	/* static list for allocated slots */
449382c8bcpl	struct aac_slot *free_io_slot_head;
4507c478bdstevel@tonic-gate
451382c8bcpl	kcondvar_t event;		/* for ioctl_send_fib() and sync IO */
4521ee13a4XinChen	kcondvar_t sync_fib_cv;		/* for sync_fib_slot_bind/release */
453382c8bcpl
454382c8bcpl	int bus_ncmds[AAC_CMDQ_NUM];	/* total outstanding async cmds */
455382c8bcpl	int bus_throttle[AAC_CMDQ_NUM];	/* hold IO cmds for the bus */
456382c8bcpl	int ndrains;			/* number of draining threads */
457382c8bcpl	timeout_id_t drain_timeid;	/* for outstanding cmd drain */
458382c8bcpl	kcondvar_t drain_cv;		/* for quiesce drain */
459830d82fpl
4600749e8dXin Chen - Sun Microsystems - Beijing China	/* Internal timer */
4610749e8dXin Chen - Sun Microsystems - Beijing China	kmutex_t time_mutex;
4620749e8dXin Chen - Sun Microsystems - Beijing China	timeout_id_t timeout_id;	/* for timeout daemon */
4630749e8dXin Chen - Sun Microsystems - Beijing China	uint32_t timebase;		/* internal timer in seconds */
4640749e8dXin Chen - Sun Microsystems - Beijing China	uint32_t time_sync;		/* next time to sync with firmware */
4650749e8dXin Chen - Sun Microsystems - Beijing China	uint32_t time_out;		/* next time to check timeout */
4660749e8dXin Chen - Sun Microsystems - Beijing China	uint32_t time_throttle;		/* next time to restore throttle */
4670749e8dXin Chen - Sun Microsystems - Beijing China
4680749e8dXin Chen - Sun Microsystems - Beijing China	/* Internal events handling */
4690749e8dXin Chen - Sun Microsystems - Beijing China	kmutex_t ev_lock;
4700749e8dXin Chen - Sun Microsystems - Beijing China	int events;
4710749e8dXin Chen - Sun Microsystems - Beijing China	kthread_t *event_thread;	/* for AIF & timeout */
4720749e8dXin Chen - Sun Microsystems - Beijing China	kcondvar_t event_wait_cv;
4730749e8dXin Chen - Sun Microsystems - Beijing China	kcondvar_t event_disp_cv;
4740749e8dXin Chen - Sun Microsystems - Beijing China
475830d82fpl	/* AIF */
476830d82fpl	kmutex_t aifq_mutex;		/* for AIF queue aifq */
4770749e8dXin Chen - Sun Microsystems - Beijing China	kcondvar_t aifq_cv;
478942c5e3pl	union aac_fib_align aifq[AAC_AIFQ_LENGTH];
479c4219f5xc	int aifq_idx;			/* slot for next new AIF */
480c4219f5xc	int aifq_wrap;			/* AIF queue has ever been wrapped */
4810749e8dXin Chen - Sun Microsystems - Beijing China	struct aac_fib_context aifctx;	/* sys aif ctx */
4820749e8dXin Chen - Sun Microsystems - Beijing China	struct aac_fib_context *fibctx_p;
483830d82fpl	int devcfg_wait_on;		/* AIF event waited for rescan */
4841dd0a2dpl
4857675db5yw	int fm_capabilities;
4867675db5yw
487b6094a8jd	/* MSI specific fields */
488b6094a8jd	ddi_intr_handle_t *htable;	/* For array of interrupts */
489b6094a8jd	int intr_type;			/* What type of interrupt */
490b6094a8jd	int intr_cnt;			/* # of intrs count returned */
491f42c2f5zhongyan gu - Sun Microsystems - Beijing China	int intr_size;
492b6094a8jd	uint_t intr_pri;		/* Interrupt priority   */
493b6094a8jd	int intr_cap;			/* Interrupt capabilities */
494b6094a8jd
4951dd0a2dpl#ifdef DEBUG
4961dd0a2dpl	/* UART trace printf variables */
4971dd0a2dpl	uint32_t debug_flags;		/* debug print flags bitmap */
49858bc78cXin Chen<Xin.Chen@Sun.COM>	uint32_t debug_fib_flags;	/* debug FIB print flags bitmap */
4991dd0a2dpl	uint32_t debug_fw_flags;	/* FW debug flags */
5001dd0a2dpl	uint32_t debug_buf_offset;	/* offset from DPMEM start */
5011dd0a2dpl	uint32_t debug_buf_size;	/* FW debug buffer size in bytes */
5021dd0a2dpl	uint32_t debug_header_size;	/* size of debug header */
5031dd0a2dpl#endif
5047c478bdstevel@tonic-gate};
5057c478bdstevel@tonic-gate
506942c5e3pl/*
507942c5e3pl * The following data are kept stable because they are only written at driver
508942c5e3pl * initialization, and we do not allow them changed otherwise even at driver
509942c5e3pl * re-initialization.
510942c5e3pl */
511382c8bcpl_NOTE(SCHEME_PROTECTS_DATA("stable data", aac_softstate::{flags slen \
512942c5e3pl    buf_dma_attr pci_mem_handle pci_mem_base_vaddr \
513382c8bcpl    comm_space_acc_handle comm_space_dma_handle aac_max_fib_size \
51458bc78cXin Chen<Xin.Chen@Sun.COM>    aac_sg_tablesize aac_cmd_fib aac_cmd_fib_scsi debug_flags bus_max tgt_max}))
515942c5e3pl
5161dd0a2dpl#ifdef DEBUG
5171dd0a2dpl
5181dd0a2dpl#define	AACDB_FLAGS_MASK		0x0000ffff
5191dd0a2dpl#define	AACDB_FLAGS_KERNEL_PRINT	0x00000001
5201dd0a2dpl#define	AACDB_FLAGS_FW_PRINT		0x00000002
521942c5e3pl#define	AACDB_FLAGS_NO_HEADERS		0x00000004
522942c5e3pl
523942c5e3pl#define	AACDB_FLAGS_MISC		0x00000010
524942c5e3pl#define	AACDB_FLAGS_FUNC1		0x00000020
525942c5e3pl#define	AACDB_FLAGS_FUNC2		0x00000040
526942c5e3pl#define	AACDB_FLAGS_SCMD		0x00000080
527942c5e3pl#define	AACDB_FLAGS_AIF			0x00000100
528942c5e3pl#define	AACDB_FLAGS_FIB			0x00000200
529942c5e3pl#define	AACDB_FLAGS_IOCTL		0x00000400
5301dd0a2dpl
53158bc78cXin Chen<Xin.Chen@Sun.COM>/*
53258bc78cXin Chen<Xin.Chen@Sun.COM> * Flags for FIB print
53358bc78cXin Chen<Xin.Chen@Sun.COM> */
53458bc78cXin Chen<Xin.Chen@Sun.COM>/* FIB sources */
53558bc78cXin Chen<Xin.Chen@Sun.COM>#define	AACDB_FLAGS_FIB_SCMD		0x00000001
53658bc78cXin Chen<Xin.Chen@Sun.COM>#define	AACDB_FLAGS_FIB_IOCTL		0x00000002
53758bc78cXin Chen<Xin.Chen@Sun.COM>#define	AACDB_FLAGS_FIB_SRB		0x00000004
53858bc78cXin Chen<Xin.Chen@Sun.COM>#define	AACDB_FLAGS_FIB_SYNC		0x00000008
53958bc78cXin Chen<Xin.Chen@Sun.COM>/* FIB components */
54058bc78cXin Chen<Xin.Chen@Sun.COM>#define	AACDB_FLAGS_FIB_HEADER		0x00000010
54158bc78cXin Chen<Xin.Chen@Sun.COM>/* FIB states */
54258bc78cXin Chen<Xin.Chen@Sun.COM>#define	AACDB_FLAGS_FIB_TIMEOUT		0x00000100
54358bc78cXin Chen<Xin.Chen@Sun.COM>
5441dd0a2dplextern uint32_t aac_debug_flags;
5451dd0a2dplextern int aac_dbflag_on(struct aac_softstate *, int);
5461dd0a2dplextern void aac_printf(struct aac_softstate *, uint_t, const char *, ...);
54758bc78cXin Chen<Xin.Chen@Sun.COM>extern void aac_print_fib(struct aac_softstate *, struct aac_slot *);
5481dd0a2dpl
5491dd0a2dpl#define	AACDB_PRINT(s, lev, ...) { \
5501dd0a2dpl	if (aac_dbflag_on((s), AACDB_FLAGS_MISC)) \
5511dd0a2dpl		aac_printf((s), (lev), __VA_ARGS__); }
5521dd0a2dpl
5531dd0a2dpl#define	AACDB_PRINT_IOCTL(s, ...) { \
5541dd0a2dpl	if (aac_dbflag_on((s), AACDB_FLAGS_IOCTL)) \
5551dd0a2dpl		aac_printf((s), CE_NOTE, __VA_ARGS__); }
5561dd0a2dpl
5571dd0a2dpl#define	AACDB_PRINT_TRAN(s, ...) { \
5581dd0a2dpl	if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) \
5591dd0a2dpl		aac_printf((s), CE_NOTE, __VA_ARGS__); }
5601dd0a2dpl
5611dd0a2dpl#define	DBCALLED(s, n) { \
5621dd0a2dpl	if (aac_dbflag_on((s), AACDB_FLAGS_FUNC ## n)) \
5631dd0a2dpl		aac_printf((s), CE_NOTE, "--- %s() called ---", __func__); }
5641dd0a2dpl
5651dd0a2dpl#define	AACDB_PRINT_SCMD(s, x) { \
5661dd0a2dpl	if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) aac_print_scmd((s), (x)); }
5671dd0a2dpl
5681dd0a2dpl#define	AACDB_PRINT_AIF(s, x) { \
5691dd0a2dpl	if (aac_dbflag_on((s), AACDB_FLAGS_AIF)) aac_print_aif((s), (x)); }
5701dd0a2dpl
5711dd0a2dpl#define	AACDB_PRINT_FIB(s, x) { \
5721dd0a2dpl	if (aac_dbflag_on((s), AACDB_FLAGS_FIB)) aac_print_fib((s), (x)); }
5731dd0a2dpl
5741dd0a2dpl#else /* DEBUG */
5751dd0a2dpl
5761dd0a2dpl#define	AACDB_PRINT(s, lev, ...)
5771dd0a2dpl#define	AACDB_PRINT_IOCTL(s, ...)
5781dd0a2dpl#define	AACDB_PRINT_TRAN(s, ...)
5791dd0a2dpl#define	AACDB_PRINT_FIB(s, x)
5801dd0a2dpl#define	AACDB_PRINT_SCMD(s, x)
5811dd0a2dpl#define	AACDB_PRINT_AIF(s, x)
5821dd0a2dpl#define	DBCALLED(s, n)
5831dd0a2dpl
5841dd0a2dpl#endif /* DEBUG */
5851dd0a2dpl
5867c478bdstevel@tonic-gate#ifdef	__cplusplus
5877c478bdstevel@tonic-gate}
5887c478bdstevel@tonic-gate#endif
5897c478bdstevel@tonic-gate
5907c478bdstevel@tonic-gate#endif /* _AAC_H_ */
591