blob: 0e954e37f0b5f3923980ee684e55ffef5b296510 [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
Mark Haverkampbed30de2005-08-03 15:38:51 -070046struct aac_common aac_config = {
47 .irq_mod = 1
48};
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign)
51{
52 unsigned char *base;
53 unsigned long size, align;
Mahesh Rajashekharaef616232015-03-26 10:41:30 -040054 const unsigned long fibsize = dev->max_fib_size;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070055 const unsigned long printfbufsiz = 256;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070056 unsigned long host_rrq_size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 struct aac_init *init;
58 dma_addr_t phys;
Leubner, Achimd8e965072009-04-01 07:16:08 -070059 unsigned long aac_max_hostphysmempages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +053061 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
62 dev->comm_interface == AAC_COMM_MESSAGE_TYPE2)
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070063 host_rrq_size = (dev->scsi_host_ptr->can_queue
64 + AAC_NUM_MGT_FIB) * sizeof(u32);
65 size = fibsize + sizeof(struct aac_init) + commsize +
66 commalign + printfbufsiz + host_rrq_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 base = pci_alloc_consistent(dev->pdev, size, &phys);
69
70 if(base == NULL)
71 {
72 printk(KERN_ERR "aacraid: unable to create mapping.\n");
73 return 0;
74 }
75 dev->comm_addr = (void *)base;
76 dev->comm_phys = phys;
77 dev->comm_size = size;
78
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +053079 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
80 dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070081 dev->host_rrq = (u32 *)(base + fibsize);
82 dev->host_rrq_pa = phys + fibsize;
83 memset(dev->host_rrq, 0, host_rrq_size);
84 }
85
86 dev->init = (struct aac_init *)(base + fibsize + host_rrq_size);
87 dev->init_pa = phys + fibsize + host_rrq_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 init = dev->init;
90
91 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070092 if (dev->max_fib_size != sizeof(struct hw_fib))
93 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -040094 init->Sa_MSIXVectors = cpu_to_le32(Sa_MINIPORT_REVISION);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 init->fsrev = cpu_to_le32(dev->fsrev);
96
97 /*
98 * Adapter Fibs are the first thing allocated so that they
99 * start page aligned
100 */
101 dev->aif_base_va = (struct hw_fib *)base;
102
103 init->AdapterFibsVirtualAddress = 0;
104 init->AdapterFibsPhysicalAddress = cpu_to_le32((u32)phys);
105 init->AdapterFibsSize = cpu_to_le32(fibsize);
106 init->AdapterFibAlign = cpu_to_le32(sizeof(struct hw_fib));
Leubner, Achimd8e965072009-04-01 07:16:08 -0700107 /*
108 * number of 4k pages of host physical memory. The aacraid fw needs
109 * this number to be less than 4gb worth of pages. New firmware doesn't
110 * have any issues with the mapping system, but older Firmware did, and
111 * had *troubles* dealing with the math overloading past 32 bits, thus
112 * we must limit this field.
113 */
114 aac_max_hostphysmempages = dma_get_required_mask(&dev->pdev->dev) >> 12;
115 if (aac_max_hostphysmempages < AAC_MAX_HOSTPHYSMEMPAGES)
116 init->HostPhysMemPages = cpu_to_le32(aac_max_hostphysmempages);
117 else
118 init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530120 init->InitFlags = cpu_to_le32(INITFLAGS_DRIVER_USES_UTC_TIME |
121 INITFLAGS_DRIVER_SUPPORTS_PM);
122 init->MaxIoCommands = cpu_to_le32(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
123 init->MaxIoSize = cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
124 init->MaxFibSize = cpu_to_le32(dev->max_fib_size);
125 init->MaxNumAif = cpu_to_le32(dev->max_num_aif);
126
Mark Haverkamp28713322007-01-23 14:59:20 -0800127 if (dev->comm_interface == AAC_COMM_MESSAGE) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700128 init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700129 dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700130 } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) {
131 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_6);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530132 init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
133 INITFLAGS_NEW_COMM_TYPE1_SUPPORTED | INITFLAGS_FAST_JBOD_SUPPORTED);
134 init->HostRRQ_AddrHigh = cpu_to_le32((u32)((u64)dev->host_rrq_pa >> 32));
135 init->HostRRQ_AddrLow = cpu_to_le32((u32)(dev->host_rrq_pa & 0xffffffff));
136 dprintk((KERN_WARNING"aacraid: New Comm Interface type1 enabled\n"));
137 } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
138 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_7);
139 init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED |
140 INITFLAGS_NEW_COMM_TYPE2_SUPPORTED | INITFLAGS_FAST_JBOD_SUPPORTED);
141 init->HostRRQ_AddrHigh = cpu_to_le32((u32)((u64)dev->host_rrq_pa >> 32));
142 init->HostRRQ_AddrLow = cpu_to_le32((u32)(dev->host_rrq_pa & 0xffffffff));
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400143 /* number of MSI-X */
144 init->Sa_MSIXVectors = cpu_to_le32(dev->max_msix);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530145 dprintk((KERN_WARNING"aacraid: New Comm Interface type2 enabled\n"));
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700146 }
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 /*
149 * Increment the base address by the amount already used
150 */
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700151 base = base + fibsize + host_rrq_size + sizeof(struct aac_init);
152 phys = (dma_addr_t)((ulong)phys + fibsize + host_rrq_size +
153 sizeof(struct aac_init));
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 /*
156 * Align the beginning of Headers to commalign
157 */
Al Viro142956a2007-10-29 05:11:28 +0000158 align = (commalign - ((uintptr_t)(base) & (commalign - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 base = base + align;
160 phys = phys + align;
161 /*
162 * Fill in addresses of the Comm Area Headers and Queues
163 */
164 *commaddr = base;
165 init->CommHeaderAddress = cpu_to_le32((u32)phys);
166 /*
167 * Increment the base address by the size of the CommArea
168 */
169 base = base + commsize;
170 phys = phys + commsize;
171 /*
172 * Place the Printf buffer area after the Fast I/O comm area.
173 */
174 dev->printfbuf = (void *)base;
175 init->printfbuf = cpu_to_le32(phys);
176 init->printfbufsiz = cpu_to_le32(printfbufsiz);
177 memset(base, 0, printfbufsiz);
178 return 1;
179}
180
181static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize)
182{
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400183 atomic_set(&q->numpending, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 q->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 init_waitqueue_head(&q->cmdready);
186 INIT_LIST_HEAD(&q->cmdq);
187 init_waitqueue_head(&q->qfull);
188 spin_lock_init(&q->lockdata);
189 q->lock = &q->lockdata;
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700190 q->headers.producer = (__le32 *)mem;
191 q->headers.consumer = (__le32 *)(mem+1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 *(q->headers.producer) = cpu_to_le32(qsize);
193 *(q->headers.consumer) = cpu_to_le32(qsize);
194 q->entries = qsize;
195}
196
197/**
198 * aac_send_shutdown - shutdown an adapter
199 * @dev: Adapter to shutdown
200 *
201 * This routine will send a VM_CloseAll (shutdown) request to the adapter.
202 */
203
204int aac_send_shutdown(struct aac_dev * dev)
205{
206 struct fib * fibctx;
207 struct aac_close *cmd;
208 int status;
209
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800210 fibctx = aac_fib_alloc(dev);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700211 if (!fibctx)
212 return -ENOMEM;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800213 aac_fib_init(fibctx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 cmd = (struct aac_close *) fib_data(fibctx);
216
217 cmd->command = cpu_to_le32(VM_CloseAll);
Mahesh Rajashekhara2c10cd42013-03-19 12:37:26 +0530218 cmd->cid = cpu_to_le32(0xfffffffe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800220 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 fibctx,
222 sizeof(struct aac_close),
223 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -0700224 -2 /* Timeout silently */, 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 NULL, NULL);
226
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700227 if (status >= 0)
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800228 aac_fib_complete(fibctx);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530229 /* FIB should be freed only after getting the response from the F/W */
230 if (status != -ERESTARTSYS)
231 aac_fib_free(fibctx);
Mahesh Rajashekharaf9c42592015-03-26 10:41:29 -0400232 dev->adapter_shutdown = 1;
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400233 if ((dev->pdev->device == PMC_DEVICE_S7 ||
234 dev->pdev->device == PMC_DEVICE_S8 ||
235 dev->pdev->device == PMC_DEVICE_S9) &&
236 dev->msi_enabled)
237 aac_src_access_devreg(dev, AAC_ENABLE_INTX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return status;
239}
240
241/**
242 * aac_comm_init - Initialise FSA data structures
243 * @dev: Adapter to initialise
244 *
245 * Initializes the data structures that are required for the FSA commuication
246 * interface to operate.
247 * Returns
248 * 1 - if we were able to init the commuication interface.
249 * 0 - If there were errors initing. This is a fatal error.
250 */
251
Adrian Bunk 48338692005-04-25 19:45:58 -0700252static int aac_comm_init(struct aac_dev * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
254 unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
255 unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
256 u32 *headers;
257 struct aac_entry * queues;
258 unsigned long size;
259 struct aac_queue_block * comm = dev->queues;
260 /*
261 * Now allocate and initialize the zone structures used as our
262 * pool of FIB context records. The size of the zone is based
263 * on the system memory size. We also initialize the mutex used
264 * to protect the zone.
265 */
266 spin_lock_init(&dev->fib_lock);
267
268 /*
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200269 * Allocate the physically contiguous space for the commuication
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 * queue headers.
271 */
272
273 size = hdrsize + queuesize;
274
275 if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT))
276 return -ENOMEM;
277
278 queues = (struct aac_entry *)(((ulong)headers) + hdrsize);
279
280 /* Adapter to Host normal priority Command queue */
281 comm->queue[HostNormCmdQueue].base = queues;
282 aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES);
283 queues += HOST_NORM_CMD_ENTRIES;
284 headers += 2;
285
286 /* Adapter to Host high priority command queue */
287 comm->queue[HostHighCmdQueue].base = queues;
288 aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES);
289
290 queues += HOST_HIGH_CMD_ENTRIES;
291 headers +=2;
292
293 /* Host to adapter normal priority command queue */
294 comm->queue[AdapNormCmdQueue].base = queues;
295 aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES);
296
297 queues += ADAP_NORM_CMD_ENTRIES;
298 headers += 2;
299
300 /* host to adapter high priority command queue */
301 comm->queue[AdapHighCmdQueue].base = queues;
302 aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES);
303
304 queues += ADAP_HIGH_CMD_ENTRIES;
305 headers += 2;
306
307 /* adapter to host normal priority response queue */
308 comm->queue[HostNormRespQueue].base = queues;
309 aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES);
310 queues += HOST_NORM_RESP_ENTRIES;
311 headers += 2;
312
313 /* adapter to host high priority response queue */
314 comm->queue[HostHighRespQueue].base = queues;
315 aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES);
316
317 queues += HOST_HIGH_RESP_ENTRIES;
318 headers += 2;
319
320 /* host to adapter normal priority response queue */
321 comm->queue[AdapNormRespQueue].base = queues;
322 aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES);
323
324 queues += ADAP_NORM_RESP_ENTRIES;
325 headers += 2;
326
327 /* host to adapter high priority response queue */
328 comm->queue[AdapHighRespQueue].base = queues;
329 aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES);
330
331 comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock;
332 comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock;
333 comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock;
334 comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock;
335
336 return 0;
337}
338
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400339void aac_define_int_mode(struct aac_dev *dev)
340{
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400341 int i, msi_count, min_msix;
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400342
343 msi_count = i = 0;
344 /* max. vectors from GET_COMM_PREFERRED_SETTINGS */
345 if (dev->max_msix == 0 ||
346 dev->pdev->device == PMC_DEVICE_S6 ||
347 dev->sync_mode) {
348 dev->max_msix = 1;
349 dev->vector_cap =
350 dev->scsi_host_ptr->can_queue +
351 AAC_NUM_MGT_FIB;
352 return;
353 }
354
355 /* Don't bother allocating more MSI-X vectors than cpus */
356 msi_count = min(dev->max_msix,
357 (unsigned int)num_online_cpus());
358
359 dev->max_msix = msi_count;
360
361 if (msi_count > AAC_MAX_MSIX)
362 msi_count = AAC_MAX_MSIX;
363
364 for (i = 0; i < msi_count; i++)
365 dev->msixentry[i].entry = i;
366
367 if (msi_count > 1 &&
368 pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400369 min_msix = 2;
370 i = pci_enable_msix_range(dev->pdev,
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400371 dev->msixentry,
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400372 min_msix,
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400373 msi_count);
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400374 if (i > 0) {
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400375 dev->msi_enabled = 1;
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400376 msi_count = i;
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400377 } else {
378 dev->msi_enabled = 0;
379 printk(KERN_ERR "%s%d: MSIX not supported!! Will try MSI 0x%x.\n",
380 dev->name, dev->id, i);
381 }
382 }
383
384 if (!dev->msi_enabled) {
385 msi_count = 1;
386 i = pci_enable_msi(dev->pdev);
387
388 if (!i) {
389 dev->msi_enabled = 1;
390 dev->msi = 1;
391 } else {
392 printk(KERN_ERR "%s%d: MSI not supported!! Will try INTx 0x%x.\n",
393 dev->name, dev->id, i);
394 }
395 }
396
397 if (!dev->msi_enabled)
398 dev->max_msix = msi_count = 1;
399 else {
400 if (dev->max_msix > msi_count)
401 dev->max_msix = msi_count;
402 }
403 dev->vector_cap =
404 (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) /
405 msi_count;
406}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407struct aac_dev *aac_init_adapter(struct aac_dev *dev)
408{
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700409 u32 status[5];
410 struct Scsi_Host * host = dev->scsi_host_ptr;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800411 extern int aac_sync_mode;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700412
413 /*
414 * Check the preferred comm settings, defaults from template.
415 */
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530416 dev->management_fib_count = 0;
417 spin_lock_init(&dev->manage_lock);
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800418 spin_lock_init(&dev->sync_lock);
Mahesh Rajashekharac6992782015-08-28 06:38:36 -0400419 spin_lock_init(&dev->iq_lock);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700420 dev->max_fib_size = sizeof(struct hw_fib);
421 dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size
422 - sizeof(struct aac_fibhdr)
Mark Haverkamp63a70ee2005-09-20 12:57:04 -0700423 - sizeof(struct aac_write) + sizeof(struct sgentry))
424 / sizeof(struct sgentry);
Mark Haverkamp28713322007-01-23 14:59:20 -0800425 dev->comm_interface = AAC_COMM_PRODUCER;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700426 dev->raw_io_interface = dev->raw_io_64 = 0;
427
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700428 if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
Mahesh Rajashekharadafde942015-03-26 10:41:28 -0400429 0, 0, 0, 0, 0, 0,
430 status+0, status+1, status+2, status+3, NULL)) &&
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700431 (status[0] == 0x00000001)) {
Mahesh Rajashekharadafde942015-03-26 10:41:28 -0400432 dev->doorbell_mask = status[3];
Salyzyn, Marka3940da2008-01-08 12:48:25 -0800433 if (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_64))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700434 dev->raw_io_64 = 1;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800435 dev->sync_mode = aac_sync_mode;
436 if (dev->a_ops.adapter_comm &&
437 (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM))) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700438 dev->comm_interface = AAC_COMM_MESSAGE;
439 dev->raw_io_interface = 1;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800440 if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE1))) {
441 /* driver supports TYPE1 (Tupelo) */
442 dev->comm_interface = AAC_COMM_MESSAGE_TYPE1;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530443 } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE2))) {
444 /* driver supports TYPE2 (Denali) */
445 dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800446 } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE4)) ||
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530447 (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE3))) {
448 /* driver doesn't TYPE3 and TYPE4 */
449 /* switch to sync. mode */
450 dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
451 dev->sync_mode = 1;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700452 }
453 }
Mark Haverkamp28713322007-01-23 14:59:20 -0800454 if ((dev->comm_interface == AAC_COMM_MESSAGE) &&
455 (status[2] > dev->base_size)) {
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700456 aac_adapter_ioremap(dev, 0);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700457 dev->base_size = status[2];
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700458 if (aac_adapter_ioremap(dev, status[2])) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700459 /* remap failed, go back ... */
Mark Haverkamp28713322007-01-23 14:59:20 -0800460 dev->comm_interface = AAC_COMM_PRODUCER;
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700461 if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700462 printk(KERN_WARNING
463 "aacraid: unable to map adapter.\n");
464 return NULL;
465 }
466 }
467 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700468 }
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400469 dev->max_msix = 0;
470 dev->msi_enabled = 0;
Mahesh Rajashekharaf9c42592015-03-26 10:41:29 -0400471 dev->adapter_shutdown = 0;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700472 if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS,
473 0, 0, 0, 0, 0, 0,
474 status+0, status+1, status+2, status+3, status+4))
475 && (status[0] == 0x00000001)) {
476 /*
477 * status[1] >> 16 maximum command size in KB
478 * status[1] & 0xFFFF maximum FIB size
479 * status[2] >> 16 maximum SG elements to driver
480 * status[2] & 0xFFFF maximum SG elements from driver
481 * status[3] & 0xFFFF maximum number FIBs outstanding
482 */
483 host->max_sectors = (status[1] >> 16) << 1;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700484 /* Multiple of 32 for PMC */
485 dev->max_fib_size = status[1] & 0xFFE0;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700486 host->sg_tablesize = status[2] >> 16;
487 dev->sg_tablesize = status[2] & 0xFFFF;
Mahesh Rajashekhara2b4df6e2013-01-10 17:52:51 +0530488 if (dev->pdev->device == PMC_DEVICE_S7 ||
489 dev->pdev->device == PMC_DEVICE_S8 ||
490 dev->pdev->device == PMC_DEVICE_S9)
491 host->can_queue = ((status[3] >> 16) ? (status[3] >> 16) :
492 (status[3] & 0xFFFF)) - AAC_NUM_MGT_FIB;
493 else
494 host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700495 dev->max_num_aif = status[4] & 0xFFFF;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700496 /*
497 * NOTE:
498 * All these overrides are based on a fixed internal
499 * knowledge and understanding of existing adapters,
500 * acbsize should be set with caution.
501 */
502 if (acbsize == 512) {
503 host->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
504 dev->max_fib_size = 512;
505 dev->sg_tablesize = host->sg_tablesize
506 = (512 - sizeof(struct aac_fibhdr)
Mark Haverkamp63a70ee2005-09-20 12:57:04 -0700507 - sizeof(struct aac_write) + sizeof(struct sgentry))
508 / sizeof(struct sgentry);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700509 host->can_queue = AAC_NUM_IO_FIB;
510 } else if (acbsize == 2048) {
511 host->max_sectors = 512;
512 dev->max_fib_size = 2048;
513 host->sg_tablesize = 65;
514 dev->sg_tablesize = 81;
515 host->can_queue = 512 - AAC_NUM_MGT_FIB;
516 } else if (acbsize == 4096) {
517 host->max_sectors = 1024;
518 dev->max_fib_size = 4096;
519 host->sg_tablesize = 129;
520 dev->sg_tablesize = 166;
521 host->can_queue = 256 - AAC_NUM_MGT_FIB;
522 } else if (acbsize == 8192) {
523 host->max_sectors = 2048;
524 dev->max_fib_size = 8192;
525 host->sg_tablesize = 257;
526 dev->sg_tablesize = 337;
527 host->can_queue = 128 - AAC_NUM_MGT_FIB;
528 } else if (acbsize > 0) {
529 printk("Illegal acbsize=%d ignored\n", acbsize);
530 }
531 }
532 {
533
534 if (numacb > 0) {
535 if (numacb < host->can_queue)
536 host->can_queue = numacb;
537 else
538 printk("numacb=%d ignored\n", numacb);
539 }
540 }
541
Mahesh Rajashekhara2b4df6e2013-01-10 17:52:51 +0530542 if (host->can_queue > AAC_NUM_IO_FIB)
543 host->can_queue = AAC_NUM_IO_FIB;
544
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400545 if (dev->pdev->device == PMC_DEVICE_S6 ||
546 dev->pdev->device == PMC_DEVICE_S7 ||
547 dev->pdev->device == PMC_DEVICE_S8 ||
548 dev->pdev->device == PMC_DEVICE_S9)
549 aac_define_int_mode(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 /*
551 * Ok now init the communication subsystem
552 */
553
Salyzyn, Mark4dbc22d2007-04-16 11:21:50 -0400554 dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 if (dev->queues == NULL) {
556 printk(KERN_ERR "Error could not allocate comm region.\n");
557 return NULL;
558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 if (aac_comm_init(dev)<0){
561 kfree(dev->queues);
562 return NULL;
563 }
564 /*
565 * Initialize the list of fibs
566 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800567 if (aac_fib_setup(dev) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 kfree(dev->queues);
569 return NULL;
570 }
571
572 INIT_LIST_HEAD(&dev->fib_list);
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800573 INIT_LIST_HEAD(&dev->sync_fib_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
575 return dev;
576}
577