ia64/xen-unstable

view xen/drivers/scsi/aacraid/sa.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 * sa.c
26 *
27 * Abstract: Drawbridge specific support functions
28 *
29 */
31 #include <linux/config.h>
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/blk.h>
40 #include <linux/delay.h>
41 /*#include <linux/completion.h>*/
42 /*#include <asm/semaphore.h>*/
43 #include "scsi.h"
44 #include "hosts.h"
46 #include "aacraid.h"
48 static void aac_sa_intr(int irq, void *dev_id, struct pt_regs *regs)
49 {
50 struct aac_dev *dev = dev_id;
51 unsigned short intstat, mask;
53 intstat = sa_readw(dev, DoorbellReg_p);
54 /*
55 * Read mask and invert because drawbridge is reversed.
56 * This allows us to only service interrupts that have been enabled.
57 */
58 mask = ~(sa_readw(dev, SaDbCSR.PRISETIRQMASK));
60 /* Check to see if this is our interrupt. If it isn't just return */
62 if (intstat & mask) {
63 if (intstat & PrintfReady) {
64 aac_printf(dev, le32_to_cpu(sa_readl(dev, Mailbox5)));
65 sa_writew(dev, DoorbellClrReg_p, PrintfReady); /* clear PrintfReady */
66 sa_writew(dev, DoorbellReg_s, PrintfDone);
67 } else if (intstat & DOORBELL_1) { // dev -> Host Normal Command Ready
68 aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
69 sa_writew(dev, DoorbellClrReg_p, DOORBELL_1);
70 } else if (intstat & DOORBELL_2) { // dev -> Host Normal Response Ready
71 aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
72 sa_writew(dev, DoorbellClrReg_p, DOORBELL_2);
73 } else if (intstat & DOORBELL_3) { // dev -> Host Normal Command Not Full
74 sa_writew(dev, DoorbellClrReg_p, DOORBELL_3);
75 } else if (intstat & DOORBELL_4) { // dev -> Host Normal Response Not Full
76 sa_writew(dev, DoorbellClrReg_p, DOORBELL_4);
77 }
78 }
79 }
81 /**
82 * aac_sa_enable_interrupt - enable an interrupt event
83 * @dev: Which adapter to enable.
84 * @event: Which adapter event.
85 *
86 * This routine will enable the corresponding adapter event to cause an interrupt on
87 * the host.
88 */
90 void aac_sa_enable_interrupt(struct aac_dev *dev, u32 event)
91 {
92 switch (event) {
94 case HostNormCmdQue:
95 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_1);
96 break;
98 case HostNormRespQue:
99 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_2);
100 break;
102 case AdapNormCmdNotFull:
103 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_3);
104 break;
106 case AdapNormRespNotFull:
107 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_4);
108 break;
109 }
110 }
112 /**
113 * aac_sa_disable_interrupt - disable an interrupt event
114 * @dev: Which adapter to enable.
115 * @event: Which adapter event.
116 *
117 * This routine will enable the corresponding adapter event to cause an interrupt on
118 * the host.
119 */
121 void aac_sa_disable_interrupt (struct aac_dev *dev, u32 event)
122 {
123 switch (event) {
125 case HostNormCmdQue:
126 sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_1);
127 break;
129 case HostNormRespQue:
130 sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_2);
131 break;
133 case AdapNormCmdNotFull:
134 sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_3);
135 break;
137 case AdapNormRespNotFull:
138 sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_4);
139 break;
140 }
141 }
143 /**
144 * aac_sa_notify_adapter - handle adapter notification
145 * @dev: Adapter that notification is for
146 * @event: Event to notidy
147 *
148 * Notify the adapter of an event
149 */
151 void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
152 {
153 switch (event) {
155 case AdapNormCmdQue:
156 sa_writew(dev, DoorbellReg_s,DOORBELL_1);
157 break;
158 case HostNormRespNotFull:
159 sa_writew(dev, DoorbellReg_s,DOORBELL_4);
160 break;
161 case AdapNormRespQue:
162 sa_writew(dev, DoorbellReg_s,DOORBELL_2);
163 break;
164 case HostNormCmdNotFull:
165 sa_writew(dev, DoorbellReg_s,DOORBELL_3);
166 break;
167 case HostShutdown:
168 //sa_sync_cmd(dev, HOST_CRASHING, 0, &ret);
169 break;
170 case FastIo:
171 sa_writew(dev, DoorbellReg_s,DOORBELL_6);
172 break;
173 case AdapPrintfDone:
174 sa_writew(dev, DoorbellReg_s,DOORBELL_5);
175 break;
176 default:
177 BUG();
178 break;
179 }
180 }
183 /**
184 * sa_sync_cmd - send a command and wait
185 * @dev: Adapter
186 * @command: Command to execute
187 * @p1: first parameter
188 * @ret: adapter status
189 *
190 * This routine will send a synchronous comamnd to the adapter and wait
191 * for its completion.
192 */
194 static int sa_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *ret)
195 {
196 unsigned long start;
197 int ok;
198 /*
199 * Write the Command into Mailbox 0
200 */
201 sa_writel(dev, Mailbox0, cpu_to_le32(command));
202 /*
203 * Write the parameters into Mailboxes 1 - 4
204 */
205 sa_writel(dev, Mailbox1, cpu_to_le32(p1));
206 sa_writel(dev, Mailbox2, 0);
207 sa_writel(dev, Mailbox3, 0);
208 sa_writel(dev, Mailbox4, 0);
209 /*
210 * Clear the synch command doorbell to start on a clean slate.
211 */
212 sa_writew(dev, DoorbellClrReg_p, DOORBELL_0);
213 /*
214 * Signal that there is a new synch command
215 */
216 sa_writew(dev, DoorbellReg_s, DOORBELL_0);
218 ok = 0;
219 start = jiffies;
221 while(time_before(jiffies, start+30*HZ))
222 {
223 /*
224 * Delay 5uS so that the monitor gets access
225 */
226 udelay(5);
227 /*
228 * Mon110 will set doorbell0 bit when it has
229 * completed the command.
230 */
231 if(sa_readw(dev, DoorbellReg_p) & DOORBELL_0) {
232 ok = 1;
233 break;
234 }
235 #if 0
236 set_current_state(TASK_UNINTERRUPTIBLE);
237 schedule_timeout(1);
238 #else
239 mdelay(100);
240 #endif
241 }
243 if (ok != 1)
244 return -ETIMEDOUT;
245 /*
246 * Clear the synch command doorbell.
247 */
248 sa_writew(dev, DoorbellClrReg_p, DOORBELL_0);
249 /*
250 * Pull the synch status from Mailbox 0.
251 */
252 *ret = le32_to_cpu(sa_readl(dev, Mailbox0));
253 return 0;
254 }
256 /**
257 * aac_sa_interrupt_adapter - interrupt an adapter
258 * @dev: Which adapter to enable.
259 *
260 * Breakpoint an adapter.
261 */
263 static void aac_sa_interrupt_adapter (struct aac_dev *dev)
264 {
265 u32 ret;
266 sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, &ret);
267 }
269 /**
270 * aac_sa_start_adapter - activate adapter
271 * @dev: Adapter
272 *
273 * Start up processing on an ARM based AAC adapter
274 */
276 static void aac_sa_start_adapter(struct aac_dev *dev)
277 {
278 u32 ret;
279 struct aac_init *init;
280 /*
281 * Fill in the remaining pieces of the init.
282 */
283 init = dev->init;
284 init->HostElapsedSeconds = cpu_to_le32(jiffies/HZ);
286 dprintk(("INIT\n"));
287 /*
288 * Tell the adapter we are back and up and running so it will scan its command
289 * queues and enable our interrupts
290 */
291 dev->irq_mask = (PrintfReady | DOORBELL_1 | DOORBELL_2 | DOORBELL_3 | DOORBELL_4);
292 /*
293 * First clear out all interrupts. Then enable the one's that
294 * we can handle.
295 */
296 dprintk(("MASK\n"));
297 sa_writew(dev, SaDbCSR.PRISETIRQMASK, cpu_to_le16(0xffff));
298 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 | DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
299 dprintk(("SYNCCMD\n"));
300 /* We can only use a 32 bit address here */
301 sa_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa, &ret);
302 }
304 /**
305 * aac_sa_init - initialize an ARM based AAC card
306 * @dev: device to configure
307 * @devnum: adapter number
308 *
309 * Allocate and set up resources for the ARM based AAC variants. The
310 * device_interface in the commregion will be allocated and linked
311 * to the comm region.
312 */
314 int aac_sa_init(struct aac_dev *dev, unsigned long devnum)
315 {
316 unsigned long start;
317 unsigned long status;
318 int instance;
319 const char *name;
321 dev->devnum = devnum;
323 dprintk(("PREINST\n"));
324 instance = dev->id;
325 name = dev->name;
327 /*
328 * Map in the registers from the adapter.
329 */
330 dprintk(("PREMAP\n"));
332 if((dev->regs.sa = (struct sa_registers *)ioremap((unsigned long)dev->scsi_host_ptr->base, 8192))==NULL)
333 {
334 printk(KERN_WARNING "aacraid: unable to map ARM.\n" );
335 return -1;
336 }
337 /*
338 * Check to see if the board failed any self tests.
339 */
340 if (sa_readl(dev, Mailbox7) & SELF_TEST_FAILED) {
341 printk(KERN_WARNING "%s%d: adapter self-test failed.\n", name, instance);
342 return -1;
343 }
344 /*
345 * Check to see if the board panic'd while booting.
346 */
347 if (sa_readl(dev, Mailbox7) & KERNEL_PANIC) {
348 printk(KERN_WARNING "%s%d: adapter kernel panic'd.\n", name, instance);
349 return -1;
350 }
351 start = jiffies;
352 /*
353 * Wait for the adapter to be up and running. Wait up to 3 minutes.
354 */
355 while (!(sa_readl(dev, Mailbox7) & KERNEL_UP_AND_RUNNING)) {
356 if (time_after(jiffies, start+180*HZ)) {
357 status = sa_readl(dev, Mailbox7) >> 16;
358 printk(KERN_WARNING "%s%d: adapter kernel failed to start, init status = %d.\n", name, instance, le32_to_cpu(status));
359 return -1;
360 }
361 #if 0
362 set_current_state(TASK_UNINTERRUPTIBLE);
363 schedule_timeout(1);
364 #else
365 mdelay(100);
366 #endif
367 }
369 dprintk(("ATIRQ\n"));
370 if (request_irq(dev->scsi_host_ptr->irq, aac_sa_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev ) < 0) {
371 printk(KERN_WARNING "%s%d: Interrupt unavailable.\n", name, instance);
372 return -1;
373 }
375 /*
376 * Fill in the function dispatch table.
377 */
379 dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter;
380 dev->a_ops.adapter_enable_int = aac_sa_enable_interrupt;
381 dev->a_ops.adapter_disable_int = aac_sa_disable_interrupt;
382 dev->a_ops.adapter_notify = aac_sa_notify_adapter;
383 dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
385 dprintk(("FUNCDONE\n"));
387 if(aac_init_adapter(dev) == NULL)
388 return -1;
390 dprintk(("NEWADAPTDONE\n"));
391 #if 0
392 /*
393 * Start any kernel threads needed
394 */
395 dev->thread_pid = kernel_thread((int (*)(void *))aac_command_thread, dev, 0);
396 if (dev->thread_pid < 0) {
397 printk(KERN_ERR "aacraid: Unable to create command thread.\n");
398 return -1;
399 }
400 #endif
401 /*
402 * Tell the adapter that all is configure, and it can start
403 * accepting requests
404 */
405 dprintk(("STARTING\n"));
406 aac_sa_start_adapter(dev);
407 dprintk(("STARTED\n"));
408 return 0;
409 }