1 /*
2  *	Adaptec AAC series RAID controller driver
3  *	(c) Copyright 2001 Red Hat Inc.
4  *
5  * based on the old aacraid driver that is..
6  * Adaptec aacraid device driver for Linux.
7  *
8  * Copyright (c) 2000-2010 Adaptec, Inc.
9  *               2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2, or (at your option)
14  * any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; see the file COPYING.  If not, write to
23  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  * Module Name:
26  *  comminit.c
27  *
28  * Abstract: This supports the initialization of the host adapter commuication interface.
29  *    This is a platform dependent module for the pci cyclone board.
30  *
31  */
32 
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/pci.h>
37 #include <linux/spinlock.h>
38 #include <linux/slab.h>
39 #include <linux/blkdev.h>
40 #include <linux/delay.h>
41 #include <linux/completion.h>
42 #include <linux/mm.h>
43 #include <scsi/scsi_host.h>
44 
45 #include "aacraid.h"
46 
47 struct aac_common aac_config = {
48 	.irq_mod = 1
49 };
50 
aac_is_msix_mode(struct aac_dev * dev)51 static inline int aac_is_msix_mode(struct aac_dev *dev)
52 {
53 	u32 status;
54 
55 	status = src_readl(dev, MUnit.OMR);
56 	return (status & AAC_INT_MODE_MSIX);
57 }
58 
aac_change_to_intx(struct aac_dev * dev)59 static inline void aac_change_to_intx(struct aac_dev *dev)
60 {
61 	aac_src_access_devreg(dev, AAC_DISABLE_MSIX);
62 	aac_src_access_devreg(dev, AAC_ENABLE_INTX);
63 }
64 
aac_alloc_comm(struct aac_dev * dev,void ** commaddr,unsigned long commsize,unsigned long commalign)65 static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign)
66 {
67 	unsigned char *base;
68 	unsigned long size, align;
69 	const unsigned long fibsize = dev->max_fib_size;
70 	const unsigned long printfbufsiz = 256;
71 	unsigned long host_rrq_size = 0;
72 	struct aac_init *init;
73 	dma_addr_t phys;
74 	unsigned long aac_max_hostphysmempages;
75 
76 	if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
77 	    dev->comm_interface == AAC_COMM_MESSAGE_TYPE2)
78 		host_rrq_size = (dev->scsi_host_ptr->can_queue
79 			+ AAC_NUM_MGT_FIB) * sizeof(u32);
80 	size = fibsize + sizeof(struct aac_init) + commsize +
81 			commalign + printfbufsiz + host_rrq_size;
82 
83 	base = pci_alloc_consistent(dev->pdev, size, &phys);
84 
85 	if(base == NULL)
86 	{
87 		printk(KERN_ERR "aacraid: unable to create mapping.\n");
88 		return 0;
89 	}
90 	dev->comm_addr = (void *)base;
91 	dev->comm_phys = phys;
92 	dev->comm_size = size;
93 
94 	if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
95 	    dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
96 		dev->host_rrq = (u32 *)(base + fibsize);
97 		dev->host_rrq_pa = phys + fibsize;
98 		memset(dev->host_rrq, 0, host_rrq_size);
99 	}
100 
101 	dev->init = (struct aac_init *)(base + fibsize + host_rrq_size);
102 	dev->init_pa = phys + fibsize + host_rrq_size;
103 
104 	init = dev->init;
105 
106 	init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
107 	if (dev->max_fib_size != sizeof(struct hw_fib))
108 		init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
109 	init->Sa_MSIXVectors = cpu_to_le32(Sa_MINIPORT_REVISION);
110 	init->fsrev = cpu_to_le32(dev->fsrev);
111 
112 	/*
113 	 *	Adapter Fibs are the first thing allocated so that they
114 	 *	start page aligned
115 	 */
116 	dev->aif_base_va = (struct hw_fib *)base;
117 
118 	init->AdapterFibsVirtualAddress = 0;
119 	init->AdapterFibsPhysicalAddress = cpu_to_le32((u32)phys);
120 	init->AdapterFibsSize = cpu_to_le32(fibsize);
121 	init->AdapterFibAlign = cpu_to_le32(sizeof(struct hw_fib));
122 	/*
123 	 * number of 4k pages of host physical memory. The aacraid fw needs
124 	 * this number to be less than 4gb worth of pages. New firmware doesn't
125 	 * have any issues with the mapping system, but older Firmware did, and
126 	 * had *troubles* dealing with the math overloading past 32 bits, thus
127 	 * we must limit this field.
128 	 */
129 	aac_max_hostphysmempages = dma_get_required_mask(&dev->pdev->dev) >> 12;
130 	if (aac_max_hostphysmempages < AAC_MAX_HOSTPHYSMEMPAGES)
131 		init->HostPhysMemPages = cpu_to_le32(aac_max_hostphysmempages);
132 	else
133 		init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
134 
135 	init->InitFlags = cpu_to_le32(INITFLAGS_DRIVER_USES_UTC_TIME |
136 		INITFLAGS_DRIVER_SUPPORTS_PM);
137 	init->MaxIoCommands = cpu_to_le32(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
138 	init->MaxIoSize = cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
139 	init->MaxFibSize = cpu_to_le32(dev->max_fib_size);
140 	init->MaxNumAif = cpu_to_le32(dev->max_num_aif);
141 
142 	if (dev->comm_interface == AAC_COMM_MESSAGE) {
143 		init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
144 		dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
145 	} else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) {
146 		init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_6);
147 		init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
148 			INITFLAGS_NEW_COMM_TYPE1_SUPPORTED | INITFLAGS_FAST_JBOD_SUPPORTED);
149 		init->HostRRQ_AddrHigh = cpu_to_le32((u32)((u64)dev->host_rrq_pa >> 32));
150 		init->HostRRQ_AddrLow = cpu_to_le32((u32)(dev->host_rrq_pa & 0xffffffff));
151 		dprintk((KERN_WARNING"aacraid: New Comm Interface type1 enabled\n"));
152 	} else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
153 		init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_7);
154 		init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
155 			INITFLAGS_NEW_COMM_TYPE2_SUPPORTED | INITFLAGS_FAST_JBOD_SUPPORTED);
156 		init->HostRRQ_AddrHigh = cpu_to_le32((u32)((u64)dev->host_rrq_pa >> 32));
157 		init->HostRRQ_AddrLow = cpu_to_le32((u32)(dev->host_rrq_pa & 0xffffffff));
158 		/* number of MSI-X */
159 		init->Sa_MSIXVectors = cpu_to_le32(dev->max_msix);
160 		dprintk((KERN_WARNING"aacraid: New Comm Interface type2 enabled\n"));
161 	}
162 
163 	/*
164 	 * Increment the base address by the amount already used
165 	 */
166 	base = base + fibsize + host_rrq_size + sizeof(struct aac_init);
167 	phys = (dma_addr_t)((ulong)phys + fibsize + host_rrq_size +
168 		sizeof(struct aac_init));
169 
170 	/*
171 	 *	Align the beginning of Headers to commalign
172 	 */
173 	align = (commalign - ((uintptr_t)(base) & (commalign - 1)));
174 	base = base + align;
175 	phys = phys + align;
176 	/*
177 	 *	Fill in addresses of the Comm Area Headers and Queues
178 	 */
179 	*commaddr = base;
180 	init->CommHeaderAddress = cpu_to_le32((u32)phys);
181 	/*
182 	 *	Increment the base address by the size of the CommArea
183 	 */
184 	base = base + commsize;
185 	phys = phys + commsize;
186 	/*
187 	 *	 Place the Printf buffer area after the Fast I/O comm area.
188 	 */
189 	dev->printfbuf = (void *)base;
190 	init->printfbuf = cpu_to_le32(phys);
191 	init->printfbufsiz = cpu_to_le32(printfbufsiz);
192 	memset(base, 0, printfbufsiz);
193 	return 1;
194 }
195 
aac_queue_init(struct aac_dev * dev,struct aac_queue * q,u32 * mem,int qsize)196 static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize)
197 {
198 	atomic_set(&q->numpending, 0);
199 	q->dev = dev;
200 	init_waitqueue_head(&q->cmdready);
201 	INIT_LIST_HEAD(&q->cmdq);
202 	init_waitqueue_head(&q->qfull);
203 	spin_lock_init(&q->lockdata);
204 	q->lock = &q->lockdata;
205 	q->headers.producer = (__le32 *)mem;
206 	q->headers.consumer = (__le32 *)(mem+1);
207 	*(q->headers.producer) = cpu_to_le32(qsize);
208 	*(q->headers.consumer) = cpu_to_le32(qsize);
209 	q->entries = qsize;
210 }
211 
212 /**
213  *	aac_send_shutdown		-	shutdown an adapter
214  *	@dev: Adapter to shutdown
215  *
216  *	This routine will send a VM_CloseAll (shutdown) request to the adapter.
217  */
218 
aac_send_shutdown(struct aac_dev * dev)219 int aac_send_shutdown(struct aac_dev * dev)
220 {
221 	struct fib * fibctx;
222 	struct aac_close *cmd;
223 	int status;
224 
225 	fibctx = aac_fib_alloc(dev);
226 	if (!fibctx)
227 		return -ENOMEM;
228 	aac_fib_init(fibctx);
229 
230 	cmd = (struct aac_close *) fib_data(fibctx);
231 
232 	cmd->command = cpu_to_le32(VM_CloseAll);
233 	cmd->cid = cpu_to_le32(0xfffffffe);
234 
235 	status = aac_fib_send(ContainerCommand,
236 			  fibctx,
237 			  sizeof(struct aac_close),
238 			  FsaNormal,
239 			  -2 /* Timeout silently */, 1,
240 			  NULL, NULL);
241 
242 	if (status >= 0)
243 		aac_fib_complete(fibctx);
244 	/* FIB should be freed only after getting the response from the F/W */
245 	if (status != -ERESTARTSYS)
246 		aac_fib_free(fibctx);
247 	dev->adapter_shutdown = 1;
248 	if ((dev->pdev->device == PMC_DEVICE_S7 ||
249 	     dev->pdev->device == PMC_DEVICE_S8 ||
250 	     dev->pdev->device == PMC_DEVICE_S9) &&
251 	     dev->msi_enabled)
252 		aac_src_access_devreg(dev, AAC_ENABLE_INTX);
253 	return status;
254 }
255 
256 /**
257  *	aac_comm_init	-	Initialise FSA data structures
258  *	@dev:	Adapter to initialise
259  *
260  *	Initializes the data structures that are required for the FSA commuication
261  *	interface to operate.
262  *	Returns
263  *		1 - if we were able to init the commuication interface.
264  *		0 - If there were errors initing. This is a fatal error.
265  */
266 
aac_comm_init(struct aac_dev * dev)267 static int aac_comm_init(struct aac_dev * dev)
268 {
269 	unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
270 	unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
271 	u32 *headers;
272 	struct aac_entry * queues;
273 	unsigned long size;
274 	struct aac_queue_block * comm = dev->queues;
275 	/*
276 	 *	Now allocate and initialize the zone structures used as our
277 	 *	pool of FIB context records.  The size of the zone is based
278 	 *	on the system memory size.  We also initialize the mutex used
279 	 *	to protect the zone.
280 	 */
281 	spin_lock_init(&dev->fib_lock);
282 
283 	/*
284 	 *	Allocate the physically contiguous space for the commuication
285 	 *	queue headers.
286 	 */
287 
288 	size = hdrsize + queuesize;
289 
290 	if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT))
291 		return -ENOMEM;
292 
293 	queues = (struct aac_entry *)(((ulong)headers) + hdrsize);
294 
295 	/* Adapter to Host normal priority Command queue */
296 	comm->queue[HostNormCmdQueue].base = queues;
297 	aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES);
298 	queues += HOST_NORM_CMD_ENTRIES;
299 	headers += 2;
300 
301 	/* Adapter to Host high priority command queue */
302 	comm->queue[HostHighCmdQueue].base = queues;
303 	aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES);
304 
305 	queues += HOST_HIGH_CMD_ENTRIES;
306 	headers +=2;
307 
308 	/* Host to adapter normal priority command queue */
309 	comm->queue[AdapNormCmdQueue].base = queues;
310 	aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES);
311 
312 	queues += ADAP_NORM_CMD_ENTRIES;
313 	headers += 2;
314 
315 	/* host to adapter high priority command queue */
316 	comm->queue[AdapHighCmdQueue].base = queues;
317 	aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES);
318 
319 	queues += ADAP_HIGH_CMD_ENTRIES;
320 	headers += 2;
321 
322 	/* adapter to host normal priority response queue */
323 	comm->queue[HostNormRespQueue].base = queues;
324 	aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES);
325 	queues += HOST_NORM_RESP_ENTRIES;
326 	headers += 2;
327 
328 	/* adapter to host high priority response queue */
329 	comm->queue[HostHighRespQueue].base = queues;
330 	aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES);
331 
332 	queues += HOST_HIGH_RESP_ENTRIES;
333 	headers += 2;
334 
335 	/* host to adapter normal priority response queue */
336 	comm->queue[AdapNormRespQueue].base = queues;
337 	aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES);
338 
339 	queues += ADAP_NORM_RESP_ENTRIES;
340 	headers += 2;
341 
342 	/* host to adapter high priority response queue */
343 	comm->queue[AdapHighRespQueue].base = queues;
344 	aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES);
345 
346 	comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock;
347 	comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock;
348 	comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock;
349 	comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock;
350 
351 	return 0;
352 }
353 
aac_define_int_mode(struct aac_dev * dev)354 void aac_define_int_mode(struct aac_dev *dev)
355 {
356 	int i, msi_count, min_msix;
357 
358 	msi_count = i = 0;
359 	/* max. vectors from GET_COMM_PREFERRED_SETTINGS */
360 	if (dev->max_msix == 0 ||
361 	    dev->pdev->device == PMC_DEVICE_S6 ||
362 	    dev->sync_mode) {
363 		dev->max_msix = 1;
364 		dev->vector_cap =
365 			dev->scsi_host_ptr->can_queue +
366 			AAC_NUM_MGT_FIB;
367 		return;
368 	}
369 
370 	/* Don't bother allocating more MSI-X vectors than cpus */
371 	msi_count = min(dev->max_msix,
372 		(unsigned int)num_online_cpus());
373 
374 	dev->max_msix = msi_count;
375 
376 	if (msi_count > AAC_MAX_MSIX)
377 		msi_count = AAC_MAX_MSIX;
378 
379 	for (i = 0; i < msi_count; i++)
380 		dev->msixentry[i].entry = i;
381 
382 	if (msi_count > 1 &&
383 	    pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
384 		min_msix = 2;
385 		i = pci_enable_msix_range(dev->pdev,
386 				    dev->msixentry,
387 				    min_msix,
388 				    msi_count);
389 		if (i > 0) {
390 			dev->msi_enabled = 1;
391 			msi_count = i;
392 		} else {
393 			dev->msi_enabled = 0;
394 			printk(KERN_ERR "%s%d: MSIX not supported!! Will try MSI 0x%x.\n",
395 					dev->name, dev->id, i);
396 		}
397 	}
398 
399 	if (!dev->msi_enabled) {
400 		msi_count = 1;
401 		i = pci_enable_msi(dev->pdev);
402 
403 		if (!i) {
404 			dev->msi_enabled = 1;
405 			dev->msi = 1;
406 		} else {
407 			printk(KERN_ERR "%s%d: MSI not supported!! Will try INTx 0x%x.\n",
408 					dev->name, dev->id, i);
409 		}
410 	}
411 
412 	if (!dev->msi_enabled)
413 		dev->max_msix = msi_count = 1;
414 	else {
415 		if (dev->max_msix > msi_count)
416 			dev->max_msix = msi_count;
417 	}
418 	dev->vector_cap =
419 		(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) /
420 		msi_count;
421 }
aac_init_adapter(struct aac_dev * dev)422 struct aac_dev *aac_init_adapter(struct aac_dev *dev)
423 {
424 	u32 status[5];
425 	struct Scsi_Host * host = dev->scsi_host_ptr;
426 	extern int aac_sync_mode;
427 
428 	/*
429 	 *	Check the preferred comm settings, defaults from template.
430 	 */
431 	dev->management_fib_count = 0;
432 	spin_lock_init(&dev->manage_lock);
433 	spin_lock_init(&dev->sync_lock);
434 	spin_lock_init(&dev->iq_lock);
435 	dev->max_fib_size = sizeof(struct hw_fib);
436 	dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size
437 		- sizeof(struct aac_fibhdr)
438 		- sizeof(struct aac_write) + sizeof(struct sgentry))
439 			/ sizeof(struct sgentry);
440 	dev->comm_interface = AAC_COMM_PRODUCER;
441 	dev->raw_io_interface = dev->raw_io_64 = 0;
442 
443 
444 	/*
445 	 * Enable INTX mode, if not done already Enabled
446 	 */
447 	if (aac_is_msix_mode(dev)) {
448 		aac_change_to_intx(dev);
449 		dev_info(&dev->pdev->dev, "Changed firmware to INTX mode");
450 	}
451 
452 	if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
453 		0, 0, 0, 0, 0, 0,
454 		status+0, status+1, status+2, status+3, NULL)) &&
455 	 		(status[0] == 0x00000001)) {
456 		dev->doorbell_mask = status[3];
457 		if (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_64))
458 			dev->raw_io_64 = 1;
459 		dev->sync_mode = aac_sync_mode;
460 		if (dev->a_ops.adapter_comm &&
461 			(status[1] & le32_to_cpu(AAC_OPT_NEW_COMM))) {
462 				dev->comm_interface = AAC_COMM_MESSAGE;
463 				dev->raw_io_interface = 1;
464 			if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE1))) {
465 				/* driver supports TYPE1 (Tupelo) */
466 				dev->comm_interface = AAC_COMM_MESSAGE_TYPE1;
467 			} else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE2))) {
468 				/* driver supports TYPE2 (Denali) */
469 				dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
470 			} else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE4)) ||
471 				  (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE3))) {
472 				/* driver doesn't TYPE3 and TYPE4 */
473 				/* switch to sync. mode */
474 				dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
475 				dev->sync_mode = 1;
476 			}
477 		}
478 		if ((dev->comm_interface == AAC_COMM_MESSAGE) &&
479 		    (status[2] > dev->base_size)) {
480 			aac_adapter_ioremap(dev, 0);
481 			dev->base_size = status[2];
482 			if (aac_adapter_ioremap(dev, status[2])) {
483 				/* remap failed, go back ... */
484 				dev->comm_interface = AAC_COMM_PRODUCER;
485 				if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) {
486 					printk(KERN_WARNING
487 					  "aacraid: unable to map adapter.\n");
488 					return NULL;
489 				}
490 			}
491 		}
492 	}
493 	dev->max_msix = 0;
494 	dev->msi_enabled = 0;
495 	dev->adapter_shutdown = 0;
496 	if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS,
497 	  0, 0, 0, 0, 0, 0,
498 	  status+0, status+1, status+2, status+3, status+4))
499 	 && (status[0] == 0x00000001)) {
500 		/*
501 		 *	status[1] >> 16		maximum command size in KB
502 		 *	status[1] & 0xFFFF	maximum FIB size
503 		 *	status[2] >> 16		maximum SG elements to driver
504 		 *	status[2] & 0xFFFF	maximum SG elements from driver
505 		 *	status[3] & 0xFFFF	maximum number FIBs outstanding
506 		 */
507 		host->max_sectors = (status[1] >> 16) << 1;
508 		/* Multiple of 32 for PMC */
509 		dev->max_fib_size = status[1] & 0xFFE0;
510 		host->sg_tablesize = status[2] >> 16;
511 		dev->sg_tablesize = status[2] & 0xFFFF;
512 		if (dev->pdev->device == PMC_DEVICE_S7 ||
513 		    dev->pdev->device == PMC_DEVICE_S8 ||
514 		    dev->pdev->device == PMC_DEVICE_S9)
515 			host->can_queue = ((status[3] >> 16) ? (status[3] >> 16) :
516 				(status[3] & 0xFFFF)) - AAC_NUM_MGT_FIB;
517 		else
518 			host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB;
519 		dev->max_num_aif = status[4] & 0xFFFF;
520 		/*
521 		 *	NOTE:
522 		 *	All these overrides are based on a fixed internal
523 		 *	knowledge and understanding of existing adapters,
524 		 *	acbsize should be set with caution.
525 		 */
526 		if (acbsize == 512) {
527 			host->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
528 			dev->max_fib_size = 512;
529 			dev->sg_tablesize = host->sg_tablesize
530 			  = (512 - sizeof(struct aac_fibhdr)
531 			    - sizeof(struct aac_write) + sizeof(struct sgentry))
532 			     / sizeof(struct sgentry);
533 			host->can_queue = AAC_NUM_IO_FIB;
534 		} else if (acbsize == 2048) {
535 			host->max_sectors = 512;
536 			dev->max_fib_size = 2048;
537 			host->sg_tablesize = 65;
538 			dev->sg_tablesize = 81;
539 			host->can_queue = 512 - AAC_NUM_MGT_FIB;
540 		} else if (acbsize == 4096) {
541 			host->max_sectors = 1024;
542 			dev->max_fib_size = 4096;
543 			host->sg_tablesize = 129;
544 			dev->sg_tablesize = 166;
545 			host->can_queue = 256 - AAC_NUM_MGT_FIB;
546 		} else if (acbsize == 8192) {
547 			host->max_sectors = 2048;
548 			dev->max_fib_size = 8192;
549 			host->sg_tablesize = 257;
550 			dev->sg_tablesize = 337;
551 			host->can_queue = 128 - AAC_NUM_MGT_FIB;
552 		} else if (acbsize > 0) {
553 			printk("Illegal acbsize=%d ignored\n", acbsize);
554 		}
555 	}
556 	{
557 
558 		if (numacb > 0) {
559 			if (numacb < host->can_queue)
560 				host->can_queue = numacb;
561 			else
562 				printk("numacb=%d ignored\n", numacb);
563 		}
564 	}
565 
566 	if (host->can_queue > AAC_NUM_IO_FIB)
567 		host->can_queue = AAC_NUM_IO_FIB;
568 
569 	if (dev->pdev->device == PMC_DEVICE_S6 ||
570 	    dev->pdev->device == PMC_DEVICE_S7 ||
571 	    dev->pdev->device == PMC_DEVICE_S8 ||
572 	    dev->pdev->device == PMC_DEVICE_S9)
573 		aac_define_int_mode(dev);
574 	/*
575 	 *	Ok now init the communication subsystem
576 	 */
577 
578 	dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
579 	if (dev->queues == NULL) {
580 		printk(KERN_ERR "Error could not allocate comm region.\n");
581 		return NULL;
582 	}
583 
584 	if (aac_comm_init(dev)<0){
585 		kfree(dev->queues);
586 		return NULL;
587 	}
588 	/*
589 	 *	Initialize the list of fibs
590 	 */
591 	if (aac_fib_setup(dev) < 0) {
592 		kfree(dev->queues);
593 		return NULL;
594 	}
595 
596 	INIT_LIST_HEAD(&dev->fib_list);
597 	INIT_LIST_HEAD(&dev->sync_fib_list);
598 
599 	return dev;
600 }
601 
602