[SCSI] aacraid: remove x86_64 IOMMU dependent code
[linux-2.6/btrfs-unstable.git] / drivers / scsi / aacraid / comminit.c
blob1cd3584ba7ff6ee39cf3c4e40bb8b0ce5c3741e0
1 /*
2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000 Adaptec, Inc. (aacraid@adaptec.com)
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.
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.
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.
24 * Module Name:
25 * comminit.c
27 * Abstract: This supports the initialization of the host adapter commuication interface.
28 * This is a platform dependent module for the pci cyclone board.
32 #include <linux/kernel.h>
33 #include <linux/init.h>
34 #include <linux/types.h>
35 #include <linux/sched.h>
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>
42 #include <scsi/scsi_host.h>
43 #include <asm/semaphore.h>
45 #include "aacraid.h"
47 struct aac_common aac_config = {
48 .irq_mod = 1
51 static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign)
53 unsigned char *base;
54 unsigned long size, align;
55 const unsigned long fibsize = 4096;
56 const unsigned long printfbufsiz = 256;
57 struct aac_init *init;
58 dma_addr_t phys;
60 size = fibsize + sizeof(struct aac_init) + commsize + commalign + printfbufsiz;
63 base = pci_alloc_consistent(dev->pdev, size, &phys);
65 if(base == NULL)
67 printk(KERN_ERR "aacraid: unable to create mapping.\n");
68 return 0;
70 dev->comm_addr = (void *)base;
71 dev->comm_phys = phys;
72 dev->comm_size = size;
74 dev->init = (struct aac_init *)(base + fibsize);
75 dev->init_pa = phys + fibsize;
77 init = dev->init;
79 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION);
80 if (dev->max_fib_size != sizeof(struct hw_fib))
81 init->InitStructRevision = cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4);
82 init->MiniPortRevision = cpu_to_le32(Sa_MINIPORT_REVISION);
83 init->fsrev = cpu_to_le32(dev->fsrev);
86 * Adapter Fibs are the first thing allocated so that they
87 * start page aligned
89 dev->aif_base_va = (struct hw_fib *)base;
91 init->AdapterFibsVirtualAddress = 0;
92 init->AdapterFibsPhysicalAddress = cpu_to_le32((u32)phys);
93 init->AdapterFibsSize = cpu_to_le32(fibsize);
94 init->AdapterFibAlign = cpu_to_le32(sizeof(struct hw_fib));
95 init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
97 init->InitFlags = 0;
98 if (dev->new_comm_interface) {
99 init->InitFlags = cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
100 dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
102 init->MaxIoCommands = cpu_to_le32(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
103 init->MaxIoSize = cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
104 init->MaxFibSize = cpu_to_le32(dev->max_fib_size);
107 * Increment the base address by the amount already used
109 base = base + fibsize + sizeof(struct aac_init);
110 phys = (dma_addr_t)((ulong)phys + fibsize + sizeof(struct aac_init));
112 * Align the beginning of Headers to commalign
114 align = (commalign - ((unsigned long)(base) & (commalign - 1)));
115 base = base + align;
116 phys = phys + align;
118 * Fill in addresses of the Comm Area Headers and Queues
120 *commaddr = base;
121 init->CommHeaderAddress = cpu_to_le32((u32)phys);
123 * Increment the base address by the size of the CommArea
125 base = base + commsize;
126 phys = phys + commsize;
128 * Place the Printf buffer area after the Fast I/O comm area.
130 dev->printfbuf = (void *)base;
131 init->printfbuf = cpu_to_le32(phys);
132 init->printfbufsiz = cpu_to_le32(printfbufsiz);
133 memset(base, 0, printfbufsiz);
134 return 1;
137 static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize)
139 q->numpending = 0;
140 q->dev = dev;
141 init_waitqueue_head(&q->cmdready);
142 INIT_LIST_HEAD(&q->cmdq);
143 init_waitqueue_head(&q->qfull);
144 spin_lock_init(&q->lockdata);
145 q->lock = &q->lockdata;
146 q->headers.producer = (__le32 *)mem;
147 q->headers.consumer = (__le32 *)(mem+1);
148 *(q->headers.producer) = cpu_to_le32(qsize);
149 *(q->headers.consumer) = cpu_to_le32(qsize);
150 q->entries = qsize;
154 * aac_send_shutdown - shutdown an adapter
155 * @dev: Adapter to shutdown
157 * This routine will send a VM_CloseAll (shutdown) request to the adapter.
160 int aac_send_shutdown(struct aac_dev * dev)
162 struct fib * fibctx;
163 struct aac_close *cmd;
164 int status;
166 fibctx = aac_fib_alloc(dev);
167 if (!fibctx)
168 return -ENOMEM;
169 aac_fib_init(fibctx);
171 cmd = (struct aac_close *) fib_data(fibctx);
173 cmd->command = cpu_to_le32(VM_CloseAll);
174 cmd->cid = cpu_to_le32(0xffffffff);
176 status = aac_fib_send(ContainerCommand,
177 fibctx,
178 sizeof(struct aac_close),
179 FsaNormal,
180 -2 /* Timeout silently */, 1,
181 NULL, NULL);
183 if (status == 0)
184 aac_fib_complete(fibctx);
185 aac_fib_free(fibctx);
186 return status;
190 * aac_comm_init - Initialise FSA data structures
191 * @dev: Adapter to initialise
193 * Initializes the data structures that are required for the FSA commuication
194 * interface to operate.
195 * Returns
196 * 1 - if we were able to init the commuication interface.
197 * 0 - If there were errors initing. This is a fatal error.
200 static int aac_comm_init(struct aac_dev * dev)
202 unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
203 unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
204 u32 *headers;
205 struct aac_entry * queues;
206 unsigned long size;
207 struct aac_queue_block * comm = dev->queues;
209 * Now allocate and initialize the zone structures used as our
210 * pool of FIB context records. The size of the zone is based
211 * on the system memory size. We also initialize the mutex used
212 * to protect the zone.
214 spin_lock_init(&dev->fib_lock);
217 * Allocate the physically contigous space for the commuication
218 * queue headers.
221 size = hdrsize + queuesize;
223 if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT))
224 return -ENOMEM;
226 queues = (struct aac_entry *)(((ulong)headers) + hdrsize);
228 /* Adapter to Host normal priority Command queue */
229 comm->queue[HostNormCmdQueue].base = queues;
230 aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES);
231 queues += HOST_NORM_CMD_ENTRIES;
232 headers += 2;
234 /* Adapter to Host high priority command queue */
235 comm->queue[HostHighCmdQueue].base = queues;
236 aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES);
238 queues += HOST_HIGH_CMD_ENTRIES;
239 headers +=2;
241 /* Host to adapter normal priority command queue */
242 comm->queue[AdapNormCmdQueue].base = queues;
243 aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES);
245 queues += ADAP_NORM_CMD_ENTRIES;
246 headers += 2;
248 /* host to adapter high priority command queue */
249 comm->queue[AdapHighCmdQueue].base = queues;
250 aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES);
252 queues += ADAP_HIGH_CMD_ENTRIES;
253 headers += 2;
255 /* adapter to host normal priority response queue */
256 comm->queue[HostNormRespQueue].base = queues;
257 aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES);
258 queues += HOST_NORM_RESP_ENTRIES;
259 headers += 2;
261 /* adapter to host high priority response queue */
262 comm->queue[HostHighRespQueue].base = queues;
263 aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES);
265 queues += HOST_HIGH_RESP_ENTRIES;
266 headers += 2;
268 /* host to adapter normal priority response queue */
269 comm->queue[AdapNormRespQueue].base = queues;
270 aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES);
272 queues += ADAP_NORM_RESP_ENTRIES;
273 headers += 2;
275 /* host to adapter high priority response queue */
276 comm->queue[AdapHighRespQueue].base = queues;
277 aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES);
279 comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock;
280 comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock;
281 comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock;
282 comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock;
284 return 0;
287 struct aac_dev *aac_init_adapter(struct aac_dev *dev)
289 u32 status[5];
290 struct Scsi_Host * host = dev->scsi_host_ptr;
293 * Check the preferred comm settings, defaults from template.
295 dev->max_fib_size = sizeof(struct hw_fib);
296 dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size
297 - sizeof(struct aac_fibhdr)
298 - sizeof(struct aac_write) + sizeof(struct sgentry))
299 / sizeof(struct sgentry);
300 dev->new_comm_interface = 0;
301 dev->raw_io_64 = 0;
302 if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
303 0, 0, 0, 0, 0, 0, status+0, status+1, status+2, NULL, NULL)) &&
304 (status[0] == 0x00000001)) {
305 if (status[1] & AAC_OPT_NEW_COMM_64)
306 dev->raw_io_64 = 1;
307 if (status[1] & AAC_OPT_NEW_COMM)
308 dev->new_comm_interface = dev->a_ops.adapter_send != 0;
309 if (dev->new_comm_interface && (status[2] > dev->base_size)) {
310 iounmap(dev->regs.sa);
311 dev->base_size = status[2];
312 dprintk((KERN_DEBUG "ioremap(%lx,%d)\n",
313 host->base, status[2]));
314 dev->regs.sa = ioremap(host->base, status[2]);
315 if (dev->regs.sa == NULL) {
316 /* remap failed, go back ... */
317 dev->new_comm_interface = 0;
318 dev->regs.sa = ioremap(host->base,
319 AAC_MIN_FOOTPRINT_SIZE);
320 if (dev->regs.sa == NULL) {
321 printk(KERN_WARNING
322 "aacraid: unable to map adapter.\n");
323 return NULL;
328 if ((!aac_adapter_sync_cmd(dev, GET_COMM_PREFERRED_SETTINGS,
329 0, 0, 0, 0, 0, 0,
330 status+0, status+1, status+2, status+3, status+4))
331 && (status[0] == 0x00000001)) {
333 * status[1] >> 16 maximum command size in KB
334 * status[1] & 0xFFFF maximum FIB size
335 * status[2] >> 16 maximum SG elements to driver
336 * status[2] & 0xFFFF maximum SG elements from driver
337 * status[3] & 0xFFFF maximum number FIBs outstanding
339 host->max_sectors = (status[1] >> 16) << 1;
340 dev->max_fib_size = status[1] & 0xFFFF;
341 host->sg_tablesize = status[2] >> 16;
342 dev->sg_tablesize = status[2] & 0xFFFF;
343 host->can_queue = (status[3] & 0xFFFF) - AAC_NUM_MGT_FIB;
345 * NOTE:
346 * All these overrides are based on a fixed internal
347 * knowledge and understanding of existing adapters,
348 * acbsize should be set with caution.
350 if (acbsize == 512) {
351 host->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
352 dev->max_fib_size = 512;
353 dev->sg_tablesize = host->sg_tablesize
354 = (512 - sizeof(struct aac_fibhdr)
355 - sizeof(struct aac_write) + sizeof(struct sgentry))
356 / sizeof(struct sgentry);
357 host->can_queue = AAC_NUM_IO_FIB;
358 } else if (acbsize == 2048) {
359 host->max_sectors = 512;
360 dev->max_fib_size = 2048;
361 host->sg_tablesize = 65;
362 dev->sg_tablesize = 81;
363 host->can_queue = 512 - AAC_NUM_MGT_FIB;
364 } else if (acbsize == 4096) {
365 host->max_sectors = 1024;
366 dev->max_fib_size = 4096;
367 host->sg_tablesize = 129;
368 dev->sg_tablesize = 166;
369 host->can_queue = 256 - AAC_NUM_MGT_FIB;
370 } else if (acbsize == 8192) {
371 host->max_sectors = 2048;
372 dev->max_fib_size = 8192;
373 host->sg_tablesize = 257;
374 dev->sg_tablesize = 337;
375 host->can_queue = 128 - AAC_NUM_MGT_FIB;
376 } else if (acbsize > 0) {
377 printk("Illegal acbsize=%d ignored\n", acbsize);
382 if (numacb > 0) {
383 if (numacb < host->can_queue)
384 host->can_queue = numacb;
385 else
386 printk("numacb=%d ignored\n", numacb);
391 * Ok now init the communication subsystem
394 dev->queues = (struct aac_queue_block *) kmalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
395 if (dev->queues == NULL) {
396 printk(KERN_ERR "Error could not allocate comm region.\n");
397 return NULL;
399 memset(dev->queues, 0, sizeof(struct aac_queue_block));
401 if (aac_comm_init(dev)<0){
402 kfree(dev->queues);
403 return NULL;
406 * Initialize the list of fibs
408 if (aac_fib_setup(dev) < 0) {
409 kfree(dev->queues);
410 return NULL;
413 INIT_LIST_HEAD(&dev->fib_list);
415 return dev;