Merge head 'upstream' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev
[pandora-kernel.git] / drivers / scsi / aacraid / aacraid.h
1 #if (!defined(dprintk))
2 # define dprintk(x)
3 #endif
4
5 /*------------------------------------------------------------------------------
6  *              D E F I N E S
7  *----------------------------------------------------------------------------*/
8
9 #define MAXIMUM_NUM_CONTAINERS  32
10
11 #define AAC_NUM_MGT_FIB         8
12 #define AAC_NUM_IO_FIB          (512 - AAC_NUM_MGT_FIB)
13 #define AAC_NUM_FIB             (AAC_NUM_IO_FIB + AAC_NUM_MGT_FIB)
14
15 #define AAC_MAX_LUN             (8)
16
17 #define AAC_MAX_HOSTPHYSMEMPAGES (0xfffff)
18 /*
19  *  max_sectors is an unsigned short, otherwise limit is 0x100000000 / 512
20  * Linux has starvation problems if we permit larger than 4MB I/O ...
21  */
22 #define AAC_MAX_32BIT_SGBCOUNT  ((unsigned short)8192)
23
24 /*
25  * These macros convert from physical channels to virtual channels
26  */
27 #define CONTAINER_CHANNEL               (0)
28 #define ID_LUN_TO_CONTAINER(id, lun)    (id)
29 #define CONTAINER_TO_CHANNEL(cont)      (CONTAINER_CHANNEL)
30 #define CONTAINER_TO_ID(cont)           (cont)
31 #define CONTAINER_TO_LUN(cont)          (0)
32
33 #define aac_phys_to_logical(x)  (x+1)
34 #define aac_logical_to_phys(x)  (x?x-1:0)
35
36 /* #define AAC_DETAILED_STATUS_INFO */
37
38 struct diskparm
39 {
40         int heads;
41         int sectors;
42         int cylinders;
43 };
44
45
46 /*
47  *      DON'T CHANGE THE ORDER, this is set by the firmware
48  */
49  
50 #define         CT_NONE                 0
51 #define         CT_VOLUME               1
52 #define         CT_MIRROR               2
53 #define         CT_STRIPE               3
54 #define         CT_RAID5                4
55 #define         CT_SSRW                 5
56 #define         CT_SSRO                 6
57 #define         CT_MORPH                7
58 #define         CT_PASSTHRU             8
59 #define         CT_RAID4                9
60 #define         CT_RAID10               10      /* stripe of mirror */
61 #define         CT_RAID00               11      /* stripe of stripe */
62 #define         CT_VOLUME_OF_MIRRORS    12      /* volume of mirror */
63 #define         CT_PSEUDO_RAID          13      /* really raid4 */
64 #define         CT_LAST_VOLUME_TYPE     14
65 #define         CT_OK                   218
66
67 /*
68  *      Types of objects addressable in some fashion by the client.
69  *      This is a superset of those objects handled just by the filesystem
70  *      and includes "raw" objects that an administrator would use to
71  *      configure containers and filesystems.
72  */
73
74 #define         FT_REG          1       /* regular file */
75 #define         FT_DIR          2       /* directory */
76 #define         FT_BLK          3       /* "block" device - reserved */
77 #define         FT_CHR          4       /* "character special" device - reserved */
78 #define         FT_LNK          5       /* symbolic link */
79 #define         FT_SOCK         6       /* socket */
80 #define         FT_FIFO         7       /* fifo */
81 #define         FT_FILESYS      8       /* ADAPTEC's "FSA"(tm) filesystem */
82 #define         FT_DRIVE        9       /* physical disk - addressable in scsi by bus/id/lun */
83 #define         FT_SLICE        10      /* virtual disk - raw volume - slice */
84 #define         FT_PARTITION    11      /* FSA partition - carved out of a slice - building block for containers */
85 #define         FT_VOLUME       12      /* Container - Volume Set */
86 #define         FT_STRIPE       13      /* Container - Stripe Set */
87 #define         FT_MIRROR       14      /* Container - Mirror Set */
88 #define         FT_RAID5        15      /* Container - Raid 5 Set */
89 #define         FT_DATABASE     16      /* Storage object with "foreign" content manager */
90
91 /*
92  *      Host side memory scatter gather list
93  *      Used by the adapter for read, write, and readdirplus operations
94  *      We have separate 32 and 64 bit version because even
95  *      on 64 bit systems not all cards support the 64 bit version
96  */
97 struct sgentry {
98         __le32  addr;   /* 32-bit address. */
99         __le32  count;  /* Length. */
100 };
101
102 struct user_sgentry {
103         u32     addr;   /* 32-bit address. */
104         u32     count;  /* Length. */
105 };
106
107 struct sgentry64 {
108         __le32  addr[2];        /* 64-bit addr. 2 pieces for data alignment */
109         __le32  count;  /* Length. */
110 };
111
112 struct user_sgentry64 {
113         u32     addr[2];        /* 64-bit addr. 2 pieces for data alignment */
114         u32     count;  /* Length. */
115 };
116
117 /*
118  *      SGMAP
119  *
120  *      This is the SGMAP structure for all commands that use
121  *      32-bit addressing.
122  */
123
124 struct sgmap {
125         __le32          count;
126         struct sgentry  sg[1]; 
127 };
128
129 struct user_sgmap {
130         u32             count;
131         struct user_sgentry     sg[1]; 
132 };
133
134 struct sgmap64 {
135         __le32          count;
136         struct sgentry64 sg[1];
137 };
138
139 struct user_sgmap64 {
140         u32             count;
141         struct user_sgentry64 sg[1];
142 };
143
144 struct creation_info
145 {
146         u8              buildnum;               /* e.g., 588 */
147         u8              usec;                   /* e.g., 588 */
148         u8              via;                    /* e.g., 1 = FSU,
149                                                  *       2 = API
150                                                  */
151         u8              year;                   /* e.g., 1997 = 97 */
152         __le32          date;                   /*
153                                                  * unsigned     Month           :4;     // 1 - 12
154                                                  * unsigned     Day             :6;     // 1 - 32
155                                                  * unsigned     Hour            :6;     // 0 - 23
156                                                  * unsigned     Minute          :6;     // 0 - 60
157                                                  * unsigned     Second          :6;     // 0 - 60
158                                                  */
159         __le32          serial[2];                      /* e.g., 0x1DEADB0BFAFAF001 */
160 };
161
162
163 /*
164  *      Define all the constants needed for the communication interface
165  */
166
167 /*
168  *      Define how many queue entries each queue will have and the total
169  *      number of entries for the entire communication interface. Also define
170  *      how many queues we support.
171  *
172  *      This has to match the controller
173  */
174
175 #define NUMBER_OF_COMM_QUEUES  8   // 4 command; 4 response
176 #define HOST_HIGH_CMD_ENTRIES  4
177 #define HOST_NORM_CMD_ENTRIES  8
178 #define ADAP_HIGH_CMD_ENTRIES  4
179 #define ADAP_NORM_CMD_ENTRIES  512
180 #define HOST_HIGH_RESP_ENTRIES 4
181 #define HOST_NORM_RESP_ENTRIES 512
182 #define ADAP_HIGH_RESP_ENTRIES 4
183 #define ADAP_NORM_RESP_ENTRIES 8
184
185 #define TOTAL_QUEUE_ENTRIES  \
186     (HOST_NORM_CMD_ENTRIES + HOST_HIGH_CMD_ENTRIES + ADAP_NORM_CMD_ENTRIES + ADAP_HIGH_CMD_ENTRIES + \
187             HOST_NORM_RESP_ENTRIES + HOST_HIGH_RESP_ENTRIES + ADAP_NORM_RESP_ENTRIES + ADAP_HIGH_RESP_ENTRIES)
188
189
190 /*
191  *      Set the queues on a 16 byte alignment
192  */
193  
194 #define QUEUE_ALIGNMENT         16
195
196 /*
197  *      The queue headers define the Communication Region queues. These
198  *      are physically contiguous and accessible by both the adapter and the
199  *      host. Even though all queue headers are in the same contiguous block
200  *      they will be represented as individual units in the data structures.
201  */
202
203 struct aac_entry {
204         __le32 size; /* Size in bytes of Fib which this QE points to */
205         __le32 addr; /* Receiver address of the FIB */
206 };
207
208 /*
209  *      The adapter assumes the ProducerIndex and ConsumerIndex are grouped
210  *      adjacently and in that order.
211  */
212  
213 struct aac_qhdr {
214         __le64 header_addr;/* Address to hand the adapter to access 
215                               to this queue head */
216         __le32 *producer; /* The producer index for this queue (host address) */
217         __le32 *consumer; /* The consumer index for this queue (host address) */
218 };
219
220 /*
221  *      Define all the events which the adapter would like to notify
222  *      the host of.
223  */
224  
225 #define         HostNormCmdQue          1       /* Change in host normal priority command queue */
226 #define         HostHighCmdQue          2       /* Change in host high priority command queue */
227 #define         HostNormRespQue         3       /* Change in host normal priority response queue */
228 #define         HostHighRespQue         4       /* Change in host high priority response queue */
229 #define         AdapNormRespNotFull     5
230 #define         AdapHighRespNotFull     6
231 #define         AdapNormCmdNotFull      7
232 #define         AdapHighCmdNotFull      8
233 #define         SynchCommandComplete    9
234 #define         AdapInternalError       0xfe    /* The adapter detected an internal error shutting down */
235
236 /*
237  *      Define all the events the host wishes to notify the
238  *      adapter of. The first four values much match the Qid the
239  *      corresponding queue.
240  */
241
242 #define         AdapNormCmdQue          2
243 #define         AdapHighCmdQue          3
244 #define         AdapNormRespQue         6
245 #define         AdapHighRespQue         7
246 #define         HostShutdown            8
247 #define         HostPowerFail           9
248 #define         FatalCommError          10
249 #define         HostNormRespNotFull     11
250 #define         HostHighRespNotFull     12
251 #define         HostNormCmdNotFull      13
252 #define         HostHighCmdNotFull      14
253 #define         FastIo                  15
254 #define         AdapPrintfDone          16
255
256 /*
257  *      Define all the queues that the adapter and host use to communicate
258  *      Number them to match the physical queue layout.
259  */
260
261 enum aac_queue_types {
262         HostNormCmdQueue = 0,   /* Adapter to host normal priority command traffic */
263         HostHighCmdQueue,       /* Adapter to host high priority command traffic */
264         AdapNormCmdQueue,       /* Host to adapter normal priority command traffic */
265         AdapHighCmdQueue,       /* Host to adapter high priority command traffic */
266         HostNormRespQueue,      /* Adapter to host normal priority response traffic */
267         HostHighRespQueue,      /* Adapter to host high priority response traffic */
268         AdapNormRespQueue,      /* Host to adapter normal priority response traffic */
269         AdapHighRespQueue       /* Host to adapter high priority response traffic */
270 };
271
272 /*
273  *      Assign type values to the FSA communication data structures
274  */
275
276 #define         FIB_MAGIC       0x0001
277
278 /*
279  *      Define the priority levels the FSA communication routines support.
280  */
281
282 #define         FsaNormal       1
283 #define         FsaHigh         2
284
285 /*
286  * Define the FIB. The FIB is the where all the requested data and
287  * command information are put to the application on the FSA adapter.
288  */
289
290 struct aac_fibhdr {
291         __le32 XferState;       /* Current transfer state for this CCB */
292         __le16 Command;         /* Routing information for the destination */
293         u8 StructType;          /* Type FIB */
294         u8 Flags;               /* Flags for FIB */
295         __le16 Size;            /* Size of this FIB in bytes */
296         __le16 SenderSize;      /* Size of the FIB in the sender 
297                                    (for response sizing) */
298         __le32 SenderFibAddress;  /* Host defined data in the FIB */
299         __le32 ReceiverFibAddress;/* Logical address of this FIB for 
300                                      the adapter */
301         u32 SenderData;         /* Place holder for the sender to store data */
302         union {
303                 struct {
304                     __le32 _ReceiverTimeStart;  /* Timestamp for 
305                                                    receipt of fib */
306                     __le32 _ReceiverTimeDone;   /* Timestamp for 
307                                                    completion of fib */
308                 } _s;
309         } _u;
310 };
311
312 struct hw_fib {
313         struct aac_fibhdr header;
314         u8 data[512-sizeof(struct aac_fibhdr)]; // Command specific data
315 };
316
317 /*
318  *      FIB commands
319  */
320
321 #define         TestCommandResponse             1
322 #define         TestAdapterCommand              2
323 /*
324  *      Lowlevel and comm commands
325  */
326 #define         LastTestCommand                 100
327 #define         ReinitHostNormCommandQueue      101
328 #define         ReinitHostHighCommandQueue      102
329 #define         ReinitHostHighRespQueue         103
330 #define         ReinitHostNormRespQueue         104
331 #define         ReinitAdapNormCommandQueue      105
332 #define         ReinitAdapHighCommandQueue      107
333 #define         ReinitAdapHighRespQueue         108
334 #define         ReinitAdapNormRespQueue         109
335 #define         InterfaceShutdown               110
336 #define         DmaCommandFib                   120
337 #define         StartProfile                    121
338 #define         TermProfile                     122
339 #define         SpeedTest                       123
340 #define         TakeABreakPt                    124
341 #define         RequestPerfData                 125
342 #define         SetInterruptDefTimer            126
343 #define         SetInterruptDefCount            127
344 #define         GetInterruptDefStatus           128
345 #define         LastCommCommand                 129
346 /*
347  *      Filesystem commands
348  */
349 #define         NuFileSystem                    300
350 #define         UFS                             301
351 #define         HostFileSystem                  302
352 #define         LastFileSystemCommand           303
353 /*
354  *      Container Commands
355  */
356 #define         ContainerCommand                500
357 #define         ContainerCommand64              501
358 /*
359  *      Cluster Commands
360  */
361 #define         ClusterCommand                  550
362 /*
363  *      Scsi Port commands (scsi passthrough)
364  */
365 #define         ScsiPortCommand                 600
366 #define         ScsiPortCommand64               601
367 /*
368  *      Misc house keeping and generic adapter initiated commands
369  */
370 #define         AifRequest                      700
371 #define         CheckRevision                   701
372 #define         FsaHostShutdown                 702
373 #define         RequestAdapterInfo              703
374 #define         IsAdapterPaused                 704
375 #define         SendHostTime                    705
376 #define         RequestSupplementAdapterInfo    706
377 #define         LastMiscCommand                 707
378
379 /*
380  * Commands that will target the failover level on the FSA adapter
381  */
382
383 enum fib_xfer_state {
384         HostOwned                       = (1<<0),
385         AdapterOwned                    = (1<<1),
386         FibInitialized                  = (1<<2),
387         FibEmpty                        = (1<<3),
388         AllocatedFromPool               = (1<<4),
389         SentFromHost                    = (1<<5),
390         SentFromAdapter                 = (1<<6),
391         ResponseExpected                = (1<<7),
392         NoResponseExpected              = (1<<8),
393         AdapterProcessed                = (1<<9),
394         HostProcessed                   = (1<<10),
395         HighPriority                    = (1<<11),
396         NormalPriority                  = (1<<12),
397         Async                           = (1<<13),
398         AsyncIo                         = (1<<13),      // rpbfix: remove with new regime
399         PageFileIo                      = (1<<14),      // rpbfix: remove with new regime
400         ShutdownRequest                 = (1<<15),
401         LazyWrite                       = (1<<16),      // rpbfix: remove with new regime
402         AdapterMicroFib                 = (1<<17),
403         BIOSFibPath                     = (1<<18),
404         FastResponseCapable             = (1<<19),
405         ApiFib                          = (1<<20)       // Its an API Fib.
406 };
407
408 /*
409  *      The following defines needs to be updated any time there is an
410  *      incompatible change made to the aac_init structure.
411  */
412
413 #define ADAPTER_INIT_STRUCT_REVISION            3
414 #define ADAPTER_INIT_STRUCT_REVISION_4          4 // rocket science
415
416 struct aac_init
417 {
418         __le32  InitStructRevision;
419         __le32  MiniPortRevision;
420         __le32  fsrev;
421         __le32  CommHeaderAddress;
422         __le32  FastIoCommAreaAddress;
423         __le32  AdapterFibsPhysicalAddress;
424         __le32  AdapterFibsVirtualAddress;
425         __le32  AdapterFibsSize;
426         __le32  AdapterFibAlign;
427         __le32  printfbuf;
428         __le32  printfbufsiz;
429         __le32  HostPhysMemPages;   /* number of 4k pages of host 
430                                        physical memory */
431         __le32  HostElapsedSeconds; /* number of seconds since 1970. */
432         /*
433          * ADAPTER_INIT_STRUCT_REVISION_4 begins here
434          */
435         __le32  InitFlags;      /* flags for supported features */
436 #define INITFLAGS_NEW_COMM_SUPPORTED    0x00000001
437         __le32  MaxIoCommands;  /* max outstanding commands */
438         __le32  MaxIoSize;      /* largest I/O command */
439         __le32  MaxFibSize;     /* largest FIB to adapter */
440 };
441
442 enum aac_log_level {
443         LOG_AAC_INIT                    = 10,
444         LOG_AAC_INFORMATIONAL           = 20,
445         LOG_AAC_WARNING                 = 30,
446         LOG_AAC_LOW_ERROR               = 40,
447         LOG_AAC_MEDIUM_ERROR            = 50,
448         LOG_AAC_HIGH_ERROR              = 60,
449         LOG_AAC_PANIC                   = 70,
450         LOG_AAC_DEBUG                   = 80,
451         LOG_AAC_WINDBG_PRINT            = 90
452 };
453
454 #define FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT       0x030b
455 #define FSAFS_NTC_FIB_CONTEXT                   0x030c
456
457 struct aac_dev;
458
459 struct adapter_ops
460 {
461         void (*adapter_interrupt)(struct aac_dev *dev);
462         void (*adapter_notify)(struct aac_dev *dev, u32 event);
463         int  (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4);
464         int  (*adapter_check_health)(struct aac_dev *dev);
465 };
466
467 /*
468  *      Define which interrupt handler needs to be installed
469  */
470
471 struct aac_driver_ident
472 {
473         int     (*init)(struct aac_dev *dev);
474         char *  name;
475         char *  vname;
476         char *  model;
477         u16     channels;
478         int     quirks;
479 };
480 /*
481  * Some adapter firmware needs communication memory 
482  * below 2gig. This tells the init function to set the
483  * dma mask such that fib memory will be allocated where the
484  * adapter firmware can get to it.
485  */
486 #define AAC_QUIRK_31BIT 0x0001
487
488 /*
489  * Some adapter firmware, when the raid card's cache is turned off, can not
490  * split up scatter gathers in order to deal with the limits of the
491  * underlying CHIM. This limit is 34 scatter gather elements.
492  */
493 #define AAC_QUIRK_34SG  0x0002
494
495 /*
496  * This adapter is a slave (no Firmware)
497  */
498 #define AAC_QUIRK_SLAVE 0x0004
499
500 /*
501  * This adapter is a master.
502  */
503 #define AAC_QUIRK_MASTER 0x0008
504
505 /*
506  *      The adapter interface specs all queues to be located in the same
507  *      physically contigous block. The host structure that defines the
508  *      commuication queues will assume they are each a separate physically
509  *      contigous memory region that will support them all being one big
510  *      contigous block. 
511  *      There is a command and response queue for each level and direction of
512  *      commuication. These regions are accessed by both the host and adapter.
513  */
514  
515 struct aac_queue {
516         u64                     logical;        /*address we give the adapter */
517         struct aac_entry        *base;          /*system virtual address */
518         struct aac_qhdr         headers;        /*producer,consumer q headers*/
519         u32                     entries;        /*Number of queue entries */
520         wait_queue_head_t       qfull;          /*Event to wait on if q full */
521         wait_queue_head_t       cmdready;       /*Cmd ready from the adapter */
522                   /* This is only valid for adapter to host command queues. */ 
523         spinlock_t              *lock;          /* Spinlock for this queue must take this lock before accessing the lock */
524         spinlock_t              lockdata;       /* Actual lock (used only on one side of the lock) */
525         unsigned long           SavedIrql;      /* Previous IRQL when the spin lock is taken */
526         u32                     padding;        /* Padding - FIXME - can remove I believe */
527         struct list_head        cmdq;           /* A queue of FIBs which need to be prcessed by the FS thread. This is */
528                                                 /* only valid for command queues which receive entries from the adapter. */
529         struct list_head        pendingq;       /* A queue of outstanding fib's to the adapter. */
530         u32                     numpending;     /* Number of entries on outstanding queue. */
531         struct aac_dev *        dev;            /* Back pointer to adapter structure */
532 };
533
534 /*
535  *      Message queues. The order here is important, see also the 
536  *      queue type ordering
537  */
538
539 struct aac_queue_block
540 {
541         struct aac_queue queue[8];
542 };
543
544 /*
545  *      SaP1 Message Unit Registers
546  */
547  
548 struct sa_drawbridge_CSR {
549                                 /*      Offset  |  Name */
550         __le32  reserved[10];   /*      00h-27h |  Reserved */
551         u8      LUT_Offset;     /*      28h     |  Lookup Table Offset */
552         u8      reserved1[3];   /*      29h-2bh |  Reserved */
553         __le32  LUT_Data;       /*      2ch     |  Looup Table Data */
554         __le32  reserved2[26];  /*      30h-97h |  Reserved */
555         __le16  PRICLEARIRQ;    /*      98h     |  Primary Clear Irq */
556         __le16  SECCLEARIRQ;    /*      9ah     |  Secondary Clear Irq */
557         __le16  PRISETIRQ;      /*      9ch     |  Primary Set Irq */
558         __le16  SECSETIRQ;      /*      9eh     |  Secondary Set Irq */
559         __le16  PRICLEARIRQMASK;/*      a0h     |  Primary Clear Irq Mask */
560         __le16  SECCLEARIRQMASK;/*      a2h     |  Secondary Clear Irq Mask */
561         __le16  PRISETIRQMASK;  /*      a4h     |  Primary Set Irq Mask */
562         __le16  SECSETIRQMASK;  /*      a6h     |  Secondary Set Irq Mask */
563         __le32  MAILBOX0;       /*      a8h     |  Scratchpad 0 */
564         __le32  MAILBOX1;       /*      ach     |  Scratchpad 1 */
565         __le32  MAILBOX2;       /*      b0h     |  Scratchpad 2 */
566         __le32  MAILBOX3;       /*      b4h     |  Scratchpad 3 */
567         __le32  MAILBOX4;       /*      b8h     |  Scratchpad 4 */
568         __le32  MAILBOX5;       /*      bch     |  Scratchpad 5 */
569         __le32  MAILBOX6;       /*      c0h     |  Scratchpad 6 */
570         __le32  MAILBOX7;       /*      c4h     |  Scratchpad 7 */
571         __le32  ROM_Setup_Data; /*      c8h     |  Rom Setup and Data */
572         __le32  ROM_Control_Addr;/*     cch     |  Rom Control and Address */
573         __le32  reserved3[12];  /*      d0h-ffh |  reserved */
574         __le32  LUT[64];        /*    100h-1ffh |  Lookup Table Entries */
575 };
576
577 #define Mailbox0        SaDbCSR.MAILBOX0
578 #define Mailbox1        SaDbCSR.MAILBOX1
579 #define Mailbox2        SaDbCSR.MAILBOX2
580 #define Mailbox3        SaDbCSR.MAILBOX3
581 #define Mailbox4        SaDbCSR.MAILBOX4
582 #define Mailbox5        SaDbCSR.MAILBOX5
583 #define Mailbox6        SaDbCSR.MAILBOX6
584 #define Mailbox7        SaDbCSR.MAILBOX7
585         
586 #define DoorbellReg_p SaDbCSR.PRISETIRQ
587 #define DoorbellReg_s SaDbCSR.SECSETIRQ
588 #define DoorbellClrReg_p SaDbCSR.PRICLEARIRQ
589
590
591 #define DOORBELL_0      0x0001
592 #define DOORBELL_1      0x0002
593 #define DOORBELL_2      0x0004
594 #define DOORBELL_3      0x0008
595 #define DOORBELL_4      0x0010
596 #define DOORBELL_5      0x0020
597 #define DOORBELL_6      0x0040
598
599         
600 #define PrintfReady     DOORBELL_5
601 #define PrintfDone      DOORBELL_5
602         
603 struct sa_registers {
604         struct sa_drawbridge_CSR        SaDbCSR;                        /* 98h - c4h */
605 };
606         
607
608 #define Sa_MINIPORT_REVISION                    1
609
610 #define sa_readw(AEP, CSR)              readl(&((AEP)->regs.sa->CSR))
611 #define sa_readl(AEP,  CSR)             readl(&((AEP)->regs.sa->CSR))
612 #define sa_writew(AEP, CSR, value)      writew(value, &((AEP)->regs.sa->CSR))
613 #define sa_writel(AEP, CSR, value)      writel(value, &((AEP)->regs.sa->CSR))
614
615 /*
616  *      Rx Message Unit Registers
617  */
618
619 struct rx_mu_registers {
620                             /*  Local  | PCI*| Name */
621         __le32  ARSR;       /*  1300h  | 00h | APIC Register Select Register */
622         __le32  reserved0;  /*  1304h  | 04h | Reserved */
623         __le32  AWR;        /*  1308h  | 08h | APIC Window Register */
624         __le32  reserved1;  /*  130Ch  | 0Ch | Reserved */
625         __le32  IMRx[2];    /*  1310h  | 10h | Inbound Message Registers */
626         __le32  OMRx[2];    /*  1318h  | 18h | Outbound Message Registers */
627         __le32  IDR;        /*  1320h  | 20h | Inbound Doorbell Register */
628         __le32  IISR;       /*  1324h  | 24h | Inbound Interrupt 
629                                                 Status Register */
630         __le32  IIMR;       /*  1328h  | 28h | Inbound Interrupt 
631                                                 Mask Register */
632         __le32  ODR;        /*  132Ch  | 2Ch | Outbound Doorbell Register */
633         __le32  OISR;       /*  1330h  | 30h | Outbound Interrupt 
634                                                 Status Register */
635         __le32  OIMR;       /*  1334h  | 34h | Outbound Interrupt 
636                                                 Mask Register */
637                             /* * Must access through ATU Inbound 
638                                  Translation Window */
639 };
640
641 struct rx_inbound {
642         __le32  Mailbox[8];
643 };
644
645 #define InboundMailbox0         IndexRegs.Mailbox[0]
646 #define InboundMailbox1         IndexRegs.Mailbox[1]
647 #define InboundMailbox2         IndexRegs.Mailbox[2]
648 #define InboundMailbox3         IndexRegs.Mailbox[3]
649 #define InboundMailbox4         IndexRegs.Mailbox[4]
650 #define InboundMailbox5         IndexRegs.Mailbox[5]
651 #define InboundMailbox6         IndexRegs.Mailbox[6]
652
653 #define INBOUNDDOORBELL_0       0x00000001
654 #define INBOUNDDOORBELL_1       0x00000002
655 #define INBOUNDDOORBELL_2       0x00000004
656 #define INBOUNDDOORBELL_3       0x00000008
657 #define INBOUNDDOORBELL_4       0x00000010
658 #define INBOUNDDOORBELL_5       0x00000020
659 #define INBOUNDDOORBELL_6       0x00000040
660
661 #define OUTBOUNDDOORBELL_0      0x00000001
662 #define OUTBOUNDDOORBELL_1      0x00000002
663 #define OUTBOUNDDOORBELL_2      0x00000004
664 #define OUTBOUNDDOORBELL_3      0x00000008
665 #define OUTBOUNDDOORBELL_4      0x00000010
666
667 #define InboundDoorbellReg      MUnit.IDR
668 #define OutboundDoorbellReg     MUnit.ODR
669
670 struct rx_registers {
671         struct rx_mu_registers          MUnit;          /* 1300h - 1334h */
672         __le32                          reserved1[6];   /* 1338h - 134ch */
673         struct rx_inbound               IndexRegs;
674 };
675
676 #define rx_readb(AEP, CSR)              readb(&((AEP)->regs.rx->CSR))
677 #define rx_readl(AEP, CSR)              readl(&((AEP)->regs.rx->CSR))
678 #define rx_writeb(AEP, CSR, value)      writeb(value, &((AEP)->regs.rx->CSR))
679 #define rx_writel(AEP, CSR, value)      writel(value, &((AEP)->regs.rx->CSR))
680
681 /*
682  *      Rkt Message Unit Registers (same as Rx, except a larger reserve region)
683  */
684
685 #define rkt_mu_registers rx_mu_registers
686 #define rkt_inbound rx_inbound
687
688 struct rkt_registers {
689         struct rkt_mu_registers         MUnit;           /* 1300h - 1334h */
690         __le32                          reserved1[1010]; /* 1338h - 22fch */
691         struct rkt_inbound              IndexRegs;       /* 2300h - */
692 };
693
694 #define rkt_readb(AEP, CSR)             readb(&((AEP)->regs.rkt->CSR))
695 #define rkt_readl(AEP, CSR)             readl(&((AEP)->regs.rkt->CSR))
696 #define rkt_writeb(AEP, CSR, value)     writeb(value, &((AEP)->regs.rkt->CSR))
697 #define rkt_writel(AEP, CSR, value)     writel(value, &((AEP)->regs.rkt->CSR))
698
699 struct fib;
700
701 typedef void (*fib_callback)(void *ctxt, struct fib *fibctx);
702
703 struct aac_fib_context {
704         s16                     type;           // used for verification of structure   
705         s16                     size;
706         u32                     unique;         // unique value representing this context
707         ulong                   jiffies;        // used for cleanup - dmb changed to ulong
708         struct list_head        next;           // used to link context's into a linked list
709         struct semaphore        wait_sem;       // this is used to wait for the next fib to arrive.
710         int                     wait;           // Set to true when thread is in WaitForSingleObject
711         unsigned long           count;          // total number of FIBs on FibList
712         struct list_head        fib_list;       // this holds fibs and their attachd hw_fibs
713 };
714
715 struct sense_data {
716         u8 error_code;          /* 70h (current errors), 71h(deferred errors) */
717         u8 valid:1;             /* A valid bit of one indicates that the information  */
718                                 /* field contains valid information as defined in the
719                                  * SCSI-2 Standard.
720                                  */
721         u8 segment_number;      /* Only used for COPY, COMPARE, or COPY AND VERIFY Commands */
722         u8 sense_key:4;         /* Sense Key */
723         u8 reserved:1;
724         u8 ILI:1;               /* Incorrect Length Indicator */
725         u8 EOM:1;               /* End Of Medium - reserved for random access devices */
726         u8 filemark:1;          /* Filemark - reserved for random access devices */
727
728         u8 information[4];      /* for direct-access devices, contains the unsigned 
729                                  * logical block address or residue associated with 
730                                  * the sense key 
731                                  */
732         u8 add_sense_len;       /* number of additional sense bytes to follow this field */
733         u8 cmnd_info[4];        /* not used */
734         u8 ASC;                 /* Additional Sense Code */
735         u8 ASCQ;                /* Additional Sense Code Qualifier */
736         u8 FRUC;                /* Field Replaceable Unit Code - not used */
737         u8 bit_ptr:3;           /* indicates which byte of the CDB or parameter data
738                                  * was in error
739                                  */
740         u8 BPV:1;               /* bit pointer valid (BPV): 1- indicates that 
741                                  * the bit_ptr field has valid value
742                                  */
743         u8 reserved2:2;
744         u8 CD:1;                /* command data bit: 1- illegal parameter in CDB.
745                                  * 0- illegal parameter in data.
746                                  */
747         u8 SKSV:1;
748         u8 field_ptr[2];        /* byte of the CDB or parameter data in error */
749 };
750
751 struct fsa_dev_info {
752         u64             last;
753         u64             size;
754         u32             type;
755         u16             queue_depth;
756         u8              valid;
757         u8              ro;
758         u8              locked;
759         u8              deleted;
760         char            devname[8];
761         struct sense_data sense_data;
762 };
763
764 struct fib {
765         void                    *next;  /* this is used by the allocator */
766         s16                     type;
767         s16                     size;
768         /*
769          *      The Adapter that this I/O is destined for.
770          */
771         struct aac_dev          *dev;
772         /*
773          *      This is the event the sendfib routine will wait on if the
774          *      caller did not pass one and this is synch io.
775          */
776         struct semaphore        event_wait;
777         spinlock_t              event_lock;
778
779         u32                     done;   /* gets set to 1 when fib is complete */
780         fib_callback            callback;
781         void                    *callback_data;
782         u32                     flags; // u32 dmb was ulong
783         /*
784          *      The following is used to put this fib context onto the 
785          *      Outstanding I/O queue.
786          */
787         struct list_head        queue;
788         /*
789          *      And for the internal issue/reply queues (we may be able
790          *      to merge these two)
791          */
792         struct list_head        fiblink;
793         void                    *data;
794         struct hw_fib           *hw_fib;                /* Actual shared object */
795         dma_addr_t              hw_fib_pa;              /* physical address of hw_fib*/
796 };
797
798 /*
799  *      Adapter Information Block
800  *
801  *      This is returned by the RequestAdapterInfo block
802  */
803  
804 struct aac_adapter_info
805 {
806         __le32  platform;
807         __le32  cpu;
808         __le32  subcpu;
809         __le32  clock;
810         __le32  execmem;
811         __le32  buffermem;
812         __le32  totalmem;
813         __le32  kernelrev;
814         __le32  kernelbuild;
815         __le32  monitorrev;
816         __le32  monitorbuild;
817         __le32  hwrev;
818         __le32  hwbuild;
819         __le32  biosrev;
820         __le32  biosbuild;
821         __le32  cluster;
822         __le32  clusterchannelmask; 
823         __le32  serial[2];
824         __le32  battery;
825         __le32  options;
826         __le32  OEM;
827 };
828
829 struct aac_supplement_adapter_info
830 {
831         u8      AdapterTypeText[17+1];
832         u8      Pad[2];
833         __le32  FlashMemoryByteSize;
834         __le32  FlashImageId;
835         __le32  MaxNumberPorts;
836         __le32  Version;
837         __le32  FeatureBits;
838         u8      SlotNumber;
839         u8      ReservedPad0[0];
840         u8      BuildDate[12];
841         __le32  CurrentNumberPorts;
842         __le32  ReservedGrowth[24];
843 };
844 #define AAC_FEATURE_FALCON      0x00000010
845 #define AAC_SIS_VERSION_V3      3
846 #define AAC_SIS_SLOT_UNKNOWN    0xFF
847
848 #define GetBusInfo 0x00000009
849 struct aac_bus_info {
850         __le32  Command;        /* VM_Ioctl */
851         __le32  ObjType;        /* FT_DRIVE */
852         __le32  MethodId;       /* 1 = SCSI Layer */
853         __le32  ObjectId;       /* Handle */
854         __le32  CtlCmd;         /* GetBusInfo */
855 };
856
857 struct aac_bus_info_response {
858         __le32  Status;         /* ST_OK */
859         __le32  ObjType;
860         __le32  MethodId;       /* unused */
861         __le32  ObjectId;       /* unused */
862         __le32  CtlCmd;         /* unused */
863         __le32  ProbeComplete;
864         __le32  BusCount;
865         __le32  TargetsPerBus;
866         u8      InitiatorBusId[10];
867         u8      BusValid[10];
868 };
869
870 /*
871  * Battery platforms
872  */
873 #define AAC_BAT_REQ_PRESENT     (1)
874 #define AAC_BAT_REQ_NOTPRESENT  (2)
875 #define AAC_BAT_OPT_PRESENT     (3)
876 #define AAC_BAT_OPT_NOTPRESENT  (4)
877 #define AAC_BAT_NOT_SUPPORTED   (5)
878 /*
879  * cpu types
880  */
881 #define AAC_CPU_SIMULATOR       (1)
882 #define AAC_CPU_I960            (2)
883 #define AAC_CPU_STRONGARM       (3)
884
885 /*
886  * Supported Options
887  */
888 #define AAC_OPT_SNAPSHOT                cpu_to_le32(1)
889 #define AAC_OPT_CLUSTERS                cpu_to_le32(1<<1)
890 #define AAC_OPT_WRITE_CACHE             cpu_to_le32(1<<2)
891 #define AAC_OPT_64BIT_DATA              cpu_to_le32(1<<3)
892 #define AAC_OPT_HOST_TIME_FIB           cpu_to_le32(1<<4)
893 #define AAC_OPT_RAID50                  cpu_to_le32(1<<5)
894 #define AAC_OPT_4GB_WINDOW              cpu_to_le32(1<<6)
895 #define AAC_OPT_SCSI_UPGRADEABLE        cpu_to_le32(1<<7)
896 #define AAC_OPT_SOFT_ERR_REPORT         cpu_to_le32(1<<8)
897 #define AAC_OPT_SUPPORTED_RECONDITION   cpu_to_le32(1<<9)
898 #define AAC_OPT_SGMAP_HOST64            cpu_to_le32(1<<10)
899 #define AAC_OPT_ALARM                   cpu_to_le32(1<<11)
900 #define AAC_OPT_NONDASD                 cpu_to_le32(1<<12)
901 #define AAC_OPT_SCSI_MANAGED            cpu_to_le32(1<<13)
902 #define AAC_OPT_RAID_SCSI_MODE          cpu_to_le32(1<<14)
903 #define AAC_OPT_SUPPLEMENT_ADAPTER_INFO cpu_to_le32(1<<16)
904 #define AAC_OPT_NEW_COMM                cpu_to_le32(1<<17)
905 #define AAC_OPT_NEW_COMM_64             cpu_to_le32(1<<18)
906
907 struct aac_dev
908 {
909         struct list_head        entry;
910         const char              *name;
911         int                     id;
912
913         u16                     irq_mask;
914         /*
915          *      negotiated FIB settings
916          */
917         unsigned                max_fib_size;
918         unsigned                sg_tablesize;
919
920         /*
921          *      Map for 128 fib objects (64k)
922          */     
923         dma_addr_t              hw_fib_pa;
924         struct hw_fib           *hw_fib_va;
925         struct hw_fib           *aif_base_va;
926         /*
927          *      Fib Headers
928          */
929         struct fib              *fibs;
930
931         struct fib              *free_fib;
932         struct fib              *timeout_fib;
933         spinlock_t              fib_lock;
934         
935         struct aac_queue_block *queues;
936         /*
937          *      The user API will use an IOCTL to register itself to receive
938          *      FIBs from the adapter.  The following list is used to keep
939          *      track of all the threads that have requested these FIBs.  The
940          *      mutex is used to synchronize access to all data associated 
941          *      with the adapter fibs.
942          */
943         struct list_head        fib_list;
944
945         struct adapter_ops      a_ops;
946         unsigned long           fsrev;          /* Main driver's revision number */
947         
948         struct aac_init         *init;          /* Holds initialization info to communicate with adapter */
949         dma_addr_t              init_pa;        /* Holds physical address of the init struct */
950         
951         struct pci_dev          *pdev;          /* Our PCI interface */
952         void *                  printfbuf;      /* pointer to buffer used for printf's from the adapter */
953         void *                  comm_addr;      /* Base address of Comm area */
954         dma_addr_t              comm_phys;      /* Physical Address of Comm area */
955         size_t                  comm_size;
956
957         struct Scsi_Host        *scsi_host_ptr;
958         int                     maximum_num_containers;
959         int                     maximum_num_physicals;
960         int                     maximum_num_channels;
961         struct fsa_dev_info     *fsa_dev;
962         pid_t                   thread_pid;
963         int                     cardtype;
964         
965         /*
966          *      The following is the device specific extension.
967          */
968         union
969         {
970                 struct sa_registers __iomem *sa;
971                 struct rx_registers __iomem *rx;
972                 struct rkt_registers __iomem *rkt;
973         } regs;
974         u32                     OIMR; /* Mask Register Cache */
975         /*
976          *      AIF thread states
977          */
978         u32                     aif_thread;
979         struct completion       aif_completion;
980         struct aac_adapter_info adapter_info;
981         struct aac_supplement_adapter_info supplement_adapter_info;
982         /* These are in adapter info but they are in the io flow so
983          * lets break them out so we don't have to do an AND to check them
984          */
985         u8                      nondasd_support; 
986         u8                      dac_support;
987         u8                      raid_scsi_mode;
988         u8                      printf_enabled;
989 };
990
991 #define aac_adapter_interrupt(dev) \
992         (dev)->a_ops.adapter_interrupt(dev)
993
994 #define aac_adapter_notify(dev, event) \
995         (dev)->a_ops.adapter_notify(dev, event)
996
997 #define aac_adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4) \
998         (dev)->a_ops.adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4)
999
1000 #define aac_adapter_check_health(dev) \
1001         (dev)->a_ops.adapter_check_health(dev)
1002
1003
1004 #define FIB_CONTEXT_FLAG_TIMED_OUT              (0x00000001)
1005
1006 /*
1007  *      Define the command values
1008  */
1009  
1010 #define         Null                    0
1011 #define         GetAttributes           1
1012 #define         SetAttributes           2
1013 #define         Lookup                  3
1014 #define         ReadLink                4
1015 #define         Read                    5
1016 #define         Write                   6
1017 #define         Create                  7
1018 #define         MakeDirectory           8
1019 #define         SymbolicLink            9
1020 #define         MakeNode                10
1021 #define         Removex                 11
1022 #define         RemoveDirectoryx        12
1023 #define         Rename                  13
1024 #define         Link                    14
1025 #define         ReadDirectory           15
1026 #define         ReadDirectoryPlus       16
1027 #define         FileSystemStatus        17
1028 #define         FileSystemInfo          18
1029 #define         PathConfigure           19
1030 #define         Commit                  20
1031 #define         Mount                   21
1032 #define         UnMount                 22
1033 #define         Newfs                   23
1034 #define         FsCheck                 24
1035 #define         FsSync                  25
1036 #define         SimReadWrite            26
1037 #define         SetFileSystemStatus     27
1038 #define         BlockRead               28
1039 #define         BlockWrite              29
1040 #define         NvramIoctl              30
1041 #define         FsSyncWait              31
1042 #define         ClearArchiveBit         32
1043 #define         SetAcl                  33
1044 #define         GetAcl                  34
1045 #define         AssignAcl               35
1046 #define         FaultInsertion          36      /* Fault Insertion Command */
1047 #define         CrazyCache              37      /* Crazycache */
1048
1049 #define         MAX_FSACOMMAND_NUM      38
1050
1051
1052 /*
1053  *      Define the status returns. These are very unixlike although
1054  *      most are not in fact used
1055  */
1056
1057 #define         ST_OK           0
1058 #define         ST_PERM         1
1059 #define         ST_NOENT        2
1060 #define         ST_IO           5
1061 #define         ST_NXIO         6
1062 #define         ST_E2BIG        7
1063 #define         ST_ACCES        13
1064 #define         ST_EXIST        17
1065 #define         ST_XDEV         18
1066 #define         ST_NODEV        19
1067 #define         ST_NOTDIR       20
1068 #define         ST_ISDIR        21
1069 #define         ST_INVAL        22
1070 #define         ST_FBIG         27
1071 #define         ST_NOSPC        28
1072 #define         ST_ROFS         30
1073 #define         ST_MLINK        31
1074 #define         ST_WOULDBLOCK   35
1075 #define         ST_NAMETOOLONG  63
1076 #define         ST_NOTEMPTY     66
1077 #define         ST_DQUOT        69
1078 #define         ST_STALE        70
1079 #define         ST_REMOTE       71
1080 #define         ST_BADHANDLE    10001
1081 #define         ST_NOT_SYNC     10002
1082 #define         ST_BAD_COOKIE   10003
1083 #define         ST_NOTSUPP      10004
1084 #define         ST_TOOSMALL     10005
1085 #define         ST_SERVERFAULT  10006
1086 #define         ST_BADTYPE      10007
1087 #define         ST_JUKEBOX      10008
1088 #define         ST_NOTMOUNTED   10009
1089 #define         ST_MAINTMODE    10010
1090 #define         ST_STALEACL     10011
1091
1092 /*
1093  *      On writes how does the client want the data written.
1094  */
1095
1096 #define CACHE_CSTABLE           1
1097 #define CACHE_UNSTABLE          2
1098
1099 /*
1100  *      Lets the client know at which level the data was commited on
1101  *      a write request
1102  */
1103
1104 #define CMFILE_SYNCH_NVRAM      1
1105 #define CMDATA_SYNCH_NVRAM      2
1106 #define CMFILE_SYNCH            3
1107 #define CMDATA_SYNCH            4
1108 #define CMUNSTABLE              5
1109
1110 struct aac_read
1111 {
1112         __le32          command;
1113         __le32          cid;
1114         __le32          block;
1115         __le32          count;
1116         struct sgmap    sg;     // Must be last in struct because it is variable
1117 };
1118
1119 struct aac_read64
1120 {
1121         __le32          command;
1122         __le16          cid;
1123         __le16          sector_count;
1124         __le32          block;
1125         __le16          pad;
1126         __le16          flags;
1127         struct sgmap64  sg;     // Must be last in struct because it is variable
1128 };
1129
1130 struct aac_read_reply
1131 {
1132         __le32          status;
1133         __le32          count;
1134 };
1135
1136 struct aac_write
1137 {
1138         __le32          command;
1139         __le32          cid;
1140         __le32          block;
1141         __le32          count;
1142         __le32          stable; // Not used
1143         struct sgmap    sg;     // Must be last in struct because it is variable
1144 };
1145
1146 struct aac_write64
1147 {
1148         __le32          command;
1149         __le16          cid;
1150         __le16          sector_count;
1151         __le32          block;
1152         __le16          pad;
1153         __le16          flags;
1154         struct sgmap64  sg;     // Must be last in struct because it is variable
1155 };
1156 struct aac_write_reply
1157 {
1158         __le32          status;
1159         __le32          count;
1160         __le32          committed;
1161 };
1162
1163 #define CT_FLUSH_CACHE 129
1164 struct aac_synchronize {
1165         __le32          command;        /* VM_ContainerConfig */
1166         __le32          type;           /* CT_FLUSH_CACHE */
1167         __le32          cid;
1168         __le32          parm1;
1169         __le32          parm2;
1170         __le32          parm3;
1171         __le32          parm4;
1172         __le32          count;  /* sizeof(((struct aac_synchronize_reply *)NULL)->data) */
1173 };
1174
1175 struct aac_synchronize_reply {
1176         __le32          dummy0;
1177         __le32          dummy1;
1178         __le32          status; /* CT_OK */
1179         __le32          parm1;
1180         __le32          parm2;
1181         __le32          parm3;
1182         __le32          parm4;
1183         __le32          parm5;
1184         u8              data[16];
1185 };
1186
1187 struct aac_srb
1188 {
1189         __le32          function;
1190         __le32          channel;
1191         __le32          id;
1192         __le32          lun;
1193         __le32          timeout;
1194         __le32          flags;
1195         __le32          count;          // Data xfer size
1196         __le32          retry_limit;
1197         __le32          cdb_size;
1198         u8              cdb[16];
1199         struct  sgmap   sg;
1200 };
1201
1202 /*
1203  * This and assocated data structs are used by the 
1204  * ioctl caller and are in cpu order.
1205  */
1206 struct user_aac_srb
1207 {
1208         u32             function;
1209         u32             channel;
1210         u32             id;
1211         u32             lun;
1212         u32             timeout;
1213         u32             flags;
1214         u32             count;          // Data xfer size
1215         u32             retry_limit;
1216         u32             cdb_size;
1217         u8              cdb[16];
1218         struct  user_sgmap      sg;
1219 };
1220
1221 #define         AAC_SENSE_BUFFERSIZE     30
1222
1223 struct aac_srb_reply
1224 {
1225         __le32          status;
1226         __le32          srb_status;
1227         __le32          scsi_status;
1228         __le32          data_xfer_length;
1229         __le32          sense_data_size;
1230         u8              sense_data[AAC_SENSE_BUFFERSIZE]; // Can this be SCSI_SENSE_BUFFERSIZE
1231 };
1232 /*
1233  * SRB Flags
1234  */
1235 #define         SRB_NoDataXfer           0x0000
1236 #define         SRB_DisableDisconnect    0x0004
1237 #define         SRB_DisableSynchTransfer 0x0008
1238 #define         SRB_BypassFrozenQueue    0x0010
1239 #define         SRB_DisableAutosense     0x0020
1240 #define         SRB_DataIn               0x0040
1241 #define         SRB_DataOut              0x0080
1242
1243 /*
1244  * SRB Functions - set in aac_srb->function
1245  */
1246 #define SRBF_ExecuteScsi        0x0000
1247 #define SRBF_ClaimDevice        0x0001
1248 #define SRBF_IO_Control         0x0002
1249 #define SRBF_ReceiveEvent       0x0003
1250 #define SRBF_ReleaseQueue       0x0004
1251 #define SRBF_AttachDevice       0x0005
1252 #define SRBF_ReleaseDevice      0x0006
1253 #define SRBF_Shutdown           0x0007
1254 #define SRBF_Flush              0x0008
1255 #define SRBF_AbortCommand       0x0010
1256 #define SRBF_ReleaseRecovery    0x0011
1257 #define SRBF_ResetBus           0x0012
1258 #define SRBF_ResetDevice        0x0013
1259 #define SRBF_TerminateIO        0x0014
1260 #define SRBF_FlushQueue         0x0015
1261 #define SRBF_RemoveDevice       0x0016
1262 #define SRBF_DomainValidation   0x0017
1263
1264 /* 
1265  * SRB SCSI Status - set in aac_srb->scsi_status
1266  */
1267 #define SRB_STATUS_PENDING                  0x00
1268 #define SRB_STATUS_SUCCESS                  0x01
1269 #define SRB_STATUS_ABORTED                  0x02
1270 #define SRB_STATUS_ABORT_FAILED             0x03
1271 #define SRB_STATUS_ERROR                    0x04
1272 #define SRB_STATUS_BUSY                     0x05
1273 #define SRB_STATUS_INVALID_REQUEST          0x06
1274 #define SRB_STATUS_INVALID_PATH_ID          0x07
1275 #define SRB_STATUS_NO_DEVICE                0x08
1276 #define SRB_STATUS_TIMEOUT                  0x09
1277 #define SRB_STATUS_SELECTION_TIMEOUT        0x0A
1278 #define SRB_STATUS_COMMAND_TIMEOUT          0x0B
1279 #define SRB_STATUS_MESSAGE_REJECTED         0x0D
1280 #define SRB_STATUS_BUS_RESET                0x0E
1281 #define SRB_STATUS_PARITY_ERROR             0x0F
1282 #define SRB_STATUS_REQUEST_SENSE_FAILED     0x10
1283 #define SRB_STATUS_NO_HBA                   0x11
1284 #define SRB_STATUS_DATA_OVERRUN             0x12
1285 #define SRB_STATUS_UNEXPECTED_BUS_FREE      0x13
1286 #define SRB_STATUS_PHASE_SEQUENCE_FAILURE   0x14
1287 #define SRB_STATUS_BAD_SRB_BLOCK_LENGTH     0x15
1288 #define SRB_STATUS_REQUEST_FLUSHED          0x16
1289 #define SRB_STATUS_DELAYED_RETRY            0x17
1290 #define SRB_STATUS_INVALID_LUN              0x20
1291 #define SRB_STATUS_INVALID_TARGET_ID        0x21
1292 #define SRB_STATUS_BAD_FUNCTION             0x22
1293 #define SRB_STATUS_ERROR_RECOVERY           0x23
1294 #define SRB_STATUS_NOT_STARTED              0x24
1295 #define SRB_STATUS_NOT_IN_USE               0x30
1296 #define SRB_STATUS_FORCE_ABORT              0x31
1297 #define SRB_STATUS_DOMAIN_VALIDATION_FAIL   0x32
1298
1299 /*
1300  * Object-Server / Volume-Manager Dispatch Classes
1301  */
1302
1303 #define         VM_Null                 0
1304 #define         VM_NameServe            1
1305 #define         VM_ContainerConfig      2
1306 #define         VM_Ioctl                3
1307 #define         VM_FilesystemIoctl      4
1308 #define         VM_CloseAll             5
1309 #define         VM_CtBlockRead          6
1310 #define         VM_CtBlockWrite         7
1311 #define         VM_SliceBlockRead       8       /* raw access to configured "storage objects" */
1312 #define         VM_SliceBlockWrite      9
1313 #define         VM_DriveBlockRead       10      /* raw access to physical devices */
1314 #define         VM_DriveBlockWrite      11
1315 #define         VM_EnclosureMgt         12      /* enclosure management */
1316 #define         VM_Unused               13      /* used to be diskset management */
1317 #define         VM_CtBlockVerify        14
1318 #define         VM_CtPerf               15      /* performance test */
1319 #define         VM_CtBlockRead64        16
1320 #define         VM_CtBlockWrite64       17
1321 #define         VM_CtBlockVerify64      18
1322 #define         VM_CtHostRead64         19
1323 #define         VM_CtHostWrite64        20
1324
1325 #define         MAX_VMCOMMAND_NUM       21      /* used for sizing stats array - leave last */
1326
1327 /*
1328  *      Descriptive information (eg, vital stats)
1329  *      that a content manager might report.  The
1330  *      FileArray filesystem component is one example
1331  *      of a content manager.  Raw mode might be
1332  *      another.
1333  */
1334
1335 struct aac_fsinfo {
1336         __le32  fsTotalSize;    /* Consumed by fs, incl. metadata */
1337         __le32  fsBlockSize;
1338         __le32  fsFragSize;
1339         __le32  fsMaxExtendSize;
1340         __le32  fsSpaceUnits;
1341         __le32  fsMaxNumFiles;
1342         __le32  fsNumFreeFiles;
1343         __le32  fsInodeDensity;
1344 };      /* valid iff ObjType == FT_FILESYS && !(ContentState & FSCS_NOTCLEAN) */
1345
1346 union aac_contentinfo {
1347         struct aac_fsinfo filesys;      /* valid iff ObjType == FT_FILESYS && !(ContentState & FSCS_NOTCLEAN) */
1348 };
1349
1350 /*
1351  *      Query for Container Configuration Status
1352  */
1353
1354 #define CT_GET_CONFIG_STATUS 147
1355 struct aac_get_config_status {
1356         __le32          command;        /* VM_ContainerConfig */
1357         __le32          type;           /* CT_GET_CONFIG_STATUS */
1358         __le32          parm1;
1359         __le32          parm2;
1360         __le32          parm3;
1361         __le32          parm4;
1362         __le32          parm5;
1363         __le32          count;  /* sizeof(((struct aac_get_config_status_resp *)NULL)->data) */
1364 };
1365
1366 #define CFACT_CONTINUE 0
1367 #define CFACT_PAUSE    1
1368 #define CFACT_ABORT    2
1369 struct aac_get_config_status_resp {
1370         __le32          response; /* ST_OK */
1371         __le32          dummy0;
1372         __le32          status; /* CT_OK */
1373         __le32          parm1;
1374         __le32          parm2;
1375         __le32          parm3;
1376         __le32          parm4;
1377         __le32          parm5;
1378         struct {
1379                 __le32  action; /* CFACT_CONTINUE, CFACT_PAUSE or CFACT_ABORT */
1380                 __le16  flags;
1381                 __le16  count;
1382         }               data;
1383 };
1384
1385 /*
1386  *      Accept the configuration as-is
1387  */
1388
1389 #define CT_COMMIT_CONFIG 152
1390
1391 struct aac_commit_config {
1392         __le32          command;        /* VM_ContainerConfig */
1393         __le32          type;           /* CT_COMMIT_CONFIG */
1394 };
1395
1396 /*
1397  *      Query for Container Configuration Status
1398  */
1399
1400 #define CT_GET_CONTAINER_COUNT 4
1401 struct aac_get_container_count {
1402         __le32          command;        /* VM_ContainerConfig */
1403         __le32          type;           /* CT_GET_CONTAINER_COUNT */
1404 };
1405
1406 struct aac_get_container_count_resp {
1407         __le32          response; /* ST_OK */
1408         __le32          dummy0;
1409         __le32          MaxContainers;
1410         __le32          ContainerSwitchEntries;
1411         __le32          MaxPartitions;
1412 };
1413
1414
1415 /*
1416  *      Query for "mountable" objects, ie, objects that are typically
1417  *      associated with a drive letter on the client (host) side.
1418  */
1419
1420 struct aac_mntent {
1421         __le32                  oid;
1422         u8                      name[16];       /* if applicable */
1423         struct creation_info    create_info;    /* if applicable */
1424         __le32                  capacity;
1425         __le32                  vol;            /* substrate structure */
1426         __le32                  obj;            /* FT_FILESYS, 
1427                                                    FT_DATABASE, etc. */
1428         __le32                  state;          /* unready for mounting, 
1429                                                    readonly, etc. */
1430         union aac_contentinfo   fileinfo;       /* Info specific to content 
1431                                                    manager (eg, filesystem) */
1432         __le32                  altoid;         /* != oid <==> snapshot or 
1433                                                    broken mirror exists */
1434 };
1435
1436 #define FSCS_NOTCLEAN   0x0001  /* fsck is neccessary before mounting */
1437 #define FSCS_READONLY   0x0002  /* possible result of broken mirror */
1438 #define FSCS_HIDDEN     0x0004  /* should be ignored - set during a clear */
1439
1440 struct aac_query_mount {
1441         __le32          command;
1442         __le32          type;
1443         __le32          count;
1444 };
1445
1446 struct aac_mount {
1447         __le32          status;
1448         __le32          type;           /* should be same as that requested */
1449         __le32          count;
1450         struct aac_mntent mnt[1];
1451 };
1452
1453 #define CT_READ_NAME 130
1454 struct aac_get_name {
1455         __le32          command;        /* VM_ContainerConfig */
1456         __le32          type;           /* CT_READ_NAME */
1457         __le32          cid;
1458         __le32          parm1;
1459         __le32          parm2;
1460         __le32          parm3;
1461         __le32          parm4;
1462         __le32          count;  /* sizeof(((struct aac_get_name_resp *)NULL)->data) */
1463 };
1464
1465 #define CT_OK        218
1466 struct aac_get_name_resp {
1467         __le32          dummy0;
1468         __le32          dummy1;
1469         __le32          status; /* CT_OK */
1470         __le32          parm1;
1471         __le32          parm2;
1472         __le32          parm3;
1473         __le32          parm4;
1474         __le32          parm5;
1475         u8              data[16];
1476 };
1477
1478 /*
1479  * The following command is sent to shut down each container.
1480  */
1481
1482 struct aac_close {
1483         __le32  command;
1484         __le32  cid;
1485 };
1486
1487 struct aac_query_disk
1488 {
1489         s32     cnum;
1490         s32     bus;
1491         s32     id;
1492         s32     lun;
1493         u32     valid;
1494         u32     locked;
1495         u32     deleted;
1496         s32     instance;
1497         s8      name[10];
1498         u32     unmapped;
1499 };
1500
1501 struct aac_delete_disk {
1502         u32     disknum;
1503         u32     cnum;
1504 };
1505  
1506 struct fib_ioctl
1507 {
1508         u32     fibctx;
1509         s32     wait;
1510         char    __user *fib;
1511 };
1512
1513 struct revision
1514 {
1515         u32 compat;
1516         u32 version;
1517         u32 build;
1518 };
1519         
1520 /*
1521  *      Ugly - non Linux like ioctl coding for back compat.
1522  */
1523
1524 #define CTL_CODE(function, method) (                 \
1525     (4<< 16) | ((function) << 2) | (method) \
1526 )
1527
1528 /*
1529  *      Define the method codes for how buffers are passed for I/O and FS 
1530  *      controls
1531  */
1532
1533 #define METHOD_BUFFERED                 0
1534 #define METHOD_NEITHER                  3
1535
1536 /*
1537  *      Filesystem ioctls
1538  */
1539
1540 #define FSACTL_SENDFIB                          CTL_CODE(2050, METHOD_BUFFERED)
1541 #define FSACTL_SEND_RAW_SRB                     CTL_CODE(2067, METHOD_BUFFERED)
1542 #define FSACTL_DELETE_DISK                      0x163
1543 #define FSACTL_QUERY_DISK                       0x173
1544 #define FSACTL_OPEN_GET_ADAPTER_FIB             CTL_CODE(2100, METHOD_BUFFERED)
1545 #define FSACTL_GET_NEXT_ADAPTER_FIB             CTL_CODE(2101, METHOD_BUFFERED)
1546 #define FSACTL_CLOSE_GET_ADAPTER_FIB            CTL_CODE(2102, METHOD_BUFFERED)
1547 #define FSACTL_MINIPORT_REV_CHECK               CTL_CODE(2107, METHOD_BUFFERED)
1548 #define FSACTL_GET_PCI_INFO                     CTL_CODE(2119, METHOD_BUFFERED)
1549 #define FSACTL_FORCE_DELETE_DISK                CTL_CODE(2120, METHOD_NEITHER)
1550 #define FSACTL_GET_CONTAINERS                   2131
1551 #define FSACTL_SEND_LARGE_FIB                   CTL_CODE(2138, METHOD_BUFFERED)
1552
1553
1554 struct aac_common
1555 {
1556         /*
1557          *      If this value is set to 1 then interrupt moderation will occur 
1558          *      in the base commuication support.
1559          */
1560         u32 irq_mod;
1561         u32 peak_fibs;
1562         u32 zero_fibs;
1563         u32 fib_timeouts;
1564         /*
1565          *      Statistical counters in debug mode
1566          */
1567 #ifdef DBG
1568         u32 FibsSent;
1569         u32 FibRecved;
1570         u32 NoResponseSent;
1571         u32 NoResponseRecved;
1572         u32 AsyncSent;
1573         u32 AsyncRecved;
1574         u32 NormalSent;
1575         u32 NormalRecved;
1576 #endif
1577 };
1578
1579 extern struct aac_common aac_config;
1580
1581
1582 /*
1583  *      The following macro is used when sending and receiving FIBs. It is
1584  *      only used for debugging.
1585  */
1586  
1587 #ifdef DBG
1588 #define FIB_COUNTER_INCREMENT(counter)          (counter)++
1589 #else
1590 #define FIB_COUNTER_INCREMENT(counter)          
1591 #endif
1592
1593 /*
1594  *      Adapter direct commands
1595  *      Monitor/Kernel API
1596  */
1597
1598 #define BREAKPOINT_REQUEST              0x00000004
1599 #define INIT_STRUCT_BASE_ADDRESS        0x00000005
1600 #define READ_PERMANENT_PARAMETERS       0x0000000a
1601 #define WRITE_PERMANENT_PARAMETERS      0x0000000b
1602 #define HOST_CRASHING                   0x0000000d
1603 #define SEND_SYNCHRONOUS_FIB            0x0000000c
1604 #define COMMAND_POST_RESULTS            0x00000014
1605 #define GET_ADAPTER_PROPERTIES          0x00000019
1606 #define GET_DRIVER_BUFFER_PROPERTIES    0x00000023
1607 #define RCV_TEMP_READINGS               0x00000025
1608 #define GET_COMM_PREFERRED_SETTINGS     0x00000026
1609 #define IOP_RESET                       0x00001000
1610 #define RE_INIT_ADAPTER                 0x000000ee
1611
1612 /*
1613  *      Adapter Status Register
1614  *
1615  *  Phase Staus mailbox is 32bits:
1616  *      <31:16> = Phase Status
1617  *      <15:0>  = Phase
1618  *
1619  *      The adapter reports is present state through the phase.  Only
1620  *      a single phase should be ever be set.  Each phase can have multiple
1621  *      phase status bits to provide more detailed information about the 
1622  *      state of the board.  Care should be taken to ensure that any phase 
1623  *      status bits that are set when changing the phase are also valid
1624  *      for the new phase or be cleared out.  Adapter software (monitor,
1625  *      iflash, kernel) is responsible for properly maintining the phase 
1626  *      status mailbox when it is running.
1627  *                                                                                      
1628  *      MONKER_API Phases                                                       
1629  *
1630  *      Phases are bit oriented.  It is NOT valid  to have multiple bits set                                            
1631  */                                     
1632
1633 #define SELF_TEST_FAILED                0x00000004
1634 #define MONITOR_PANIC                   0x00000020
1635 #define KERNEL_UP_AND_RUNNING           0x00000080
1636 #define KERNEL_PANIC                    0x00000100
1637
1638 /*
1639  *      Doorbell bit defines
1640  */
1641
1642 #define DoorBellSyncCmdAvailable        (1<<0)  /* Host -> Adapter */
1643 #define DoorBellPrintfDone              (1<<5)  /* Host -> Adapter */
1644 #define DoorBellAdapterNormCmdReady     (1<<1)  /* Adapter -> Host */
1645 #define DoorBellAdapterNormRespReady    (1<<2)  /* Adapter -> Host */
1646 #define DoorBellAdapterNormCmdNotFull   (1<<3)  /* Adapter -> Host */
1647 #define DoorBellAdapterNormRespNotFull  (1<<4)  /* Adapter -> Host */
1648 #define DoorBellPrintfReady             (1<<5)  /* Adapter -> Host */
1649
1650 /*
1651  *      For FIB communication, we need all of the following things
1652  *      to send back to the user.
1653  */
1654  
1655 #define         AifCmdEventNotify       1       /* Notify of event */
1656 #define                 AifEnConfigChange       3       /* Adapter configuration change */
1657 #define                 AifEnContainerChange    4       /* Container configuration change */
1658 #define                 AifEnDeviceFailure      5       /* SCSI device failed */
1659 #define                 AifEnAddContainer       15      /* A new array was created */
1660 #define                 AifEnDeleteContainer    16      /* A container was deleted */
1661 #define                 AifEnExpEvent           23      /* Firmware Event Log */
1662 #define                 AifExeFirmwarePanic     3       /* Firmware Event Panic */
1663 #define                 AifHighPriority         3       /* Highest Priority Event */
1664
1665 #define         AifCmdJobProgress       2       /* Progress report */
1666 #define                 AifJobCtrZero   101     /* Array Zero progress */
1667 #define                 AifJobStsSuccess 1      /* Job completes */
1668 #define         AifCmdAPIReport         3       /* Report from other user of API */
1669 #define         AifCmdDriverNotify      4       /* Notify host driver of event */
1670 #define                 AifDenMorphComplete 200 /* A morph operation completed */
1671 #define                 AifDenVolumeExtendComplete 201 /* A volume extend completed */
1672 #define         AifReqJobList           100     /* Gets back complete job list */
1673 #define         AifReqJobsForCtr        101     /* Gets back jobs for specific container */
1674 #define         AifReqJobsForScsi       102     /* Gets back jobs for specific SCSI device */ 
1675 #define         AifReqJobReport         103     /* Gets back a specific job report or list of them */ 
1676 #define         AifReqTerminateJob      104     /* Terminates job */
1677 #define         AifReqSuspendJob        105     /* Suspends a job */
1678 #define         AifReqResumeJob         106     /* Resumes a job */ 
1679 #define         AifReqSendAPIReport     107     /* API generic report requests */
1680 #define         AifReqAPIJobStart       108     /* Start a job from the API */
1681 #define         AifReqAPIJobUpdate      109     /* Update a job report from the API */
1682 #define         AifReqAPIJobFinish      110     /* Finish a job from the API */
1683
1684 /*
1685  *      Adapter Initiated FIB command structures. Start with the adapter
1686  *      initiated FIBs that really come from the adapter, and get responded
1687  *      to by the host.
1688  */
1689
1690 struct aac_aifcmd {
1691         __le32 command;         /* Tell host what type of notify this is */
1692         __le32 seqnum;          /* To allow ordering of reports (if necessary) */
1693         u8 data[1];             /* Undefined length (from kernel viewpoint) */
1694 };
1695
1696 /**
1697  *      Convert capacity to cylinders
1698  *      accounting for the fact capacity could be a 64 bit value
1699  *
1700  */
1701 static inline u32 cap_to_cyls(sector_t capacity, u32 divisor)
1702 {
1703         sector_div(capacity, divisor);
1704         return (u32)capacity;
1705 }
1706
1707 struct scsi_cmnd;
1708
1709 const char *aac_driverinfo(struct Scsi_Host *);
1710 struct fib *fib_alloc(struct aac_dev *dev);
1711 int fib_setup(struct aac_dev *dev);
1712 void fib_map_free(struct aac_dev *dev);
1713 void fib_free(struct fib * context);
1714 void fib_init(struct fib * context);
1715 void aac_printf(struct aac_dev *dev, u32 val);
1716 int fib_send(u16 command, struct fib * context, unsigned long size, int priority, int wait, int reply, fib_callback callback, void *ctxt);
1717 int aac_consumer_get(struct aac_dev * dev, struct aac_queue * q, struct aac_entry **entry);
1718 void aac_consumer_free(struct aac_dev * dev, struct aac_queue * q, u32 qnum);
1719 int fib_complete(struct fib * context);
1720 #define fib_data(fibctx) ((void *)(fibctx)->hw_fib->data)
1721 struct aac_dev *aac_init_adapter(struct aac_dev *dev);
1722 int aac_get_config_status(struct aac_dev *dev);
1723 int aac_get_containers(struct aac_dev *dev);
1724 int aac_scsi_cmd(struct scsi_cmnd *cmd);
1725 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg);
1726 int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg);
1727 int aac_rx_init(struct aac_dev *dev);
1728 int aac_rkt_init(struct aac_dev *dev);
1729 int aac_sa_init(struct aac_dev *dev);
1730 unsigned int aac_response_normal(struct aac_queue * q);
1731 unsigned int aac_command_normal(struct aac_queue * q);
1732 int aac_command_thread(struct aac_dev * dev);
1733 int aac_close_fib_context(struct aac_dev * dev, struct aac_fib_context *fibctx);
1734 int fib_adapter_complete(struct fib * fibptr, unsigned short size);
1735 struct aac_driver_ident* aac_get_driver_ident(int devtype);
1736 int aac_get_adapter_info(struct aac_dev* dev);
1737 int aac_send_shutdown(struct aac_dev *dev);
1738 extern int numacb;
1739 extern int acbsize;