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