1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000-2001 Scott Long
4 * Copyright (c) 2000 BSDi
5 * Copyright (c) 2001 Adaptec, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 *	$FreeBSD$
30 */
31
32/*
33 * Data structures defining the interface between the driver and the Adaptec
34 * 'FSA' adapters.  Note that many field names and comments here are taken
35 * verbatim from the Adaptec driver source in order to make comparing the
36 * two slightly easier.
37 */
38
39/*
40 * Misc. magic numbers.
41 */
42#define AAC_MAX_CONTAINERS	64
43#define AAC_BLOCK_SIZE		512
44
45/*
46 * Communications interface.
47 *
48 * Where datastructure layouts are closely parallel to the Adaptec sample code,
49 * retain their naming conventions (for now) to aid in cross-referencing.
50 */
51
52/*
53 * We establish 4 command queues and matching response queues.  Queues must
54 * be 16-byte aligned, and are sized as follows:
55 */
56#define AAC_HOST_NORM_CMD_ENTRIES	8	/* command adapter->host,
57						 * normal priority */
58#define AAC_HOST_HIGH_CMD_ENTRIES	4	/* command adapter->host,
59						 * high priority */
60#define AAC_ADAP_NORM_CMD_ENTRIES	512	/* command host->adapter,
61						 * normal priority */
62#define AAC_ADAP_HIGH_CMD_ENTRIES	4	/* command host->adapter,
63						 * high priority */
64#define AAC_HOST_NORM_RESP_ENTRIES	512	/* response, adapter->host,
65						 * normal priority */
66#define AAC_HOST_HIGH_RESP_ENTRIES	4	/* response, adapter->host,
67						 * high priority */
68#define AAC_ADAP_NORM_RESP_ENTRIES	8	/* response, host->adapter,
69						 * normal priority */
70#define AAC_ADAP_HIGH_RESP_ENTRIES	4	/* response, host->adapter,
71						 * high priority */
72
73#define AAC_TOTALQ_LENGTH	(AAC_HOST_HIGH_CMD_ENTRIES +	\
74				 AAC_HOST_NORM_CMD_ENTRIES +	\
75				 AAC_ADAP_HIGH_CMD_ENTRIES +	\
76				 AAC_ADAP_NORM_CMD_ENTRIES +	\
77				 AAC_HOST_HIGH_RESP_ENTRIES +	\
78				 AAC_HOST_NORM_RESP_ENTRIES +	\
79				 AAC_ADAP_HIGH_RESP_ENTRIES +	\
80				 AAC_ADAP_NORM_RESP_ENTRIES)
81#define AAC_QUEUE_COUNT		8
82#define AAC_QUEUE_ALIGN		16
83
84struct aac_queue_entry {
85	u_int32_t	aq_fib_size;	/* FIB size in bytes */
86	u_int32_t	aq_fib_addr;	/* receiver-space address of the FIB */
87} __packed;
88
89#define AAC_PRODUCER_INDEX	0
90#define AAC_CONSUMER_INDEX	1
91
92/*
93 * Table of queue indices and queues used to communicate with the
94 * controller.  This structure must be aligned to AAC_QUEUE_ALIGN
95 */
96struct aac_queue_table {
97	/* queue consumer/producer indexes (layout mandated by adapter) */
98	u_int32_t			qt_qindex[AAC_QUEUE_COUNT][2];
99
100	/* queue entry structures (layout mandated by adapter) */
101	struct aac_queue_entry qt_HostNormCmdQueue [AAC_HOST_NORM_CMD_ENTRIES];
102	struct aac_queue_entry qt_HostHighCmdQueue [AAC_HOST_HIGH_CMD_ENTRIES];
103	struct aac_queue_entry qt_AdapNormCmdQueue [AAC_ADAP_NORM_CMD_ENTRIES];
104	struct aac_queue_entry qt_AdapHighCmdQueue [AAC_ADAP_HIGH_CMD_ENTRIES];
105	struct aac_queue_entry qt_HostNormRespQueue[AAC_HOST_NORM_RESP_ENTRIES];
106	struct aac_queue_entry qt_HostHighRespQueue[AAC_HOST_HIGH_RESP_ENTRIES];
107	struct aac_queue_entry qt_AdapNormRespQueue[AAC_ADAP_NORM_RESP_ENTRIES];
108	struct aac_queue_entry qt_AdapHighRespQueue[AAC_ADAP_HIGH_RESP_ENTRIES];
109} __packed;
110
111/*
112 * Queue names
113 *
114 * Note that we base these at 0 in order to use them as array indices.  Adaptec
115 * used base 1 for some unknown reason, and sorted them in a different order.
116 */
117#define AAC_HOST_NORM_CMD_QUEUE		0
118#define AAC_HOST_HIGH_CMD_QUEUE		1
119#define AAC_ADAP_NORM_CMD_QUEUE		2
120#define AAC_ADAP_HIGH_CMD_QUEUE		3
121#define AAC_HOST_NORM_RESP_QUEUE	4
122#define AAC_HOST_HIGH_RESP_QUEUE	5
123#define AAC_ADAP_NORM_RESP_QUEUE	6
124#define AAC_ADAP_HIGH_RESP_QUEUE	7
125
126/*
127 * List structure used to chain FIBs (used by the adapter - we hang FIBs off
128 * our private command structure and don't touch these)
129 */
130struct aac_fib_list_entry {
131	u_int32_t	Flink;
132	u_int32_t	Blink;
133} __packed;
134
135/*
136 * FIB (FSA Interface Block?); this is the datastructure passed between the host
137 * and adapter.
138 */
139struct aac_fib_header {
140	u_int32_t		XferState;
141	u_int16_t		Command;
142	u_int8_t		StructType;
143	u_int8_t		Flags;
144	u_int16_t		Size;
145	u_int16_t		SenderSize;
146	u_int32_t		SenderFibAddress;
147	u_int32_t		ReceiverFibAddress;
148	u_int32_t		SenderData;
149	union {
150		struct {
151			u_int32_t	ReceiverTimeStart;
152			u_int32_t	ReceiverTimeDone;
153		} _s;
154		struct aac_fib_list_entry FibLinks;
155	} _u;
156} __packed;
157
158#define AAC_FIB_DATASIZE	(512 - sizeof(struct aac_fib_header))
159
160struct aac_fib {
161	struct aac_fib_header	Header;
162	u_int8_t			data[AAC_FIB_DATASIZE];
163} __packed;
164
165/*
166 * FIB commands
167 */
168typedef enum {
169	TestCommandResponse =		1,
170	TestAdapterCommand =		2,
171
172	/* lowlevel and comm commands */
173	LastTestCommand =		100,
174	ReinitHostNormCommandQueue =	101,
175	ReinitHostHighCommandQueue =	102,
176	ReinitHostHighRespQueue =	103,
177	ReinitHostNormRespQueue =	104,
178	ReinitAdapNormCommandQueue =	105,
179	ReinitAdapHighCommandQueue =	107,
180	ReinitAdapHighRespQueue =	108,
181	ReinitAdapNormRespQueue =	109,
182	InterfaceShutdown =		110,
183	DmaCommandFib =			120,
184	StartProfile =			121,
185	TermProfile =			122,
186	SpeedTest =			123,
187	TakeABreakPt =			124,
188	RequestPerfData =		125,
189	SetInterruptDefTimer=		126,
190	SetInterruptDefCount=		127,
191	GetInterruptDefStatus=		128,
192	LastCommCommand =		129,
193
194	/* filesystem commands */
195	NuFileSystem =			300,
196	UFS =				301,
197	HostFileSystem =		302,
198	LastFileSystemCommand =		303,
199
200	/* Container Commands */
201	ContainerCommand =		500,
202	ContainerCommand64 =		501,
203	RawIo = 			502,
204
205	/* Cluster Commands */
206	ClusterCommand =		550,
207
208	/* Scsi Port commands (scsi passthrough) */
209	ScsiPortCommand =		600,
210	ScsiPortCommandU64 =		601,
211	SataPortCommandU64 =		602,
212	SasSmpPassThrough =		603,
213	SasRequestPhyInfo =		612,
214
215	/* misc house keeping and generic adapter initiated commands */
216	AifRequest =			700,
217	CheckRevision =			701,
218	FsaHostShutdown =		702,
219	RequestAdapterInfo =		703,
220	IsAdapterPaused =		704,
221	SendHostTime =			705,
222	RequestSupplementAdapterInfo =	706,	/* Supp. Info for set in UCC
223						 * use only if supported
224						 * (RequestAdapterInfo first) */
225	LastMiscCommand =		707,
226
227	OnLineDiagnostic =		800,
228	FduAdapterTest =		801,
229	RequestCompatibilityId =	802,
230	AdapterEnvironmentInfo =	803,	/* temp. sensors */
231	NvsramEventLog =		900,
232	ResetNvsramEventLogPointers =	901,
233	EnableEventLog =		902,
234	DisableEventLog =		903,
235	EncryptedKeyTransportFIB=	904,
236	KeyableFeaturesFIB=		905
237} AAC_FibCommands;
238
239/*
240 * FIB types
241 */
242#define AAC_FIBTYPE_TFIB	1
243#define AAC_FIBTYPE_TQE		2
244#define AAC_FIBTYPE_TCTPERF	3
245
246/*
247 * FIB transfer state
248 */
249#define AAC_FIBSTATE_HOSTOWNED		(1<<0)	/* owned by the host */
250#define AAC_FIBSTATE_ADAPTEROWNED	(1<<1)	/* owned by the adapter */
251#define AAC_FIBSTATE_INITIALISED	(1<<2)	/* initialised */
252#define AAC_FIBSTATE_EMPTY		(1<<3)	/* empty */
253#define AAC_FIBSTATE_FROMPOOL		(1<<4)	/* allocated from pool */
254#define AAC_FIBSTATE_FROMHOST		(1<<5)	/* sent from the host */
255#define AAC_FIBSTATE_FROMADAP		(1<<6)	/* sent from the adapter */
256#define AAC_FIBSTATE_REXPECTED		(1<<7)	/* response is expected */
257#define AAC_FIBSTATE_RNOTEXPECTED	(1<<8)	/* response is not expected */
258#define AAC_FIBSTATE_DONEADAP		(1<<9)	/* processed by the adapter */
259#define AAC_FIBSTATE_DONEHOST		(1<<10)	/* processed by the host */
260#define AAC_FIBSTATE_HIGH		(1<<11)	/* high priority */
261#define AAC_FIBSTATE_NORM		(1<<12)	/* normal priority */
262#define AAC_FIBSTATE_ASYNC		(1<<13)
263#define AAC_FIBSTATE_ASYNCIO		(1<<13)	/* to be removed */
264#define AAC_FIBSTATE_PAGEFILEIO		(1<<14)	/* to be removed */
265#define AAC_FIBSTATE_SHUTDOWN		(1<<15)
266#define AAC_FIBSTATE_LAZYWRITE		(1<<16)	/* to be removed */
267#define AAC_FIBSTATE_ADAPMICROFIB	(1<<17)
268#define AAC_FIBSTATE_BIOSFIB		(1<<18)
269#define AAC_FIBSTATE_FAST_RESPONSE	(1<<19)	/* fast response capable */
270#define AAC_FIBSTATE_APIFIB		(1<<20)
271
272/*
273 * FIB error values
274 */
275#define AAC_ERROR_NORMAL			0x00
276#define AAC_ERROR_PENDING			0x01
277#define AAC_ERROR_FATAL				0x02
278#define AAC_ERROR_INVALID_QUEUE			0x03
279#define AAC_ERROR_NOENTRIES			0x04
280#define AAC_ERROR_SENDFAILED			0x05
281#define AAC_ERROR_INVALID_QUEUE_PRIORITY	0x06
282#define AAC_ERROR_FIB_ALLOCATION_FAILED		0x07
283#define AAC_ERROR_FIB_DEALLOCATION_FAILED	0x08
284
285/*
286 * Adapter Init Structure: this is passed to the adapter with the
287 * AAC_MONKER_INITSTRUCT command to point it at our control structures.
288 */
289struct aac_adapter_init {
290	u_int32_t	InitStructRevision;
291#define AAC_INIT_STRUCT_REVISION		3
292#define AAC_INIT_STRUCT_REVISION_4		4
293	u_int32_t	MiniPortRevision;
294#define AAC_INIT_STRUCT_MINIPORT_REVISION	1
295	u_int32_t	FilesystemRevision;
296	u_int32_t	CommHeaderAddress;
297	u_int32_t	FastIoCommAreaAddress;
298	u_int32_t	AdapterFibsPhysicalAddress;
299	u_int32_t 	AdapterFibsVirtualAddress;
300	u_int32_t	AdapterFibsSize;
301	u_int32_t	AdapterFibAlign;
302	u_int32_t	PrintfBufferAddress;
303	u_int32_t	PrintfBufferSize;
304#define	AAC_PAGE_SIZE				4096
305	u_int32_t	HostPhysMemPages;
306	u_int32_t	HostElapsedSeconds;
307	/* ADAPTER_INIT_STRUCT_REVISION_4 begins here */
308	u_int32_t	InitFlags;			/* flags for supported features */
309#define	AAC_INITFLAGS_NEW_COMM_SUPPORTED	1
310#define	AAC_INITFLAGS_DRIVER_USES_UTC_TIME	0x10
311#define	AAC_INITFLAGS_DRIVER_SUPPORTS_PM	0x20
312	u_int32_t	MaxIoCommands;		/* max outstanding commands */
313	u_int32_t	MaxIoSize;			/* largest I/O command */
314	u_int32_t	MaxFibSize;			/* largest FIB to adapter */
315} __packed;
316
317/*
318 * Shared data types
319 */
320/*
321 * Container types
322 */
323typedef enum {
324	CT_NONE = 0,
325	CT_VOLUME,
326	CT_MIRROR,
327	CT_STRIPE,
328	CT_RAID5,
329	CT_SSRW,
330	CT_SSRO,
331	CT_MORPH,
332	CT_PASSTHRU,
333	CT_RAID4,
334	CT_RAID10,		/* stripe of mirror */
335	CT_RAID00,		/* stripe of stripe */
336	CT_VOLUME_OF_MIRRORS,	/* volume of mirror */
337	CT_PSEUDO_RAID3,	/* really raid4 */
338	CT_RAID50,		/* stripe of raid5 */
339	CT_RAID5D,		/* raid5 distributed hot-sparing */
340	CT_RAID5D0,
341	CT_RAID1E,		/* extended raid1 mirroring */
342	CT_RAID6,
343	CT_RAID60,
344} AAC_FSAVolType;
345
346/*
347 * Host-addressable object types
348 */
349typedef enum {
350	FT_REG = 1,	/* regular file */
351	FT_DIR,		/* directory */
352	FT_BLK,		/* "block" device - reserved */
353	FT_CHR,		/* "character special" device - reserved */
354	FT_LNK,		/* symbolic link */
355	FT_SOCK,	/* socket */
356	FT_FIFO,	/* fifo */
357	FT_FILESYS,	/* ADAPTEC's "FSA"(tm) filesystem */
358	FT_DRIVE,	/* physical disk - addressable in scsi by b/t/l */
359	FT_SLICE,	/* virtual disk - raw volume - slice */
360	FT_PARTITION,	/* FSA partition - carved out of a slice - building
361			 * block for containers */
362	FT_VOLUME,	/* Container - Volume Set */
363	FT_STRIPE,	/* Container - Stripe Set */
364	FT_MIRROR,	/* Container - Mirror Set */
365	FT_RAID5,	/* Container - Raid 5 Set */
366	FT_DATABASE	/* Storage object with "foreign" content manager */
367} AAC_FType;
368
369/*
370 * Host-side scatter/gather list for 32-bit commands.
371 */
372struct aac_sg_entry {
373	u_int32_t	SgAddress;
374	u_int32_t	SgByteCount;
375} __packed;
376
377struct aac_sg_entry64 {
378	u_int64_t	SgAddress;
379	u_int32_t	SgByteCount;
380} __packed;
381
382struct aac_sg_entryraw {
383	u_int32_t	Next;		/* reserved for FW use */
384	u_int32_t	Prev;		/* reserved for FW use */
385	u_int64_t	SgAddress;
386	u_int32_t	SgByteCount;
387	u_int32_t	Flags;		/* reserved for FW use */
388} __packed;
389
390struct aac_sg_table {
391	u_int32_t		SgCount;
392	struct aac_sg_entry	SgEntry[0];
393} __packed;
394
395/*
396 * Host-side scatter/gather list for 64-bit commands.
397 */
398struct aac_sg_table64 {
399	u_int32_t	SgCount;
400	struct aac_sg_entry64	SgEntry64[0];
401} __packed;
402
403/*
404 * s/g list for raw commands
405 */
406struct aac_sg_tableraw {
407	u_int32_t	SgCount;
408	struct aac_sg_entryraw	SgEntryRaw[0];
409} __packed;
410
411/*
412 * Container creation data
413 */
414struct aac_container_creation {
415	u_int8_t	ViaBuildNumber;
416	u_int8_t	MicroSecond;
417	u_int8_t	Via;		/* 1 = FSU, 2 = API, etc. */
418	u_int8_t	YearsSince1900;
419	u_int32_t	Month:4;	/* 1-12 */
420	u_int32_t	Day:6;		/* 1-32 */
421	u_int32_t	Hour:6;		/* 0-23 */
422	u_int32_t	Minute:6;	/* 0-59 */
423	u_int32_t	Second:6;	/* 0-59 */
424	u_int64_t	ViaAdapterSerialNumber;
425} __packed;
426
427/*
428 * Revision number handling
429 */
430
431typedef enum {
432	RevApplication = 1,
433	RevDkiCli,
434	RevNetService,
435	RevApi,
436	RevFileSysDriver,
437	RevMiniportDriver,
438	RevAdapterSW,
439	RevMonitor,
440	RevRemoteApi
441} RevComponent;
442
443struct FsaRevision {
444	union {
445		struct {
446			u_int8_t	dash;
447			u_int8_t	type;
448			u_int8_t	minor;
449			u_int8_t	major;
450		} comp;
451		u_int32_t	ul;
452	} external;
453	u_int32_t	buildNumber;
454}  __packed;
455
456/*
457 * Adapter Information
458 */
459
460typedef enum {
461	CPU_NTSIM = 1,
462	CPU_I960,
463	CPU_ARM,
464	CPU_SPARC,
465	CPU_POWERPC,
466	CPU_ALPHA,
467	CPU_P7,
468	CPU_I960_RX,
469	CPU_MIPS,
470	CPU_XSCALE,
471	CPU__last
472} AAC_CpuType;
473
474typedef enum {
475	CPUI960_JX = 1,
476	CPUI960_CX,
477	CPUI960_HX,
478	CPUI960_RX,
479	CPUARM_SA110,
480	CPUARM_xxx,
481	CPUPPC_603e,
482	CPUPPC_xxx,
483	CPUI960_80303,
484	CPU_XSCALE_80321,
485	CPU_MIPS_4KC,
486	CPU_MIPS_5KC,
487	CPUSUBTYPE__last
488} AAC_CpuSubType;
489
490typedef enum {
491	PLAT_NTSIM = 1,
492	PLAT_V3ADU,
493	PLAT_CYCLONE,
494	PLAT_CYCLONE_HD,
495	PLAT_BATBOARD,
496	PLAT_BATBOARD_HD,
497	PLAT_YOLO,
498	PLAT_COBRA,
499	PLAT_ANAHEIM,
500	PLAT_JALAPENO,
501	PLAT_QUEENS,
502	PLAT_JALAPENO_DELL,
503	PLAT_POBLANO,
504	PLAT_POBLANO_OPAL,
505	PLAT_POBLANO_SL0,
506	PLAT_POBLANO_SL1,
507	PLAT_POBLANO_SL2,
508	PLAT_POBLANO_XXX,
509	PLAT_JALAPENO_P2,
510	PLAT_HABANERO,
511	PLAT_VULCAN,
512	PLAT_CRUSADER,
513	PLAT_LANCER,
514	PLAT_HARRIER,
515	PLAT_TERMINATOR,
516	PLAT_SKYHAWK,
517	PLAT_CORSAIR,
518	PLAT_JAGUAR,
519	PLAT_SATAHAWK,
520	PLAT_SATANATOR,
521	PLAT_PROWLER,
522	PLAT_BLACKBIRD,
523	PLAT_SABREEXPRESS,
524	PLAT_INTRUDER,
525	PLAT__last
526} AAC_Platform;
527
528typedef enum {
529	OEM_FLAVOR_ADAPTEC = 1,
530	OEM_FLAVOR_DELL,
531	OEM_FLAVOR_HP,
532	OEM_FLAVOR_IBM,
533	OEM_FLAVOR_CPQ,
534	OEM_FLAVOR_FSC,
535	OEM_FLAVOR_DWS,
536	OEM_FLAVOR_BRAND_Z,
537	OEM_FLAVOR_LEGEND,
538	OEM_FLAVOR_HITACHI,
539	OEM_FLAVOR_ESG,
540	OEM_FLAVOR_ICP,
541	OEM_FLAVOR_SCM,
542	OEM_FLAVOR__last
543} AAC_OemFlavor;
544
545/*
546 * XXX the aac-2622 with no battery present reports PLATFORM_BAT_OPT_PRESENT
547 */
548typedef enum
549{
550	PLATFORM_BAT_REQ_PRESENT = 1,	/* BATTERY REQUIRED AND PRESENT */
551	PLATFORM_BAT_REQ_NOTPRESENT,	/* BATTERY REQUIRED AND NOT PRESENT */
552	PLATFORM_BAT_OPT_PRESENT,	/* BATTERY OPTIONAL AND PRESENT */
553	PLATFORM_BAT_OPT_NOTPRESENT,	/* BATTERY OPTIONAL AND NOT PRESENT */
554	PLATFORM_BAT_NOT_SUPPORTED	/* BATTERY NOT SUPPORTED */
555} AAC_BatteryPlatform;
556
557/*
558 * options supported by this board
559 * there has to be a one to one mapping of these defines and the ones in
560 * fsaapi.h, search for FSA_SUPPORT_SNAPSHOT
561 */
562#define AAC_SUPPORTED_SNAPSHOT		0x01
563#define AAC_SUPPORTED_CLUSTERS		0x02
564#define AAC_SUPPORTED_WRITE_CACHE	0x04
565#define AAC_SUPPORTED_64BIT_DATA	0x08
566#define AAC_SUPPORTED_HOST_TIME_FIB	0x10
567#define AAC_SUPPORTED_RAID50		0x20
568#define AAC_SUPPORTED_4GB_WINDOW	0x40
569#define AAC_SUPPORTED_SCSI_UPGRADEABLE	0x80
570#define AAC_SUPPORTED_SOFT_ERR_REPORT	0x100
571#define AAC_SUPPORTED_NOT_RECONDITION	0x200
572#define AAC_SUPPORTED_SGMAP_HOST64	0x400
573#define AAC_SUPPORTED_ALARM		0x800
574#define AAC_SUPPORTED_NONDASD		0x1000
575#define AAC_SUPPORTED_SCSI_MANAGED	0x2000
576#define AAC_SUPPORTED_RAID_SCSI_MODE	0x4000
577#define AAC_SUPPORTED_SUPPLEMENT_ADAPTER_INFO	0x10000
578#define AAC_SUPPORTED_NEW_COMM		0x20000
579#define AAC_SUPPORTED_64BIT_ARRAYSIZE	0x40000
580#define AAC_SUPPORTED_HEAT_SENSOR	0x80000
581
582/*
583 * Structure used to respond to a RequestAdapterInfo fib.
584 */
585struct aac_adapter_info {
586	AAC_Platform		PlatformBase;	 /* adapter type */
587	AAC_CpuType		CpuArchitecture; /* adapter CPU type */
588	AAC_CpuSubType		CpuVariant;	 /* adapter CPU subtype */
589	u_int32_t		ClockSpeed;	 /* adapter CPU clockspeed */
590	u_int32_t		ExecutionMem;	 /* adapter Execution Memory
591						  * size */
592	u_int32_t		BufferMem;	 /* adapter Data Memory */
593	u_int32_t		TotalMem;	 /* adapter Total Memory */
594	struct FsaRevision	KernelRevision;  /* adapter Kernel Software
595						  * Revision */
596	struct FsaRevision	MonitorRevision; /* adapter Monitor/Diagnostic
597						  * Software Revision */
598	struct FsaRevision	HardwareRevision;/* TBD */
599	struct FsaRevision	BIOSRevision;	 /* adapter BIOS Revision */
600	u_int32_t		ClusteringEnabled;
601	u_int32_t		ClusterChannelMask;
602	u_int64_t		SerialNumber;
603	AAC_BatteryPlatform	batteryPlatform;
604	u_int32_t		SupportedOptions; /* supported features of this
605						   * controller */
606	AAC_OemFlavor	OemVariant;
607} __packed;
608
609/*
610 * Structure used to respond to a RequestSupplementAdapterInfo fib.
611 */
612struct vpd_info {
613	u_int8_t		AssemblyPn[8];
614	u_int8_t		FruPn[8];
615	u_int8_t		BatteryFruPn[8];
616	u_int8_t		EcVersionString[8];
617	u_int8_t		Tsid[12];
618} __packed;
619
620#define	MFG_PCBA_SERIAL_NUMBER_WIDTH	12
621#define	MFG_WWN_WIDTH			8
622
623struct aac_supplement_adapter_info {
624	/* The assigned Adapter Type Text, extra byte for null termination */
625	int8_t		AdapterTypeText[17+1];
626	/* Pad for the text above */
627	int8_t		Pad[2];
628	/* Size in bytes of the memory that is flashed */
629	u_int32_t	FlashMemoryByteSize;
630	/* The assigned IMAGEID_xxx for this adapter */
631	u_int32_t	FlashImageId;
632	/*
633	 * The maximum number of Phys available on a SATA/SAS
634	 * Controller, 0 otherwise
635	 */
636	u_int32_t	MaxNumberPorts;
637	/* Version of expansion area */
638	u_int32_t	Version;
639	u_int32_t	FeatureBits;
640	u_int8_t		SlotNumber;
641	u_int8_t		ReservedPad0[3];
642	u_int8_t		BuildDate[12];
643	/* The current number of Ports on a SAS controller, 0 otherwise */
644	u_int32_t	CurrentNumberPorts;
645
646	struct vpd_info VpdInfo;
647
648	/* Firmware Revision (Vmaj.min-dash.) */
649	struct FsaRevision	FlashFirmwareRevision;
650	u_int32_t	RaidTypeMorphOptions;
651	/* Firmware's boot code Revision (Vmaj.min-dash.) */
652	struct FsaRevision	FlashFirmwareBootRevision;
653	/* PCBA serial no. from th MFG sector */
654	u_int8_t		MfgPcbaSerialNo[MFG_PCBA_SERIAL_NUMBER_WIDTH];
655	/* WWN from the MFG sector */
656	u_int8_t		MfgWWNName[MFG_WWN_WIDTH];
657	/* Growth Area for future expansion ((7*4) - 12 - 8)/4 = 2 words */
658	u_int32_t	ReservedGrowth[2];
659} __packed;
660
661/*
662 * Monitor/Kernel interface.
663 */
664
665/*
666 * Synchronous commands to the monitor/kernel.
667 */
668#define AAC_MONKER_BREAKPOINT	0x04
669#define AAC_MONKER_INITSTRUCT	0x05
670#define AAC_MONKER_SYNCFIB	0x0c
671#define AAC_MONKER_GETKERNVER	0x11
672#define AAC_MONKER_POSTRESULTS	0x14
673#define AAC_MONKER_GETINFO	0x19
674#define AAC_MONKER_GETDRVPROP	0x23
675#define AAC_MONKER_RCVTEMP	0x25
676#define AAC_MONKER_GETCOMMPREF	0x26
677#define AAC_MONKER_REINIT	0xee
678
679/*
680 *  Adapter Status Register
681 *
682 *  Phase Staus mailbox is 32bits:
683 *  <31:16> = Phase Status
684 *  <15:0>  = Phase
685 *
686 *  The adapter reports its present state through the phase.  Only
687 *  a single phase should be ever be set.  Each phase can have multiple
688 *  phase status bits to provide more detailed information about the
689 *  state of the adapter.
690 */
691#define AAC_SELF_TEST_FAILED	0x00000004
692#define AAC_MONITOR_PANIC	0x00000020
693#define AAC_UP_AND_RUNNING	0x00000080
694#define AAC_KERNEL_PANIC	0x00000100
695
696/*
697 * Data types relating to control and monitoring of the NVRAM/WriteCache
698 * subsystem.
699 */
700
701#define AAC_NFILESYS	24	/* maximum number of filesystems */
702
703/*
704 * NVRAM/Write Cache subsystem states
705 */
706typedef enum {
707	NVSTATUS_DISABLED = 0,	/* present, clean, not being used */
708	NVSTATUS_ENABLED,	/* present, possibly dirty, ready for use */
709	NVSTATUS_ERROR,		/* present, dirty, contains dirty data */
710	NVSTATUS_BATTERY,	/* present, bad or low battery, may contain
711				 * dirty data */
712	NVSTATUS_UNKNOWN	/* for bad/missing device */
713} AAC_NVSTATUS;
714
715/*
716 * NVRAM/Write Cache subsystem battery component states
717 *
718 */
719typedef enum {
720	NVBATTSTATUS_NONE = 0,	/* battery has no power or is not present */
721	NVBATTSTATUS_LOW,	/* battery is low on power */
722	NVBATTSTATUS_OK,	/* battery is okay - normal operation possible
723				 * only in this state */
724	NVBATTSTATUS_RECONDITIONING	/* no battery present - reconditioning
725					 * in process */
726} AAC_NVBATTSTATUS;
727
728/*
729 * Battery transition type
730 */
731typedef enum {
732	NVBATT_TRANSITION_NONE = 0,	/* battery now has no power or is not
733					 * present */
734	NVBATT_TRANSITION_LOW,		/* battery is now low on power */
735	NVBATT_TRANSITION_OK		/* battery is now okay - normal
736					 * operation possible only in this
737					 * state */
738} AAC_NVBATT_TRANSITION;
739
740/*
741 * NVRAM Info structure returned for NVRAM_GetInfo call
742 */
743struct aac_nvramdevinfo {
744	u_int32_t	NV_Enabled;	/* write caching enabled */
745	u_int32_t	NV_Error;	/* device in error state */
746	u_int32_t	NV_NDirty;	/* count of dirty NVRAM buffers */
747	u_int32_t	NV_NActive;	/* count of NVRAM buffers being
748					 * written */
749} __packed;
750
751struct aac_nvraminfo {
752	AAC_NVSTATUS		NV_Status;	/* nvram subsystem status */
753	AAC_NVBATTSTATUS	NV_BattStatus;	/* battery status */
754	u_int32_t		NV_Size;	/* size of WriteCache NVRAM in
755						 * bytes */
756	u_int32_t		NV_BufSize;	/* size of NVRAM buffers in
757						 * bytes */
758	u_int32_t		NV_NBufs;	/* number of NVRAM buffers */
759	u_int32_t		NV_NDirty;	/* Num dirty NVRAM buffers */
760	u_int32_t		NV_NClean;	/* Num clean NVRAM buffers */
761	u_int32_t		NV_NActive;	/* Num NVRAM buffers being
762						 * written */
763	u_int32_t		NV_NBrokered;	/* Num brokered NVRAM buffers */
764	struct aac_nvramdevinfo	NV_DevInfo[AAC_NFILESYS];	/* per device
765								 * info */
766	u_int32_t		NV_BattNeedsReconditioning;	/* boolean */
767	u_int32_t		NV_TotalSize;	/* size of all non-volatile
768						 * memories in bytes */
769} __packed;
770
771/*
772 * Data types relating to adapter-initiated FIBs
773 *
774 * Based on types and structures in <aifstruc.h>
775 */
776
777/*
778 * Progress Reports
779 */
780typedef enum {
781	AifJobStsSuccess = 1,
782	AifJobStsFinished,
783	AifJobStsAborted,
784	AifJobStsFailed,
785	AifJobStsLastReportMarker = 100,	/* All prior mean last report */
786	AifJobStsSuspended,
787	AifJobStsRunning
788} AAC_AifJobStatus;
789
790typedef enum {
791	AifJobScsiMin = 1,		/* Minimum value for Scsi operation */
792	AifJobScsiZero,			/* SCSI device clear operation */
793	AifJobScsiVerify,		/* SCSI device Verify operation NO
794					 * REPAIR */
795	AifJobScsiExercise,		/* SCSI device Exercise operation */
796	AifJobScsiVerifyRepair,		/* SCSI device Verify operation WITH
797					 * repair */
798	AifJobScsiWritePattern,		/* write pattern */
799	AifJobScsiMax = 99,		/* Max Scsi value */
800	AifJobCtrMin,			/* Min Ctr op value */
801	AifJobCtrZero,			/* Container clear operation */
802	AifJobCtrCopy,			/* Container copy operation */
803	AifJobCtrCreateMirror,		/* Container Create Mirror operation */
804	AifJobCtrMergeMirror,		/* Container Merge Mirror operation */
805	AifJobCtrScrubMirror,		/* Container Scrub Mirror operation */
806	AifJobCtrRebuildRaid5,		/* Container Rebuild Raid5 operation */
807	AifJobCtrScrubRaid5,		/* Container Scrub Raid5 operation */
808	AifJobCtrMorph,			/* Container morph operation */
809	AifJobCtrPartCopy,		/* Container Partition copy operation */
810	AifJobCtrRebuildMirror,		/* Container Rebuild Mirror operation */
811	AifJobCtrCrazyCache,		/* crazy cache */
812	AifJobCtrCopyback,		/* Container Copyback operation */
813	AifJobCtrCompactRaid5D,		/* Container Compaction operation */
814	AifJobCtrExpandRaid5D,		/* Container Expansion operation */
815	AifJobCtrRebuildRaid6,		/* Container Rebuild Raid6 operation */
816	AifJobCtrScrubRaid6,		/* Container Scrub Raid6 operation */
817	AifJobCtrSSBackup,		/* Container snapshot backup task */
818	AifJobCtrMax = 199,		/* Max Ctr type operation */
819	AifJobFsMin,			/* Min Fs type operation */
820	AifJobFsCreate,			/* File System Create operation */
821	AifJobFsVerify,			/* File System Verify operation */
822	AifJobFsExtend,			/* File System Extend operation */
823	AifJobFsMax = 299,		/* Max Fs type operation */
824	AifJobApiFormatNTFS,		/* Format a drive to NTFS */
825	AifJobApiFormatFAT,		/* Format a drive to FAT */
826	AifJobApiUpdateSnapshot,	/* update the read/write half of a
827					 * snapshot */
828	AifJobApiFormatFAT32,		/* Format a drive to FAT32 */
829	AifJobApiMax = 399,		/* Max API type operation */
830	AifJobCtlContinuousCtrVerify,	/* Adapter operation */
831	AifJobCtlMax = 499		/* Max Adapter type operation */
832} AAC_AifJobType;
833
834struct aac_AifContainers {
835	u_int32_t	src;		/* from/master */
836	u_int32_t	dst;		/* to/slave */
837} __packed;
838
839union aac_AifJobClient {
840	struct aac_AifContainers	container;	/* For Container and
841							 * filesystem progress
842							 * ops; */
843	int32_t				scsi_dh;	/* For SCSI progress
844							 * ops */
845};
846
847struct aac_AifJobDesc {
848	u_int32_t		jobID;		/* DO NOT FILL IN! Will be
849						 * filled in by AIF */
850	AAC_AifJobType		type;		/* Operation that is being
851						 * performed */
852	union aac_AifJobClient	client;		/* Details */
853} __packed;
854
855struct aac_AifJobProgressReport {
856	struct aac_AifJobDesc	jd;
857	AAC_AifJobStatus	status;
858	u_int32_t		finalTick;
859	u_int32_t		currentTick;
860	u_int32_t		jobSpecificData1;
861	u_int32_t		jobSpecificData2;
862} __packed;
863
864/*
865 * Event Notification
866 */
867typedef enum {
868	/* General application notifies start here */
869	AifEnGeneric = 1,		/* Generic notification */
870	AifEnTaskComplete,		/* Task has completed */
871	AifEnConfigChange,		/* Adapter config change occurred */
872	AifEnContainerChange,		/* Adapter specific container
873					 * configuration change */
874	AifEnDeviceFailure,		/* SCSI device failed */
875	AifEnMirrorFailover,		/* Mirror failover started */
876	AifEnContainerEvent,		/* Significant container event */
877	AifEnFileSystemChange,		/* File system changed */
878	AifEnConfigPause,		/* Container pause event */
879	AifEnConfigResume,		/* Container resume event */
880	AifEnFailoverChange,		/* Failover space assignment changed */
881	AifEnRAID5RebuildDone,		/* RAID5 rebuild finished */
882	AifEnEnclosureManagement,	/* Enclosure management event */
883	AifEnBatteryEvent,		/* Significant NV battery event */
884	AifEnAddContainer,		/* A new container was created. */
885	AifEnDeleteContainer,		/* A container was deleted. */
886	AifEnSMARTEvent,		/* SMART Event */
887	AifEnBatteryNeedsRecond,	/* The battery needs reconditioning */
888	AifEnClusterEvent,		/* Some cluster event */
889	AifEnDiskSetEvent,		/* A disk set event occured. */
890	AifEnContainerScsiEvent,	/* a container event with no. and scsi id */
891	AifEnPicBatteryEvent,	/* An event gen. by pic_battery.c for an ABM */
892	AifEnExpEvent,		/* Exp. Event Type to replace CTPopUp messages */
893	AifEnRAID6RebuildDone,	/* RAID6 rebuild finished */
894	AifEnSensorOverHeat,	/* Heat Sensor indicate overheat */
895	AifEnSensorCoolDown,	/* Heat Sensor ind. cooled down after overheat */
896	AifFeatureKeysModified,	/* notif. of updated feature keys */
897	AifApplicationExpirationEvent,	/* notif. on app. expiration status */
898	AifEnBackgroundConsistencyCheck,/* BCC notif. for NEC - DDTS 94700 */
899	AifEnAddJBOD,		/* A new JBOD type drive was created (30) */
900	AifEnDeleteJBOD,	/* A JBOD type drive was deleted (31) */
901	AifDriverNotifyStart=199,	/* Notifies for host driver go here */
902	/* Host driver notifications start here */
903	AifDenMorphComplete, 		/* A morph operation completed */
904	AifDenVolumeExtendComplete 	/* Volume expand operation completed */
905} AAC_AifEventNotifyType;
906
907struct aac_AifEnsGeneric {
908	char	text[132];		/* Generic text */
909} __packed;
910
911struct aac_AifEnsDeviceFailure {
912	u_int32_t	deviceHandle;	/* SCSI device handle */
913} __packed;
914
915struct aac_AifEnsMirrorFailover {
916	u_int32_t	container;	/* Container with failed element */
917	u_int32_t	failedSlice;	/* Old slice which failed */
918	u_int32_t	creatingSlice;	/* New slice used for auto-create */
919} __packed;
920
921struct aac_AifEnsContainerChange {
922	u_int32_t	container[2];	/* container that changed, -1 if no
923					 * container */
924} __packed;
925
926struct aac_AifEnsContainerEvent {
927	u_int32_t	container;	/* container number  */
928	u_int32_t	eventType;	/* event type */
929} __packed;
930
931struct aac_AifEnsEnclosureEvent {
932	u_int32_t	empID;		/* enclosure management proc number  */
933	u_int32_t	unitID;		/* unitId, fan id, power supply id,
934					 * slot id, tempsensor id.  */
935	u_int32_t	eventType;	/* event type */
936} __packed;
937
938typedef enum {
939	AIF_EM_DRIVE_INSERTION=31,
940	AIF_EM_DRIVE_REMOVAL
941} aac_AifEMEventType;
942
943struct aac_AifEnsBatteryEvent {
944	AAC_NVBATT_TRANSITION	transition_type;	/* eg from low to ok */
945	AAC_NVBATTSTATUS	current_state;		/* current batt state */
946	AAC_NVBATTSTATUS	prior_state;		/* prev batt state */
947} __packed;
948
949struct aac_AifEnsDiskSetEvent {
950	u_int32_t	eventType;
951	u_int64_t	DsNum;
952	u_int64_t	CreatorId;
953} __packed;
954
955typedef enum {
956	CLUSTER_NULL_EVENT = 0,
957	CLUSTER_PARTNER_NAME_EVENT,	/* change in partner hostname or
958					 * adaptername from NULL to non-NULL */
959	/* (partner's agent may be up) */
960	CLUSTER_PARTNER_NULL_NAME_EVENT	/* change in partner hostname or
961					 * adaptername from non-null to NULL */
962	/* (partner has rebooted) */
963} AAC_ClusterAifEvent;
964
965struct aac_AifEnsClusterEvent {
966	AAC_ClusterAifEvent	eventType;
967} __packed;
968
969struct aac_AifEventNotify {
970	AAC_AifEventNotifyType	type;
971	union {
972		struct aac_AifEnsGeneric		EG;
973		struct aac_AifEnsDeviceFailure		EDF;
974		struct aac_AifEnsMirrorFailover		EMF;
975		struct aac_AifEnsContainerChange	ECC;
976		struct aac_AifEnsContainerEvent		ECE;
977		struct aac_AifEnsEnclosureEvent		EEE;
978		struct aac_AifEnsBatteryEvent		EBE;
979		struct aac_AifEnsDiskSetEvent		EDS;
980/*		struct aac_AifEnsSMARTEvent		ES;*/
981		struct aac_AifEnsClusterEvent		ECLE;
982	} data;
983} __packed;
984
985/*
986 * Adapter Initiated FIB command structures. Start with the adapter
987 * initiated FIBs that really come from the adapter, and get responded
988 * to by the host.
989 */
990#define AAC_AIF_REPORT_MAX_SIZE 64
991
992typedef enum {
993	AifCmdEventNotify = 1,	/* Notify of event */
994	AifCmdJobProgress,	/* Progress report */
995	AifCmdAPIReport,	/* Report from other user of API */
996	AifCmdDriverNotify,	/* Notify host driver of event */
997	AifReqJobList = 100,	/* Gets back complete job list */
998	AifReqJobsForCtr,	/* Gets back jobs for specific container */
999	AifReqJobsForScsi,	/* Gets back jobs for specific SCSI device */
1000	AifReqJobReport,	/* Gets back a specific job report or list */
1001	AifReqTerminateJob,	/* Terminates job */
1002	AifReqSuspendJob,	/* Suspends a job */
1003	AifReqResumeJob,	/* Resumes a job */
1004	AifReqSendAPIReport,	/* API generic report requests */
1005	AifReqAPIJobStart,	/* Start a job from the API */
1006	AifReqAPIJobUpdate,	/* Update a job report from the API */
1007	AifReqAPIJobFinish	/* Finish a job from the API */
1008} AAC_AifCommand;
1009
1010struct aac_aif_command {
1011	AAC_AifCommand	command;	/* Tell host what type of
1012					 * notify this is */
1013	u_int32_t	seqNumber;	/* To allow ordering of
1014					 * reports (if necessary) */
1015	union {
1016		struct aac_AifEventNotify	EN;	/* Event notify */
1017		struct aac_AifJobProgressReport	PR[1];	/* Progress report */
1018		u_int8_t			AR[AAC_AIF_REPORT_MAX_SIZE];
1019		u_int8_t			data[AAC_FIB_DATASIZE - 8];
1020	} data;
1021} __packed;
1022
1023/*
1024 * Filesystem commands/data
1025 *
1026 * The adapter has a very complex filesystem interface, most of which we ignore.
1027 * (And which seems not to be implemented, anyway.)
1028 */
1029
1030/*
1031 * FSA commands
1032 * (not used?)
1033 */
1034typedef enum {
1035	Null = 0,
1036	GetAttributes,
1037	SetAttributes,
1038	Lookup,
1039	ReadLink,
1040	Read,
1041	Write,
1042	Create,
1043	MakeDirectory,
1044	SymbolicLink,
1045	MakeNode,
1046	Removex,
1047	RemoveDirectory,
1048	Rename,
1049	Link,
1050	ReadDirectory,
1051	ReadDirectoryPlus,
1052	FileSystemStatus,
1053	FileSystemInfo,
1054	PathConfigure,
1055	Commit,
1056	Mount,
1057	UnMount,
1058	Newfs,
1059	FsCheck,
1060	FsSync,
1061	SimReadWrite,
1062	SetFileSystemStatus,
1063	BlockRead,
1064	BlockWrite,
1065	NvramIoctl,
1066	FsSyncWait,
1067	ClearArchiveBit,
1068	SetAcl,
1069	GetAcl,
1070	AssignAcl,
1071	FaultInsertion,
1072	CrazyCache
1073} AAC_FSACommand;
1074
1075/*
1076 * Command status values
1077 */
1078typedef enum {
1079	ST_OK = 0,
1080	ST_PERM = 1,
1081	ST_NOENT = 2,
1082	ST_IO = 5,
1083	ST_NXIO = 6,
1084	ST_E2BIG = 7,
1085	ST_ACCES = 13,
1086	ST_EXIST = 17,
1087	ST_XDEV = 18,
1088	ST_NODEV = 19,
1089	ST_NOTDIR = 20,
1090	ST_ISDIR = 21,
1091	ST_INVAL = 22,
1092	ST_FBIG = 27,
1093	ST_NOSPC = 28,
1094	ST_ROFS = 30,
1095	ST_MLINK = 31,
1096	ST_WOULDBLOCK = 35,
1097	ST_NAMETOOLONG = 63,
1098	ST_NOTEMPTY = 66,
1099	ST_DQUOT = 69,
1100	ST_STALE = 70,
1101	ST_REMOTE = 71,
1102	ST_NOT_READY = 72,
1103	ST_BADHANDLE = 10001,
1104	ST_NOT_SYNC = 10002,
1105	ST_BAD_COOKIE = 10003,
1106	ST_NOTSUPP = 10004,
1107	ST_TOOSMALL = 10005,
1108	ST_SERVERFAULT = 10006,
1109	ST_BADTYPE = 10007,
1110	ST_JUKEBOX = 10008,
1111	ST_NOTMOUNTED = 10009,
1112	ST_MAINTMODE = 10010,
1113	ST_STALEACL = 10011,
1114	ST_BUS_RESET = 20001
1115} AAC_FSAStatus;
1116
1117/*
1118 * Volume manager commands
1119 */
1120typedef enum _VM_COMMANDS {
1121	VM_Null = 0,
1122	VM_NameServe,
1123	VM_ContainerConfig,
1124	VM_Ioctl,
1125	VM_FilesystemIoctl,
1126	VM_CloseAll,
1127	VM_CtBlockRead,
1128	VM_CtBlockWrite,
1129	VM_SliceBlockRead,	 /* raw access to configured storage objects */
1130	VM_SliceBlockWrite,
1131	VM_DriveBlockRead,	 /* raw access to physical devices */
1132	VM_DriveBlockWrite,
1133	VM_EnclosureMgt,	 /* enclosure management */
1134	VM_Unused,		 /* used to be diskset management */
1135	VM_CtBlockVerify,
1136	VM_CtPerf,		 /* performance test */
1137	VM_CtBlockRead64,
1138	VM_CtBlockWrite64,
1139	VM_CtBlockVerify64,
1140	VM_CtHostRead64,
1141	VM_CtHostWrite64,
1142	VM_DrvErrTblLog,	/* drive error table/log type of command */
1143	VM_NameServe64
1144} AAC_VMCommand;
1145
1146/*
1147 * "mountable object"
1148 */
1149struct aac_mntobj {
1150	u_int32_t			ObjectId;
1151	char				FileSystemName[16];
1152	struct aac_container_creation	CreateInfo;
1153	u_int32_t			Capacity;
1154	u_int32_t			VolType;
1155	u_int32_t			ObjType;
1156	u_int32_t			ContentState;
1157#define FSCS_READONLY		0x0002		/* XXX need more information
1158						 * than this */
1159	union {
1160		u_int32_t	pad[8];
1161	} ObjExtension;
1162	u_int32_t			AlterEgoId;
1163	u_int32_t			CapacityHigh;
1164} __packed;
1165
1166struct aac_mntinfo {
1167	u_int32_t		Command;
1168	u_int32_t		MntType;
1169	u_int32_t		MntCount;
1170} __packed;
1171
1172struct aac_mntinforesp {
1173	u_int32_t		Status;
1174	u_int32_t		MntType;
1175	u_int32_t		MntRespCount;
1176	struct aac_mntobj	MntTable[1];
1177} __packed;
1178
1179/*
1180 * Container shutdown command.
1181 */
1182struct aac_closecommand {
1183	u_int32_t	Command;
1184	u_int32_t	ContainerId;
1185} __packed;
1186
1187/*
1188 * Container Config Command
1189 */
1190#define CT_GET_SCSI_METHOD	64
1191struct aac_ctcfg {
1192	u_int32_t		Command;
1193	u_int32_t		cmd;
1194	u_int32_t		param;
1195} __packed;
1196
1197struct aac_ctcfg_resp {
1198	u_int32_t		Status;
1199	u_int32_t		resp;
1200	u_int32_t		param;
1201} __packed;
1202
1203/*
1204 * 'Ioctl' commads
1205 */
1206#define AAC_SCSI_MAX_PORTS	10
1207#define AAC_BUS_NO_EXIST	0
1208#define AAC_BUS_VALID		1
1209#define AAC_BUS_FAULTED		2
1210#define AAC_BUS_DISABLED	3
1211#define GetBusInfo		0x9
1212
1213struct aac_getbusinf {
1214	u_int32_t		ProbeComplete;
1215	u_int32_t		BusCount;
1216	u_int32_t		TargetsPerBus;
1217	u_int8_t		InitiatorBusId[AAC_SCSI_MAX_PORTS];
1218	u_int8_t		BusValid[AAC_SCSI_MAX_PORTS];
1219} __packed;
1220
1221struct aac_vmioctl {
1222	u_int32_t		Command;
1223	u_int32_t		ObjType;
1224	u_int32_t		MethId;
1225	u_int32_t		ObjId;
1226	u_int32_t		IoctlCmd;
1227	u_int32_t		IoctlBuf[1];	/* Placeholder? */
1228} __packed;
1229
1230struct aac_vmi_businf_resp {
1231	u_int32_t		Status;
1232	u_int32_t		ObjType;
1233	u_int32_t		MethId;
1234	u_int32_t		ObjId;
1235	u_int32_t		IoctlCmd;
1236	struct aac_getbusinf	BusInf;
1237} __packed;
1238
1239#if 0
1240#define AAC_BTL_TO_HANDLE(b, t, l) \
1241    (((b & 0x3f) << 7) | ((l & 0x7) << 4) | (t & 0xf))
1242#else
1243#define AAC_BTL_TO_HANDLE(b, t, l) \
1244    ((((u_int32_t)b & 0x0f) << 24) | \
1245     (((u_int32_t)l & 0xff) << 16) | \
1246     ((u_int32_t)t & 0xffff))
1247#endif
1248#define GetDeviceProbeInfo 0x5
1249
1250struct aac_vmi_devinfo_resp {
1251	u_int32_t		Status;
1252	u_int32_t		ObjType;
1253	u_int32_t		MethId;
1254	u_int32_t		ObjId;
1255	u_int32_t		IoctlCmd;
1256	u_int8_t		VendorId[8];
1257	u_int8_t		ProductId[16];
1258	u_int8_t		ProductRev[4];
1259	u_int32_t		Inquiry7;
1260	u_int32_t		align1;
1261	u_int32_t		Inquiry0;
1262	u_int32_t		align2;
1263	u_int32_t		Inquiry1;
1264	u_int32_t		align3;
1265	u_int32_t		reserved[2];
1266	u_int8_t		VendorSpecific[20];
1267	u_int32_t		Smart:1;
1268	u_int32_t		AAC_Managed:1;
1269	u_int32_t		align4;
1270	u_int32_t		reserved2:6;
1271	u_int32_t		Bus;
1272	u_int32_t		Target;
1273	u_int32_t		Lun;
1274	u_int32_t		ultraEnable:1,
1275				disconnectEnable:1,
1276				fast20EnabledW:1,
1277				scamDevice:1,
1278				scamTolerant:1,
1279				setForSync:1,
1280				setForWide:1,
1281				syncDevice:1,
1282				wideDevice:1,
1283				reserved1:7,
1284				ScsiRate:8,
1285				ScsiOffset:8;
1286}; /* Do not pack */
1287
1288#define ResetBus 0x16
1289struct aac_resetbus {
1290	u_int32_t		BusNumber;
1291};
1292
1293/*
1294 * Write 'stability' options.
1295 */
1296typedef enum {
1297	CSTABLE = 1,
1298	CUNSTABLE
1299} AAC_CacheLevel;
1300
1301/*
1302 * Commit level response for a write request.
1303 */
1304typedef enum {
1305	CMFILE_SYNC_NVRAM = 1,
1306	CMDATA_SYNC_NVRAM,
1307	CMFILE_SYNC,
1308	CMDATA_SYNC,
1309	CMUNSTABLE
1310} AAC_CommitLevel;
1311
1312/*
1313 * Block read/write operations.
1314 * These structures are packed into the 'data' area in the FIB.
1315 */
1316
1317struct aac_blockread {
1318	u_int32_t		Command;	/* not FSACommand! */
1319	u_int32_t		ContainerId;
1320	u_int32_t		BlockNumber;
1321	u_int32_t		ByteCount;
1322	struct aac_sg_table	SgMap;		/* variable size */
1323} __packed;
1324
1325struct aac_blockread64 {
1326	u_int32_t		Command;
1327	u_int16_t		ContainerId;
1328	u_int16_t		SectorCount;
1329	u_int32_t		BlockNumber;
1330	u_int16_t		Pad;
1331	u_int16_t		Flags;
1332	struct aac_sg_table64	SgMap64;
1333} __packed;
1334
1335struct aac_blockread_response {
1336	u_int32_t		Status;
1337	u_int32_t		ByteCount;
1338} __packed;
1339
1340struct aac_blockwrite {
1341	u_int32_t		Command;	/* not FSACommand! */
1342	u_int32_t		ContainerId;
1343	u_int32_t		BlockNumber;
1344	u_int32_t		ByteCount;
1345	u_int32_t		Stable;
1346	struct aac_sg_table	SgMap;		/* variable size */
1347} __packed;
1348
1349struct aac_blockwrite64 {
1350	u_int32_t		Command;	/* not FSACommand! */
1351	u_int16_t		ContainerId;
1352	u_int16_t		SectorCount;
1353	u_int32_t		BlockNumber;
1354	u_int16_t		Pad;
1355	u_int16_t		Flags;
1356	struct aac_sg_table64	SgMap64;	/* variable size */
1357} __packed;
1358
1359struct aac_blockwrite_response {
1360	u_int32_t		Status;
1361	u_int32_t		ByteCount;
1362	u_int32_t		Committed;
1363} __packed;
1364
1365struct aac_raw_io {
1366	u_int64_t		BlockNumber;
1367	u_int32_t		ByteCount;
1368	u_int16_t		ContainerId;
1369	u_int16_t		Flags;				/* 0: W, 1: R */
1370	u_int16_t		BpTotal;			/* reserved for FW use */
1371	u_int16_t		BpComplete;			/* reserved for FW use */
1372	struct aac_sg_tableraw	SgMapRaw;	/* variable size */
1373} __packed;
1374
1375/*
1376 * Container shutdown command.
1377 */
1378struct aac_close_command {
1379	u_int32_t		Command;
1380	u_int32_t		ContainerId;
1381};
1382
1383/*
1384 * SCSI Passthrough structures
1385 */
1386struct aac_srb {
1387	u_int32_t		function;
1388	u_int32_t		bus;
1389	u_int32_t		target;
1390	u_int32_t		lun;
1391	u_int32_t		timeout;
1392	u_int32_t		flags;
1393	u_int32_t		data_len;
1394	u_int32_t		retry_limit;
1395	u_int32_t		cdb_len;
1396	u_int8_t		cdb[16];
1397	struct aac_sg_table	sg_map;
1398};
1399
1400enum {
1401	AAC_SRB_FUNC_EXECUTE_SCSI	= 0x00,
1402	AAC_SRB_FUNC_CLAIM_DEVICE,
1403	AAC_SRB_FUNC_IO_CONTROL,
1404	AAC_SRB_FUNC_RECEIVE_EVENT,
1405	AAC_SRB_FUNC_RELEASE_QUEUE,
1406	AAC_SRB_FUNC_ATTACH_DEVICE,
1407	AAC_SRB_FUNC_RELEASE_DEVICE,
1408	AAC_SRB_FUNC_SHUTDOWN,
1409	AAC_SRB_FUNC_FLUSH,
1410	AAC_SRB_FUNC_ABORT_COMMAND	= 0x10,
1411	AAC_SRB_FUNC_RELEASE_RECOVERY,
1412	AAC_SRB_FUNC_RESET_BUS,
1413	AAC_SRB_FUNC_RESET_DEVICE,
1414	AAC_SRB_FUNC_TERMINATE_IO,
1415	AAC_SRB_FUNC_FLUSH_QUEUE,
1416	AAC_SRB_FUNC_REMOVE_DEVICE,
1417	AAC_SRB_FUNC_DOMAIN_VALIDATION
1418};
1419
1420#define AAC_SRB_FLAGS_NO_DATA_XFER		0x0000
1421#define	AAC_SRB_FLAGS_DISABLE_DISCONNECT	0x0004
1422#define	AAC_SRB_FLAGS_DISABLE_SYNC_TRANSFER	0x0008
1423#define AAC_SRB_FLAGS_BYPASS_FROZEN_QUEUE	0x0010
1424#define	AAC_SRB_FLAGS_DISABLE_AUTOSENSE		0x0020
1425#define	AAC_SRB_FLAGS_DATA_IN			0x0040
1426#define AAC_SRB_FLAGS_DATA_OUT			0x0080
1427#define	AAC_SRB_FLAGS_UNSPECIFIED_DIRECTION \
1428			(AAC_SRB_FLAGS_DATA_IN | AAC_SRB_FLAGS_DATA_OUT)
1429
1430#define AAC_HOST_SENSE_DATA_MAX			30
1431
1432struct aac_srb_response {
1433	u_int32_t	fib_status;
1434	u_int32_t	srb_status;
1435	u_int32_t	scsi_status;
1436	u_int32_t	data_len;
1437	u_int32_t	sense_len;
1438	u_int8_t	sense[AAC_HOST_SENSE_DATA_MAX];
1439};
1440
1441/*
1442 * Status codes for SCSI passthrough commands.  Since they are based on ASPI,
1443 * they also exactly match CAM status codes in both enumeration and meaning.
1444 * They seem to also be used as status codes for synchronous FIBs.
1445 */
1446enum {
1447	AAC_SRB_STS_PENDING			= 0x00,
1448	AAC_SRB_STS_SUCCESS,
1449	AAC_SRB_STS_ABORTED,
1450	AAC_SRB_STS_ABORT_FAILED,
1451	AAC_SRB_STS_ERROR,
1452	AAC_SRB_STS_BUSY,
1453	AAC_SRB_STS_INVALID_REQUEST,
1454	AAC_SRB_STS_INVALID_PATH_ID,
1455	AAC_SRB_STS_NO_DEVICE,
1456	AAC_SRB_STS_TIMEOUT,
1457	AAC_SRB_STS_SELECTION_TIMEOUT,
1458	AAC_SRB_STS_COMMAND_TIMEOUT,
1459	AAC_SRB_STS_MESSAGE_REJECTED		= 0x0D,
1460	AAC_SRB_STS_BUS_RESET,
1461	AAC_SRB_STS_PARITY_ERROR,
1462	AAC_SRB_STS_REQUEST_SENSE_FAILED,
1463	AAC_SRB_STS_NO_HBA,
1464	AAC_SRB_STS_DATA_OVERRUN,
1465	AAC_SRB_STS_UNEXPECTED_BUS_FREE,
1466	AAC_SRB_STS_PHASE_SEQUENCE_FAILURE,
1467	AAC_SRB_STS_BAD_SRB_BLOCK_LENGTH,
1468	AAC_SRB_STS_REQUEST_FLUSHED,
1469	AAC_SRB_STS_INVALID_LUN			= 0x20,
1470	AAC_SRB_STS_INVALID_TARGET_ID,
1471	AAC_SRB_STS_BAD_FUNCTION,
1472	AAC_SRB_STS_ERROR_RECOVERY
1473};
1474
1475/*
1476 * Register definitions for the Adaptec AAC-364 'Jalapeno I/II' adapters, based
1477 * on the SA110 'StrongArm'.
1478 */
1479
1480#define AAC_SA_DOORBELL0_CLEAR		0x98	/* doorbell 0 (adapter->host) */
1481#define AAC_SA_DOORBELL0_SET		0x9c
1482#define AAC_SA_DOORBELL0		0x9c
1483#define AAC_SA_MASK0_CLEAR		0xa0
1484#define AAC_SA_MASK0_SET		0xa4
1485
1486#define AAC_SA_DOORBELL1_CLEAR		0x9a	/* doorbell 1 (host->adapter) */
1487#define AAC_SA_DOORBELL1_SET		0x9e
1488#define AAC_SA_DOORBELL1		0x9e
1489#define AAC_SA_MASK1_CLEAR		0xa2
1490#define AAC_SA_MASK1_SET		0xa6
1491
1492#define AAC_SA_MAILBOX			0xa8	/* mailbox (20 bytes) */
1493#define AAC_SA_FWSTATUS			0xc4
1494
1495/*
1496 * Register definitions for the Adaptec 'Pablano' adapters, based on the i960Rx,
1497 * and other related adapters.
1498 */
1499
1500#define AAC_RX_OMR0		0x18	/* outbound message register 0 */
1501#define AAC_RX_OMR1		0x1c	/* outbound message register 1 */
1502#define AAC_RX_IDBR		0x20	/* inbound doorbell register */
1503#define AAC_RX_IISR		0x24	/* inbound interrupt status register */
1504#define AAC_RX_IIMR		0x28	/* inbound interrupt mask register */
1505#define AAC_RX_ODBR		0x2c	/* outbound doorbell register */
1506#define AAC_RX_OISR		0x30	/* outbound interrupt status register */
1507#define AAC_RX_OIMR		0x34	/* outbound interrupt mask register */
1508#define AAC_RX_IQUE		0x40	/* inbound queue */
1509#define AAC_RX_OQUE		0x44	/* outbound queue */
1510
1511#define AAC_RX_MAILBOX		0x50	/* mailbox (20 bytes) */
1512#define AAC_RX_FWSTATUS		0x6c
1513
1514/*
1515 * Register definitions for the Adaptec 'Rocket' RAID-On-Chip adapters.
1516 * Unsurprisingly, it's quite similar to the i960!
1517 */
1518
1519#define AAC_RKT_OMR0		0x18	/* outbound message register 0 */
1520#define AAC_RKT_OMR1		0x1c	/* outbound message register 1 */
1521#define AAC_RKT_IDBR		0x20	/* inbound doorbell register */
1522#define AAC_RKT_IISR		0x24	/* inbound interrupt status register */
1523#define AAC_RKT_IIMR		0x28	/* inbound interrupt mask register */
1524#define AAC_RKT_ODBR		0x2c	/* outbound doorbell register */
1525#define AAC_RKT_OISR		0x30	/* outbound interrupt status register */
1526#define AAC_RKT_OIMR		0x34	/* outbound interrupt mask register */
1527#define AAC_RKT_IQUE		0x40	/* inbound queue */
1528#define AAC_RKT_OQUE		0x44	/* outbound queue */
1529
1530#define AAC_RKT_MAILBOX		0x1000	/* mailbox */
1531#define AAC_RKT_FWSTATUS	0x101c	/* Firmware Status (mailbox 7) */
1532
1533/*
1534 * Common bit definitions for the doorbell registers.
1535 */
1536
1537/*
1538 * Status bits in the doorbell registers.
1539 */
1540#define AAC_DB_SYNC_COMMAND	(1<<0)	/* send/completed synchronous FIB */
1541#define AAC_DB_COMMAND_READY	(1<<1)	/* posted one or more commands */
1542#define AAC_DB_RESPONSE_READY	(1<<2)	/* one or more commands complete */
1543#define AAC_DB_COMMAND_NOT_FULL	(1<<3)	/* command queue not full */
1544#define AAC_DB_RESPONSE_NOT_FULL (1<<4)	/* response queue not full */
1545
1546/*
1547 * The adapter can request the host print a message by setting the
1548 * DB_PRINTF flag in DOORBELL0.  The driver responds by collecting the
1549 * message from the printf buffer, clearing the DB_PRINTF flag in
1550 * DOORBELL0 and setting it in DOORBELL1.
1551 * (ODBR and IDBR respectively for the i960Rx adapters)
1552 */
1553#define AAC_DB_PRINTF		(1<<5)	/* adapter requests host printf */
1554#define AAC_PRINTF_DONE		(1<<5)	/* Host completed printf processing */
1555
1556/*
1557 * Mask containing the interrupt bits we care about.  We don't anticipate (or
1558 * want) interrupts not in this mask.
1559 */
1560#define AAC_DB_INTERRUPTS	(AAC_DB_COMMAND_READY  |	\
1561				 AAC_DB_RESPONSE_READY |	\
1562				 AAC_DB_PRINTF)
1563#define AAC_DB_INT_NEW_COMM		0x08
1564
1565