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