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