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