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