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)
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.
27 * Abstract: Drawbridge specific support functions
31 #include <linux/kernel.h>
32 #include <linux/init.h>
33 #include <linux/types.h>
34 #include <linux/spinlock.h>
35 #include <linux/slab.h>
36 #include <linux/blkdev.h>
37 #include <linux/delay.h>
38 #include <linux/completion.h>
39 #include <linux/time.h>
40 #include <linux/interrupt.h>
41 #include <asm/semaphore.h>
43 #include <scsi/scsi_host.h>
47 static irqreturn_t aac_sa_intr(int irq, void *dev_id)
49 struct aac_dev *dev = dev_id;
50 unsigned short intstat, mask;
52 intstat = sa_readw(dev, DoorbellReg_p);
54 * Read mask and invert because drawbridge is reversed.
55 * This allows us to only service interrupts that have been enabled.
57 mask = ~(sa_readw(dev, SaDbCSR.PRISETIRQMASK));
59 /* Check to see if this is our interrupt. If it isn't just return */
62 if (intstat & PrintfReady) {
63 aac_printf(dev, sa_readl(dev, Mailbox5));
64 sa_writew(dev, DoorbellClrReg_p, PrintfReady); /* clear PrintfReady */
65 sa_writew(dev, DoorbellReg_s, PrintfDone);
66 } else if (intstat & DOORBELL_1) { // dev -> Host Normal Command Ready
67 sa_writew(dev, DoorbellClrReg_p, DOORBELL_1);
68 aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
69 } else if (intstat & DOORBELL_2) { // dev -> Host Normal Response Ready
70 sa_writew(dev, DoorbellClrReg_p, DOORBELL_2);
71 aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
72 } else if (intstat & DOORBELL_3) { // dev -> Host Normal Command Not Full
73 sa_writew(dev, DoorbellClrReg_p, DOORBELL_3);
74 } else if (intstat & DOORBELL_4) { // dev -> Host Normal Response Not Full
75 sa_writew(dev, DoorbellClrReg_p, DOORBELL_4);
83 * aac_sa_disable_interrupt - disable interrupt
84 * @dev: Which adapter to enable.
87 static void aac_sa_disable_interrupt (struct aac_dev *dev)
89 sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
93 * aac_sa_enable_interrupt - enable interrupt
94 * @dev: Which adapter to enable.
97 static void aac_sa_enable_interrupt (struct aac_dev *dev)
99 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 |
100 DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
104 * aac_sa_notify_adapter - handle adapter notification
105 * @dev: Adapter that notification is for
106 * @event: Event to notidy
108 * Notify the adapter of an event
111 static void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
116 sa_writew(dev, DoorbellReg_s,DOORBELL_1);
118 case HostNormRespNotFull:
119 sa_writew(dev, DoorbellReg_s,DOORBELL_4);
121 case AdapNormRespQue:
122 sa_writew(dev, DoorbellReg_s,DOORBELL_2);
124 case HostNormCmdNotFull:
125 sa_writew(dev, DoorbellReg_s,DOORBELL_3);
129 sa_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
130 NULL, NULL, NULL, NULL, NULL);
134 sa_writew(dev, DoorbellReg_s,DOORBELL_6);
137 sa_writew(dev, DoorbellReg_s,DOORBELL_5);
147 * sa_sync_cmd - send a command and wait
149 * @command: Command to execute
150 * @p1: first parameter
151 * @ret: adapter status
153 * This routine will send a synchronous command to the adapter and wait
154 * for its completion.
157 static int sa_sync_cmd(struct aac_dev *dev, u32 command,
158 u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
159 u32 *ret, u32 *r1, u32 *r2, u32 *r3, u32 *r4)
164 * Write the Command into Mailbox 0
166 sa_writel(dev, Mailbox0, command);
168 * Write the parameters into Mailboxes 1 - 4
170 sa_writel(dev, Mailbox1, p1);
171 sa_writel(dev, Mailbox2, p2);
172 sa_writel(dev, Mailbox3, p3);
173 sa_writel(dev, Mailbox4, p4);
176 * Clear the synch command doorbell to start on a clean slate.
178 sa_writew(dev, DoorbellClrReg_p, DOORBELL_0);
180 * Signal that there is a new synch command
182 sa_writew(dev, DoorbellReg_s, DOORBELL_0);
187 while(time_before(jiffies, start+30*HZ))
190 * Delay 5uS so that the monitor gets access
194 * Mon110 will set doorbell0 bit when it has
195 * completed the command.
197 if(sa_readw(dev, DoorbellReg_p) & DOORBELL_0) {
207 * Clear the synch command doorbell.
209 sa_writew(dev, DoorbellClrReg_p, DOORBELL_0);
211 * Pull the synch status from Mailbox 0.
214 *ret = sa_readl(dev, Mailbox0);
216 *r1 = sa_readl(dev, Mailbox1);
218 *r2 = sa_readl(dev, Mailbox2);
220 *r3 = sa_readl(dev, Mailbox3);
222 *r4 = sa_readl(dev, Mailbox4);
227 * aac_sa_interrupt_adapter - interrupt an adapter
228 * @dev: Which adapter to enable.
230 * Breakpoint an adapter.
233 static void aac_sa_interrupt_adapter (struct aac_dev *dev)
235 sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
236 NULL, NULL, NULL, NULL, NULL);
240 * aac_sa_start_adapter - activate adapter
243 * Start up processing on an ARM based AAC adapter
246 static void aac_sa_start_adapter(struct aac_dev *dev)
248 struct aac_init *init;
250 * Fill in the remaining pieces of the init.
253 init->HostElapsedSeconds = cpu_to_le32(get_seconds());
254 /* We can only use a 32 bit address here */
255 sa_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS,
256 (u32)(ulong)dev->init_pa, 0, 0, 0, 0, 0,
257 NULL, NULL, NULL, NULL, NULL);
261 * aac_sa_check_health
262 * @dev: device to check if healthy
264 * Will attempt to determine if the specified adapter is alive and
265 * capable of handling requests, returning 0 if alive.
267 static int aac_sa_check_health(struct aac_dev *dev)
269 long status = sa_readl(dev, Mailbox7);
272 * Check to see if the board failed any self tests.
274 if (status & SELF_TEST_FAILED)
277 * Check to see if the board panic'd while booting.
279 if (status & KERNEL_PANIC)
282 * Wait for the adapter to be up and running. Wait up to 3 minutes
284 if (!(status & KERNEL_UP_AND_RUNNING))
294 * @size: mapping resize request
297 static int aac_sa_ioremap(struct aac_dev * dev, u32 size)
300 iounmap(dev->regs.sa);
303 dev->base = dev->regs.sa = ioremap(dev->scsi_host_ptr->base, size);
304 return (dev->base == NULL) ? -1 : 0;
308 * aac_sa_init - initialize an ARM based AAC card
309 * @dev: device to configure
311 * Allocate and set up resources for the ARM based AAC variants. The
312 * device_interface in the commregion will be allocated and linked
313 * to the comm region.
316 int aac_sa_init(struct aac_dev *dev)
319 unsigned long status;
326 if (aac_sa_ioremap(dev, dev->base_size)) {
327 printk(KERN_WARNING "%s: unable to map adapter.\n", name);
332 * Check to see if the board failed any self tests.
334 if (sa_readl(dev, Mailbox7) & SELF_TEST_FAILED) {
335 printk(KERN_WARNING "%s%d: adapter self-test failed.\n", name, instance);
339 * Check to see if the board panic'd while booting.
341 if (sa_readl(dev, Mailbox7) & KERNEL_PANIC) {
342 printk(KERN_WARNING "%s%d: adapter kernel panic'd.\n", name, instance);
347 * Wait for the adapter to be up and running. Wait up to 3 minutes.
349 while (!(sa_readl(dev, Mailbox7) & KERNEL_UP_AND_RUNNING)) {
350 if (time_after(jiffies, start+startup_timeout*HZ)) {
351 status = sa_readl(dev, Mailbox7);
352 printk(KERN_WARNING "%s%d: adapter kernel failed to start, init status = %lx.\n",
353 name, instance, status);
360 * Fill in the function dispatch table.
363 dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter;
364 dev->a_ops.adapter_disable_int = aac_sa_disable_interrupt;
365 dev->a_ops.adapter_enable_int = aac_sa_enable_interrupt;
366 dev->a_ops.adapter_notify = aac_sa_notify_adapter;
367 dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
368 dev->a_ops.adapter_check_health = aac_sa_check_health;
369 dev->a_ops.adapter_intr = aac_sa_intr;
370 dev->a_ops.adapter_ioremap = aac_sa_ioremap;
373 * First clear out all interrupts. Then enable the one's that
376 aac_adapter_disable_int(dev);
377 aac_adapter_enable_int(dev);
379 if(aac_init_adapter(dev) == NULL)
381 if (request_irq(dev->scsi_host_ptr->irq, dev->a_ops.adapter_intr,
382 IRQF_SHARED|IRQF_DISABLED,
383 "aacraid", (void *)dev ) < 0) {
384 printk(KERN_WARNING "%s%d: Interrupt unavailable.\n",
388 aac_adapter_enable_int(dev);
391 * Tell the adapter that all is configure, and it can start
394 aac_sa_start_adapter(dev);
398 aac_sa_disable_interrupt(dev);
399 free_irq(dev->scsi_host_ptr->irq, (void *)dev);