xref: /openbmc/linux/drivers/scsi/aacraid/comminit.c (revision d503e2fd)
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 
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 
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 
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, aac_init_size;
72 	union 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 		(dev->comm_interface == AAC_COMM_MESSAGE_TYPE3 &&
79 		!dev->sa_firmware)) {
80 		host_rrq_size =
81 			(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB)
82 				* sizeof(u32);
83 		aac_init_size = sizeof(union aac_init);
84 	} else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3 &&
85 		dev->sa_firmware) {
86 		host_rrq_size = (dev->scsi_host_ptr->can_queue
87 			+ AAC_NUM_MGT_FIB) * sizeof(u32)  * AAC_MAX_MSIX;
88 		aac_init_size = sizeof(union aac_init) +
89 			(AAC_MAX_HRRQ - 1) * sizeof(struct _rrq);
90 	} else {
91 		host_rrq_size = 0;
92 		aac_init_size = sizeof(union aac_init);
93 	}
94 	size = fibsize + aac_init_size + commsize + commalign +
95 			printfbufsiz + host_rrq_size;
96 
97 	base = pci_alloc_consistent(dev->pdev, size, &phys);
98 
99 	if (base == NULL) {
100 		printk(KERN_ERR "aacraid: unable to create mapping.\n");
101 		return 0;
102 	}
103 
104 	dev->comm_addr = (void *)base;
105 	dev->comm_phys = phys;
106 	dev->comm_size = size;
107 
108 	if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) ||
109 	    (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) ||
110 	    (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3)) {
111 		dev->host_rrq = (u32 *)(base + fibsize);
112 		dev->host_rrq_pa = phys + fibsize;
113 		memset(dev->host_rrq, 0, host_rrq_size);
114 	}
115 
116 	dev->init = (union aac_init *)(base + fibsize + host_rrq_size);
117 	dev->init_pa = phys + fibsize + host_rrq_size;
118 
119 	init = dev->init;
120 
121 	if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) {
122 		int i;
123 		u64 addr;
124 
125 		init->r8.init_struct_revision =
126 			cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_8);
127 		init->r8.init_flags = cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
128 					INITFLAGS_DRIVER_USES_UTC_TIME |
129 					INITFLAGS_DRIVER_SUPPORTS_PM);
130 		init->r8.init_flags |=
131 				cpu_to_le32(INITFLAGS_DRIVER_SUPPORTS_HBA_MODE);
132 		init->r8.rr_queue_count = cpu_to_le32(dev->max_msix);
133 		init->r8.max_io_size =
134 			cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
135 		init->r8.max_num_aif = init->r8.reserved1 =
136 			init->r8.reserved2 = 0;
137 
138 		for (i = 0; i < dev->max_msix; i++) {
139 			addr = (u64)dev->host_rrq_pa + dev->vector_cap * i *
140 					sizeof(u32);
141 			init->r8.rrq[i].host_addr_high = cpu_to_le32(
142 						upper_32_bits(addr));
143 			init->r8.rrq[i].host_addr_low = cpu_to_le32(
144 						lower_32_bits(addr));
145 			init->r8.rrq[i].msix_id = i;
146 			init->r8.rrq[i].element_count = cpu_to_le16(
147 					(u16)dev->vector_cap);
148 			init->r8.rrq[i].comp_thresh =
149 					init->r8.rrq[i].unused = 0;
150 		}
151 
152 		pr_warn("aacraid: Comm Interface type3 enabled\n");
153 	} else {
154 		init->r7.init_struct_revision =
155 			cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
156 		if (dev->max_fib_size != sizeof(struct hw_fib))
157 			init->r7.init_struct_revision =
158 				cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
159 		init->r7.no_of_msix_vectors = cpu_to_le32(SA_MINIPORT_REVISION);
160 		init->r7.fsrev = cpu_to_le32(dev->fsrev);
161 
162 		/*
163 		 *	Adapter Fibs are the first thing allocated so that they
164 		 *	start page aligned
165 		 */
166 		dev->aif_base_va = (struct hw_fib *)base;
167 
168 		init->r7.adapter_fibs_virtual_address = 0;
169 		init->r7.adapter_fibs_physical_address = cpu_to_le32((u32)phys);
170 		init->r7.adapter_fibs_size = cpu_to_le32(fibsize);
171 		init->r7.adapter_fib_align = cpu_to_le32(sizeof(struct hw_fib));
172 
173 		/*
174 		 * number of 4k pages of host physical memory. The aacraid fw
175 		 * needs this number to be less than 4gb worth of pages. New
176 		 * firmware doesn't have any issues with the mapping system, but
177 		 * older Firmware did, and had *troubles* dealing with the math
178 		 * overloading past 32 bits, thus we must limit this field.
179 		 */
180 		aac_max_hostphysmempages =
181 				dma_get_required_mask(&dev->pdev->dev) >> 12;
182 		if (aac_max_hostphysmempages < AAC_MAX_HOSTPHYSMEMPAGES)
183 			init->r7.host_phys_mem_pages =
184 					cpu_to_le32(aac_max_hostphysmempages);
185 		else
186 			init->r7.host_phys_mem_pages =
187 					cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
188 
189 		init->r7.init_flags =
190 			cpu_to_le32(INITFLAGS_DRIVER_USES_UTC_TIME |
191 			INITFLAGS_DRIVER_SUPPORTS_PM);
192 		init->r7.max_io_commands =
193 			cpu_to_le32(dev->scsi_host_ptr->can_queue +
194 					AAC_NUM_MGT_FIB);
195 		init->r7.max_io_size =
196 			cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
197 		init->r7.max_fib_size = cpu_to_le32(dev->max_fib_size);
198 		init->r7.max_num_aif = cpu_to_le32(dev->max_num_aif);
199 
200 		if (dev->comm_interface == AAC_COMM_MESSAGE) {
201 			init->r7.init_flags |=
202 				cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
203 			pr_warn("aacraid: Comm Interface enabled\n");
204 		} else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) {
205 			init->r7.init_struct_revision =
206 				cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_6);
207 			init->r7.init_flags |=
208 				cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
209 				INITFLAGS_NEW_COMM_TYPE1_SUPPORTED |
210 				INITFLAGS_FAST_JBOD_SUPPORTED);
211 			init->r7.host_rrq_addr_high =
212 				cpu_to_le32(upper_32_bits(dev->host_rrq_pa));
213 			init->r7.host_rrq_addr_low =
214 				cpu_to_le32(lower_32_bits(dev->host_rrq_pa));
215 			pr_warn("aacraid: Comm Interface type1 enabled\n");
216 		} else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
217 			init->r7.init_struct_revision =
218 				cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_7);
219 			init->r7.init_flags |=
220 				cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
221 				INITFLAGS_NEW_COMM_TYPE2_SUPPORTED |
222 				INITFLAGS_FAST_JBOD_SUPPORTED);
223 			init->r7.host_rrq_addr_high =
224 				cpu_to_le32(upper_32_bits(dev->host_rrq_pa));
225 			init->r7.host_rrq_addr_low =
226 				cpu_to_le32(lower_32_bits(dev->host_rrq_pa));
227 			init->r7.no_of_msix_vectors =
228 				cpu_to_le32(dev->max_msix);
229 			/* must be the COMM_PREFERRED_SETTINGS values */
230 			pr_warn("aacraid: Comm Interface type2 enabled\n");
231 		}
232 	}
233 
234 	/*
235 	 * Increment the base address by the amount already used
236 	 */
237 	base = base + fibsize + host_rrq_size + aac_init_size;
238 	phys = (dma_addr_t)((ulong)phys + fibsize + host_rrq_size +
239 			aac_init_size);
240 
241 	/*
242 	 *	Align the beginning of Headers to commalign
243 	 */
244 	align = (commalign - ((uintptr_t)(base) & (commalign - 1)));
245 	base = base + align;
246 	phys = phys + align;
247 	/*
248 	 *	Fill in addresses of the Comm Area Headers and Queues
249 	 */
250 	*commaddr = base;
251 	if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE3)
252 		init->r7.comm_header_address = cpu_to_le32((u32)phys);
253 	/*
254 	 *	Increment the base address by the size of the CommArea
255 	 */
256 	base = base + commsize;
257 	phys = phys + commsize;
258 	/*
259 	 *	 Place the Printf buffer area after the Fast I/O comm area.
260 	 */
261 	dev->printfbuf = (void *)base;
262 	if (dev->comm_interface != AAC_COMM_MESSAGE_TYPE3) {
263 		init->r7.printfbuf = cpu_to_le32(phys);
264 		init->r7.printfbufsiz = cpu_to_le32(printfbufsiz);
265 	}
266 	memset(base, 0, printfbufsiz);
267 	return 1;
268 }
269 
270 static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize)
271 {
272 	atomic_set(&q->numpending, 0);
273 	q->dev = dev;
274 	init_waitqueue_head(&q->cmdready);
275 	INIT_LIST_HEAD(&q->cmdq);
276 	init_waitqueue_head(&q->qfull);
277 	spin_lock_init(&q->lockdata);
278 	q->lock = &q->lockdata;
279 	q->headers.producer = (__le32 *)mem;
280 	q->headers.consumer = (__le32 *)(mem+1);
281 	*(q->headers.producer) = cpu_to_le32(qsize);
282 	*(q->headers.consumer) = cpu_to_le32(qsize);
283 	q->entries = qsize;
284 }
285 
286 /**
287  *	aac_send_shutdown		-	shutdown an adapter
288  *	@dev: Adapter to shutdown
289  *
290  *	This routine will send a VM_CloseAll (shutdown) request to the adapter.
291  */
292 
293 int aac_send_shutdown(struct aac_dev * dev)
294 {
295 	struct fib * fibctx;
296 	struct aac_close *cmd;
297 	int status;
298 
299 	fibctx = aac_fib_alloc(dev);
300 	if (!fibctx)
301 		return -ENOMEM;
302 	aac_fib_init(fibctx);
303 
304 	mutex_lock(&dev->ioctl_mutex);
305 	dev->adapter_shutdown = 1;
306 	mutex_unlock(&dev->ioctl_mutex);
307 
308 	cmd = (struct aac_close *) fib_data(fibctx);
309 	cmd->command = cpu_to_le32(VM_CloseAll);
310 	cmd->cid = cpu_to_le32(0xfffffffe);
311 
312 	status = aac_fib_send(ContainerCommand,
313 			  fibctx,
314 			  sizeof(struct aac_close),
315 			  FsaNormal,
316 			  -2 /* Timeout silently */, 1,
317 			  NULL, NULL);
318 
319 	if (status >= 0)
320 		aac_fib_complete(fibctx);
321 	/* FIB should be freed only after getting the response from the F/W */
322 	if (status != -ERESTARTSYS)
323 		aac_fib_free(fibctx);
324 	if ((dev->pdev->device == PMC_DEVICE_S7 ||
325 	     dev->pdev->device == PMC_DEVICE_S8 ||
326 	     dev->pdev->device == PMC_DEVICE_S9) &&
327 	     dev->msi_enabled)
328 		aac_src_access_devreg(dev, AAC_ENABLE_INTX);
329 	return status;
330 }
331 
332 /**
333  *	aac_comm_init	-	Initialise FSA data structures
334  *	@dev:	Adapter to initialise
335  *
336  *	Initializes the data structures that are required for the FSA commuication
337  *	interface to operate.
338  *	Returns
339  *		1 - if we were able to init the commuication interface.
340  *		0 - If there were errors initing. This is a fatal error.
341  */
342 
343 static int aac_comm_init(struct aac_dev * dev)
344 {
345 	unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
346 	unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
347 	u32 *headers;
348 	struct aac_entry * queues;
349 	unsigned long size;
350 	struct aac_queue_block * comm = dev->queues;
351 	/*
352 	 *	Now allocate and initialize the zone structures used as our
353 	 *	pool of FIB context records.  The size of the zone is based
354 	 *	on the system memory size.  We also initialize the mutex used
355 	 *	to protect the zone.
356 	 */
357 	spin_lock_init(&dev->fib_lock);
358 
359 	/*
360 	 *	Allocate the physically contiguous space for the commuication
361 	 *	queue headers.
362 	 */
363 
364 	size = hdrsize + queuesize;
365 
366 	if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT))
367 		return -ENOMEM;
368 
369 	queues = (struct aac_entry *)(((ulong)headers) + hdrsize);
370 
371 	/* Adapter to Host normal priority Command queue */
372 	comm->queue[HostNormCmdQueue].base = queues;
373 	aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES);
374 	queues += HOST_NORM_CMD_ENTRIES;
375 	headers += 2;
376 
377 	/* Adapter to Host high priority command queue */
378 	comm->queue[HostHighCmdQueue].base = queues;
379 	aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES);
380 
381 	queues += HOST_HIGH_CMD_ENTRIES;
382 	headers +=2;
383 
384 	/* Host to adapter normal priority command queue */
385 	comm->queue[AdapNormCmdQueue].base = queues;
386 	aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES);
387 
388 	queues += ADAP_NORM_CMD_ENTRIES;
389 	headers += 2;
390 
391 	/* host to adapter high priority command queue */
392 	comm->queue[AdapHighCmdQueue].base = queues;
393 	aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES);
394 
395 	queues += ADAP_HIGH_CMD_ENTRIES;
396 	headers += 2;
397 
398 	/* adapter to host normal priority response queue */
399 	comm->queue[HostNormRespQueue].base = queues;
400 	aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES);
401 	queues += HOST_NORM_RESP_ENTRIES;
402 	headers += 2;
403 
404 	/* adapter to host high priority response queue */
405 	comm->queue[HostHighRespQueue].base = queues;
406 	aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES);
407 
408 	queues += HOST_HIGH_RESP_ENTRIES;
409 	headers += 2;
410 
411 	/* host to adapter normal priority response queue */
412 	comm->queue[AdapNormRespQueue].base = queues;
413 	aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES);
414 
415 	queues += ADAP_NORM_RESP_ENTRIES;
416 	headers += 2;
417 
418 	/* host to adapter high priority response queue */
419 	comm->queue[AdapHighRespQueue].base = queues;
420 	aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES);
421 
422 	comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock;
423 	comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock;
424 	comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock;
425 	comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock;
426 
427 	return 0;
428 }
429 
430 void aac_define_int_mode(struct aac_dev *dev)
431 {
432 	int i, msi_count, min_msix;
433 
434 	msi_count = i = 0;
435 	/* max. vectors from GET_COMM_PREFERRED_SETTINGS */
436 	if (dev->max_msix == 0 ||
437 	    dev->pdev->device == PMC_DEVICE_S6 ||
438 	    dev->sync_mode) {
439 		dev->max_msix = 1;
440 		dev->vector_cap =
441 			dev->scsi_host_ptr->can_queue +
442 			AAC_NUM_MGT_FIB;
443 		return;
444 	}
445 
446 	/* Don't bother allocating more MSI-X vectors than cpus */
447 	msi_count = min(dev->max_msix,
448 		(unsigned int)num_online_cpus());
449 
450 	dev->max_msix = msi_count;
451 
452 	if (msi_count > AAC_MAX_MSIX)
453 		msi_count = AAC_MAX_MSIX;
454 
455 	if (msi_count > 1 &&
456 	    pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
457 		min_msix = 2;
458 		i = pci_alloc_irq_vectors(dev->pdev,
459 					  min_msix, msi_count,
460 					  PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
461 		if (i > 0) {
462 			dev->msi_enabled = 1;
463 			msi_count = i;
464 		} else {
465 			dev->msi_enabled = 0;
466 			dev_err(&dev->pdev->dev,
467 			"MSIX not supported!! Will try INTX 0x%x.\n", i);
468 		}
469 	}
470 
471 	if (!dev->msi_enabled)
472 		dev->max_msix = msi_count = 1;
473 	else {
474 		if (dev->max_msix > msi_count)
475 			dev->max_msix = msi_count;
476 	}
477 	if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE3 && dev->sa_firmware)
478 		dev->vector_cap = dev->scsi_host_ptr->can_queue +
479 				AAC_NUM_MGT_FIB;
480 	else
481 		dev->vector_cap = (dev->scsi_host_ptr->can_queue +
482 				AAC_NUM_MGT_FIB) / msi_count;
483 
484 }
485 struct aac_dev *aac_init_adapter(struct aac_dev *dev)
486 {
487 	u32 status[5];
488 	struct Scsi_Host * host = dev->scsi_host_ptr;
489 	extern int aac_sync_mode;
490 
491 	/*
492 	 *	Check the preferred comm settings, defaults from template.
493 	 */
494 	dev->management_fib_count = 0;
495 	spin_lock_init(&dev->manage_lock);
496 	spin_lock_init(&dev->sync_lock);
497 	spin_lock_init(&dev->iq_lock);
498 	dev->max_fib_size = sizeof(struct hw_fib);
499 	dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size
500 		- sizeof(struct aac_fibhdr)
501 		- sizeof(struct aac_write) + sizeof(struct sgentry))
502 			/ sizeof(struct sgentry);
503 	dev->comm_interface = AAC_COMM_PRODUCER;
504 	dev->raw_io_interface = dev->raw_io_64 = 0;
505 
506 
507 	/*
508 	 * Enable INTX mode, if not done already Enabled
509 	 */
510 	if (aac_is_msix_mode(dev)) {
511 		aac_change_to_intx(dev);
512 		dev_info(&dev->pdev->dev, "Changed firmware to INTX mode");
513 	}
514 
515 	if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
516 		0, 0, 0, 0, 0, 0,
517 		status+0, status+1, status+2, status+3, status+4)) &&
518 		(status[0] == 0x00000001)) {
519 		dev->doorbell_mask = status[3];
520 		if (status[1] & AAC_OPT_NEW_COMM_64)
521 			dev->raw_io_64 = 1;
522 		dev->sync_mode = aac_sync_mode;
523 		if (dev->a_ops.adapter_comm &&
524 			(status[1] & AAC_OPT_NEW_COMM)) {
525 				dev->comm_interface = AAC_COMM_MESSAGE;
526 				dev->raw_io_interface = 1;
527 			if ((status[1] & AAC_OPT_NEW_COMM_TYPE1)) {
528 				/* driver supports TYPE1 (Tupelo) */
529 				dev->comm_interface = AAC_COMM_MESSAGE_TYPE1;
530 			} else if (status[1] & AAC_OPT_NEW_COMM_TYPE2) {
531 				/* driver supports TYPE2 (Denali, Yosemite) */
532 				dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
533 			} else if (status[1] & AAC_OPT_NEW_COMM_TYPE3) {
534 				/* driver supports TYPE3 (Yosemite, Thor) */
535 				dev->comm_interface = AAC_COMM_MESSAGE_TYPE3;
536 			} else if (status[1] & AAC_OPT_NEW_COMM_TYPE4) {
537 				/* not supported TYPE - switch to sync. mode */
538 				dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
539 				dev->sync_mode = 1;
540 			}
541 		}
542 		if ((status[1] & le32_to_cpu(AAC_OPT_EXTENDED)) &&
543 			(status[4] & le32_to_cpu(AAC_EXTOPT_SA_FIRMWARE)))
544 			dev->sa_firmware = 1;
545 		else
546 			dev->sa_firmware = 0;
547 
548 		if ((dev->comm_interface == AAC_COMM_MESSAGE) &&
549 		    (status[2] > dev->base_size)) {
550 			aac_adapter_ioremap(dev, 0);
551 			dev->base_size = status[2];
552 			if (aac_adapter_ioremap(dev, status[2])) {
553 				/* remap failed, go back ... */
554 				dev->comm_interface = AAC_COMM_PRODUCER;
555 				if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) {
556 					printk(KERN_WARNING
557 					  "aacraid: unable to map adapter.\n");
558 					return NULL;
559 				}
560 			}
561 		}
562 	}
563 	dev->max_msix = 0;
564 	dev->msi_enabled = 0;
565 	dev->adapter_shutdown = 0;
566 	if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS,
567 	  0, 0, 0, 0, 0, 0,
568 	  status+0, status+1, status+2, status+3, status+4))
569 	 && (status[0] == 0x00000001)) {
570 		/*
571 		 *	status[1] >> 16		maximum command size in KB
572 		 *	status[1] & 0xFFFF	maximum FIB size
573 		 *	status[2] >> 16		maximum SG elements to driver
574 		 *	status[2] & 0xFFFF	maximum SG elements from driver
575 		 *	status[3] & 0xFFFF	maximum number FIBs outstanding
576 		 */
577 		host->max_sectors = (status[1] >> 16) << 1;
578 		/* Multiple of 32 for PMC */
579 		dev->max_fib_size = status[1] & 0xFFE0;
580 		host->sg_tablesize = status[2] >> 16;
581 		dev->sg_tablesize = status[2] & 0xFFFF;
582 		if (dev->pdev->device == PMC_DEVICE_S7 ||
583 		    dev->pdev->device == PMC_DEVICE_S8 ||
584 		    dev->pdev->device == PMC_DEVICE_S9) {
585 			if (host->can_queue > (status[3] >> 16) -
586 					AAC_NUM_MGT_FIB)
587 				host->can_queue = (status[3] >> 16) -
588 					AAC_NUM_MGT_FIB;
589 		} else if (host->can_queue > (status[3] & 0xFFFF) -
590 				AAC_NUM_MGT_FIB)
591 			host->can_queue = (status[3] & 0xFFFF) -
592 				AAC_NUM_MGT_FIB;
593 
594 		dev->max_num_aif = status[4] & 0xFFFF;
595 	}
596 	if (numacb > 0) {
597 		if (numacb < host->can_queue)
598 			host->can_queue = numacb;
599 		else
600 			pr_warn("numacb=%d ignored\n", numacb);
601 	}
602 
603 	if (dev->pdev->device == PMC_DEVICE_S6 ||
604 	    dev->pdev->device == PMC_DEVICE_S7 ||
605 	    dev->pdev->device == PMC_DEVICE_S8 ||
606 	    dev->pdev->device == PMC_DEVICE_S9)
607 		aac_define_int_mode(dev);
608 	/*
609 	 *	Ok now init the communication subsystem
610 	 */
611 
612 	dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
613 	if (dev->queues == NULL) {
614 		printk(KERN_ERR "Error could not allocate comm region.\n");
615 		return NULL;
616 	}
617 
618 	if (aac_comm_init(dev)<0){
619 		kfree(dev->queues);
620 		return NULL;
621 	}
622 	/*
623 	 *	Initialize the list of fibs
624 	 */
625 	if (aac_fib_setup(dev) < 0) {
626 		kfree(dev->queues);
627 		return NULL;
628 	}
629 
630 	INIT_LIST_HEAD(&dev->fib_list);
631 	INIT_LIST_HEAD(&dev->sync_fib_list);
632 
633 	return dev;
634 }
635 
636