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