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