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