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: Hardware miniport for Drawbridge specific hardware 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/time.h>
42 #include <linux/interrupt.h>
43 #include <asm/semaphore.h>
45 #include <scsi/scsi_host.h>
49 static irqreturn_t
aac_rkt_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
51 struct aac_dev
*dev
= dev_id
;
53 if (dev
->new_comm_interface
) {
54 u32 Index
= rkt_readl(dev
, MUnit
.OutboundQueue
);
55 if (Index
== 0xFFFFFFFFL
)
56 Index
= rkt_readl(dev
, MUnit
.OutboundQueue
);
57 if (Index
!= 0xFFFFFFFFL
) {
59 if (aac_intr_normal(dev
, Index
)) {
60 rkt_writel(dev
, MUnit
.OutboundQueue
, Index
);
61 rkt_writel(dev
, MUnit
.ODR
, DoorBellAdapterNormRespReady
);
63 Index
= rkt_readl(dev
, MUnit
.OutboundQueue
);
64 } while (Index
!= 0xFFFFFFFFL
);
68 unsigned long bellbits
;
70 intstat
= rkt_readb(dev
, MUnit
.OISR
);
72 * Read mask and invert because drawbridge is reversed.
73 * This allows us to only service interrupts that have
75 * Check to see if this is our interrupt. If it isn't just return
77 if (intstat
& ~(dev
->OIMR
))
79 bellbits
= rkt_readl(dev
, OutboundDoorbellReg
);
80 if (bellbits
& DoorBellPrintfReady
) {
81 aac_printf(dev
, rkt_readl (dev
, IndexRegs
.Mailbox
[5]));
82 rkt_writel(dev
, MUnit
.ODR
,DoorBellPrintfReady
);
83 rkt_writel(dev
, InboundDoorbellReg
,DoorBellPrintfDone
);
85 else if (bellbits
& DoorBellAdapterNormCmdReady
) {
86 rkt_writel(dev
, MUnit
.ODR
, DoorBellAdapterNormCmdReady
);
87 aac_command_normal(&dev
->queues
->queue
[HostNormCmdQueue
]);
88 // rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
90 else if (bellbits
& DoorBellAdapterNormRespReady
) {
91 rkt_writel(dev
, MUnit
.ODR
,DoorBellAdapterNormRespReady
);
92 aac_response_normal(&dev
->queues
->queue
[HostNormRespQueue
]);
94 else if (bellbits
& DoorBellAdapterNormCmdNotFull
) {
95 rkt_writel(dev
, MUnit
.ODR
, DoorBellAdapterNormCmdNotFull
);
97 else if (bellbits
& DoorBellAdapterNormRespNotFull
) {
98 rkt_writel(dev
, MUnit
.ODR
, DoorBellAdapterNormCmdNotFull
);
99 rkt_writel(dev
, MUnit
.ODR
, DoorBellAdapterNormRespNotFull
);
108 * aac_rkt_disable_interrupt - Disable interrupts
112 static void aac_rkt_disable_interrupt(struct aac_dev
*dev
)
114 rkt_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xff);
118 * rkt_sync_cmd - send a command and wait
120 * @command: Command to execute
121 * @p1: first parameter
122 * @ret: adapter status
124 * This routine will send a synchronous command to the adapter and wait
125 * for its completion.
128 static int rkt_sync_cmd(struct aac_dev
*dev
, u32 command
,
129 u32 p1
, u32 p2
, u32 p3
, u32 p4
, u32 p5
, u32 p6
,
130 u32
*status
, u32
*r1
, u32
*r2
, u32
*r3
, u32
*r4
)
135 * Write the command into Mailbox 0
137 rkt_writel(dev
, InboundMailbox0
, command
);
139 * Write the parameters into Mailboxes 1 - 6
141 rkt_writel(dev
, InboundMailbox1
, p1
);
142 rkt_writel(dev
, InboundMailbox2
, p2
);
143 rkt_writel(dev
, InboundMailbox3
, p3
);
144 rkt_writel(dev
, InboundMailbox4
, p4
);
146 * Clear the synch command doorbell to start on a clean slate.
148 rkt_writel(dev
, OutboundDoorbellReg
, OUTBOUNDDOORBELL_0
);
150 * Disable doorbell interrupts
152 rkt_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xff);
154 * Force the completion of the mask register write before issuing
157 rkt_readb (dev
, MUnit
.OIMR
);
159 * Signal that there is a new synch command
161 rkt_writel(dev
, InboundDoorbellReg
, INBOUNDDOORBELL_0
);
167 * Wait up to 30 seconds
169 while (time_before(jiffies
, start
+30*HZ
))
171 udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
173 * Mon960 will set doorbell0 bit when it has completed the command.
175 if (rkt_readl(dev
, OutboundDoorbellReg
) & OUTBOUNDDOORBELL_0
) {
177 * Clear the doorbell.
179 rkt_writel(dev
, OutboundDoorbellReg
, OUTBOUNDDOORBELL_0
);
184 * Yield the processor in case we are slow
190 * Restore interrupt mask even though we timed out
192 if (dev
->new_comm_interface
)
193 rkt_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xf7);
195 rkt_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xfb);
199 * Pull the synch status from Mailbox 0.
202 *status
= rkt_readl(dev
, IndexRegs
.Mailbox
[0]);
204 *r1
= rkt_readl(dev
, IndexRegs
.Mailbox
[1]);
206 *r2
= rkt_readl(dev
, IndexRegs
.Mailbox
[2]);
208 *r3
= rkt_readl(dev
, IndexRegs
.Mailbox
[3]);
210 *r4
= rkt_readl(dev
, IndexRegs
.Mailbox
[4]);
212 * Clear the synch command doorbell.
214 rkt_writel(dev
, OutboundDoorbellReg
, OUTBOUNDDOORBELL_0
);
216 * Restore interrupt mask
218 if (dev
->new_comm_interface
)
219 rkt_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xf7);
221 rkt_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xfb);
227 * aac_rkt_interrupt_adapter - interrupt adapter
230 * Send an interrupt to the i960 and breakpoint it.
233 static void aac_rkt_interrupt_adapter(struct aac_dev
*dev
)
235 rkt_sync_cmd(dev
, BREAKPOINT_REQUEST
, 0, 0, 0, 0, 0, 0,
236 NULL
, NULL
, NULL
, NULL
, NULL
);
240 * aac_rkt_notify_adapter - send an event to the adapter
242 * @event: Event to send
244 * Notify the i960 that something it probably cares about has
248 static void aac_rkt_notify_adapter(struct aac_dev
*dev
, u32 event
)
253 rkt_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_1
);
255 case HostNormRespNotFull
:
256 rkt_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_4
);
258 case AdapNormRespQue
:
259 rkt_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_2
);
261 case HostNormCmdNotFull
:
262 rkt_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_3
);
265 // rkt_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
266 // NULL, NULL, NULL, NULL, NULL);
269 rkt_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_6
);
272 rkt_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_5
);
281 * aac_rkt_start_adapter - activate adapter
284 * Start up processing on an i960 based AAC adapter
287 static void aac_rkt_start_adapter(struct aac_dev
*dev
)
289 struct aac_init
*init
;
292 init
->HostElapsedSeconds
= cpu_to_le32(get_seconds());
293 // We can only use a 32 bit address here
294 rkt_sync_cmd(dev
, INIT_STRUCT_BASE_ADDRESS
, (u32
)(ulong
)dev
->init_pa
,
295 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
299 * aac_rkt_check_health
300 * @dev: device to check if healthy
302 * Will attempt to determine if the specified adapter is alive and
303 * capable of handling requests, returning 0 if alive.
305 static int aac_rkt_check_health(struct aac_dev
*dev
)
307 u32 status
= rkt_readl(dev
, MUnit
.OMRx
[0]);
310 * Check to see if the board failed any self tests.
312 if (status
& SELF_TEST_FAILED
)
315 * Check to see if the board panic'd.
317 if (status
& KERNEL_PANIC
) {
323 dma_addr_t paddr
, baddr
;
326 if ((status
& 0xFF000000L
) == 0xBC000000L
)
327 return (status
>> 16) & 0xFF;
328 buffer
= pci_alloc_consistent(dev
->pdev
, 512, &baddr
);
332 post
= pci_alloc_consistent(dev
->pdev
,
333 sizeof(struct POSTSTATUS
), &paddr
);
335 pci_free_consistent(dev
->pdev
, 512, buffer
, baddr
);
338 memset(buffer
, 0, 512);
339 post
->Post_Command
= cpu_to_le32(COMMAND_POST_RESULTS
);
340 post
->Post_Address
= cpu_to_le32(baddr
);
341 rkt_writel(dev
, MUnit
.IMRx
[0], paddr
);
342 rkt_sync_cmd(dev
, COMMAND_POST_RESULTS
, baddr
, 0, 0, 0, 0, 0,
343 NULL
, NULL
, NULL
, NULL
, NULL
);
344 pci_free_consistent(dev
->pdev
, sizeof(struct POSTSTATUS
),
346 if ((buffer
[0] == '0') && ((buffer
[1] == 'x') || (buffer
[1] == 'X'))) {
347 ret
= (buffer
[2] <= '9') ? (buffer
[2] - '0') : (buffer
[2] - 'A' + 10);
349 ret
+= (buffer
[3] <= '9') ? (buffer
[3] - '0') : (buffer
[3] - 'A' + 10);
351 pci_free_consistent(dev
->pdev
, 512, buffer
, baddr
);
355 * Wait for the adapter to be up and running.
357 if (!(status
& KERNEL_UP_AND_RUNNING
))
369 * Will send a fib, returning 0 if successful.
371 static int aac_rkt_send(struct fib
* fib
)
373 u64 addr
= fib
->hw_fib_pa
;
374 struct aac_dev
*dev
= fib
->dev
;
375 volatile void __iomem
*device
= dev
->regs
.rkt
;
378 dprintk((KERN_DEBUG
"%p->aac_rkt_send(%p->%llx)\n", dev
, fib
, addr
));
379 Index
= rkt_readl(dev
, MUnit
.InboundQueue
);
380 if (Index
== 0xFFFFFFFFL
)
381 Index
= rkt_readl(dev
, MUnit
.InboundQueue
);
382 dprintk((KERN_DEBUG
"Index = 0x%x\n", Index
));
383 if (Index
== 0xFFFFFFFFL
)
386 dprintk((KERN_DEBUG
"entry = %x %x %u\n", (u32
)(addr
& 0xffffffff),
387 (u32
)(addr
>> 32), (u32
)le16_to_cpu(fib
->hw_fib
->header
.Size
)));
388 writel((u32
)(addr
& 0xffffffff), device
);
389 device
+= sizeof(u32
);
390 writel((u32
)(addr
>> 32), device
);
391 device
+= sizeof(u32
);
392 writel(le16_to_cpu(fib
->hw_fib
->header
.Size
), device
);
393 rkt_writel(dev
, MUnit
.InboundQueue
, Index
);
394 dprintk((KERN_DEBUG
"aac_rkt_send - return 0\n"));
399 * aac_rkt_init - initialize an i960 based AAC card
400 * @dev: device to configure
402 * Allocate and set up resources for the i960 based AAC variants. The
403 * device_interface in the commregion will be allocated and linked
404 * to the comm region.
407 int aac_rkt_init(struct aac_dev
*dev
)
410 unsigned long status
;
418 * Check to see if the board panic'd while booting.
421 * Check to see if the board failed any self tests.
423 if (rkt_readl(dev
, MUnit
.OMRx
[0]) & SELF_TEST_FAILED
) {
424 printk(KERN_ERR
"%s%d: adapter self-test failed.\n", dev
->name
, instance
);
428 * Check to see if the monitor panic'd while booting.
430 if (rkt_readl(dev
, MUnit
.OMRx
[0]) & MONITOR_PANIC
) {
431 printk(KERN_ERR
"%s%d: adapter monitor panic.\n", dev
->name
, instance
);
435 * Check to see if the board panic'd while booting.
437 if (rkt_readl(dev
, MUnit
.OMRx
[0]) & KERNEL_PANIC
) {
438 printk(KERN_ERR
"%s%d: adapter kernel panic'd.\n", dev
->name
, instance
);
443 * Wait for the adapter to be up and running. Wait up to 3 minutes
445 while (!(rkt_readl(dev
, MUnit
.OMRx
[0]) & KERNEL_UP_AND_RUNNING
))
447 if(time_after(jiffies
, start
+180*HZ
))
449 status
= rkt_readl(dev
, MUnit
.OMRx
[0]);
450 printk(KERN_ERR
"%s%d: adapter kernel failed to start, init status = %lx.\n",
451 dev
->name
, instance
, status
);
454 schedule_timeout_uninterruptible(1);
456 if (request_irq(dev
->scsi_host_ptr
->irq
, aac_rkt_intr
, SA_SHIRQ
|SA_INTERRUPT
, "aacraid", (void *)dev
)<0)
458 printk(KERN_ERR
"%s%d: Interrupt unavailable.\n", name
, instance
);
462 * Fill in the function dispatch table.
464 dev
->a_ops
.adapter_interrupt
= aac_rkt_interrupt_adapter
;
465 dev
->a_ops
.adapter_disable_int
= aac_rkt_disable_interrupt
;
466 dev
->a_ops
.adapter_notify
= aac_rkt_notify_adapter
;
467 dev
->a_ops
.adapter_sync_cmd
= rkt_sync_cmd
;
468 dev
->a_ops
.adapter_check_health
= aac_rkt_check_health
;
469 dev
->a_ops
.adapter_send
= aac_rkt_send
;
472 * First clear out all interrupts. Then enable the one's that we
475 rkt_writeb(dev
, MUnit
.OIMR
, 0xff);
476 rkt_writel(dev
, MUnit
.ODR
, 0xffffffff);
477 rkt_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xfb);
479 if (aac_init_adapter(dev
) == NULL
)
481 if (dev
->new_comm_interface
) {
483 * FIB Setup has already been done, but we can minimize the
484 * damage by at least ensuring the OS never issues more
485 * commands than we can handle. The Rocket adapters currently
486 * can only handle 246 commands and 8 AIFs at the same time,
487 * and in fact do notify us accordingly if we negotiate the
488 * FIB size. The problem that causes us to add this check is
489 * to ensure that we do not overdo it with the adapter when a
490 * hard coded FIB override is being utilized. This special
491 * case warrants this half baked, but convenient, check here.
493 if (dev
->scsi_host_ptr
->can_queue
> (246 - AAC_NUM_MGT_FIB
)) {
494 dev
->init
->MaxIoCommands
= cpu_to_le32(246);
495 dev
->scsi_host_ptr
->can_queue
= 246 - AAC_NUM_MGT_FIB
;
497 rkt_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xf7);
500 * Tell the adapter that all is configured, and it can start
503 aac_rkt_start_adapter(dev
);
507 rkt_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xff);
508 free_irq(dev
->scsi_host_ptr
->irq
, (void *)dev
);