blob: 792d3e7e35e2ee1a64c793f80042a2087b9cc7cc [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>
Raghava Aditya Renukunta78cbccd2016-04-25 23:32:37 -070040#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/completion.h>
42#include <linux/mm.h>
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070043#include <scsi/scsi_host.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#include "aacraid.h"
46
Mark Haverkampbed30de2005-08-03 15:38:51 -070047struct aac_common aac_config = {
48 .irq_mod = 1
49};
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Raghava Aditya Renukunta78cbccd2016-04-25 23:32:37 -070051static inline int aac_is_msix_mode(struct aac_dev *dev)
52{
Dave Carroll5684c7d2017-02-09 11:04:47 -070053 u32 status = 0;
Raghava Aditya Renukunta78cbccd2016-04-25 23:32:37 -070054
Dave Carroll5684c7d2017-02-09 11:04:47 -070055 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 }
Raghava Aditya Renukunta78cbccd2016-04-25 23:32:37 -070060 return (status & AAC_INT_MODE_MSIX);
61}
62
63static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static 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;
Mahesh Rajashekharaef616232015-03-26 10:41:30 -040073 const unsigned long fibsize = dev->max_fib_size;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -070074 const unsigned long printfbufsiz = 256;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070075 unsigned long host_rrq_size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 struct aac_init *init;
77 dma_addr_t phys;
Leubner, Achimd8e965072009-04-01 07:16:08 -070078 unsigned long aac_max_hostphysmempages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +053080 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
81 dev->comm_interface == AAC_COMM_MESSAGE_TYPE2)
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -070082 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
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
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +053098 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 ||
99 dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700100 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 init = dev->init;
109
110 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700111 if (dev->max_fib_size != sizeof(struct hw_fib))
112 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
Raghava Aditya Renukuntaa6cd4542016-04-25 23:31:03 -0700113 init->Sa_MSIXVectors = cpu_to_le32(SA_INIT_NUM_MSIXVECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 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));
Leubner, Achimd8e965072009-04-01 07:16:08 -0700126 /*
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530139 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
Mark Haverkamp28713322007-01-23 14:59:20 -0800146 if (dev->comm_interface == AAC_COMM_MESSAGE) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700147 init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700148 dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700149 } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) {
150 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_6);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530151 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));
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400162 /* number of MSI-X */
163 init->Sa_MSIXVectors = cpu_to_le32(dev->max_msix);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530164 dprintk((KERN_WARNING"aacraid: New Comm Interface type2 enabled\n"));
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700165 }
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 /*
168 * Increment the base address by the amount already used
169 */
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700170 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 /*
175 * Align the beginning of Headers to commalign
176 */
Al Viro142956a2007-10-29 05:11:28 +0000177 align = (commalign - ((uintptr_t)(base) & (commalign - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 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
200static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize)
201{
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400202 atomic_set(&q->numpending, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 q->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 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;
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700209 q->headers.producer = (__le32 *)mem;
210 q->headers.consumer = (__le32 *)(mem+1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 *(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
223int aac_send_shutdown(struct aac_dev * dev)
224{
225 struct fib * fibctx;
226 struct aac_close *cmd;
227 int status;
228
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800229 fibctx = aac_fib_alloc(dev);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700230 if (!fibctx)
231 return -ENOMEM;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800232 aac_fib_init(fibctx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Raghava Aditya Renukuntafbd185982016-02-03 15:06:06 -0800234 mutex_lock(&dev->ioctl_mutex);
235 dev->adapter_shutdown = 1;
236 mutex_unlock(&dev->ioctl_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Raghava Aditya Renukuntafbd185982016-02-03 15:06:06 -0800238 cmd = (struct aac_close *) fib_data(fibctx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 cmd->command = cpu_to_le32(VM_CloseAll);
Mahesh Rajashekhara2c10cd42013-03-19 12:37:26 +0530240 cmd->cid = cpu_to_le32(0xfffffffe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800242 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 fibctx,
244 sizeof(struct aac_close),
245 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -0700246 -2 /* Timeout silently */, 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 NULL, NULL);
248
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700249 if (status >= 0)
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800250 aac_fib_complete(fibctx);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530251 /* FIB should be freed only after getting the response from the F/W */
252 if (status != -ERESTARTSYS)
253 aac_fib_free(fibctx);
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400254 if ((dev->pdev->device == PMC_DEVICE_S7 ||
255 dev->pdev->device == PMC_DEVICE_S8 ||
256 dev->pdev->device == PMC_DEVICE_S9) &&
257 dev->msi_enabled)
258 aac_src_access_devreg(dev, AAC_ENABLE_INTX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return status;
260}
261
262/**
263 * aac_comm_init - Initialise FSA data structures
264 * @dev: Adapter to initialise
265 *
266 * Initializes the data structures that are required for the FSA commuication
267 * interface to operate.
268 * Returns
269 * 1 - if we were able to init the commuication interface.
270 * 0 - If there were errors initing. This is a fatal error.
271 */
272
Adrian Bunk 48338692005-04-25 19:45:58 -0700273static int aac_comm_init(struct aac_dev * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
275 unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
276 unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
277 u32 *headers;
278 struct aac_entry * queues;
279 unsigned long size;
280 struct aac_queue_block * comm = dev->queues;
281 /*
282 * Now allocate and initialize the zone structures used as our
283 * pool of FIB context records. The size of the zone is based
284 * on the system memory size. We also initialize the mutex used
285 * to protect the zone.
286 */
287 spin_lock_init(&dev->fib_lock);
288
289 /*
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200290 * Allocate the physically contiguous space for the commuication
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 * queue headers.
292 */
293
294 size = hdrsize + queuesize;
295
296 if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT))
297 return -ENOMEM;
298
299 queues = (struct aac_entry *)(((ulong)headers) + hdrsize);
300
301 /* Adapter to Host normal priority Command queue */
302 comm->queue[HostNormCmdQueue].base = queues;
303 aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES);
304 queues += HOST_NORM_CMD_ENTRIES;
305 headers += 2;
306
307 /* Adapter to Host high priority command queue */
308 comm->queue[HostHighCmdQueue].base = queues;
309 aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES);
310
311 queues += HOST_HIGH_CMD_ENTRIES;
312 headers +=2;
313
314 /* Host to adapter normal priority command queue */
315 comm->queue[AdapNormCmdQueue].base = queues;
316 aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES);
317
318 queues += ADAP_NORM_CMD_ENTRIES;
319 headers += 2;
320
321 /* host to adapter high priority command queue */
322 comm->queue[AdapHighCmdQueue].base = queues;
323 aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES);
324
325 queues += ADAP_HIGH_CMD_ENTRIES;
326 headers += 2;
327
328 /* adapter to host normal priority response queue */
329 comm->queue[HostNormRespQueue].base = queues;
330 aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES);
331 queues += HOST_NORM_RESP_ENTRIES;
332 headers += 2;
333
334 /* adapter to host high priority response queue */
335 comm->queue[HostHighRespQueue].base = queues;
336 aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES);
337
338 queues += HOST_HIGH_RESP_ENTRIES;
339 headers += 2;
340
341 /* host to adapter normal priority response queue */
342 comm->queue[AdapNormRespQueue].base = queues;
343 aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES);
344
345 queues += ADAP_NORM_RESP_ENTRIES;
346 headers += 2;
347
348 /* host to adapter high priority response queue */
349 comm->queue[AdapHighRespQueue].base = queues;
350 aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES);
351
352 comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock;
353 comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock;
354 comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock;
355 comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock;
356
357 return 0;
358}
359
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400360void aac_define_int_mode(struct aac_dev *dev)
361{
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400362 int i, msi_count, min_msix;
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400363
364 msi_count = i = 0;
365 /* max. vectors from GET_COMM_PREFERRED_SETTINGS */
366 if (dev->max_msix == 0 ||
367 dev->pdev->device == PMC_DEVICE_S6 ||
368 dev->sync_mode) {
369 dev->max_msix = 1;
370 dev->vector_cap =
371 dev->scsi_host_ptr->can_queue +
372 AAC_NUM_MGT_FIB;
373 return;
374 }
375
376 /* Don't bother allocating more MSI-X vectors than cpus */
377 msi_count = min(dev->max_msix,
378 (unsigned int)num_online_cpus());
379
380 dev->max_msix = msi_count;
381
382 if (msi_count > AAC_MAX_MSIX)
383 msi_count = AAC_MAX_MSIX;
384
385 for (i = 0; i < msi_count; i++)
386 dev->msixentry[i].entry = i;
387
388 if (msi_count > 1 &&
389 pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400390 min_msix = 2;
391 i = pci_enable_msix_range(dev->pdev,
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400392 dev->msixentry,
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400393 min_msix,
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400394 msi_count);
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400395 if (i > 0) {
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400396 dev->msi_enabled = 1;
Mahesh Rajashekhara84859c92015-08-28 06:38:40 -0400397 msi_count = i;
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400398 } else {
399 dev->msi_enabled = 0;
Raghava Aditya Renukuntae4d5c4e2016-04-25 23:31:43 -0700400 dev_err(&dev->pdev->dev,
401 "MSIX not supported!! Will try INTX 0x%x.\n", i);
Mahesh Rajashekharade665f22015-08-28 06:38:34 -0400402 }
403 }
404
405 if (!dev->msi_enabled)
406 dev->max_msix = msi_count = 1;
407 else {
408 if (dev->max_msix > msi_count)
409 dev->max_msix = msi_count;
410 }
411 dev->vector_cap =
412 (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) /
413 msi_count;
414}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415struct aac_dev *aac_init_adapter(struct aac_dev *dev)
416{
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700417 u32 status[5];
418 struct Scsi_Host * host = dev->scsi_host_ptr;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800419 extern int aac_sync_mode;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700420
421 /*
422 * Check the preferred comm settings, defaults from template.
423 */
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530424 dev->management_fib_count = 0;
425 spin_lock_init(&dev->manage_lock);
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800426 spin_lock_init(&dev->sync_lock);
Mahesh Rajashekharac6992782015-08-28 06:38:36 -0400427 spin_lock_init(&dev->iq_lock);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700428 dev->max_fib_size = sizeof(struct hw_fib);
429 dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size
430 - sizeof(struct aac_fibhdr)
Mark Haverkamp63a70ee2005-09-20 12:57:04 -0700431 - sizeof(struct aac_write) + sizeof(struct sgentry))
432 / sizeof(struct sgentry);
Mark Haverkamp28713322007-01-23 14:59:20 -0800433 dev->comm_interface = AAC_COMM_PRODUCER;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700434 dev->raw_io_interface = dev->raw_io_64 = 0;
435
Raghava Aditya Renukunta78cbccd2016-04-25 23:32:37 -0700436
437 /*
438 * Enable INTX mode, if not done already Enabled
439 */
440 if (aac_is_msix_mode(dev)) {
441 aac_change_to_intx(dev);
442 dev_info(&dev->pdev->dev, "Changed firmware to INTX mode");
443 }
444
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700445 if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
Mahesh Rajashekharadafde942015-03-26 10:41:28 -0400446 0, 0, 0, 0, 0, 0,
447 status+0, status+1, status+2, status+3, NULL)) &&
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700448 (status[0] == 0x00000001)) {
Mahesh Rajashekharadafde942015-03-26 10:41:28 -0400449 dev->doorbell_mask = status[3];
Salyzyn, Marka3940da2008-01-08 12:48:25 -0800450 if (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_64))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700451 dev->raw_io_64 = 1;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800452 dev->sync_mode = aac_sync_mode;
453 if (dev->a_ops.adapter_comm &&
454 (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM))) {
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700455 dev->comm_interface = AAC_COMM_MESSAGE;
456 dev->raw_io_interface = 1;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800457 if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE1))) {
458 /* driver supports TYPE1 (Tupelo) */
459 dev->comm_interface = AAC_COMM_MESSAGE_TYPE1;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530460 } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE2))) {
461 /* driver supports TYPE2 (Denali) */
462 dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800463 } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE4)) ||
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530464 (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE3))) {
465 /* driver doesn't TYPE3 and TYPE4 */
466 /* switch to sync. mode */
467 dev->comm_interface = AAC_COMM_MESSAGE_TYPE2;
468 dev->sync_mode = 1;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700469 }
470 }
Mark Haverkamp28713322007-01-23 14:59:20 -0800471 if ((dev->comm_interface == AAC_COMM_MESSAGE) &&
472 (status[2] > dev->base_size)) {
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700473 aac_adapter_ioremap(dev, 0);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700474 dev->base_size = status[2];
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700475 if (aac_adapter_ioremap(dev, status[2])) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700476 /* remap failed, go back ... */
Mark Haverkamp28713322007-01-23 14:59:20 -0800477 dev->comm_interface = AAC_COMM_PRODUCER;
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700478 if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700479 printk(KERN_WARNING
480 "aacraid: unable to map adapter.\n");
481 return NULL;
482 }
483 }
484 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -0700485 }
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400486 dev->max_msix = 0;
487 dev->msi_enabled = 0;
Mahesh Rajashekharaf9c42592015-03-26 10:41:29 -0400488 dev->adapter_shutdown = 0;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700489 if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS,
490 0, 0, 0, 0, 0, 0,
491 status+0, status+1, status+2, status+3, status+4))
492 && (status[0] == 0x00000001)) {
493 /*
494 * status[1] >> 16 maximum command size in KB
495 * status[1] & 0xFFFF maximum FIB size
496 * status[2] >> 16 maximum SG elements to driver
497 * status[2] & 0xFFFF maximum SG elements from driver
498 * status[3] & 0xFFFF maximum number FIBs outstanding
499 */
500 host->max_sectors = (status[1] >> 16) << 1;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700501 /* Multiple of 32 for PMC */
502 dev->max_fib_size = status[1] & 0xFFE0;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700503 host->sg_tablesize = status[2] >> 16;
504 dev->sg_tablesize = status[2] & 0xFFFF;
Mahesh Rajashekhara2b4df6e2013-01-10 17:52:51 +0530505 if (dev->pdev->device == PMC_DEVICE_S7 ||
506 dev->pdev->device == PMC_DEVICE_S8 ||
507 dev->pdev->device == PMC_DEVICE_S9)
508 host->can_queue = ((status[3] >> 16) ? (status[3] >> 16) :
509 (status[3] & 0xFFFF)) - AAC_NUM_MGT_FIB;
510 else
511 host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700512 dev->max_num_aif = status[4] & 0xFFFF;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700513 /*
514 * NOTE:
515 * All these overrides are based on a fixed internal
516 * knowledge and understanding of existing adapters,
517 * acbsize should be set with caution.
518 */
519 if (acbsize == 512) {
520 host->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
521 dev->max_fib_size = 512;
522 dev->sg_tablesize = host->sg_tablesize
523 = (512 - sizeof(struct aac_fibhdr)
Mark Haverkamp63a70ee2005-09-20 12:57:04 -0700524 - sizeof(struct aac_write) + sizeof(struct sgentry))
525 / sizeof(struct sgentry);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700526 host->can_queue = AAC_NUM_IO_FIB;
527 } else if (acbsize == 2048) {
528 host->max_sectors = 512;
529 dev->max_fib_size = 2048;
530 host->sg_tablesize = 65;
531 dev->sg_tablesize = 81;
532 host->can_queue = 512 - AAC_NUM_MGT_FIB;
533 } else if (acbsize == 4096) {
534 host->max_sectors = 1024;
535 dev->max_fib_size = 4096;
536 host->sg_tablesize = 129;
537 dev->sg_tablesize = 166;
538 host->can_queue = 256 - AAC_NUM_MGT_FIB;
539 } else if (acbsize == 8192) {
540 host->max_sectors = 2048;
541 dev->max_fib_size = 8192;
542 host->sg_tablesize = 257;
543 dev->sg_tablesize = 337;
544 host->can_queue = 128 - AAC_NUM_MGT_FIB;
545 } else if (acbsize > 0) {
546 printk("Illegal acbsize=%d ignored\n", acbsize);
547 }
548 }
549 {
550
551 if (numacb > 0) {
552 if (numacb < host->can_queue)
553 host->can_queue = numacb;
554 else
555 printk("numacb=%d ignored\n", numacb);
556 }
557 }
558
Mahesh Rajashekhara2b4df6e2013-01-10 17:52:51 +0530559 if (host->can_queue > AAC_NUM_IO_FIB)
560 host->can_queue = AAC_NUM_IO_FIB;
561
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -0400562 if (dev->pdev->device == PMC_DEVICE_S6 ||
563 dev->pdev->device == PMC_DEVICE_S7 ||
564 dev->pdev->device == PMC_DEVICE_S8 ||
565 dev->pdev->device == PMC_DEVICE_S9)
566 aac_define_int_mode(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 /*
568 * Ok now init the communication subsystem
569 */
570
Salyzyn, Mark4dbc22d2007-04-16 11:21:50 -0400571 dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 if (dev->queues == NULL) {
573 printk(KERN_ERR "Error could not allocate comm region.\n");
574 return NULL;
575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 if (aac_comm_init(dev)<0){
578 kfree(dev->queues);
579 return NULL;
580 }
581 /*
582 * Initialize the list of fibs
583 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800584 if (aac_fib_setup(dev) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 kfree(dev->queues);
586 return NULL;
587 }
588
589 INIT_LIST_HEAD(&dev->fib_list);
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800590 INIT_LIST_HEAD(&dev->sync_fib_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 return dev;
593}
594