| 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 |  * | 
| Salyzyn, Mark | 4dfb7cb | 2007-03-27 15:07:28 -0400 | [diff] [blame] | 8 |  * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 |  * | 
 | 10 |  * This program is free software; you can redistribute it and/or modify | 
 | 11 |  * it under the terms of the GNU General Public License as published by | 
 | 12 |  * the Free Software Foundation; either version 2, or (at your option) | 
 | 13 |  * any later version. | 
 | 14 |  * | 
 | 15 |  * This program is distributed in the hope that it will be useful, | 
 | 16 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 17 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 18 |  * GNU General Public License for more details. | 
 | 19 |  * | 
 | 20 |  * You should have received a copy of the GNU General Public License | 
 | 21 |  * along with this program; see the file COPYING.  If not, write to | 
 | 22 |  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
 | 23 |  * | 
 | 24 |  * Module Name: | 
 | 25 |  *  comminit.c | 
 | 26 |  * | 
 | 27 |  * Abstract: This supports the initialization of the host adapter commuication interface. | 
 | 28 |  *    This is a platform dependent module for the pci cyclone board. | 
 | 29 |  * | 
 | 30 |  */ | 
 | 31 |  | 
 | 32 | #include <linux/kernel.h> | 
 | 33 | #include <linux/init.h> | 
 | 34 | #include <linux/types.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/pci.h> | 
 | 36 | #include <linux/spinlock.h> | 
 | 37 | #include <linux/slab.h> | 
 | 38 | #include <linux/blkdev.h> | 
 | 39 | #include <linux/completion.h> | 
 | 40 | #include <linux/mm.h> | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 41 | #include <scsi/scsi_host.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 |  | 
 | 43 | #include "aacraid.h" | 
 | 44 |  | 
| Mark Haverkamp | bed30de | 2005-08-03 15:38:51 -0700 | [diff] [blame] | 45 | struct aac_common aac_config = { | 
 | 46 | 	.irq_mod = 1 | 
 | 47 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 |  | 
 | 49 | static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign) | 
 | 50 | { | 
 | 51 | 	unsigned char *base; | 
 | 52 | 	unsigned long size, align; | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 53 | 	const unsigned long fibsize = 4096; | 
 | 54 | 	const unsigned long printfbufsiz = 256; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | 	struct aac_init *init; | 
 | 56 | 	dma_addr_t phys; | 
| Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 57 | 	unsigned long aac_max_hostphysmempages; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |  | 
 | 59 | 	size = fibsize + sizeof(struct aac_init) + commsize + commalign + printfbufsiz; | 
 | 60 |  | 
 | 61 |   | 
 | 62 | 	base = pci_alloc_consistent(dev->pdev, size, &phys); | 
 | 63 |  | 
 | 64 | 	if(base == NULL) | 
 | 65 | 	{ | 
 | 66 | 		printk(KERN_ERR "aacraid: unable to create mapping.\n"); | 
 | 67 | 		return 0; | 
 | 68 | 	} | 
 | 69 | 	dev->comm_addr = (void *)base; | 
 | 70 | 	dev->comm_phys = phys; | 
 | 71 | 	dev->comm_size = size; | 
 | 72 | 	 | 
 | 73 | 	dev->init = (struct aac_init *)(base + fibsize); | 
 | 74 | 	dev->init_pa = phys + fibsize; | 
 | 75 |  | 
 | 76 | 	init = dev->init; | 
 | 77 |  | 
 | 78 | 	init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION); | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 79 | 	if (dev->max_fib_size != sizeof(struct hw_fib)) | 
 | 80 | 		init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | 	init->MiniPortRevision = cpu_to_le32(Sa_MINIPORT_REVISION); | 
 | 82 | 	init->fsrev = cpu_to_le32(dev->fsrev); | 
 | 83 |  | 
 | 84 | 	/* | 
 | 85 | 	 *	Adapter Fibs are the first thing allocated so that they | 
 | 86 | 	 *	start page aligned | 
 | 87 | 	 */ | 
 | 88 | 	dev->aif_base_va = (struct hw_fib *)base; | 
 | 89 | 	 | 
 | 90 | 	init->AdapterFibsVirtualAddress = 0; | 
 | 91 | 	init->AdapterFibsPhysicalAddress = cpu_to_le32((u32)phys); | 
 | 92 | 	init->AdapterFibsSize = cpu_to_le32(fibsize); | 
 | 93 | 	init->AdapterFibAlign = cpu_to_le32(sizeof(struct hw_fib)); | 
| Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 94 | 	/* | 
 | 95 | 	 * number of 4k pages of host physical memory. The aacraid fw needs | 
 | 96 | 	 * this number to be less than 4gb worth of pages. New firmware doesn't | 
 | 97 | 	 * have any issues with the mapping system, but older Firmware did, and | 
 | 98 | 	 * had *troubles* dealing with the math overloading past 32 bits, thus | 
 | 99 | 	 * we must limit this field. | 
 | 100 | 	 */ | 
 | 101 | 	aac_max_hostphysmempages = dma_get_required_mask(&dev->pdev->dev) >> 12; | 
 | 102 | 	if (aac_max_hostphysmempages < AAC_MAX_HOSTPHYSMEMPAGES) | 
 | 103 | 		init->HostPhysMemPages = cpu_to_le32(aac_max_hostphysmempages); | 
 | 104 | 	else | 
 | 105 | 		init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 |  | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 107 | 	init->InitFlags = 0; | 
| Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 108 | 	if (dev->comm_interface == AAC_COMM_MESSAGE) { | 
| Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 109 | 		init->InitFlags = cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED); | 
 | 110 | 		dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n")); | 
 | 111 | 	} | 
| Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 112 | 	init->InitFlags |= cpu_to_le32(INITFLAGS_DRIVER_USES_UTC_TIME | | 
 | 113 | 				       INITFLAGS_DRIVER_SUPPORTS_PM); | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 114 | 	init->MaxIoCommands = cpu_to_le32(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); | 
 | 115 | 	init->MaxIoSize = cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9); | 
 | 116 | 	init->MaxFibSize = cpu_to_le32(dev->max_fib_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 |  | 
 | 118 | 	/* | 
 | 119 | 	 * Increment the base address by the amount already used | 
 | 120 | 	 */ | 
 | 121 | 	base = base + fibsize + sizeof(struct aac_init); | 
 | 122 | 	phys = (dma_addr_t)((ulong)phys + fibsize + sizeof(struct aac_init)); | 
 | 123 | 	/* | 
 | 124 | 	 *	Align the beginning of Headers to commalign | 
 | 125 | 	 */ | 
| Al Viro | 142956a | 2007-10-29 05:11:28 +0000 | [diff] [blame] | 126 | 	align = (commalign - ((uintptr_t)(base) & (commalign - 1))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | 	base = base + align; | 
 | 128 | 	phys = phys + align; | 
 | 129 | 	/* | 
 | 130 | 	 *	Fill in addresses of the Comm Area Headers and Queues | 
 | 131 | 	 */ | 
 | 132 | 	*commaddr = base; | 
 | 133 | 	init->CommHeaderAddress = cpu_to_le32((u32)phys); | 
 | 134 | 	/* | 
 | 135 | 	 *	Increment the base address by the size of the CommArea | 
 | 136 | 	 */ | 
 | 137 | 	base = base + commsize; | 
 | 138 | 	phys = phys + commsize; | 
 | 139 | 	/* | 
 | 140 | 	 *	 Place the Printf buffer area after the Fast I/O comm area. | 
 | 141 | 	 */ | 
 | 142 | 	dev->printfbuf = (void *)base; | 
 | 143 | 	init->printfbuf = cpu_to_le32(phys); | 
 | 144 | 	init->printfbufsiz = cpu_to_le32(printfbufsiz); | 
 | 145 | 	memset(base, 0, printfbufsiz); | 
 | 146 | 	return 1; | 
 | 147 | } | 
 | 148 |      | 
 | 149 | static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize) | 
 | 150 | { | 
 | 151 | 	q->numpending = 0; | 
 | 152 | 	q->dev = dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | 	init_waitqueue_head(&q->cmdready); | 
 | 154 | 	INIT_LIST_HEAD(&q->cmdq); | 
 | 155 | 	init_waitqueue_head(&q->qfull); | 
 | 156 | 	spin_lock_init(&q->lockdata); | 
 | 157 | 	q->lock = &q->lockdata; | 
| Mark Haverkamp  | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 158 | 	q->headers.producer = (__le32 *)mem; | 
 | 159 | 	q->headers.consumer = (__le32 *)(mem+1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | 	*(q->headers.producer) = cpu_to_le32(qsize); | 
 | 161 | 	*(q->headers.consumer) = cpu_to_le32(qsize); | 
 | 162 | 	q->entries = qsize; | 
 | 163 | } | 
 | 164 |  | 
 | 165 | /** | 
 | 166 |  *	aac_send_shutdown		-	shutdown an adapter | 
 | 167 |  *	@dev: Adapter to shutdown | 
 | 168 |  * | 
 | 169 |  *	This routine will send a VM_CloseAll (shutdown) request to the adapter. | 
 | 170 |  */ | 
 | 171 |  | 
 | 172 | int aac_send_shutdown(struct aac_dev * dev) | 
 | 173 | { | 
 | 174 | 	struct fib * fibctx; | 
 | 175 | 	struct aac_close *cmd; | 
 | 176 | 	int status; | 
 | 177 |  | 
| Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 178 | 	fibctx = aac_fib_alloc(dev); | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 179 | 	if (!fibctx) | 
 | 180 | 		return -ENOMEM; | 
| Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 181 | 	aac_fib_init(fibctx); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 |  | 
 | 183 | 	cmd = (struct aac_close *) fib_data(fibctx); | 
 | 184 |  | 
 | 185 | 	cmd->command = cpu_to_le32(VM_CloseAll); | 
 | 186 | 	cmd->cid = cpu_to_le32(0xffffffff); | 
 | 187 |  | 
| Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 188 | 	status = aac_fib_send(ContainerCommand, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | 			  fibctx, | 
 | 190 | 			  sizeof(struct aac_close), | 
 | 191 | 			  FsaNormal, | 
| Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 192 | 			  -2 /* Timeout silently */, 1, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | 			  NULL, NULL); | 
 | 194 |  | 
| Mark Haverkamp | 90ee346 | 2006-08-03 08:03:07 -0700 | [diff] [blame] | 195 | 	if (status >= 0) | 
| Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 196 | 		aac_fib_complete(fibctx); | 
| Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 197 | 	/* FIB should be freed only after getting the response from the F/W */ | 
 | 198 | 	if (status != -ERESTARTSYS) | 
 | 199 | 		aac_fib_free(fibctx); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | 	return status; | 
 | 201 | } | 
 | 202 |  | 
 | 203 | /** | 
 | 204 |  *	aac_comm_init	-	Initialise FSA data structures | 
 | 205 |  *	@dev:	Adapter to initialise | 
 | 206 |  * | 
 | 207 |  *	Initializes the data structures that are required for the FSA commuication | 
 | 208 |  *	interface to operate.  | 
 | 209 |  *	Returns | 
 | 210 |  *		1 - if we were able to init the commuication interface. | 
 | 211 |  *		0 - If there were errors initing. This is a fatal error. | 
 | 212 |  */ | 
 | 213 |   | 
| Adrian Bunk  | 4833869 | 2005-04-25 19:45:58 -0700 | [diff] [blame] | 214 | static int aac_comm_init(struct aac_dev * dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { | 
 | 216 | 	unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2; | 
 | 217 | 	unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES; | 
 | 218 | 	u32 *headers; | 
 | 219 | 	struct aac_entry * queues; | 
 | 220 | 	unsigned long size; | 
 | 221 | 	struct aac_queue_block * comm = dev->queues; | 
 | 222 | 	/* | 
 | 223 | 	 *	Now allocate and initialize the zone structures used as our  | 
 | 224 | 	 *	pool of FIB context records.  The size of the zone is based | 
 | 225 | 	 *	on the system memory size.  We also initialize the mutex used | 
 | 226 | 	 *	to protect the zone. | 
 | 227 | 	 */ | 
 | 228 | 	spin_lock_init(&dev->fib_lock); | 
 | 229 |  | 
 | 230 | 	/* | 
| André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 231 | 	 *	Allocate the physically contiguous space for the commuication | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | 	 *	queue headers.  | 
 | 233 | 	 */ | 
 | 234 |  | 
 | 235 | 	size = hdrsize + queuesize; | 
 | 236 |  | 
 | 237 | 	if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT)) | 
 | 238 | 		return -ENOMEM; | 
 | 239 |  | 
 | 240 | 	queues = (struct aac_entry *)(((ulong)headers) + hdrsize); | 
 | 241 |  | 
 | 242 | 	/* Adapter to Host normal priority Command queue */  | 
 | 243 | 	comm->queue[HostNormCmdQueue].base = queues; | 
 | 244 | 	aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES); | 
 | 245 | 	queues += HOST_NORM_CMD_ENTRIES; | 
 | 246 | 	headers += 2; | 
 | 247 |  | 
 | 248 | 	/* Adapter to Host high priority command queue */ | 
 | 249 | 	comm->queue[HostHighCmdQueue].base = queues; | 
 | 250 | 	aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES); | 
 | 251 |      | 
 | 252 | 	queues += HOST_HIGH_CMD_ENTRIES; | 
 | 253 | 	headers +=2; | 
 | 254 |  | 
 | 255 | 	/* Host to adapter normal priority command queue */ | 
 | 256 | 	comm->queue[AdapNormCmdQueue].base = queues; | 
 | 257 | 	aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES); | 
 | 258 |      | 
 | 259 | 	queues += ADAP_NORM_CMD_ENTRIES; | 
 | 260 | 	headers += 2; | 
 | 261 |  | 
 | 262 | 	/* host to adapter high priority command queue */ | 
 | 263 | 	comm->queue[AdapHighCmdQueue].base = queues; | 
 | 264 | 	aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES); | 
 | 265 |      | 
 | 266 | 	queues += ADAP_HIGH_CMD_ENTRIES; | 
 | 267 | 	headers += 2; | 
 | 268 |  | 
 | 269 | 	/* adapter to host normal priority response queue */ | 
 | 270 | 	comm->queue[HostNormRespQueue].base = queues; | 
 | 271 | 	aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES); | 
 | 272 | 	queues += HOST_NORM_RESP_ENTRIES; | 
 | 273 | 	headers += 2; | 
 | 274 |  | 
 | 275 | 	/* adapter to host high priority response queue */ | 
 | 276 | 	comm->queue[HostHighRespQueue].base = queues; | 
 | 277 | 	aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES); | 
 | 278 |     | 
 | 279 | 	queues += HOST_HIGH_RESP_ENTRIES; | 
 | 280 | 	headers += 2; | 
 | 281 |  | 
 | 282 | 	/* host to adapter normal priority response queue */ | 
 | 283 | 	comm->queue[AdapNormRespQueue].base = queues; | 
 | 284 | 	aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES); | 
 | 285 |  | 
 | 286 | 	queues += ADAP_NORM_RESP_ENTRIES; | 
 | 287 | 	headers += 2; | 
 | 288 | 	 | 
 | 289 | 	/* host to adapter high priority response queue */  | 
 | 290 | 	comm->queue[AdapHighRespQueue].base = queues; | 
 | 291 | 	aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES); | 
 | 292 |  | 
 | 293 | 	comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock; | 
 | 294 | 	comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock; | 
 | 295 | 	comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock; | 
 | 296 | 	comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock; | 
 | 297 |  | 
 | 298 | 	return 0; | 
 | 299 | } | 
 | 300 |  | 
 | 301 | struct aac_dev *aac_init_adapter(struct aac_dev *dev) | 
 | 302 | { | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 303 | 	u32 status[5]; | 
 | 304 | 	struct Scsi_Host * host = dev->scsi_host_ptr; | 
 | 305 |  | 
 | 306 | 	/* | 
 | 307 | 	 *	Check the preferred comm settings, defaults from template. | 
 | 308 | 	 */ | 
| Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 309 | 	dev->management_fib_count = 0; | 
 | 310 | 	spin_lock_init(&dev->manage_lock); | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 311 | 	dev->max_fib_size = sizeof(struct hw_fib); | 
 | 312 | 	dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size | 
 | 313 | 		- sizeof(struct aac_fibhdr) | 
| Mark Haverkamp | 63a70ee | 2005-09-20 12:57:04 -0700 | [diff] [blame] | 314 | 		- sizeof(struct aac_write) + sizeof(struct sgentry)) | 
 | 315 | 			/ sizeof(struct sgentry); | 
| Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 316 | 	dev->comm_interface = AAC_COMM_PRODUCER; | 
| Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 317 | 	dev->raw_io_64 = 0; | 
 | 318 | 	if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES, | 
 | 319 | 		0, 0, 0, 0, 0, 0, status+0, status+1, status+2, NULL, NULL)) && | 
 | 320 | 	 		(status[0] == 0x00000001)) { | 
| Salyzyn, Mark | a3940da | 2008-01-08 12:48:25 -0800 | [diff] [blame] | 321 | 		if (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM_64)) | 
| Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 322 | 			dev->raw_io_64 = 1; | 
| Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 323 | 		if (dev->a_ops.adapter_comm && | 
| Salyzyn, Mark | a3940da | 2008-01-08 12:48:25 -0800 | [diff] [blame] | 324 | 		    (status[1] & le32_to_cpu(AAC_OPT_NEW_COMM))) | 
| Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 325 | 			dev->comm_interface = AAC_COMM_MESSAGE; | 
 | 326 | 		if ((dev->comm_interface == AAC_COMM_MESSAGE) && | 
 | 327 | 		    (status[2] > dev->base_size)) { | 
| Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 328 | 			aac_adapter_ioremap(dev, 0); | 
| Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 329 | 			dev->base_size = status[2]; | 
| Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 330 | 			if (aac_adapter_ioremap(dev, status[2])) { | 
| Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 331 | 				/* remap failed, go back ... */ | 
| Mark Haverkamp | 2871332 | 2007-01-23 14:59:20 -0800 | [diff] [blame] | 332 | 				dev->comm_interface = AAC_COMM_PRODUCER; | 
| Mark Haverkamp | 76a7f8f | 2006-09-19 09:00:02 -0700 | [diff] [blame] | 333 | 				if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) { | 
| Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 334 | 					printk(KERN_WARNING | 
 | 335 | 					  "aacraid: unable to map adapter.\n"); | 
 | 336 | 					return NULL; | 
 | 337 | 				} | 
 | 338 | 			} | 
 | 339 | 		} | 
| Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 340 | 	} | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 341 | 	if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS, | 
 | 342 | 	  0, 0, 0, 0, 0, 0, | 
 | 343 | 	  status+0, status+1, status+2, status+3, status+4)) | 
 | 344 | 	 && (status[0] == 0x00000001)) { | 
 | 345 | 		/* | 
 | 346 | 		 *	status[1] >> 16		maximum command size in KB | 
 | 347 | 		 *	status[1] & 0xFFFF	maximum FIB size | 
 | 348 | 		 *	status[2] >> 16		maximum SG elements to driver | 
 | 349 | 		 *	status[2] & 0xFFFF	maximum SG elements from driver | 
 | 350 | 		 *	status[3] & 0xFFFF	maximum number FIBs outstanding | 
 | 351 | 		 */ | 
 | 352 | 		host->max_sectors = (status[1] >> 16) << 1; | 
 | 353 | 		dev->max_fib_size = status[1] & 0xFFFF; | 
 | 354 | 		host->sg_tablesize = status[2] >> 16; | 
 | 355 | 		dev->sg_tablesize = status[2] & 0xFFFF; | 
 | 356 | 		host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB; | 
 | 357 | 		/* | 
 | 358 | 		 *	NOTE: | 
 | 359 | 		 *	All these overrides are based on a fixed internal | 
 | 360 | 		 *	knowledge and understanding of existing adapters, | 
 | 361 | 		 *	acbsize should be set with caution. | 
 | 362 | 		 */ | 
 | 363 | 		if (acbsize == 512) { | 
 | 364 | 			host->max_sectors = AAC_MAX_32BIT_SGBCOUNT; | 
 | 365 | 			dev->max_fib_size = 512; | 
 | 366 | 			dev->sg_tablesize = host->sg_tablesize | 
 | 367 | 			  = (512 - sizeof(struct aac_fibhdr) | 
| Mark Haverkamp | 63a70ee | 2005-09-20 12:57:04 -0700 | [diff] [blame] | 368 | 			    - sizeof(struct aac_write) + sizeof(struct sgentry)) | 
 | 369 | 			     / sizeof(struct sgentry); | 
| Mark Haverkamp  | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 370 | 			host->can_queue = AAC_NUM_IO_FIB; | 
 | 371 | 		} else if (acbsize == 2048) { | 
 | 372 | 			host->max_sectors = 512; | 
 | 373 | 			dev->max_fib_size = 2048; | 
 | 374 | 			host->sg_tablesize = 65; | 
 | 375 | 			dev->sg_tablesize = 81; | 
 | 376 | 			host->can_queue = 512 - AAC_NUM_MGT_FIB; | 
 | 377 | 		} else if (acbsize == 4096) { | 
 | 378 | 			host->max_sectors = 1024; | 
 | 379 | 			dev->max_fib_size = 4096; | 
 | 380 | 			host->sg_tablesize = 129; | 
 | 381 | 			dev->sg_tablesize = 166; | 
 | 382 | 			host->can_queue = 256 - AAC_NUM_MGT_FIB; | 
 | 383 | 		} else if (acbsize == 8192) { | 
 | 384 | 			host->max_sectors = 2048; | 
 | 385 | 			dev->max_fib_size = 8192; | 
 | 386 | 			host->sg_tablesize = 257; | 
 | 387 | 			dev->sg_tablesize = 337; | 
 | 388 | 			host->can_queue = 128 - AAC_NUM_MGT_FIB; | 
 | 389 | 		} else if (acbsize > 0) { | 
 | 390 | 			printk("Illegal acbsize=%d ignored\n", acbsize); | 
 | 391 | 		} | 
 | 392 | 	} | 
 | 393 | 	{ | 
 | 394 |  | 
 | 395 | 		if (numacb > 0) { | 
 | 396 | 			if (numacb < host->can_queue) | 
 | 397 | 				host->can_queue = numacb; | 
 | 398 | 			else | 
 | 399 | 				printk("numacb=%d ignored\n", numacb); | 
 | 400 | 		} | 
 | 401 | 	} | 
 | 402 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | 	/* | 
 | 404 | 	 *	Ok now init the communication subsystem | 
 | 405 | 	 */ | 
 | 406 |  | 
| Salyzyn, Mark | 4dbc22d | 2007-04-16 11:21:50 -0400 | [diff] [blame] | 407 | 	dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | 	if (dev->queues == NULL) { | 
 | 409 | 		printk(KERN_ERR "Error could not allocate comm region.\n"); | 
 | 410 | 		return NULL; | 
 | 411 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 |  | 
 | 413 | 	if (aac_comm_init(dev)<0){ | 
 | 414 | 		kfree(dev->queues); | 
 | 415 | 		return NULL; | 
 | 416 | 	} | 
 | 417 | 	/* | 
 | 418 | 	 *	Initialize the list of fibs | 
 | 419 | 	 */ | 
| Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 420 | 	if (aac_fib_setup(dev) < 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | 		kfree(dev->queues); | 
 | 422 | 		return NULL; | 
 | 423 | 	} | 
 | 424 | 		 | 
 | 425 | 	INIT_LIST_HEAD(&dev->fib_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 |  | 
 | 427 | 	return dev; | 
 | 428 | } | 
 | 429 |  | 
 | 430 |      |