blob: 45db84ad322f20de892a16e675acd3da6b8cbe84 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
Alan Coxfa195af2008-10-27 15:16:36 +00003 * (c) Copyright 2001 Red Hat Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07008 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#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>
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070042#include <scsi/scsi_host.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#include "aacraid.h"
45
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -040046static void aac_define_int_mode(struct aac_dev *dev);
47
Mark Haverkampbed30de2005-08-03 15:38:51 -070048struct aac_common aac_config = {
49 .irq_mod = 1
50};
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
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;
Mahesh Rajashekharaef616232015-03-26 10:41:30 -040056 const unsigned long fibsize = dev->max_fib_size;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070057 const unsigned long printfbufsiz = 256;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070058 unsigned long host_rrq_size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 struct aac_init *init;
60 dma_addr_t phys;
Leubner, Achimd8e965072009-04-01 07:16:08 -070061 unsigned long aac_max_hostphysmempages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +053063 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
64 dev->comm_interface == AAC_COMM_MESSAGE_TYPE2)
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070065 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
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
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +053081 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
82 dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070083 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 init = dev->init;
92
93 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070094 if (dev->max_fib_size != sizeof(struct hw_fib))
95 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -040096 init->Sa_MSIXVectors = cpu_to_le32(Sa_MINIPORT_REVISION);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 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));
Leubner, Achimd8e965072009-04-01 07:16:08 -0700109 /*
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530122 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
Mark Haverkamp28713322007-01-23 14:59:20 -0800129 if (dev->comm_interface == AAC_COMM_MESSAGE) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700130 init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700131 dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700132 } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) {
133 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_6);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530134 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));
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400145 /* number of MSI-X */
146 init->Sa_MSIXVectors = cpu_to_le32(dev->max_msix);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530147 dprintk((KERN_WARNING"aacraid: New Comm Interface type2 enabled\n"));
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700148 }
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 /*
151 * Increment the base address by the amount already used
152 */
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700153 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 /*
158 * Align the beginning of Headers to commalign
159 */
Al Viro142956a2007-10-29 05:11:28 +0000160 align = (commalign - ((uintptr_t)(base) & (commalign - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 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{
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400185 atomic_set(&q->numpending, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 q->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 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;
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700192 q->headers.producer = (__le32 *)mem;
193 q->headers.consumer = (__le32 *)(mem+1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 *(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
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800212 fibctx = aac_fib_alloc(dev);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700213 if (!fibctx)
214 return -ENOMEM;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800215 aac_fib_init(fibctx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 cmd = (struct aac_close *) fib_data(fibctx);
218
219 cmd->command = cpu_to_le32(VM_CloseAll);
Mahesh Rajashekhara2c10cd42013-03-19 12:37:26 +0530220 cmd->cid = cpu_to_le32(0xfffffffe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800222 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 fibctx,
224 sizeof(struct aac_close),
225 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -0700226 -2 /* Timeout silently */, 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 NULL, NULL);
228
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700229 if (status >= 0)
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800230 aac_fib_complete(fibctx);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530231 /* FIB should be freed only after getting the response from the F/W */
232 if (status != -ERESTARTSYS)
233 aac_fib_free(fibctx);
Mahesh Rajashekharaf9c42592015-03-26 10:41:29 -0400234 dev->adapter_shutdown = 1;
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400235 if ((dev->pdev->device == PMC_DEVICE_S7 ||
236 dev->pdev->device == PMC_DEVICE_S8 ||
237 dev->pdev->device == PMC_DEVICE_S9) &&
238 dev->msi_enabled)
239 aac_src_access_devreg(dev, AAC_ENABLE_INTX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return status;
241}
242
243/**
244 * aac_comm_init - Initialise FSA data structures
245 * @dev: Adapter to initialise
246 *
247 * Initializes the data structures that are required for the FSA commuication
248 * interface to operate.
249 * Returns
250 * 1 - if we were able to init the commuication interface.
251 * 0 - If there were errors initing. This is a fatal error.
252 */
253
Adrian Bunk 48338692005-04-25 19:45:58 -0700254static int aac_comm_init(struct aac_dev * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
257 unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
258 u32 *headers;
259 struct aac_entry * queues;
260 unsigned long size;
261 struct aac_queue_block * comm = dev->queues;
262 /*
263 * Now allocate and initialize the zone structures used as our
264 * pool of FIB context records. The size of the zone is based
265 * on the system memory size. We also initialize the mutex used
266 * to protect the zone.
267 */
268 spin_lock_init(&dev->fib_lock);
269
270 /*
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200271 * Allocate the physically contiguous space for the commuication
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 * queue headers.
273 */
274
275 size = hdrsize + queuesize;
276
277 if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT))
278 return -ENOMEM;
279
280 queues = (struct aac_entry *)(((ulong)headers) + hdrsize);
281
282 /* Adapter to Host normal priority Command queue */
283 comm->queue[HostNormCmdQueue].base = queues;
284 aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES);
285 queues += HOST_NORM_CMD_ENTRIES;
286 headers += 2;
287
288 /* Adapter to Host high priority command queue */
289 comm->queue[HostHighCmdQueue].base = queues;
290 aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES);
291
292 queues += HOST_HIGH_CMD_ENTRIES;
293 headers +=2;
294
295 /* Host to adapter normal priority command queue */
296 comm->queue[AdapNormCmdQueue].base = queues;
297 aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES);
298
299 queues += ADAP_NORM_CMD_ENTRIES;
300 headers += 2;
301
302 /* host to adapter high priority command queue */
303 comm->queue[AdapHighCmdQueue].base = queues;
304 aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES);
305
306 queues += ADAP_HIGH_CMD_ENTRIES;
307 headers += 2;
308
309 /* adapter to host normal priority response queue */
310 comm->queue[HostNormRespQueue].base = queues;
311 aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES);
312 queues += HOST_NORM_RESP_ENTRIES;
313 headers += 2;
314
315 /* adapter to host high priority response queue */
316 comm->queue[HostHighRespQueue].base = queues;
317 aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES);
318
319 queues += HOST_HIGH_RESP_ENTRIES;
320 headers += 2;
321
322 /* host to adapter normal priority response queue */
323 comm->queue[AdapNormRespQueue].base = queues;
324 aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES);
325
326 queues += ADAP_NORM_RESP_ENTRIES;
327 headers += 2;
328
329 /* host to adapter high priority response queue */
330 comm->queue[AdapHighRespQueue].base = queues;
331 aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES);
332
333 comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock;
334 comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock;
335 comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock;
336 comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock;
337
338 return 0;
339}
340
341struct aac_dev *aac_init_adapter(struct aac_dev *dev)
342{
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700343 u32 status[5];
344 struct Scsi_Host * host = dev->scsi_host_ptr;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800345 extern int aac_sync_mode;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700346
347 /*
348 * Check the preferred comm settings, defaults from template.
349 */
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530350 dev->management_fib_count = 0;
351 spin_lock_init(&dev->manage_lock);
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800352 spin_lock_init(&dev->sync_lock);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700353 dev->max_fib_size = sizeof(struct hw_fib);
354 dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size
355 - sizeof(struct aac_fibhdr)
Mark Haverkamp63a70ee2005-09-20 12:57:04 -0700356 - sizeof(struct aac_write) + sizeof(struct sgentry))
357 / sizeof(struct sgentry);
Mark Haverkamp28713322007-01-23 14:59:20 -0800358 dev->comm_interface = AAC_COMM_PRODUCER;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700359 dev->raw_io_interface = dev->raw_io_64 = 0;
360
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700361 if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
Mahesh Rajashekharadafde942015-03-26 10:41:28 -0400362 0, 0, 0, 0, 0, 0,
363 status+0, status+1, status+2, status+3, NULL)) &&
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700364 (status[0] == 0x00000001)) {
Mahesh Rajashekharadafde942015-03-26 10:41:28 -0400365 dev->doorbell_mask = status[3];
Salyzyn, Marka3940da2008-01-08 12:48:25 -0800366 if (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_64))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700367 dev->raw_io_64 = 1;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800368 dev->sync_mode = aac_sync_mode;
369 if (dev->a_ops.adapter_comm &&
370 (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM))) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700371 dev->comm_interface = AAC_COMM_MESSAGE;
372 dev->raw_io_interface = 1;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800373 if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE1))) {
374 /* driver supports TYPE1 (Tupelo) */
375 dev->comm_interface = AAC_COMM_MESSAGE_TYPE1;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530376 } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE2))) {
377 /* driver supports TYPE2 (Denali) */
378 dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800379 } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE4)) ||
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530380 (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE3))) {
381 /* driver doesn't TYPE3 and TYPE4 */
382 /* switch to sync. mode */
383 dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
384 dev->sync_mode = 1;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700385 }
386 }
Mark Haverkamp28713322007-01-23 14:59:20 -0800387 if ((dev->comm_interface == AAC_COMM_MESSAGE) &&
388 (status[2] > dev->base_size)) {
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700389 aac_adapter_ioremap(dev, 0);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700390 dev->base_size = status[2];
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700391 if (aac_adapter_ioremap(dev, status[2])) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700392 /* remap failed, go back ... */
Mark Haverkamp28713322007-01-23 14:59:20 -0800393 dev->comm_interface = AAC_COMM_PRODUCER;
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700394 if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700395 printk(KERN_WARNING
396 "aacraid: unable to map adapter.\n");
397 return NULL;
398 }
399 }
400 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700401 }
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400402 dev->max_msix = 0;
403 dev->msi_enabled = 0;
Mahesh Rajashekharaf9c42592015-03-26 10:41:29 -0400404 dev->adapter_shutdown = 0;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700405 if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS,
406 0, 0, 0, 0, 0, 0,
407 status+0, status+1, status+2, status+3, status+4))
408 && (status[0] == 0x00000001)) {
409 /*
410 * status[1] >> 16 maximum command size in KB
411 * status[1] & 0xFFFF maximum FIB size
412 * status[2] >> 16 maximum SG elements to driver
413 * status[2] & 0xFFFF maximum SG elements from driver
414 * status[3] & 0xFFFF maximum number FIBs outstanding
415 */
416 host->max_sectors = (status[1] >> 16) << 1;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700417 /* Multiple of 32 for PMC */
418 dev->max_fib_size = status[1] & 0xFFE0;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700419 host->sg_tablesize = status[2] >> 16;
420 dev->sg_tablesize = status[2] & 0xFFFF;
Mahesh Rajashekhara2b4df6e2013-01-10 17:52:51 +0530421 if (dev->pdev->device == PMC_DEVICE_S7 ||
422 dev->pdev->device == PMC_DEVICE_S8 ||
423 dev->pdev->device == PMC_DEVICE_S9)
424 host->can_queue = ((status[3] >> 16) ? (status[3] >> 16) :
425 (status[3] & 0xFFFF)) - AAC_NUM_MGT_FIB;
426 else
427 host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700428 dev->max_num_aif = status[4] & 0xFFFF;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700429 /*
430 * NOTE:
431 * All these overrides are based on a fixed internal
432 * knowledge and understanding of existing adapters,
433 * acbsize should be set with caution.
434 */
435 if (acbsize == 512) {
436 host->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
437 dev->max_fib_size = 512;
438 dev->sg_tablesize = host->sg_tablesize
439 = (512 - sizeof(struct aac_fibhdr)
Mark Haverkamp63a70ee2005-09-20 12:57:04 -0700440 - sizeof(struct aac_write) + sizeof(struct sgentry))
441 / sizeof(struct sgentry);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700442 host->can_queue = AAC_NUM_IO_FIB;
443 } else if (acbsize == 2048) {
444 host->max_sectors = 512;
445 dev->max_fib_size = 2048;
446 host->sg_tablesize = 65;
447 dev->sg_tablesize = 81;
448 host->can_queue = 512 - AAC_NUM_MGT_FIB;
449 } else if (acbsize == 4096) {
450 host->max_sectors = 1024;
451 dev->max_fib_size = 4096;
452 host->sg_tablesize = 129;
453 dev->sg_tablesize = 166;
454 host->can_queue = 256 - AAC_NUM_MGT_FIB;
455 } else if (acbsize == 8192) {
456 host->max_sectors = 2048;
457 dev->max_fib_size = 8192;
458 host->sg_tablesize = 257;
459 dev->sg_tablesize = 337;
460 host->can_queue = 128 - AAC_NUM_MGT_FIB;
461 } else if (acbsize > 0) {
462 printk("Illegal acbsize=%d ignored\n", acbsize);
463 }
464 }
465 {
466
467 if (numacb > 0) {
468 if (numacb < host->can_queue)
469 host->can_queue = numacb;
470 else
471 printk("numacb=%d ignored\n", numacb);
472 }
473 }
474
Mahesh Rajashekhara2b4df6e2013-01-10 17:52:51 +0530475 if (host->can_queue > AAC_NUM_IO_FIB)
476 host->can_queue = AAC_NUM_IO_FIB;
477
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400478 if (dev->pdev->device == PMC_DEVICE_S6 ||
479 dev->pdev->device == PMC_DEVICE_S7 ||
480 dev->pdev->device == PMC_DEVICE_S8 ||
481 dev->pdev->device == PMC_DEVICE_S9)
482 aac_define_int_mode(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 /*
484 * Ok now init the communication subsystem
485 */
486
Salyzyn, Mark4dbc22d2007-04-16 11:21:50 -0400487 dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 if (dev->queues == NULL) {
489 printk(KERN_ERR "Error could not allocate comm region.\n");
490 return NULL;
491 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 if (aac_comm_init(dev)<0){
494 kfree(dev->queues);
495 return NULL;
496 }
497 /*
498 * Initialize the list of fibs
499 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800500 if (aac_fib_setup(dev) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 kfree(dev->queues);
502 return NULL;
503 }
504
505 INIT_LIST_HEAD(&dev->fib_list);
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800506 INIT_LIST_HEAD(&dev->sync_fib_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508 return dev;
509}
510
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400511static void aac_define_int_mode(struct aac_dev *dev)
512{
513
514 int i, msi_count;
515
Mahesh Rajashekharaf9c42592015-03-26 10:41:29 -0400516 msi_count = i = 0;
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400517 /* max. vectors from GET_COMM_PREFERRED_SETTINGS */
518 if (dev->max_msix == 0 ||
519 dev->pdev->device == PMC_DEVICE_S6 ||
520 dev->sync_mode) {
521 dev->max_msix = 1;
522 dev->vector_cap =
523 dev->scsi_host_ptr->can_queue +
524 AAC_NUM_MGT_FIB;
525 return;
526 }
527
528 msi_count = min(dev->max_msix,
529 (unsigned int)num_online_cpus());
530
531 dev->max_msix = msi_count;
532
533 if (msi_count > AAC_MAX_MSIX)
534 msi_count = AAC_MAX_MSIX;
535
536 for (i = 0; i < msi_count; i++)
537 dev->msixentry[i].entry = i;
538
539 if (msi_count > 1 &&
540 pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
541 i = pci_enable_msix(dev->pdev,
542 dev->msixentry,
543 msi_count);
544 /* Check how many MSIX vectors are allocated */
545 if (i >= 0) {
546 dev->msi_enabled = 1;
547 if (i) {
548 msi_count = i;
549 if (pci_enable_msix(dev->pdev,
550 dev->msixentry,
551 msi_count)) {
552 dev->msi_enabled = 0;
553 printk(KERN_ERR "%s%d: MSIX not supported!! Will try MSI 0x%x.\n",
554 dev->name, dev->id, i);
555 }
556 }
557 } else {
558 dev->msi_enabled = 0;
559 printk(KERN_ERR "%s%d: MSIX not supported!! Will try MSI 0x%x.\n",
560 dev->name, dev->id, i);
561 }
562 }
563
564 if (!dev->msi_enabled) {
565 msi_count = 1;
566 i = pci_enable_msi(dev->pdev);
567
568 if (!i) {
569 dev->msi_enabled = 1;
570 dev->msi = 1;
571 } else {
572 printk(KERN_ERR "%s%d: MSI not supported!! Will try INTx 0x%x.\n",
573 dev->name, dev->id, i);
574 }
575 }
576
577 if (!dev->msi_enabled)
578 dev->max_msix = msi_count = 1;
579 else {
580 if (dev->max_msix > msi_count)
581 dev->max_msix = msi_count;
582 }
583 dev->vector_cap =
584 (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) /
585 msi_count;
586}