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