xref: /illumos-gate/usr/src/uts/common/io/aac/aac.h (revision b6094a86b9116e02728dfbe9a1d4ecfa4cfd90f5)
17c478bd9Sstevel@tonic-gate /*
26d1d45eeSjd  * Copyright 2008 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
47830d82f7Spl #define	AAC_ROUNDUP(x, y)		(((x) + (y) - 1) / (y) * (y))
48830d82f7Spl 
49830d82f7Spl #define	AAC_TYPE_DEVO			1
50830d82f7Spl #define	AAC_TYPE_ALPHA			2
51830d82f7Spl #define	AAC_TYPE_BETA			3
52830d82f7Spl #define	AAC_TYPE_RELEASE		4
53830d82f7Spl 
54830d82f7Spl #ifndef	AAC_DRIVER_BUILD
55830d82f7Spl #define	AAC_DRIVER_BUILD		1
56830d82f7Spl #endif
57830d82f7Spl 
58830d82f7Spl #define	AAC_DRIVER_MAJOR_VERSION	2
59942c5e3cSpl #define	AAC_DRIVER_MINOR_VERSION	2
60*b6094a86Sjd #define	AAC_DRIVER_BUGFIX_LEVEL		3
61830d82f7Spl #define	AAC_DRIVER_TYPE			AAC_TYPE_RELEASE
627c478bd9Sstevel@tonic-gate 
63832e0b5aSpl #define	STR(s)				# s
64832e0b5aSpl #define	AAC_VERSION(a, b, c)		STR(a.b.c)
65832e0b5aSpl #define	AAC_DRIVER_VERSION		AAC_VERSION(AAC_DRIVER_MAJOR_VERSION, \
66832e0b5aSpl 					AAC_DRIVER_MINOR_VERSION, \
67832e0b5aSpl 					AAC_DRIVER_BUGFIX_LEVEL)
68832e0b5aSpl 
69830d82f7Spl #define	AACOK				0
70830d82f7Spl #define	AACERR				-1
71830d82f7Spl 
72830d82f7Spl #define	AAC_MAX_ADAPTERS		64
73830d82f7Spl 
74830d82f7Spl /* Definitions for mode sense */
757c478bd9Sstevel@tonic-gate #ifndef	SD_MODE_SENSE_PAGE3_CODE
76830d82f7Spl #define	SD_MODE_SENSE_PAGE3_CODE	0x03
777c478bd9Sstevel@tonic-gate #endif
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #ifndef	SD_MODE_SENSE_PAGE4_CODE
80830d82f7Spl #define	SD_MODE_SENSE_PAGE4_CODE	0x04
817c478bd9Sstevel@tonic-gate #endif
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #ifndef	SCMD_SYNCHRONIZE_CACHE
84830d82f7Spl #define	SCMD_SYNCHRONIZE_CACHE		0x35
857c478bd9Sstevel@tonic-gate #endif
867c478bd9Sstevel@tonic-gate 
87830d82f7Spl /*
88830d82f7Spl  * The controller reports status events in AIFs. We hang on to a number of
89830d82f7Spl  * these in order to pass them out to user-space management tools.
90830d82f7Spl  */
91830d82f7Spl #define	AAC_AIFQ_LENGTH			64
92830d82f7Spl 
93942c5e3cSpl #ifdef __x86
94830d82f7Spl #define	AAC_IMMEDIATE_TIMEOUT		30	/* seconds */
95942c5e3cSpl #else
96942c5e3cSpl #define	AAC_IMMEDIATE_TIMEOUT		60	/* seconds */
97942c5e3cSpl #endif
98830d82f7Spl #define	AAC_FWUP_TIMEOUT		180	/* wait up to 3 minutes */
99830d82f7Spl #define	AAC_IOCTL_TIMEOUT		180	/* wait up to 3 minutes */
1007c478bd9Sstevel@tonic-gate 
101830d82f7Spl /* Adapter hardware interface types */
102830d82f7Spl #define	AAC_HWIF_UNKNOWN		0
103830d82f7Spl #define	AAC_HWIF_I960RX			1
104830d82f7Spl #define	AAC_HWIF_RKT			2
105830d82f7Spl 
106830d82f7Spl #define	AAC_TYPE_UNKNOWN		0
107830d82f7Spl #define	AAC_TYPE_SCSI			1
108830d82f7Spl #define	AAC_TYPE_SATA			2
109830d82f7Spl #define	AAC_TYPE_SAS			3
110fd4ae32fSyf 
111942c5e3cSpl #define	AAC_LS32(d)			((uint32_t)((d) & 0xffffffffull))
112942c5e3cSpl #define	AAC_MS32(d)			((uint32_t)((d) >> 32))
113942c5e3cSpl #define	AAC_LO32(p64)			((uint32_t *)(p64))
114942c5e3cSpl #define	AAC_HI32(p64)			((uint32_t *)(p64) + 1)
115942c5e3cSpl 
116382c8bcaSpl /*
117382c8bcaSpl  * AAC_CMDQ_SYNC should be 0 and AAC_CMDQ_ASYNC be 1 for Sync FIB io
118382c8bcaSpl  * to be served before async FIB io, see aac_start_waiting_io().
119382c8bcaSpl  * So that io requests sent by interactive userland commands get
120382c8bcaSpl  * responded asap.
121382c8bcaSpl  */
122382c8bcaSpl enum aac_cmdq {
123382c8bcaSpl 	AAC_CMDQ_SYNC,	/* sync FIB queue */
124382c8bcaSpl 	AAC_CMDQ_ASYNC,	/* async FIB queue */
125382c8bcaSpl 	AAC_CMDQ_NUM
126382c8bcaSpl };
127382c8bcaSpl 
128382c8bcaSpl /*
129382c8bcaSpl  * IO command flags
130382c8bcaSpl  */
131382c8bcaSpl #define	AAC_IOCMD_SYNC		(1 << AAC_CMDQ_SYNC)
132382c8bcaSpl #define	AAC_IOCMD_ASYNC		(1 << AAC_CMDQ_ASYNC)
133382c8bcaSpl #define	AAC_IOCMD_OUTSTANDING	(1 << AAC_CMDQ_NUM)
134382c8bcaSpl #define	AAC_IOCMD_ALL		(AAC_IOCMD_SYNC | AAC_IOCMD_ASYNC | \
135382c8bcaSpl 				AAC_IOCMD_OUTSTANDING)
136382c8bcaSpl 
137382c8bcaSpl struct aac_cmd_queue {
138382c8bcaSpl 	struct aac_cmd *q_head; /* also as the header of aac_cmd */
139382c8bcaSpl 	struct aac_cmd *q_tail;
140382c8bcaSpl };
141382c8bcaSpl 
1427c478bd9Sstevel@tonic-gate struct aac_card_type {
143830d82f7Spl 	uint16_t vendor;	/* PCI Vendor ID */
144830d82f7Spl 	uint16_t device;	/* PCI Device ID */
145830d82f7Spl 	uint16_t subvendor;	/* PCI Subsystem Vendor ID */
146830d82f7Spl 	uint16_t subsys;	/* PCI Subsystem ID */
147830d82f7Spl 	uint16_t hwif;		/* card chip type: i960 or Rocket */
148830d82f7Spl 	uint16_t quirks;	/* card odd limits */
149830d82f7Spl 	uint16_t type;		/* hard drive type */
150830d82f7Spl 	char *vid;		/* ASCII data for INQUIRY command vendor id */
151830d82f7Spl 	char *desc;		/* ASCII data for INQUIRY command product id */
1527c478bd9Sstevel@tonic-gate };
1537c478bd9Sstevel@tonic-gate 
154d937e6ebSpl /* Array description */
1557c478bd9Sstevel@tonic-gate struct aac_container {
156382c8bcaSpl 	uint8_t valid;
157830d82f7Spl 	uint32_t cid;		/* container id */
158830d82f7Spl 	uint32_t uid;		/* container uid */
159382c8bcaSpl 	uint64_t size;		/* in block */
160382c8bcaSpl 	uint8_t locked;
161382c8bcaSpl 	uint8_t deleted;
162942c5e3cSpl 	uint8_t reset;			/* container is being reseted */
163382c8bcaSpl 	int ncmds[AAC_CMDQ_NUM];	/* outstanding cmds of the device */
164382c8bcaSpl 	int throttle[AAC_CMDQ_NUM];	/* hold IO cmds for the device */
1657c478bd9Sstevel@tonic-gate };
1667c478bd9Sstevel@tonic-gate 
167830d82f7Spl /*
168830d82f7Spl  * The firmware can support a lot of outstanding commands. Each aac_slot
169830d82f7Spl  * is corresponding to one of such commands. It records the command and
170830d82f7Spl  * associated DMA resource for FIB command.
171830d82f7Spl  */
1727c478bd9Sstevel@tonic-gate struct aac_slot {
173382c8bcaSpl 	struct aac_slot *next;	/* next slot in the free slot list */
174382c8bcaSpl 	int index;		/* index of this slot */
1757c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t fib_acc_handle;
1767c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t fib_dma_handle;
177830d82f7Spl 	uint64_t fib_phyaddr;	/* physical address of FIB memory */
178830d82f7Spl 	struct aac_cmd *acp;	/* command using this slot */
179830d82f7Spl 	struct aac_fib *fibp;	/* virtual address of FIB memory */
1807c478bd9Sstevel@tonic-gate };
1817c478bd9Sstevel@tonic-gate 
182382c8bcaSpl /* Flags for attach tracking */
183830d82f7Spl #define	AAC_ATTACH_SOFTSTATE_ALLOCED	(1 << 0)
184830d82f7Spl #define	AAC_ATTACH_CARD_DETECTED	(1 << 1)
185830d82f7Spl #define	AAC_ATTACH_PCI_MEM_MAPPED	(1 << 2)
186830d82f7Spl #define	AAC_ATTACH_KMUTEX_INITED	(1 << 3)
187830d82f7Spl #define	AAC_ATTACH_HARD_INTR_SETUP	(1 << 4)
188830d82f7Spl #define	AAC_ATTACH_SOFT_INTR_SETUP	(1 << 5)
189830d82f7Spl #define	AAC_ATTACH_SCSI_TRAN_SETUP	(1 << 6)
190830d82f7Spl #define	AAC_ATTACH_COMM_SPACE_SETUP	(1 << 7)
191830d82f7Spl #define	AAC_ATTACH_CREATE_DEVCTL	(1 << 8)
192830d82f7Spl #define	AAC_ATTACH_CREATE_SCSI		(1 << 9)
193830d82f7Spl 
194382c8bcaSpl /* Driver running states */
195382c8bcaSpl #define	AAC_STATE_STOPPED	0
196382c8bcaSpl #define	AAC_STATE_RUN		(1 << 0)
197382c8bcaSpl #define	AAC_STATE_RESET		(1 << 1)
198382c8bcaSpl #define	AAC_STATE_QUIESCED	(1 << 2)
199382c8bcaSpl #define	AAC_STATE_DEAD		(1 << 3)
200830d82f7Spl 
201382c8bcaSpl /*
202382c8bcaSpl  * Flags for aac firmware
203382c8bcaSpl  * Note: Quirks are only valid for the older cards. These cards only supported
204382c8bcaSpl  * old comm. Thus they are not valid for any cards that support new comm.
205382c8bcaSpl  */
206830d82f7Spl #define	AAC_FLAGS_SG_64BIT	(1 << 0) /* Use 64-bit S/G addresses */
207830d82f7Spl #define	AAC_FLAGS_4GB_WINDOW	(1 << 1) /* Can access host mem 2-4GB range */
208382c8bcaSpl #define	AAC_FLAGS_NO4GB	(1 << 2)	/* quirk: FIB addresses must reside */
209382c8bcaSpl 					/*	  between 0x2000 & 0x7FFFFFFF */
210382c8bcaSpl #define	AAC_FLAGS_256FIBS	(1 << 3) /* quirk: Can only do 256 commands */
211830d82f7Spl #define	AAC_FLAGS_NEW_COMM	(1 << 4) /* New comm. interface supported */
212830d82f7Spl #define	AAC_FLAGS_RAW_IO	(1 << 5) /* Raw I/O interface */
213830d82f7Spl #define	AAC_FLAGS_ARRAY_64BIT	(1 << 6) /* 64-bit array size */
214830d82f7Spl #define	AAC_FLAGS_LBA_64BIT	(1 << 7) /* 64-bit LBA supported */
215382c8bcaSpl #define	AAC_FLAGS_17SG		(1 << 8) /* quirk: 17 scatter gather maximum */
216382c8bcaSpl #define	AAC_FLAGS_34SG		(1 << 9) /* quirk: 34 scatter gather maximum */
217830d82f7Spl 
218830d82f7Spl struct aac_softstate;
219830d82f7Spl struct aac_interface {
220830d82f7Spl 	int (*aif_get_fwstatus)(struct aac_softstate *);
221d937e6ebSpl 	int (*aif_get_mailbox)(struct aac_softstate *, int);
222d937e6ebSpl 	void (*aif_set_mailbox)(struct aac_softstate *, uint32_t,
223c9487164Spl 	    uint32_t, uint32_t, uint32_t, uint32_t);
224830d82f7Spl };
225830d82f7Spl 
226830d82f7Spl struct aac_fib_context {
227830d82f7Spl 	uint32_t unique;
228830d82f7Spl 	int ctx_idx;
229c4219f59Sxc 	int ctx_filled;		/* aifq is full for this fib context */
230830d82f7Spl 	struct aac_fib_context *next, *prev;
231830d82f7Spl };
2327c478bd9Sstevel@tonic-gate 
233942c5e3cSpl typedef void (*aac_cmd_fib_t)(struct aac_softstate *, struct aac_cmd *);
234d7c5bf88Spl 
235d937e6ebSpl #define	AAC_VENDOR_LEN		8
236d937e6ebSpl #define	AAC_PRODUCT_LEN		16
237d937e6ebSpl 
2387c478bd9Sstevel@tonic-gate struct aac_softstate {
239830d82f7Spl 	int card;		/* index to aac_cards */
240d937e6ebSpl 	uint16_t hwif;		/* card chip type: i960 or Rocket */
2411cea6be9Sxc 	uint16_t vendid;	/* vendor id */
2421cea6be9Sxc 	uint16_t subvendid;	/* sub vendor id */
2431cea6be9Sxc 	uint16_t devid;		/* device id */
2441cea6be9Sxc 	uint16_t subsysid;	/* sub system id */
245d937e6ebSpl 	char vendor_name[AAC_VENDOR_LEN + 1];
246d937e6ebSpl 	char product_name[AAC_PRODUCT_LEN + 1];
247830d82f7Spl 	uint32_t support_opt;	/* firmware features */
248830d82f7Spl 	uint32_t atu_size;	/* actual size of PCI mem space */
249830d82f7Spl 	uint32_t map_size;	/* mapped PCI mem space size */
250830d82f7Spl 	uint32_t map_size_min;	/* minimum size of PCI mem that must be */
251830d82f7Spl 				/* mapped to address the card */
252c9487164Spl 	int flags;		/* firmware features enabled */
2531dd0a2dbSpl 	int instance;
2547c478bd9Sstevel@tonic-gate 	dev_info_t *devinfo_p;
255d7c5bf88Spl 	int slen;
256830d82f7Spl 
257c9487164Spl 	/* DMA attributes */
258830d82f7Spl 	ddi_dma_attr_t buf_dma_attr;
259830d82f7Spl 	ddi_dma_attr_t addr_dma_attr;
2607c478bd9Sstevel@tonic-gate 
261c9487164Spl 	/* PCI spaces */
2627c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t pci_mem_handle;
2631dd0a2dbSpl 	char *pci_mem_base_vaddr;
2641dd0a2dbSpl 	uint32_t pci_mem_base_paddr;
2657c478bd9Sstevel@tonic-gate 
266c9487164Spl 	struct aac_interface aac_if;	/* adapter hardware interface */
2677c478bd9Sstevel@tonic-gate 
268942c5e3cSpl 	struct aac_slot sync_slot;	/* sync FIB */
2697c478bd9Sstevel@tonic-gate 
270c9487164Spl 	/* Communication space */
2717c478bd9Sstevel@tonic-gate 	struct aac_comm_space *comm_space;
2727c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t comm_space_acc_handle;
2737c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t comm_space_dma_handle;
274830d82f7Spl 	uint32_t comm_space_phyaddr;
2757c478bd9Sstevel@tonic-gate 
276c9487164Spl 	/* Old Comm. interface: message queues */
2777c478bd9Sstevel@tonic-gate 	struct aac_queue_table *qtablep;
2787c478bd9Sstevel@tonic-gate 	struct aac_queue_entry *qentries[AAC_QUEUE_COUNT];
2797c478bd9Sstevel@tonic-gate 
280c9487164Spl 	/* New Comm. interface */
281c9487164Spl 	uint32_t aac_max_fibs;		/* max. FIB count */
282c9487164Spl 	uint32_t aac_max_fib_size;	/* max. FIB size */
283c9487164Spl 	uint32_t aac_sg_tablesize;	/* max. sg count from host */
284c9487164Spl 	uint32_t aac_max_sectors;	/* max. I/O size from host (blocks) */
285c9487164Spl 
286d7c5bf88Spl 	aac_cmd_fib_t aac_cmd_fib;	/* IO cmd FIB construct function */
287942c5e3cSpl 	aac_cmd_fib_t aac_cmd_fib_scsi;	/* SRB construct function */
288d7c5bf88Spl 
289c9487164Spl 	ddi_softintr_t softint_id;	/* soft intr */
290c9487164Spl 
291382c8bcaSpl 	kmutex_t io_lock;
292c9487164Spl 	int state;			/* driver state */
293c9487164Spl 
294942c5e3cSpl 	struct aac_container containers[AAC_MAX_LD];
295c9487164Spl 	int container_count;		/* max container id + 1 */
2967c478bd9Sstevel@tonic-gate 
297830d82f7Spl 	/*
298830d82f7Spl 	 * Command queues
299830d82f7Spl 	 * Each aac command flows through wait(or wait_sync) queue,
300382c8bcaSpl 	 * busy queue, and complete queue sequentially.
301830d82f7Spl 	 */
302382c8bcaSpl 	struct aac_cmd_queue q_wait[AAC_CMDQ_NUM];
303382c8bcaSpl 	struct aac_cmd_queue q_busy;	/* outstanding cmd queue */
304382c8bcaSpl 	kmutex_t q_comp_mutex;
305c9487164Spl 	struct aac_cmd_queue q_comp;	/* completed io requests */
306830d82f7Spl 
307d937e6ebSpl 	/* I/O slots and FIBs */
308830d82f7Spl 	int total_slots;		/* total slots allocated */
309830d82f7Spl 	int total_fibs;			/* total FIBs allocated */
310830d82f7Spl 	struct aac_slot *io_slot;	/* static list for allocated slots */
311382c8bcaSpl 	struct aac_slot *free_io_slot_head;
3127c478bd9Sstevel@tonic-gate 
313382c8bcaSpl 	timeout_id_t timeout_id;	/* for timeout daemon */
314830d82f7Spl 
315382c8bcaSpl 	kcondvar_t event;		/* for ioctl_send_fib() and sync IO */
316382c8bcaSpl 
317382c8bcaSpl 	int bus_ncmds[AAC_CMDQ_NUM];	/* total outstanding async cmds */
318382c8bcaSpl 	int bus_throttle[AAC_CMDQ_NUM];	/* hold IO cmds for the bus */
319382c8bcaSpl 	int ndrains;			/* number of draining threads */
320382c8bcaSpl 	timeout_id_t drain_timeid;	/* for outstanding cmd drain */
321382c8bcaSpl 	kcondvar_t drain_cv;		/* for quiesce drain */
322830d82f7Spl 
323830d82f7Spl 	/* AIF */
324830d82f7Spl 	kmutex_t aifq_mutex;		/* for AIF queue aifq */
325830d82f7Spl 	kcondvar_t aifv;
326942c5e3cSpl 	union aac_fib_align aifq[AAC_AIFQ_LENGTH];
327c4219f59Sxc 	int aifq_idx;			/* slot for next new AIF */
328c4219f59Sxc 	int aifq_wrap;			/* AIF queue has ever been wrapped */
329830d82f7Spl 	struct aac_fib_context *fibctx;
330830d82f7Spl 	int devcfg_wait_on;		/* AIF event waited for rescan */
3311dd0a2dbSpl 
3327675db54Syw 	int fm_capabilities;
3337675db54Syw 
334*b6094a86Sjd 	/* MSI specific fields */
335*b6094a86Sjd 	ddi_intr_handle_t *htable;	/* For array of interrupts */
336*b6094a86Sjd 	int intr_type;			/* What type of interrupt */
337*b6094a86Sjd 	int intr_cnt;			/* # of intrs count returned */
338*b6094a86Sjd 	uint_t intr_pri;		/* Interrupt priority   */
339*b6094a86Sjd 	int intr_cap;			/* Interrupt capabilities */
340*b6094a86Sjd 
3411dd0a2dbSpl #ifdef DEBUG
3421dd0a2dbSpl 	/* UART trace printf variables */
3431dd0a2dbSpl 	uint32_t debug_flags;		/* debug print flags bitmap */
3441dd0a2dbSpl 	uint32_t debug_fw_flags;	/* FW debug flags */
3451dd0a2dbSpl 	uint32_t debug_buf_offset;	/* offset from DPMEM start */
3461dd0a2dbSpl 	uint32_t debug_buf_size;	/* FW debug buffer size in bytes */
3471dd0a2dbSpl 	uint32_t debug_header_size;	/* size of debug header */
3481dd0a2dbSpl #endif
3497c478bd9Sstevel@tonic-gate };
3507c478bd9Sstevel@tonic-gate 
351942c5e3cSpl /*
352942c5e3cSpl  * The following data are kept stable because they are only written at driver
353942c5e3cSpl  * initialization, and we do not allow them changed otherwise even at driver
354942c5e3cSpl  * re-initialization.
355942c5e3cSpl  */
356382c8bcaSpl _NOTE(SCHEME_PROTECTS_DATA("stable data", aac_softstate::{flags slen \
357942c5e3cSpl     buf_dma_attr pci_mem_handle pci_mem_base_vaddr \
358382c8bcaSpl     comm_space_acc_handle comm_space_dma_handle aac_max_fib_size \
359942c5e3cSpl     aac_sg_tablesize aac_cmd_fib aac_cmd_fib_scsi debug_flags}))
360942c5e3cSpl 
361942c5e3cSpl /*
362942c5e3cSpl  * Scatter-gather list structure defined by HBA hardware
363942c5e3cSpl  */
364942c5e3cSpl struct aac_sge {
365942c5e3cSpl 	uint32_t bcount;	/* byte count */
366942c5e3cSpl 	union {
367942c5e3cSpl 		uint32_t ad32;	/* 32 bit address */
368942c5e3cSpl 		struct {
369942c5e3cSpl 			uint32_t lo;
370942c5e3cSpl 			uint32_t hi;
371942c5e3cSpl 		} ad64;		/* 64 bit address */
372942c5e3cSpl 	} addr;
373942c5e3cSpl };
374382c8bcaSpl 
375830d82f7Spl /* aac_cmd flags */
376830d82f7Spl #define	AAC_CMD_CONSISTENT		(1 << 0)
377830d82f7Spl #define	AAC_CMD_DMA_PARTIAL		(1 << 1)
378d7c5bf88Spl #define	AAC_CMD_DMA_VALID		(1 << 2)
379d7c5bf88Spl #define	AAC_CMD_BUF_READ		(1 << 3)
380d7c5bf88Spl #define	AAC_CMD_BUF_WRITE		(1 << 4)
381d7c5bf88Spl #define	AAC_CMD_SYNC			(1 << 5) /* use sync FIB */
382382c8bcaSpl #define	AAC_CMD_NO_INTR			(1 << 6) /* poll IO, no intr */
383382c8bcaSpl #define	AAC_CMD_NO_CB			(1 << 7) /* sync IO, no callback */
384382c8bcaSpl #define	AAC_CMD_NTAG			(1 << 8)
385382c8bcaSpl #define	AAC_CMD_CMPLT			(1 << 9) /* cmd exec'ed by driver/fw */
386382c8bcaSpl #define	AAC_CMD_ABORT			(1 << 10)
387382c8bcaSpl #define	AAC_CMD_TIMEOUT			(1 << 11)
388382c8bcaSpl #define	AAC_CMD_ERR			(1 << 12)
389830d82f7Spl 
3907c478bd9Sstevel@tonic-gate struct aac_cmd {
391382c8bcaSpl 	/*
392382c8bcaSpl 	 * Note: should be the first member for aac_cmd_queue to work
393382c8bcaSpl 	 * correctly.
394382c8bcaSpl 	 */
3957c478bd9Sstevel@tonic-gate 	struct aac_cmd *next;
396382c8bcaSpl 	struct aac_cmd *prev;
397382c8bcaSpl 
3987c478bd9Sstevel@tonic-gate 	struct scsi_pkt *pkt;
3997c478bd9Sstevel@tonic-gate 	int cmdlen;
4007c478bd9Sstevel@tonic-gate 	int flags;
401382c8bcaSpl 	uint32_t timeout; /* time when the cmd should have completed */
4027c478bd9Sstevel@tonic-gate 	struct buf *bp;
4037c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t buf_dma_handle;
404830d82f7Spl 
405830d82f7Spl 	/* For non-aligned buffer and SRB */
406830d82f7Spl 	caddr_t abp;
407830d82f7Spl 	ddi_acc_handle_t abh;
408830d82f7Spl 
409c9487164Spl 	/* Data transfer state */
4107c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t cookie;
4117c478bd9Sstevel@tonic-gate 	uint_t left_cookien;
4127c478bd9Sstevel@tonic-gate 	uint_t cur_win;
4137c478bd9Sstevel@tonic-gate 	uint_t total_nwin;
4147c478bd9Sstevel@tonic-gate 	size_t total_xfer;
415d7c5bf88Spl 	uint64_t blkno;
416d7c5bf88Spl 	uint32_t bcount;	/* buffer size in byte */
417942c5e3cSpl 	struct aac_sge *sgt;	/* sg table */
418d7c5bf88Spl 
419942c5e3cSpl 	/* FIB construct function */
420942c5e3cSpl 	aac_cmd_fib_t aac_cmd_fib;
421d7c5bf88Spl 	/* Call back function for completed command */
422d7c5bf88Spl 	void (*ac_comp)(struct aac_softstate *, struct aac_cmd *);
423d7c5bf88Spl 
424830d82f7Spl 	struct aac_slot *slotp;	/* slot used by this command */
425d7c5bf88Spl 	struct aac_container *dvp;	/* target device */
4267c478bd9Sstevel@tonic-gate 
427d7c5bf88Spl 	/* FIB for this IO command */
428d7c5bf88Spl 	int fib_size; /* size of the FIB xferred to/from the card */
429d7c5bf88Spl 	struct aac_fib *fibp;
4307c478bd9Sstevel@tonic-gate };
4317c478bd9Sstevel@tonic-gate 
4321dd0a2dbSpl #ifdef DEBUG
4331dd0a2dbSpl 
4341dd0a2dbSpl #define	AACDB_FLAGS_MASK		0x0000ffff
4351dd0a2dbSpl #define	AACDB_FLAGS_KERNEL_PRINT	0x00000001
4361dd0a2dbSpl #define	AACDB_FLAGS_FW_PRINT		0x00000002
437942c5e3cSpl #define	AACDB_FLAGS_NO_HEADERS		0x00000004
438942c5e3cSpl 
439942c5e3cSpl #define	AACDB_FLAGS_MISC		0x00000010
440942c5e3cSpl #define	AACDB_FLAGS_FUNC1		0x00000020
441942c5e3cSpl #define	AACDB_FLAGS_FUNC2		0x00000040
442942c5e3cSpl #define	AACDB_FLAGS_SCMD		0x00000080
443942c5e3cSpl #define	AACDB_FLAGS_AIF			0x00000100
444942c5e3cSpl #define	AACDB_FLAGS_FIB			0x00000200
445942c5e3cSpl #define	AACDB_FLAGS_IOCTL		0x00000400
4461dd0a2dbSpl 
4471dd0a2dbSpl extern uint32_t aac_debug_flags;
4481dd0a2dbSpl extern int aac_dbflag_on(struct aac_softstate *, int);
4491dd0a2dbSpl extern void aac_printf(struct aac_softstate *, uint_t, const char *, ...);
4501dd0a2dbSpl extern void aac_print_fib(struct aac_softstate *, struct aac_fib *);
4511dd0a2dbSpl 
4521dd0a2dbSpl #define	AACDB_PRINT(s, lev, ...) { \
4531dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_MISC)) \
4541dd0a2dbSpl 		aac_printf((s), (lev), __VA_ARGS__); }
4551dd0a2dbSpl 
4561dd0a2dbSpl #define	AACDB_PRINT_IOCTL(s, ...) { \
4571dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_IOCTL)) \
4581dd0a2dbSpl 		aac_printf((s), CE_NOTE, __VA_ARGS__); }
4591dd0a2dbSpl 
4601dd0a2dbSpl #define	AACDB_PRINT_TRAN(s, ...) { \
4611dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) \
4621dd0a2dbSpl 		aac_printf((s), CE_NOTE, __VA_ARGS__); }
4631dd0a2dbSpl 
4641dd0a2dbSpl #define	DBCALLED(s, n) { \
4651dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_FUNC ## n)) \
4661dd0a2dbSpl 		aac_printf((s), CE_NOTE, "--- %s() called ---", __func__); }
4671dd0a2dbSpl 
4681dd0a2dbSpl #define	AACDB_PRINT_SCMD(s, x) { \
4691dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_SCMD)) aac_print_scmd((s), (x)); }
4701dd0a2dbSpl 
4711dd0a2dbSpl #define	AACDB_PRINT_AIF(s, x) { \
4721dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_AIF)) aac_print_aif((s), (x)); }
4731dd0a2dbSpl 
4741dd0a2dbSpl #define	AACDB_PRINT_FIB(s, x) { \
4751dd0a2dbSpl 	if (aac_dbflag_on((s), AACDB_FLAGS_FIB)) aac_print_fib((s), (x)); }
4761dd0a2dbSpl 
4771dd0a2dbSpl #else /* DEBUG */
4781dd0a2dbSpl 
4791dd0a2dbSpl #define	AACDB_PRINT(s, lev, ...)
4801dd0a2dbSpl #define	AACDB_PRINT_IOCTL(s, ...)
4811dd0a2dbSpl #define	AACDB_PRINT_TRAN(s, ...)
4821dd0a2dbSpl #define	AACDB_PRINT_FIB(s, x)
4831dd0a2dbSpl #define	AACDB_PRINT_SCMD(s, x)
4841dd0a2dbSpl #define	AACDB_PRINT_AIF(s, x)
4851dd0a2dbSpl #define	DBCALLED(s, n)
4861dd0a2dbSpl 
4871dd0a2dbSpl #endif /* DEBUG */
4881dd0a2dbSpl 
4897c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate #endif
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate #endif /* _AAC_H_ */
494