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/sched.h>
35 #include <linux/pci.h>
36 #include <linux/spinlock.h>
37 #include <linux/slab.h>
38 #include <linux/blkdev.h>
39 #include <linux/delay.h>
40 #include <linux/completion.h>
41 #include <linux/interrupt.h>
42 #include <asm/semaphore.h>
44 #include <scsi/scsi_host.h>
48 static irqreturn_t aac_sa_intr(int irq, void *dev_id, struct pt_regs *regs)
50 struct aac_dev *dev = dev_id;
51 unsigned short intstat, mask;
53 intstat = sa_readw(dev, DoorbellReg_p);
55 * Read mask and invert because drawbridge is reversed.
56 * This allows us to only service interrupts that have been enabled.
58 mask = ~(sa_readw(dev, SaDbCSR.PRISETIRQMASK));
60 /* Check to see if this is our interrupt. If it isn't just return */
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);
84 * aac_sa_enable_interrupt - enable an interrupt event
85 * @dev: Which adapter to enable.
86 * @event: Which adapter event.
88 * This routine will enable the corresponding adapter event to cause an interrupt on
92 void aac_sa_enable_interrupt(struct aac_dev *dev, u32 event)
97 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_1);
100 case HostNormRespQue:
101 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_2);
104 case AdapNormCmdNotFull:
105 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_3);
108 case AdapNormRespNotFull:
109 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, DOORBELL_4);
115 * aac_sa_disable_interrupt - disable an interrupt event
116 * @dev: Which adapter to enable.
117 * @event: Which adapter event.
119 * This routine will enable the corresponding adapter event to cause an interrupt on
123 void aac_sa_disable_interrupt (struct aac_dev *dev, u32 event)
128 sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_1);
131 case HostNormRespQue:
132 sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_2);
135 case AdapNormCmdNotFull:
136 sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_3);
139 case AdapNormRespNotFull:
140 sa_writew(dev, SaDbCSR.PRISETIRQMASK, DOORBELL_4);
146 * aac_sa_notify_adapter - handle adapter notification
147 * @dev: Adapter that notification is for
148 * @event: Event to notidy
150 * Notify the adapter of an event
153 void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
158 sa_writew(dev, DoorbellReg_s,DOORBELL_1);
160 case HostNormRespNotFull:
161 sa_writew(dev, DoorbellReg_s,DOORBELL_4);
163 case AdapNormRespQue:
164 sa_writew(dev, DoorbellReg_s,DOORBELL_2);
166 case HostNormCmdNotFull:
167 sa_writew(dev, DoorbellReg_s,DOORBELL_3);
170 //sa_sync_cmd(dev, HOST_CRASHING, 0, &ret);
173 sa_writew(dev, DoorbellReg_s,DOORBELL_6);
176 sa_writew(dev, DoorbellReg_s,DOORBELL_5);
186 * sa_sync_cmd - send a command and wait
188 * @command: Command to execute
189 * @p1: first parameter
190 * @ret: adapter status
192 * This routine will send a synchronous comamnd to the adapter and wait
193 * for its completion.
196 static int sa_sync_cmd(struct aac_dev *dev, u32 command, u32 p1, u32 *ret)
201 * Write the Command into Mailbox 0
203 sa_writel(dev, Mailbox0, cpu_to_le32(command));
205 * Write the parameters into Mailboxes 1 - 4
207 sa_writel(dev, Mailbox1, cpu_to_le32(p1));
208 sa_writel(dev, Mailbox2, 0);
209 sa_writel(dev, Mailbox3, 0);
210 sa_writel(dev, Mailbox4, 0);
212 * Clear the synch command doorbell to start on a clean slate.
214 sa_writew(dev, DoorbellClrReg_p, DOORBELL_0);
216 * Signal that there is a new synch command
218 sa_writew(dev, DoorbellReg_s, DOORBELL_0);
223 while(time_before(jiffies, start+30*HZ))
226 * Delay 5uS so that the monitor gets access
230 * Mon110 will set doorbell0 bit when it has
231 * completed the command.
233 if(sa_readw(dev, DoorbellReg_p) & DOORBELL_0) {
237 set_current_state(TASK_UNINTERRUPTIBLE);
244 * Clear the synch command doorbell.
246 sa_writew(dev, DoorbellClrReg_p, DOORBELL_0);
248 * Pull the synch status from Mailbox 0.
250 *ret = le32_to_cpu(sa_readl(dev, Mailbox0));
255 * aac_sa_interrupt_adapter - interrupt an adapter
256 * @dev: Which adapter to enable.
258 * Breakpoint an adapter.
261 static void aac_sa_interrupt_adapter (struct aac_dev *dev)
264 sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, &ret);
268 * aac_sa_start_adapter - activate adapter
271 * Start up processing on an ARM based AAC adapter
274 static void aac_sa_start_adapter(struct aac_dev *dev)
277 struct aac_init *init;
279 * Fill in the remaining pieces of the init.
282 init->HostElapsedSeconds = cpu_to_le32(jiffies/HZ);
286 * Tell the adapter we are back and up and running so it will scan its command
287 * queues and enable our interrupts
289 dev->irq_mask = (PrintfReady | DOORBELL_1 | DOORBELL_2 | DOORBELL_3 | DOORBELL_4);
291 * First clear out all interrupts. Then enable the one's that
295 sa_writew(dev, SaDbCSR.PRISETIRQMASK, cpu_to_le16(0xffff));
296 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 | DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
297 dprintk(("SYNCCMD\n"));
298 /* We can only use a 32 bit address here */
299 sa_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa, &ret);
303 * aac_sa_check_health
304 * @dev: device to check if healthy
306 * Will attempt to determine if the specified adapter is alive and
307 * capable of handling requests, returning 0 if alive.
309 static int aac_sa_check_health(struct aac_dev *dev)
311 long status = sa_readl(dev, Mailbox7);
314 * Check to see if the board failed any self tests.
316 if (status & SELF_TEST_FAILED)
319 * Check to see if the board panic'd while booting.
321 if (status & KERNEL_PANIC)
324 * Wait for the adapter to be up and running. Wait up to 3 minutes
326 if (!(status & KERNEL_UP_AND_RUNNING))
332 } /* aac_sa_check_health */
335 * aac_sa_init - initialize an ARM based AAC card
336 * @dev: device to configure
337 * @devnum: adapter number
339 * Allocate and set up resources for the ARM based AAC variants. The
340 * device_interface in the commregion will be allocated and linked
341 * to the comm region.
344 int aac_sa_init(struct aac_dev *dev, unsigned long devnum)
347 unsigned long status;
351 dev->devnum = devnum;
353 dprintk(("PREINST\n"));
358 * Map in the registers from the adapter.
360 dprintk(("PREMAP\n"));
362 if((dev->regs.sa = (struct sa_registers *)ioremap((unsigned long)dev->scsi_host_ptr->base, 8192))==NULL)
364 printk(KERN_WARNING "aacraid: unable to map ARM.\n" );
368 * Check to see if the board failed any self tests.
370 if (sa_readl(dev, Mailbox7) & SELF_TEST_FAILED) {
371 printk(KERN_WARNING "%s%d: adapter self-test failed.\n", name, instance);
375 * Check to see if the board panic'd while booting.
377 if (sa_readl(dev, Mailbox7) & KERNEL_PANIC) {
378 printk(KERN_WARNING "%s%d: adapter kernel panic'd.\n", name, instance);
383 * Wait for the adapter to be up and running. Wait up to 3 minutes.
385 while (!(sa_readl(dev, Mailbox7) & KERNEL_UP_AND_RUNNING)) {
386 if (time_after(jiffies, start+180*HZ)) {
387 status = sa_readl(dev, Mailbox7) >> 16;
388 printk(KERN_WARNING "%s%d: adapter kernel failed to start, init status = %d.\n", name, instance, le32_to_cpu(status));
391 set_current_state(TASK_UNINTERRUPTIBLE);
395 dprintk(("ATIRQ\n"));
396 if (request_irq(dev->scsi_host_ptr->irq, aac_sa_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev ) < 0) {
397 printk(KERN_WARNING "%s%d: Interrupt unavailable.\n", name, instance);
402 * Fill in the function dispatch table.
405 dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter;
406 dev->a_ops.adapter_enable_int = aac_sa_enable_interrupt;
407 dev->a_ops.adapter_disable_int = aac_sa_disable_interrupt;
408 dev->a_ops.adapter_notify = aac_sa_notify_adapter;
409 dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
410 dev->a_ops.adapter_check_health = aac_sa_check_health;
412 dprintk(("FUNCDONE\n"));
414 if(aac_init_adapter(dev) == NULL)
417 dprintk(("NEWADAPTDONE\n"));
419 * Start any kernel threads needed
421 dev->thread_pid = kernel_thread((int (*)(void *))aac_command_thread, dev, 0);
422 if (dev->thread_pid < 0) {
423 printk(KERN_ERR "aacraid: Unable to create command thread.\n");
428 * Tell the adapter that all is configure, and it can start
431 dprintk(("STARTING\n"));
432 aac_sa_start_adapter(dev);
433 dprintk(("STARTED\n"));