ia64/xen-unstable

view xen/drivers/scsi/aacraid/comminit.c @ 945:db2e1ea917df

bitkeeper revision 1.596.1.3 (3fb3b41eWUoRU0H8A0jEX5roXjxKkA)

Many files:
Greatly simplified Xen softirqs. They are now only executed in outermost Xen activation; they are never called within an irq context.
author kaf24@scramble.cl.cam.ac.uk
date Thu Nov 13 16:41:02 2003 +0000 (2003-11-13)
parents 3946af49a538
children 890460f07ddf
line source
1 /*
2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
4 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
8 * Copyright (c) 2000 Adaptec, Inc. (aacraid@adaptec.com)
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 */
32 #include <linux/config.h>
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/sched.h>
37 #include <linux/pci.h>
38 #include <linux/spinlock.h>
39 #include <linux/slab.h>
40 #include <linux/blk.h>
41 /*#include <linux/completion.h>*/
42 #include <linux/mm.h>
43 /*#include <asm/semaphore.h>*/
44 #include "scsi.h"
45 #include "hosts.h"
47 #include "aacraid.h"
49 struct aac_common aac_config;
51 static struct aac_dev *devices;
53 static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign)
54 {
55 unsigned char *base;
56 unsigned long size, align;
57 unsigned long fibsize = 4096;
58 unsigned long printfbufsiz = 256;
59 struct aac_init *init;
60 dma_addr_t phys;
62 size = fibsize + sizeof(struct aac_init) + commsize + commalign + printfbufsiz;
64 base = pci_alloc_consistent(dev->pdev, size, &phys);
65 if(base == NULL)
66 {
67 printk(KERN_ERR "aacraid: unable to create mapping.\n");
68 return 0;
69 }
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 init->MiniPortRevision = cpu_to_le32(Sa_MINIPORT_REVISION);
81 init->fsrev = cpu_to_le32(dev->fsrev);
83 /*
84 * Adapter Fibs are the first thing allocated so that they
85 * start page aligned
86 */
87 dev->fib_base_va = (ulong)base;
89 /* We submit the physical address for AIF tags to limit to 32 bits */
90 init->AdapterFibsVirtualAddress = cpu_to_le32((u32)phys);
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));
94 init->HostPhysMemPages = cpu_to_le32(4096); // number of 4k pages of host physical memory
96 /*
97 * Increment the base address by the amount already used
98 */
99 base = base + fibsize + sizeof(struct aac_init);
100 phys = (dma_addr_t)((ulong)phys + fibsize + sizeof(struct aac_init));
101 /*
102 * Align the beginning of Headers to commalign
103 */
104 align = (commalign - ((unsigned long)(base) & (commalign - 1)));
105 base = base + align;
106 phys = phys + align;
107 /*
108 * Fill in addresses of the Comm Area Headers and Queues
109 */
110 *commaddr = base;
111 init->CommHeaderAddress = cpu_to_le32((u32)phys);
112 /*
113 * Increment the base address by the size of the CommArea
114 */
115 base = base + commsize;
116 phys = phys + commsize;
117 /*
118 * Place the Printf buffer area after the Fast I/O comm area.
119 */
120 dev->printfbuf = (void *)base;
121 init->printfbuf = cpu_to_le32(phys);
122 init->printfbufsiz = cpu_to_le32(printfbufsiz);
123 memset(base, 0, printfbufsiz);
124 return 1;
125 }
127 static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, int qsize)
128 {
129 q->numpending = 0;
130 q->dev = dev;
131 INIT_LIST_HEAD(&q->pendingq);
132 #if 0
133 init_waitqueue_head(&q->cmdready);
134 #endif
135 INIT_LIST_HEAD(&q->cmdq);
136 #if 0
137 init_waitqueue_head(&q->qfull);
138 #endif
139 spin_lock_init(&q->lockdata);
140 q->lock = &q->lockdata;
141 q->headers.producer = mem;
142 q->headers.consumer = mem+1;
143 *(q->headers.producer) = cpu_to_le32(qsize);
144 *(q->headers.consumer) = cpu_to_le32(qsize);
145 q->entries = qsize;
146 }
148 /**
149 * aac_send_shutdown - shutdown an adapter
150 * @dev: Adapter to shutdown
151 *
152 * This routine will send a VM_CloseAll (shutdown) request to the adapter.
153 */
155 static int aac_send_shutdown(struct aac_dev * dev)
156 {
157 struct fib * fibctx;
158 struct aac_close *cmd;
159 int status;
161 fibctx = fib_alloc(dev);
162 fib_init(fibctx);
164 cmd = (struct aac_close *) fib_data(fibctx);
166 cmd->command = cpu_to_le32(VM_CloseAll);
167 cmd->cid = cpu_to_le32(0xffffffff);
169 status = fib_send(ContainerCommand,
170 fibctx,
171 sizeof(struct aac_close),
172 FsaNormal,
173 1, 1,
174 NULL, NULL);
176 if (status == 0)
177 fib_complete(fibctx);
178 fib_free(fibctx);
179 return status;
180 }
182 /**
183 * aac_detach - detach adapter
184 * @detach: adapter to disconnect
185 *
186 * Disconnect and shutdown an AAC based adapter, freeing resources
187 * as we go.
188 */
190 int aac_detach(struct aac_dev *detach)
191 {
192 struct aac_dev **dev = &devices;
194 while(*dev)
195 {
196 if(*dev == detach)
197 {
198 *dev = detach->next;
199 aac_send_shutdown(detach);
200 fib_map_free(detach);
201 pci_free_consistent(detach->pdev, detach->comm_size, detach->comm_addr, detach->comm_phys);
202 kfree(detach->queues);
203 return 1;
204 }
205 dev=&((*dev)->next);
206 }
207 BUG();
208 return 0;
209 }
211 /**
212 * aac_comm_init - Initialise FSA data structures
213 * @dev: Adapter to intialise
214 *
215 * Initializes the data structures that are required for the FSA commuication
216 * interface to operate.
217 * Returns
218 * 1 - if we were able to init the commuication interface.
219 * 0 - If there were errors initing. This is a fatal error.
220 */
222 int aac_comm_init(struct aac_dev * dev)
223 {
224 unsigned long hdrsize = (sizeof(u32) * NUMBER_OF_COMM_QUEUES) * 2;
225 unsigned long queuesize = sizeof(struct aac_entry) * TOTAL_QUEUE_ENTRIES;
226 u32 *headers;
227 struct aac_entry * queues;
228 unsigned long size;
229 struct aac_queue_block * comm = dev->queues;
231 /*
232 * Now allocate and initialize the zone structures used as our
233 * pool of FIB context records. The size of the zone is based
234 * on the system memory size. We also initialize the mutex used
235 * to protect the zone.
236 */
237 spin_lock_init(&dev->fib_lock);
239 /*
240 * Allocate the physically contigous space for the commuication
241 * queue headers.
242 */
244 size = hdrsize + queuesize;
246 if (!aac_alloc_comm(dev, (void * *)&headers, size, QUEUE_ALIGNMENT))
247 return -ENOMEM;
249 queues = (struct aac_entry *)(((ulong)headers) + hdrsize);
251 /* Adapter to Host normal priority Command queue */
252 comm->queue[HostNormCmdQueue].base = queues;
253 aac_queue_init(dev, &comm->queue[HostNormCmdQueue], headers, HOST_NORM_CMD_ENTRIES);
254 queues += HOST_NORM_CMD_ENTRIES;
255 headers += 2;
257 /* Adapter to Host high priority command queue */
258 comm->queue[HostHighCmdQueue].base = queues;
259 aac_queue_init(dev, &comm->queue[HostHighCmdQueue], headers, HOST_HIGH_CMD_ENTRIES);
261 queues += HOST_HIGH_CMD_ENTRIES;
262 headers +=2;
264 /* Host to adapter normal priority command queue */
265 comm->queue[AdapNormCmdQueue].base = queues;
266 aac_queue_init(dev, &comm->queue[AdapNormCmdQueue], headers, ADAP_NORM_CMD_ENTRIES);
268 queues += ADAP_NORM_CMD_ENTRIES;
269 headers += 2;
271 /* host to adapter high priority command queue */
272 comm->queue[AdapHighCmdQueue].base = queues;
273 aac_queue_init(dev, &comm->queue[AdapHighCmdQueue], headers, ADAP_HIGH_CMD_ENTRIES);
275 queues += ADAP_HIGH_CMD_ENTRIES;
276 headers += 2;
278 /* adapter to host normal priority response queue */
279 comm->queue[HostNormRespQueue].base = queues;
280 aac_queue_init(dev, &comm->queue[HostNormRespQueue], headers, HOST_NORM_RESP_ENTRIES);
282 queues += HOST_NORM_RESP_ENTRIES;
283 headers += 2;
285 /* adapter to host high priority response queue */
286 comm->queue[HostHighRespQueue].base = queues;
287 aac_queue_init(dev, &comm->queue[HostHighRespQueue], headers, HOST_HIGH_RESP_ENTRIES);
289 queues += HOST_HIGH_RESP_ENTRIES;
290 headers += 2;
292 /* host to adapter normal priority response queue */
293 comm->queue[AdapNormRespQueue].base = queues;
294 aac_queue_init(dev, &comm->queue[AdapNormRespQueue], headers, ADAP_NORM_RESP_ENTRIES);
296 queues += ADAP_NORM_RESP_ENTRIES;
297 headers += 2;
299 /* host to adapter high priority response queue */
300 comm->queue[AdapHighRespQueue].base = queues;
301 aac_queue_init(dev, &comm->queue[AdapHighRespQueue], headers, ADAP_HIGH_RESP_ENTRIES);
303 comm->queue[AdapNormCmdQueue].lock = comm->queue[HostNormRespQueue].lock;
304 comm->queue[AdapHighCmdQueue].lock = comm->queue[HostHighRespQueue].lock;
305 comm->queue[AdapNormRespQueue].lock = comm->queue[HostNormCmdQueue].lock;
306 comm->queue[AdapHighRespQueue].lock = comm->queue[HostHighCmdQueue].lock;
308 return 0;
309 }
311 struct aac_dev *aac_init_adapter(struct aac_dev *dev)
312 {
313 /*
314 * Ok now init the communication subsystem
315 */
316 dev->queues = (struct aac_queue_block *) kmalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
317 if (dev->queues == NULL) {
318 printk(KERN_ERR "Error could not allocate comm region.\n");
319 return NULL;
320 }
321 memset(dev->queues, 0, sizeof(struct aac_queue_block));
323 if (aac_comm_init(dev)<0){
324 kfree(dev->queues);
325 return NULL;
326 }
327 /*
328 * Initialize the list of fibs
329 */
330 if(fib_setup(dev)<0){
331 kfree(dev->queues);
332 return NULL;
333 }
335 INIT_LIST_HEAD(&dev->fib_list);
336 #if 0
337 init_completion(&dev->aif_completion);
338 #endif
339 /*
340 * Add this adapter in to our dev List.
341 */
342 dev->next = devices;
343 devices = dev;
344 return dev;
345 }