ia64/xen-unstable

view xen/drivers/scsi/aacraid/rx.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 7a554cbf0f58
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 * rx.c
26 *
27 * Abstract: Hardware miniport for Drawbridge specific hardware 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_rx_intr(int irq, void *dev_id, struct pt_regs *regs)
49 {
50 struct aac_dev *dev = dev_id;
51 unsigned long bellbits;
52 u8 intstat, mask;
53 intstat = rx_readb(dev, MUnit.OISR);
54 /*
55 * Read mask and invert because drawbridge is reversed.
56 * This allows us to only service interrupts that have
57 * been enabled.
58 */
59 mask = ~(rx_readb(dev, MUnit.OIMR));
60 /* Check to see if this is our interrupt. If it isn't just return */
61 if (intstat & mask)
62 {
63 bellbits = rx_readl(dev, OutboundDoorbellReg);
64 if (bellbits & DoorBellPrintfReady) {
65 aac_printf(dev, le32_to_cpu(rx_readl (dev, IndexRegs.Mailbox[5])));
66 rx_writel(dev, MUnit.ODR,DoorBellPrintfReady);
67 rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
68 }
69 else if (bellbits & DoorBellAdapterNormCmdReady) {
70 aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
71 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
72 }
73 else if (bellbits & DoorBellAdapterNormRespReady) {
74 aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
75 rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
76 }
77 else if (bellbits & DoorBellAdapterNormCmdNotFull) {
78 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
79 }
80 else if (bellbits & DoorBellAdapterNormRespNotFull) {
81 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
82 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
83 }
84 }
85 }
87 /**
88 * aac_rx_enable_interrupt - Enable event reporting
89 * @dev: Adapter
90 * @event: Event to enable
91 *
92 * Enable event reporting from the i960 for a given event.
93 */
95 static void aac_rx_enable_interrupt(struct aac_dev * dev, u32 event)
96 {
97 switch (event) {
99 case HostNormCmdQue:
100 dev->irq_mask &= ~(OUTBOUNDDOORBELL_1);
101 break;
103 case HostNormRespQue:
104 dev->irq_mask &= ~(OUTBOUNDDOORBELL_2);
105 break;
107 case AdapNormCmdNotFull:
108 dev->irq_mask &= ~(OUTBOUNDDOORBELL_3);
109 break;
111 case AdapNormRespNotFull:
112 dev->irq_mask &= ~(OUTBOUNDDOORBELL_4);
113 break;
114 }
115 }
117 /**
118 * aac_rx_disable_interrupt - Disable event reporting
119 * @dev: Adapter
120 * @event: Event to enable
121 *
122 * Disable event reporting from the i960 for a given event.
123 */
125 static void aac_rx_disable_interrupt(struct aac_dev *dev, u32 event)
126 {
127 switch (event) {
129 case HostNormCmdQue:
130 dev->irq_mask |= (OUTBOUNDDOORBELL_1);
131 break;
133 case HostNormRespQue:
134 dev->irq_mask |= (OUTBOUNDDOORBELL_2);
135 break;
137 case AdapNormCmdNotFull:
138 dev->irq_mask |= (OUTBOUNDDOORBELL_3);
139 break;
141 case AdapNormRespNotFull:
142 dev->irq_mask |= (OUTBOUNDDOORBELL_4);
143 break;
144 }
145 }
147 /**
148 * rx_sync_cmd - send a command and wait
149 * @dev: Adapter
150 * @command: Command to execute
151 * @p1: first parameter
152 * @ret: adapter status
153 *
154 * This routine will send a synchronous comamnd to the adapter and wait
155 * for its completion.
156 */
158 static int rx_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *status)
159 {
160 unsigned long start;
161 int ok;
162 /*
163 * Write the command into Mailbox 0
164 */
165 rx_writel(dev, InboundMailbox0, cpu_to_le32(command));
166 /*
167 * Write the parameters into Mailboxes 1 - 4
168 */
169 rx_writel(dev, InboundMailbox1, cpu_to_le32(p1));
170 rx_writel(dev, InboundMailbox2, 0);
171 rx_writel(dev, InboundMailbox3, 0);
172 rx_writel(dev, InboundMailbox4, 0);
173 /*
174 * Clear the synch command doorbell to start on a clean slate.
175 */
176 rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
177 /*
178 * Disable doorbell interrupts
179 */
180 rx_writeb(dev, MUnit.OIMR, rx_readb(dev, MUnit.OIMR) | 0x04);
181 /*
182 * Force the completion of the mask register write before issuing
183 * the interrupt.
184 */
185 rx_readb (dev, MUnit.OIMR);
186 /*
187 * Signal that there is a new synch command
188 */
189 rx_writel(dev, InboundDoorbellReg, INBOUNDDOORBELL_0);
191 ok = 0;
192 start = jiffies;
194 /*
195 * Wait up to 30 seconds
196 */
197 while (time_before(jiffies, start+30*HZ))
198 {
199 udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
200 /*
201 * Mon960 will set doorbell0 bit when it has completed the command.
202 */
203 if (rx_readl(dev, OutboundDoorbellReg) & OUTBOUNDDOORBELL_0) {
204 /*
205 * Clear the doorbell.
206 */
207 rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
208 ok = 1;
209 break;
210 }
211 #if 0
212 /*
213 * Yield the processor in case we are slow
214 */
215 set_current_state(TASK_UNINTERRUPTIBLE);
216 schedule_timeout(1);
217 #else
218 /* XXX SMH: not in xen we don't */
219 mdelay(50);
220 #endif
221 }
222 if (ok != 1) {
223 /*
224 * Restore interrupt mask even though we timed out
225 */
226 rx_writeb(dev, MUnit.OIMR, rx_readl(dev, MUnit.OIMR) & 0xfb);
227 return -ETIMEDOUT;
228 }
229 /*
230 * Pull the synch status from Mailbox 0.
231 */
232 *status = le32_to_cpu(rx_readl(dev, IndexRegs.Mailbox[0]));
233 /*
234 * Clear the synch command doorbell.
235 */
236 rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
237 /*
238 * Restore interrupt mask
239 */
240 rx_writeb(dev, MUnit.OIMR, rx_readl(dev, MUnit.OIMR) & 0xfb);
241 return 0;
243 }
245 /**
246 * aac_rx_interrupt_adapter - interrupt adapter
247 * @dev: Adapter
248 *
249 * Send an interrupt to the i960 and breakpoint it.
250 */
252 static void aac_rx_interrupt_adapter(struct aac_dev *dev)
253 {
254 u32 ret;
255 rx_sync_cmd(dev, BREAKPOINT_REQUEST, 0, &ret);
256 }
258 /**
259 * aac_rx_notify_adapter - send an event to the adapter
260 * @dev: Adapter
261 * @event: Event to send
262 *
263 * Notify the i960 that something it probably cares about has
264 * happened.
265 */
267 static void aac_rx_notify_adapter(struct aac_dev *dev, u32 event)
268 {
269 switch (event) {
271 case AdapNormCmdQue:
272 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_1);
273 break;
274 case HostNormRespNotFull:
275 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_4);
276 break;
277 case AdapNormRespQue:
278 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_2);
279 break;
280 case HostNormCmdNotFull:
281 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3);
282 break;
283 case HostShutdown:
284 // rx_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, &ret);
285 break;
286 case FastIo:
287 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6);
288 break;
289 case AdapPrintfDone:
290 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_5);
291 break;
292 default:
293 BUG();
294 break;
295 }
296 }
298 /**
299 * aac_rx_start_adapter - activate adapter
300 * @dev: Adapter
301 *
302 * Start up processing on an i960 based AAC adapter
303 */
305 static void aac_rx_start_adapter(struct aac_dev *dev)
306 {
307 u32 status;
308 struct aac_init *init;
310 init = dev->init;
311 init->HostElapsedSeconds = cpu_to_le32(jiffies/HZ);
312 /*
313 * Tell the adapter we are back and up and running so it will scan
314 * its command queues and enable our interrupts
315 */
316 dev->irq_mask = (DoorBellPrintfReady | OUTBOUNDDOORBELL_1 | OUTBOUNDDOORBELL_2 | OUTBOUNDDOORBELL_3 | OUTBOUNDDOORBELL_4);
317 /*
318 * First clear out all interrupts. Then enable the one's that we
319 * can handle.
320 */
321 rx_writeb(dev, MUnit.OIMR, 0xff);
322 rx_writel(dev, MUnit.ODR, 0xffffffff);
323 // rx_writeb(dev, MUnit.OIMR, ~(u8)OUTBOUND_DOORBELL_INTERRUPT_MASK);
324 rx_writeb(dev, MUnit.OIMR, 0xfb);
326 // We can only use a 32 bit address here
327 rx_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa, &status);
328 }
330 /**
331 * aac_rx_init - initialize an i960 based AAC card
332 * @dev: device to configure
333 * @devnum: adapter number
334 *
335 * Allocate and set up resources for the i960 based AAC variants. The
336 * device_interface in the commregion will be allocated and linked
337 * to the comm region.
338 */
340 int aac_rx_init(struct aac_dev *dev, unsigned long num)
341 {
342 unsigned long start;
343 unsigned long status;
344 int instance;
345 const char * name;
347 dev->devnum = num;
348 instance = dev->id;
349 name = dev->name;
351 /*
352 * Map in the registers from the adapter.
353 */
354 if((dev->regs.rx = (struct rx_registers *)ioremap((unsigned long)dev->scsi_host_ptr->base, 8192))==NULL)
355 {
356 printk(KERN_WARNING "aacraid: unable to map i960.\n" );
357 return -1;
358 }
359 /*
360 * Check to see if the board failed any self tests.
361 */
362 if (rx_readl(dev, IndexRegs.Mailbox[7]) & SELF_TEST_FAILED) {
363 printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
364 return -1;
365 }
366 /*
367 * Check to see if the board panic'd while booting.
368 */
369 if (rx_readl(dev, IndexRegs.Mailbox[7]) & KERNEL_PANIC) {
370 printk(KERN_ERR "%s%d: adapter kernel panic'd.\n", dev->name, instance);
371 return -1;
372 }
373 start = jiffies;
374 /*
375 * Wait for the adapter to be up and running. Wait up to 3 minutes
376 */
377 while (!(rx_readl(dev, IndexRegs.Mailbox[7]) & KERNEL_UP_AND_RUNNING))
378 {
379 if(time_after(jiffies, start+180*HZ))
380 {
381 status = rx_readl(dev, IndexRegs.Mailbox[7]) >> 16;
382 printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %ld.\n", dev->name, instance, status);
383 return -1;
384 }
385 #if 0
386 set_current_state(TASK_UNINTERRUPTIBLE);
387 schedule_timeout(1);
388 #else
389 /* XXX SMH: no sleeping for us (we're the xen idle task) */
390 mdelay(50);
391 #endif
392 }
393 if (request_irq(dev->scsi_host_ptr->irq, aac_rx_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev)<0)
394 {
395 printk(KERN_ERR "%s%d: Interrupt unavailable.\n", name, instance);
396 return -1;
397 }
398 /*
399 * Fill in the function dispatch table.
400 */
401 dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter;
402 dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt;
403 dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt;
404 dev->a_ops.adapter_notify = aac_rx_notify_adapter;
405 dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
407 if (aac_init_adapter(dev) == NULL)
408 return -1;
409 /*
410 * Tell the adapter that all is configured, and it can start
411 * accepting requests
412 */
413 aac_rx_start_adapter(dev);
414 return 0;
415 }