Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Adaptec AAC series RAID controller driver |
Alan Cox | fa195af | 2008-10-27 15:16:36 +0000 | [diff] [blame] | 3 | * (c) Copyright 2001 Red Hat Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * based on the old aacraid driver that is.. |
| 6 | * Adaptec aacraid device driver for Linux. |
| 7 | * |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 8 | * Copyright (c) 2000-2010 Adaptec, Inc. |
| 9 | * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 42 | #include <scsi/scsi_host.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #include "aacraid.h" |
| 45 | |
Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 46 | struct aac_common aac_config = { |
| 47 | .irq_mod = 1 |
| 48 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | static 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; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 54 | const unsigned long fibsize = 4096; |
| 55 | const unsigned long printfbufsiz = 256; |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 56 | unsigned long host_rrq_size = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | struct aac_init *init; |
| 58 | dma_addr_t phys; |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 59 | unsigned long aac_max_hostphysmempages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 61 | if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 || |
| 62 | dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 63 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 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 Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 79 | if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1 || |
| 80 | dev->comm_interface == AAC_COMM_MESSAGE_TYPE2) { |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 81 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | init = dev->init; |
| 90 | |
| 91 | init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 92 | if (dev->max_fib_size != sizeof(struct hw_fib)) |
| 93 | init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | init->MiniPortRevision = cpu_to_le32(Sa_MINIPORT_REVISION); |
| 95 | 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, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 107 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 120 | 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 Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 127 | if (dev->comm_interface == AAC_COMM_MESSAGE) { |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 128 | init->InitFlags |= cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 129 | dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n")); |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 130 | } else if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE1) { |
| 131 | init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_6); |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 132 | 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)); |
| 143 | init->MiniPortRevision = cpu_to_le32(0L); /* number of MSI-X */ |
| 144 | dprintk((KERN_WARNING"aacraid: New Comm Interface type2 enabled\n")); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 145 | } |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* |
| 148 | * Increment the base address by the amount already used |
| 149 | */ |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 150 | base = base + fibsize + host_rrq_size + sizeof(struct aac_init); |
| 151 | phys = (dma_addr_t)((ulong)phys + fibsize + host_rrq_size + |
| 152 | sizeof(struct aac_init)); |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | /* |
| 155 | * Align the beginning of Headers to commalign |
| 156 | */ |
Al Viro | 142956a | 2007-10-29 05:11:28 +0000 | [diff] [blame] | 157 | align = (commalign - ((uintptr_t)(base) & (commalign - 1))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | base = base + align; |
| 159 | phys = phys + align; |
| 160 | /* |
| 161 | * Fill in addresses of the Comm Area Headers and Queues |
| 162 | */ |
| 163 | *commaddr = base; |
| 164 | init->CommHeaderAddress = cpu_to_le32((u32)phys); |
| 165 | /* |
| 166 | * Increment the base address by the size of the CommArea |
| 167 | */ |
| 168 | base = base + commsize; |
| 169 | phys = phys + commsize; |
| 170 | /* |
| 171 | * Place the Printf buffer area after the Fast I/O comm area. |
| 172 | */ |
| 173 | dev->printfbuf = (void *)base; |
| 174 | init->printfbuf = cpu_to_le32(phys); |
| 175 | init->printfbufsiz = cpu_to_le32(printfbufsiz); |
| 176 | memset(base, 0, printfbufsiz); |
| 177 | return 1; |
| 178 | } |
| 179 | |
| 180 | static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize) |
| 181 | { |
| 182 | q->numpending = 0; |
| 183 | q->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | init_waitqueue_head(&q->cmdready); |
| 185 | INIT_LIST_HEAD(&q->cmdq); |
| 186 | init_waitqueue_head(&q->qfull); |
| 187 | spin_lock_init(&q->lockdata); |
| 188 | q->lock = &q->lockdata; |
Mark Haverkamp | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 189 | q->headers.producer = (__le32 *)mem; |
| 190 | q->headers.consumer = (__le32 *)(mem+1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | *(q->headers.producer) = cpu_to_le32(qsize); |
| 192 | *(q->headers.consumer) = cpu_to_le32(qsize); |
| 193 | q->entries = qsize; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * aac_send_shutdown - shutdown an adapter |
| 198 | * @dev: Adapter to shutdown |
| 199 | * |
| 200 | * This routine will send a VM_CloseAll (shutdown) request to the adapter. |
| 201 | */ |
| 202 | |
| 203 | int aac_send_shutdown(struct aac_dev * dev) |
| 204 | { |
| 205 | struct fib * fibctx; |
| 206 | struct aac_close *cmd; |
| 207 | int status; |
| 208 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 209 | fibctx = aac_fib_alloc(dev); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 210 | if (!fibctx) |
| 211 | return -ENOMEM; |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 212 | aac_fib_init(fibctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | cmd = (struct aac_close *) fib_data(fibctx); |
| 215 | |
| 216 | cmd->command = cpu_to_le32(VM_CloseAll); |
Mahesh Rajashekhara | 2c10cd4 | 2013-03-19 12:37:26 +0530 | [diff] [blame] | 217 | cmd->cid = cpu_to_le32(0xfffffffe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 219 | status = aac_fib_send(ContainerCommand, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | fibctx, |
| 221 | sizeof(struct aac_close), |
| 222 | FsaNormal, |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 223 | -2 /* Timeout silently */, 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | NULL, NULL); |
| 225 | |
Mark Haverkamp | 90ee346 | 2006-08-03 08:03:07 -0700 | [diff] [blame] | 226 | if (status >= 0) |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 227 | aac_fib_complete(fibctx); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 228 | /* FIB should be freed only after getting the response from the F/W */ |
| 229 | if (status != -ERESTARTSYS) |
| 230 | aac_fib_free(fibctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | return status; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * aac_comm_init - Initialise FSA data structures |
| 236 | * @dev: Adapter to initialise |
| 237 | * |
| 238 | * Initializes the data structures that are required for the FSA commuication |
| 239 | * interface to operate. |
| 240 | * Returns |
| 241 | * 1 - if we were able to init the commuication interface. |
| 242 | * 0 - If there were errors initing. This is a fatal error. |
| 243 | */ |
| 244 | |
Adrian Bunk | 4833869 | 2005-04-25 19:45:58 -0700 | [diff] [blame] | 245 | static int aac_comm_init(struct aac_dev * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
| 247 | unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2; |
| 248 | unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES; |
| 249 | u32 *headers; |
| 250 | struct aac_entry * queues; |
| 251 | unsigned long size; |
| 252 | struct aac_queue_block * comm = dev->queues; |
| 253 | /* |
| 254 | * Now allocate and initialize the zone structures used as our |
| 255 | * pool of FIB context records. The size of the zone is based |
| 256 | * on the system memory size. We also initialize the mutex used |
| 257 | * to protect the zone. |
| 258 | */ |
| 259 | spin_lock_init(&dev->fib_lock); |
| 260 | |
| 261 | /* |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 262 | * Allocate the physically contiguous space for the commuication |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | * queue headers. |
| 264 | */ |
| 265 | |
| 266 | size = hdrsize + queuesize; |
| 267 | |
| 268 | if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT)) |
| 269 | return -ENOMEM; |
| 270 | |
| 271 | queues = (struct aac_entry *)(((ulong)headers) + hdrsize); |
| 272 | |
| 273 | /* Adapter to Host normal priority Command queue */ |
| 274 | comm->queue[HostNormCmdQueue].base = queues; |
| 275 | aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES); |
| 276 | queues += HOST_NORM_CMD_ENTRIES; |
| 277 | headers += 2; |
| 278 | |
| 279 | /* Adapter to Host high priority command queue */ |
| 280 | comm->queue[HostHighCmdQueue].base = queues; |
| 281 | aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES); |
| 282 | |
| 283 | queues += HOST_HIGH_CMD_ENTRIES; |
| 284 | headers +=2; |
| 285 | |
| 286 | /* Host to adapter normal priority command queue */ |
| 287 | comm->queue[AdapNormCmdQueue].base = queues; |
| 288 | aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES); |
| 289 | |
| 290 | queues += ADAP_NORM_CMD_ENTRIES; |
| 291 | headers += 2; |
| 292 | |
| 293 | /* host to adapter high priority command queue */ |
| 294 | comm->queue[AdapHighCmdQueue].base = queues; |
| 295 | aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES); |
| 296 | |
| 297 | queues += ADAP_HIGH_CMD_ENTRIES; |
| 298 | headers += 2; |
| 299 | |
| 300 | /* adapter to host normal priority response queue */ |
| 301 | comm->queue[HostNormRespQueue].base = queues; |
| 302 | aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES); |
| 303 | queues += HOST_NORM_RESP_ENTRIES; |
| 304 | headers += 2; |
| 305 | |
| 306 | /* adapter to host high priority response queue */ |
| 307 | comm->queue[HostHighRespQueue].base = queues; |
| 308 | aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES); |
| 309 | |
| 310 | queues += HOST_HIGH_RESP_ENTRIES; |
| 311 | headers += 2; |
| 312 | |
| 313 | /* host to adapter normal priority response queue */ |
| 314 | comm->queue[AdapNormRespQueue].base = queues; |
| 315 | aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES); |
| 316 | |
| 317 | queues += ADAP_NORM_RESP_ENTRIES; |
| 318 | headers += 2; |
| 319 | |
| 320 | /* host to adapter high priority response queue */ |
| 321 | comm->queue[AdapHighRespQueue].base = queues; |
| 322 | aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES); |
| 323 | |
| 324 | comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock; |
| 325 | comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock; |
| 326 | comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock; |
| 327 | comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock; |
| 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | struct aac_dev *aac_init_adapter(struct aac_dev *dev) |
| 333 | { |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 334 | u32 status[5]; |
| 335 | struct Scsi_Host * host = dev->scsi_host_ptr; |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame] | 336 | extern int aac_sync_mode; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 337 | |
| 338 | /* |
| 339 | * Check the preferred comm settings, defaults from template. |
| 340 | */ |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 341 | dev->management_fib_count = 0; |
| 342 | spin_lock_init(&dev->manage_lock); |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame] | 343 | spin_lock_init(&dev->sync_lock); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 344 | dev->max_fib_size = sizeof(struct hw_fib); |
| 345 | dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size |
| 346 | - sizeof(struct aac_fibhdr) |
Mark Haverkamp | 63a70ee | 2005-09-20 12:57:04 -0700 | [diff] [blame] | 347 | - sizeof(struct aac_write) + sizeof(struct sgentry)) |
| 348 | / sizeof(struct sgentry); |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 349 | dev->comm_interface = AAC_COMM_PRODUCER; |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 350 | dev->raw_io_interface = dev->raw_io_64 = 0; |
| 351 | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 352 | if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES, |
| 353 | 0, 0, 0, 0, 0, 0, status+0, status+1, status+2, NULL, NULL)) && |
| 354 | (status[0] == 0x00000001)) { |
Salyzyn, Mark | a3940da | 2008-01-08 12:48:25 -0800 | [diff] [blame] | 355 | if (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_64)) |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 356 | dev->raw_io_64 = 1; |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame] | 357 | dev->sync_mode = aac_sync_mode; |
| 358 | if (dev->a_ops.adapter_comm && |
| 359 | (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM))) { |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 360 | dev->comm_interface = AAC_COMM_MESSAGE; |
| 361 | dev->raw_io_interface = 1; |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame] | 362 | if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE1))) { |
| 363 | /* driver supports TYPE1 (Tupelo) */ |
| 364 | dev->comm_interface = AAC_COMM_MESSAGE_TYPE1; |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 365 | } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE2))) { |
| 366 | /* driver supports TYPE2 (Denali) */ |
| 367 | dev->comm_interface = AAC_COMM_MESSAGE_TYPE2; |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame] | 368 | } else if ((status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE4)) || |
Mahesh Rajashekhara | 85d22bb | 2012-07-14 18:18:51 +0530 | [diff] [blame] | 369 | (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_TYPE3))) { |
| 370 | /* driver doesn't TYPE3 and TYPE4 */ |
| 371 | /* switch to sync. mode */ |
| 372 | dev->comm_interface = AAC_COMM_MESSAGE_TYPE2; |
| 373 | dev->sync_mode = 1; |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 376 | if ((dev->comm_interface == AAC_COMM_MESSAGE) && |
| 377 | (status[2] > dev->base_size)) { |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 378 | aac_adapter_ioremap(dev, 0); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 379 | dev->base_size = status[2]; |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 380 | if (aac_adapter_ioremap(dev, status[2])) { |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 381 | /* remap failed, go back ... */ |
Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 382 | dev->comm_interface = AAC_COMM_PRODUCER; |
Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 383 | if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) { |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 384 | printk(KERN_WARNING |
| 385 | "aacraid: unable to map adapter.\n"); |
| 386 | return NULL; |
| 387 | } |
| 388 | } |
| 389 | } |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 390 | } |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 391 | if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS, |
| 392 | 0, 0, 0, 0, 0, 0, |
| 393 | status+0, status+1, status+2, status+3, status+4)) |
| 394 | && (status[0] == 0x00000001)) { |
| 395 | /* |
| 396 | * status[1] >> 16 maximum command size in KB |
| 397 | * status[1] & 0xFFFF maximum FIB size |
| 398 | * status[2] >> 16 maximum SG elements to driver |
| 399 | * status[2] & 0xFFFF maximum SG elements from driver |
| 400 | * status[3] & 0xFFFF maximum number FIBs outstanding |
| 401 | */ |
| 402 | host->max_sectors = (status[1] >> 16) << 1; |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 403 | /* Multiple of 32 for PMC */ |
| 404 | dev->max_fib_size = status[1] & 0xFFE0; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 405 | host->sg_tablesize = status[2] >> 16; |
| 406 | dev->sg_tablesize = status[2] & 0xFFFF; |
Mahesh Rajashekhara | 2b4df6e | 2013-01-10 17:52:51 +0530 | [diff] [blame] | 407 | if (dev->pdev->device == PMC_DEVICE_S7 || |
| 408 | dev->pdev->device == PMC_DEVICE_S8 || |
| 409 | dev->pdev->device == PMC_DEVICE_S9) |
| 410 | host->can_queue = ((status[3] >> 16) ? (status[3] >> 16) : |
| 411 | (status[3] & 0xFFFF)) - AAC_NUM_MGT_FIB; |
| 412 | else |
| 413 | host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB; |
Mahesh Rajashekhara | e8b12f0 | 2011-03-17 02:10:32 -0700 | [diff] [blame] | 414 | dev->max_num_aif = status[4] & 0xFFFF; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 415 | /* |
| 416 | * NOTE: |
| 417 | * All these overrides are based on a fixed internal |
| 418 | * knowledge and understanding of existing adapters, |
| 419 | * acbsize should be set with caution. |
| 420 | */ |
| 421 | if (acbsize == 512) { |
| 422 | host->max_sectors = AAC_MAX_32BIT_SGBCOUNT; |
| 423 | dev->max_fib_size = 512; |
| 424 | dev->sg_tablesize = host->sg_tablesize |
| 425 | = (512 - sizeof(struct aac_fibhdr) |
Mark Haverkamp | 63a70ee | 2005-09-20 12:57:04 -0700 | [diff] [blame] | 426 | - sizeof(struct aac_write) + sizeof(struct sgentry)) |
| 427 | / sizeof(struct sgentry); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 428 | host->can_queue = AAC_NUM_IO_FIB; |
| 429 | } else if (acbsize == 2048) { |
| 430 | host->max_sectors = 512; |
| 431 | dev->max_fib_size = 2048; |
| 432 | host->sg_tablesize = 65; |
| 433 | dev->sg_tablesize = 81; |
| 434 | host->can_queue = 512 - AAC_NUM_MGT_FIB; |
| 435 | } else if (acbsize == 4096) { |
| 436 | host->max_sectors = 1024; |
| 437 | dev->max_fib_size = 4096; |
| 438 | host->sg_tablesize = 129; |
| 439 | dev->sg_tablesize = 166; |
| 440 | host->can_queue = 256 - AAC_NUM_MGT_FIB; |
| 441 | } else if (acbsize == 8192) { |
| 442 | host->max_sectors = 2048; |
| 443 | dev->max_fib_size = 8192; |
| 444 | host->sg_tablesize = 257; |
| 445 | dev->sg_tablesize = 337; |
| 446 | host->can_queue = 128 - AAC_NUM_MGT_FIB; |
| 447 | } else if (acbsize > 0) { |
| 448 | printk("Illegal acbsize=%d ignored\n", acbsize); |
| 449 | } |
| 450 | } |
| 451 | { |
| 452 | |
| 453 | if (numacb > 0) { |
| 454 | if (numacb < host->can_queue) |
| 455 | host->can_queue = numacb; |
| 456 | else |
| 457 | printk("numacb=%d ignored\n", numacb); |
| 458 | } |
| 459 | } |
| 460 | |
Mahesh Rajashekhara | 2b4df6e | 2013-01-10 17:52:51 +0530 | [diff] [blame] | 461 | if (host->can_queue > AAC_NUM_IO_FIB) |
| 462 | host->can_queue = AAC_NUM_IO_FIB; |
| 463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | /* |
| 465 | * Ok now init the communication subsystem |
| 466 | */ |
| 467 | |
Salyzyn, Mark | 4dbc22d | 2007-04-16 11:21:50 -0400 | [diff] [blame] | 468 | dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | if (dev->queues == NULL) { |
| 470 | printk(KERN_ERR "Error could not allocate comm region.\n"); |
| 471 | return NULL; |
| 472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | if (aac_comm_init(dev)<0){ |
| 475 | kfree(dev->queues); |
| 476 | return NULL; |
| 477 | } |
| 478 | /* |
| 479 | * Initialize the list of fibs |
| 480 | */ |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 481 | if (aac_fib_setup(dev) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | kfree(dev->queues); |
| 483 | return NULL; |
| 484 | } |
| 485 | |
| 486 | INIT_LIST_HEAD(&dev->fib_list); |
Mahesh Rajashekhara | 1160461 | 2012-02-08 22:51:04 -0800 | [diff] [blame] | 487 | INIT_LIST_HEAD(&dev->sync_fib_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | return dev; |
| 490 | } |
| 491 | |
| 492 | |