2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Abstract: Hardware Device Interface for PMC SRC based controllers
32 #include <linux/kernel.h>
33 #include <linux/init.h>
34 #include <linux/types.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 <scsi/scsi_host.h>
47 static irqreturn_t
aac_src_intr_message(int irq
, void *dev_id
)
49 struct aac_dev
*dev
= dev_id
;
50 unsigned long bellbits
, bellbits_shifted
;
51 int our_interrupt
= 0;
55 bellbits
= src_readl(dev
, MUnit
.ODR_R
);
56 if (bellbits
& PmDoorBellResponseSent
) {
57 bellbits
= PmDoorBellResponseSent
;
58 /* handle async. status */
60 index
= dev
->host_rrq_idx
;
61 if (dev
->host_rrq
[index
] == 0) {
62 u32 old_index
= index
;
66 if (index
== dev
->scsi_host_ptr
->can_queue
+
69 if (dev
->host_rrq
[index
] != 0)
71 } while (index
!= old_index
);
72 dev
->host_rrq_idx
= index
;
76 /* remove toggle bit (31) */
77 handle
= (dev
->host_rrq
[index
] & 0x7fffffff);
78 /* check fast response bit (30) */
79 if (handle
& 0x40000000)
85 aac_intr_normal(dev
, handle
-1, 0, isFastResponse
, NULL
);
87 dev
->host_rrq
[index
++] = 0;
88 if (index
== dev
->scsi_host_ptr
->can_queue
+
91 dev
->host_rrq_idx
= index
;
94 bellbits_shifted
= (bellbits
>> SRC_ODR_SHIFT
);
95 if (bellbits_shifted
& DoorBellAifPending
) {
98 aac_intr_normal(dev
, 0, 2, 0, NULL
);
99 } else if (bellbits_shifted
& OUTBOUNDDOORBELL_0
) {
100 unsigned long sflags
;
101 struct list_head
*entry
;
106 if (dev
->sync_fib
->callback
)
107 dev
->sync_fib
->callback(dev
->sync_fib
->callback_data
,
109 spin_lock_irqsave(&dev
->sync_fib
->event_lock
, sflags
);
110 if (dev
->sync_fib
->flags
& FIB_CONTEXT_FLAG_WAIT
) {
111 dev
->management_fib_count
--;
112 up(&dev
->sync_fib
->event_wait
);
114 spin_unlock_irqrestore(&dev
->sync_fib
->event_lock
, sflags
);
115 spin_lock_irqsave(&dev
->sync_lock
, sflags
);
116 if (!list_empty(&dev
->sync_fib_list
)) {
117 entry
= dev
->sync_fib_list
.next
;
118 dev
->sync_fib
= list_entry(entry
, struct fib
, fiblink
);
122 dev
->sync_fib
= NULL
;
124 spin_unlock_irqrestore(&dev
->sync_lock
, sflags
);
126 aac_adapter_sync_cmd(dev
, SEND_SYNCHRONOUS_FIB
,
127 (u32
)dev
->sync_fib
->hw_fib_pa
, 0, 0, 0, 0, 0,
128 NULL
, NULL
, NULL
, NULL
, NULL
);
135 src_writel(dev
, MUnit
.ODR_C
, bellbits
);
142 * aac_src_disable_interrupt - Disable interrupts
146 static void aac_src_disable_interrupt(struct aac_dev
*dev
)
148 src_writel(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xffffffff);
152 * aac_src_enable_interrupt_message - Enable interrupts
156 static void aac_src_enable_interrupt_message(struct aac_dev
*dev
)
158 src_writel(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xfffffff8);
162 * src_sync_cmd - send a command and wait
164 * @command: Command to execute
165 * @p1: first parameter
166 * @ret: adapter status
168 * This routine will send a synchronous command to the adapter and wait
169 * for its completion.
172 static int src_sync_cmd(struct aac_dev
*dev
, u32 command
,
173 u32 p1
, u32 p2
, u32 p3
, u32 p4
, u32 p5
, u32 p6
,
174 u32
*status
, u32
* r1
, u32
* r2
, u32
* r3
, u32
* r4
)
180 * Write the command into Mailbox 0
182 writel(command
, &dev
->IndexRegs
->Mailbox
[0]);
184 * Write the parameters into Mailboxes 1 - 6
186 writel(p1
, &dev
->IndexRegs
->Mailbox
[1]);
187 writel(p2
, &dev
->IndexRegs
->Mailbox
[2]);
188 writel(p3
, &dev
->IndexRegs
->Mailbox
[3]);
189 writel(p4
, &dev
->IndexRegs
->Mailbox
[4]);
192 * Clear the synch command doorbell to start on a clean slate.
194 src_writel(dev
, MUnit
.ODR_C
, OUTBOUNDDOORBELL_0
<< SRC_ODR_SHIFT
);
197 * Disable doorbell interrupts
199 src_writel(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xffffffff);
202 * Force the completion of the mask register write before issuing
205 src_readl(dev
, MUnit
.OIMR
);
208 * Signal that there is a new synch command
210 src_writel(dev
, MUnit
.IDR
, INBOUNDDOORBELL_0
<< SRC_IDR_SHIFT
);
212 if (!dev
->sync_mode
|| command
!= SEND_SYNCHRONOUS_FIB
) {
217 * Wait up to 5 minutes
219 while (time_before(jiffies
, start
+300*HZ
)) {
220 udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
222 * Mon960 will set doorbell0 bit when it has completed the command.
224 if ((src_readl(dev
, MUnit
.ODR_R
) >> SRC_ODR_SHIFT
) & OUTBOUNDDOORBELL_0
) {
226 * Clear the doorbell.
228 src_writel(dev
, MUnit
.ODR_C
, OUTBOUNDDOORBELL_0
<< SRC_ODR_SHIFT
);
233 * Yield the processor in case we are slow
237 if (unlikely(ok
!= 1)) {
239 * Restore interrupt mask even though we timed out
241 aac_adapter_enable_int(dev
);
245 * Pull the synch status from Mailbox 0.
248 *status
= readl(&dev
->IndexRegs
->Mailbox
[0]);
250 *r1
= readl(&dev
->IndexRegs
->Mailbox
[1]);
252 *r2
= readl(&dev
->IndexRegs
->Mailbox
[2]);
254 *r3
= readl(&dev
->IndexRegs
->Mailbox
[3]);
256 *r4
= readl(&dev
->IndexRegs
->Mailbox
[4]);
259 * Clear the synch command doorbell.
261 src_writel(dev
, MUnit
.ODR_C
, OUTBOUNDDOORBELL_0
<< SRC_ODR_SHIFT
);
265 * Restore interrupt mask
267 aac_adapter_enable_int(dev
);
272 * aac_src_interrupt_adapter - interrupt adapter
275 * Send an interrupt to the i960 and breakpoint it.
278 static void aac_src_interrupt_adapter(struct aac_dev
*dev
)
280 src_sync_cmd(dev
, BREAKPOINT_REQUEST
,
282 NULL
, NULL
, NULL
, NULL
, NULL
);
286 * aac_src_notify_adapter - send an event to the adapter
288 * @event: Event to send
290 * Notify the i960 that something it probably cares about has
294 static void aac_src_notify_adapter(struct aac_dev
*dev
, u32 event
)
299 src_writel(dev
, MUnit
.ODR_C
,
300 INBOUNDDOORBELL_1
<< SRC_ODR_SHIFT
);
302 case HostNormRespNotFull
:
303 src_writel(dev
, MUnit
.ODR_C
,
304 INBOUNDDOORBELL_4
<< SRC_ODR_SHIFT
);
306 case AdapNormRespQue
:
307 src_writel(dev
, MUnit
.ODR_C
,
308 INBOUNDDOORBELL_2
<< SRC_ODR_SHIFT
);
310 case HostNormCmdNotFull
:
311 src_writel(dev
, MUnit
.ODR_C
,
312 INBOUNDDOORBELL_3
<< SRC_ODR_SHIFT
);
315 src_writel(dev
, MUnit
.ODR_C
,
316 INBOUNDDOORBELL_6
<< SRC_ODR_SHIFT
);
319 src_writel(dev
, MUnit
.ODR_C
,
320 INBOUNDDOORBELL_5
<< SRC_ODR_SHIFT
);
329 * aac_src_start_adapter - activate adapter
332 * Start up processing on an i960 based AAC adapter
335 static void aac_src_start_adapter(struct aac_dev
*dev
)
337 struct aac_init
*init
;
340 init
->HostElapsedSeconds
= cpu_to_le32(get_seconds());
342 /* We can only use a 32 bit address here */
343 src_sync_cmd(dev
, INIT_STRUCT_BASE_ADDRESS
, (u32
)(ulong
)dev
->init_pa
,
344 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
348 * aac_src_check_health
349 * @dev: device to check if healthy
351 * Will attempt to determine if the specified adapter is alive and
352 * capable of handling requests, returning 0 if alive.
354 static int aac_src_check_health(struct aac_dev
*dev
)
356 u32 status
= src_readl(dev
, MUnit
.OMR
);
359 * Check to see if the board failed any self tests.
361 if (unlikely(status
& SELF_TEST_FAILED
))
365 * Check to see if the board panic'd.
367 if (unlikely(status
& KERNEL_PANIC
))
368 return (status
>> 16) & 0xFF;
370 * Wait for the adapter to be up and running.
372 if (unlikely(!(status
& KERNEL_UP_AND_RUNNING
)))
381 * aac_src_deliver_message
384 * Will send a fib, returning 0 if successful.
386 static int aac_src_deliver_message(struct fib
*fib
)
388 struct aac_dev
*dev
= fib
->dev
;
389 struct aac_queue
*q
= &dev
->queues
->queue
[AdapNormCmdQueue
];
390 unsigned long qflags
;
393 struct aac_fib_xporthdr
*pFibX
;
395 spin_lock_irqsave(q
->lock
, qflags
);
397 spin_unlock_irqrestore(q
->lock
, qflags
);
399 /* Calculate the amount to the fibsize bits */
400 fibsize
= (sizeof(struct aac_fib_xporthdr
) +
401 fib
->hw_fib_va
->header
.Size
+ 127) / 128 - 1;
402 if (fibsize
> (ALIGN32
- 1))
403 fibsize
= ALIGN32
- 1;
405 /* Fill XPORT header */
406 pFibX
= (struct aac_fib_xporthdr
*)
407 ((unsigned char *)fib
->hw_fib_va
-
408 sizeof(struct aac_fib_xporthdr
));
409 pFibX
->Handle
= fib
->hw_fib_va
->header
.SenderData
+ 1;
410 pFibX
->HostAddress
= fib
->hw_fib_pa
;
411 pFibX
->Size
= fib
->hw_fib_va
->header
.Size
;
412 address
= fib
->hw_fib_pa
- (u64
)sizeof(struct aac_fib_xporthdr
);
414 src_writel(dev
, MUnit
.IQ_H
, (u32
)(address
>> 32));
415 src_writel(dev
, MUnit
.IQ_L
, (u32
)(address
& 0xffffffff) + fibsize
);
421 * @size: mapping resize request
424 static int aac_src_ioremap(struct aac_dev
*dev
, u32 size
)
427 iounmap(dev
->regs
.src
.bar1
);
428 dev
->regs
.src
.bar1
= NULL
;
429 iounmap(dev
->regs
.src
.bar0
);
430 dev
->base
= dev
->regs
.src
.bar0
= NULL
;
433 dev
->regs
.src
.bar1
= ioremap(pci_resource_start(dev
->pdev
, 2),
434 AAC_MIN_SRC_BAR1_SIZE
);
436 if (dev
->regs
.src
.bar1
== NULL
)
438 dev
->base
= dev
->regs
.src
.bar0
= ioremap(dev
->scsi_host_ptr
->base
,
440 if (dev
->base
== NULL
) {
441 iounmap(dev
->regs
.src
.bar1
);
442 dev
->regs
.src
.bar1
= NULL
;
445 dev
->IndexRegs
= &((struct src_registers __iomem
*)
446 dev
->base
)->u
.tupelo
.IndexRegs
;
452 * @size: mapping resize request
455 static int aac_srcv_ioremap(struct aac_dev
*dev
, u32 size
)
458 iounmap(dev
->regs
.src
.bar0
);
459 dev
->base
= dev
->regs
.src
.bar0
= NULL
;
462 dev
->base
= dev
->regs
.src
.bar0
= ioremap(dev
->scsi_host_ptr
->base
, size
);
463 if (dev
->base
== NULL
)
465 dev
->IndexRegs
= &((struct src_registers __iomem
*)
466 dev
->base
)->u
.denali
.IndexRegs
;
470 static int aac_src_restart_adapter(struct aac_dev
*dev
, int bled
)
476 printk(KERN_ERR
"%s%d: adapter kernel panic'd %x.\n",
477 dev
->name
, dev
->id
, bled
);
478 bled
= aac_adapter_sync_cmd(dev
, IOP_RESET_ALWAYS
,
479 0, 0, 0, 0, 0, 0, &var
, &reset_mask
, NULL
, NULL
, NULL
);
480 if (bled
|| (var
!= 0x00000001))
482 if (dev
->supplement_adapter_info
.SupportedOptions2
&
483 AAC_OPTION_DOORBELL_RESET
) {
484 src_writel(dev
, MUnit
.IDR
, reset_mask
);
485 msleep(5000); /* Delay 5 seconds */
489 if (src_readl(dev
, MUnit
.OMR
) & KERNEL_PANIC
)
492 if (startup_timeout
< 300)
493 startup_timeout
= 300;
499 * aac_src_select_comm - Select communications method
501 * @comm: communications method
503 int aac_src_select_comm(struct aac_dev
*dev
, int comm
)
506 case AAC_COMM_MESSAGE
:
507 dev
->a_ops
.adapter_enable_int
= aac_src_enable_interrupt_message
;
508 dev
->a_ops
.adapter_intr
= aac_src_intr_message
;
509 dev
->a_ops
.adapter_deliver
= aac_src_deliver_message
;
518 * aac_src_init - initialize an Cardinal Frey Bar card
519 * @dev: device to configure
523 int aac_src_init(struct aac_dev
*dev
)
526 unsigned long status
;
528 int instance
= dev
->id
;
529 const char *name
= dev
->name
;
531 dev
->a_ops
.adapter_ioremap
= aac_src_ioremap
;
532 dev
->a_ops
.adapter_comm
= aac_src_select_comm
;
534 dev
->base_size
= AAC_MIN_SRC_BAR0_SIZE
;
535 if (aac_adapter_ioremap(dev
, dev
->base_size
)) {
536 printk(KERN_WARNING
"%s: unable to map adapter.\n", name
);
540 /* Failure to reset here is an option ... */
541 dev
->a_ops
.adapter_sync_cmd
= src_sync_cmd
;
542 dev
->a_ops
.adapter_enable_int
= aac_src_disable_interrupt
;
543 if ((aac_reset_devices
|| reset_devices
) &&
544 !aac_src_restart_adapter(dev
, 0))
547 * Check to see if the board panic'd while booting.
549 status
= src_readl(dev
, MUnit
.OMR
);
550 if (status
& KERNEL_PANIC
) {
551 if (aac_src_restart_adapter(dev
, aac_src_check_health(dev
)))
556 * Check to see if the board failed any self tests.
558 status
= src_readl(dev
, MUnit
.OMR
);
559 if (status
& SELF_TEST_FAILED
) {
560 printk(KERN_ERR
"%s%d: adapter self-test failed.\n",
561 dev
->name
, instance
);
565 * Check to see if the monitor panic'd while booting.
567 if (status
& MONITOR_PANIC
) {
568 printk(KERN_ERR
"%s%d: adapter monitor panic.\n",
569 dev
->name
, instance
);
574 * Wait for the adapter to be up and running. Wait up to 3 minutes
576 while (!((status
= src_readl(dev
, MUnit
.OMR
)) &
577 KERNEL_UP_AND_RUNNING
)) {
579 (status
& (KERNEL_PANIC
|SELF_TEST_FAILED
|MONITOR_PANIC
))) ||
580 time_after(jiffies
, start
+HZ
*startup_timeout
)) {
581 printk(KERN_ERR
"%s%d: adapter kernel failed to start, init status = %lx.\n",
582 dev
->name
, instance
, status
);
586 ((status
& (KERNEL_PANIC
|SELF_TEST_FAILED
|MONITOR_PANIC
)) ||
587 time_after(jiffies
, start
+ HZ
*
588 ((startup_timeout
> 60)
589 ? (startup_timeout
- 60)
590 : (startup_timeout
/ 2))))) {
591 if (likely(!aac_src_restart_adapter(dev
,
592 aac_src_check_health(dev
))))
598 if (restart
&& aac_commit
)
601 * Fill in the common function dispatch table.
603 dev
->a_ops
.adapter_interrupt
= aac_src_interrupt_adapter
;
604 dev
->a_ops
.adapter_disable_int
= aac_src_disable_interrupt
;
605 dev
->a_ops
.adapter_notify
= aac_src_notify_adapter
;
606 dev
->a_ops
.adapter_sync_cmd
= src_sync_cmd
;
607 dev
->a_ops
.adapter_check_health
= aac_src_check_health
;
608 dev
->a_ops
.adapter_restart
= aac_src_restart_adapter
;
611 * First clear out all interrupts. Then enable the one's that we
614 aac_adapter_comm(dev
, AAC_COMM_MESSAGE
);
615 aac_adapter_disable_int(dev
);
616 src_writel(dev
, MUnit
.ODR_C
, 0xffffffff);
617 aac_adapter_enable_int(dev
);
619 if (aac_init_adapter(dev
) == NULL
)
621 if (dev
->comm_interface
!= AAC_COMM_MESSAGE_TYPE1
)
624 dev
->msi
= aac_msi
&& !pci_enable_msi(dev
->pdev
);
626 if (request_irq(dev
->pdev
->irq
, dev
->a_ops
.adapter_intr
,
627 IRQF_SHARED
|IRQF_DISABLED
, "aacraid", dev
) < 0) {
630 pci_disable_msi(dev
->pdev
);
632 printk(KERN_ERR
"%s%d: Interrupt unavailable.\n",
636 dev
->dbg_base
= pci_resource_start(dev
->pdev
, 2);
637 dev
->dbg_base_mapped
= dev
->regs
.src
.bar1
;
638 dev
->dbg_size
= AAC_MIN_SRC_BAR1_SIZE
;
640 aac_adapter_enable_int(dev
);
642 if (!dev
->sync_mode
) {
644 * Tell the adapter that all is configured, and it can
645 * start accepting requests
647 aac_src_start_adapter(dev
);
657 * aac_srcv_init - initialize an SRCv card
658 * @dev: device to configure
662 int aac_srcv_init(struct aac_dev
*dev
)
665 unsigned long status
;
667 int instance
= dev
->id
;
668 const char *name
= dev
->name
;
670 dev
->a_ops
.adapter_ioremap
= aac_srcv_ioremap
;
671 dev
->a_ops
.adapter_comm
= aac_src_select_comm
;
673 dev
->base_size
= AAC_MIN_SRCV_BAR0_SIZE
;
674 if (aac_adapter_ioremap(dev
, dev
->base_size
)) {
675 printk(KERN_WARNING
"%s: unable to map adapter.\n", name
);
679 /* Failure to reset here is an option ... */
680 dev
->a_ops
.adapter_sync_cmd
= src_sync_cmd
;
681 dev
->a_ops
.adapter_enable_int
= aac_src_disable_interrupt
;
682 if ((aac_reset_devices
|| reset_devices
) &&
683 !aac_src_restart_adapter(dev
, 0))
686 * Check to see if the board panic'd while booting.
688 status
= src_readl(dev
, MUnit
.OMR
);
689 if (status
& KERNEL_PANIC
) {
690 if (aac_src_restart_adapter(dev
, aac_src_check_health(dev
)))
695 * Check to see if the board failed any self tests.
697 status
= src_readl(dev
, MUnit
.OMR
);
698 if (status
& SELF_TEST_FAILED
) {
699 printk(KERN_ERR
"%s%d: adapter self-test failed.\n", dev
->name
, instance
);
703 * Check to see if the monitor panic'd while booting.
705 if (status
& MONITOR_PANIC
) {
706 printk(KERN_ERR
"%s%d: adapter monitor panic.\n", dev
->name
, instance
);
711 * Wait for the adapter to be up and running. Wait up to 3 minutes
713 while (!((status
= src_readl(dev
, MUnit
.OMR
)) & KERNEL_UP_AND_RUNNING
)) {
715 (status
& (KERNEL_PANIC
|SELF_TEST_FAILED
|MONITOR_PANIC
))) ||
716 time_after(jiffies
, start
+HZ
*startup_timeout
)) {
717 printk(KERN_ERR
"%s%d: adapter kernel failed to start, init status = %lx.\n",
718 dev
->name
, instance
, status
);
722 ((status
& (KERNEL_PANIC
|SELF_TEST_FAILED
|MONITOR_PANIC
)) ||
723 time_after(jiffies
, start
+ HZ
*
724 ((startup_timeout
> 60)
725 ? (startup_timeout
- 60)
726 : (startup_timeout
/ 2))))) {
727 if (likely(!aac_src_restart_adapter(dev
, aac_src_check_health(dev
))))
733 if (restart
&& aac_commit
)
736 * Fill in the common function dispatch table.
738 dev
->a_ops
.adapter_interrupt
= aac_src_interrupt_adapter
;
739 dev
->a_ops
.adapter_disable_int
= aac_src_disable_interrupt
;
740 dev
->a_ops
.adapter_notify
= aac_src_notify_adapter
;
741 dev
->a_ops
.adapter_sync_cmd
= src_sync_cmd
;
742 dev
->a_ops
.adapter_check_health
= aac_src_check_health
;
743 dev
->a_ops
.adapter_restart
= aac_src_restart_adapter
;
746 * First clear out all interrupts. Then enable the one's that we
749 aac_adapter_comm(dev
, AAC_COMM_MESSAGE
);
750 aac_adapter_disable_int(dev
);
751 src_writel(dev
, MUnit
.ODR_C
, 0xffffffff);
752 aac_adapter_enable_int(dev
);
754 if (aac_init_adapter(dev
) == NULL
)
756 if (dev
->comm_interface
!= AAC_COMM_MESSAGE_TYPE1
)
758 dev
->msi
= aac_msi
&& !pci_enable_msi(dev
->pdev
);
759 if (request_irq(dev
->pdev
->irq
, dev
->a_ops
.adapter_intr
,
760 IRQF_SHARED
|IRQF_DISABLED
, "aacraid", dev
) < 0) {
762 pci_disable_msi(dev
->pdev
);
763 printk(KERN_ERR
"%s%d: Interrupt unavailable.\n",
767 dev
->dbg_base
= dev
->scsi_host_ptr
->base
;
768 dev
->dbg_base_mapped
= dev
->base
;
769 dev
->dbg_size
= dev
->base_size
;
771 aac_adapter_enable_int(dev
);
773 if (!dev
->sync_mode
) {
775 * Tell the adapter that all is configured, and it can
776 * start accepting requests
778 aac_src_start_adapter(dev
);