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-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 * Abstract: Hardware miniport for Drawbridge specific hardware functions.
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/pci.h>
37 #include <linux/spinlock.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>
44 #include <scsi/scsi_host.h>
48 static irqreturn_t
aac_rx_intr_producer(int irq
, void *dev_id
)
50 struct aac_dev
*dev
= dev_id
;
51 unsigned long bellbits
;
52 u8 intstat
= rx_readb(dev
, MUnit
.OISR
);
55 * Read mask and invert because drawbridge is reversed.
56 * This allows us to only service interrupts that have
58 * Check to see if this is our interrupt. If it isn't just return
60 if (likely(intstat
& ~(dev
->OIMR
))) {
61 bellbits
= rx_readl(dev
, OutboundDoorbellReg
);
62 if (unlikely(bellbits
& DoorBellPrintfReady
)) {
63 aac_printf(dev
, readl (&dev
->IndexRegs
->Mailbox
[5]));
64 rx_writel(dev
, MUnit
.ODR
,DoorBellPrintfReady
);
65 rx_writel(dev
, InboundDoorbellReg
,DoorBellPrintfDone
);
67 else if (unlikely(bellbits
& DoorBellAdapterNormCmdReady
)) {
68 rx_writel(dev
, MUnit
.ODR
, DoorBellAdapterNormCmdReady
);
69 aac_command_normal(&dev
->queues
->queue
[HostNormCmdQueue
]);
71 else if (likely(bellbits
& DoorBellAdapterNormRespReady
)) {
72 rx_writel(dev
, MUnit
.ODR
,DoorBellAdapterNormRespReady
);
73 aac_response_normal(&dev
->queues
->queue
[HostNormRespQueue
]);
75 else if (unlikely(bellbits
& DoorBellAdapterNormCmdNotFull
)) {
76 rx_writel(dev
, MUnit
.ODR
, DoorBellAdapterNormCmdNotFull
);
78 else if (unlikely(bellbits
& DoorBellAdapterNormRespNotFull
)) {
79 rx_writel(dev
, MUnit
.ODR
, DoorBellAdapterNormCmdNotFull
);
80 rx_writel(dev
, MUnit
.ODR
, DoorBellAdapterNormRespNotFull
);
87 static irqreturn_t
aac_rx_intr_message(int irq
, void *dev_id
)
89 int isAif
, isFastResponse
, isSpecial
;
90 struct aac_dev
*dev
= dev_id
;
91 u32 Index
= rx_readl(dev
, MUnit
.OutboundQueue
);
92 if (unlikely(Index
== 0xFFFFFFFFL
))
93 Index
= rx_readl(dev
, MUnit
.OutboundQueue
);
94 if (likely(Index
!= 0xFFFFFFFFL
)) {
96 isAif
= isFastResponse
= isSpecial
= 0;
97 if (Index
& 0x00000002L
) {
99 if (Index
== 0xFFFFFFFEL
)
101 Index
&= ~0x00000002L
;
103 if (Index
& 0x00000001L
)
108 if (unlikely(aac_intr_normal(dev
,
110 isFastResponse
, NULL
))) {
116 DoorBellAdapterNormRespReady
);
119 Index
= rx_readl(dev
, MUnit
.OutboundQueue
);
120 } while (Index
!= 0xFFFFFFFFL
);
127 * aac_rx_disable_interrupt - Disable interrupts
131 static void aac_rx_disable_interrupt(struct aac_dev
*dev
)
133 rx_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xff);
137 * aac_rx_enable_interrupt_producer - Enable interrupts
141 static void aac_rx_enable_interrupt_producer(struct aac_dev
*dev
)
143 rx_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xfb);
147 * aac_rx_enable_interrupt_message - Enable interrupts
151 static void aac_rx_enable_interrupt_message(struct aac_dev
*dev
)
153 rx_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xf7);
157 * rx_sync_cmd - send a command and wait
159 * @command: Command to execute
160 * @p1: first parameter
161 * @ret: adapter status
163 * This routine will send a synchronous command to the adapter and wait
164 * for its completion.
167 static int rx_sync_cmd(struct aac_dev
*dev
, u32 command
,
168 u32 p1
, u32 p2
, u32 p3
, u32 p4
, u32 p5
, u32 p6
,
169 u32
*status
, u32
* r1
, u32
* r2
, u32
* r3
, u32
* r4
)
174 * Write the command into Mailbox 0
176 writel(command
, &dev
->IndexRegs
->Mailbox
[0]);
178 * Write the parameters into Mailboxes 1 - 6
180 writel(p1
, &dev
->IndexRegs
->Mailbox
[1]);
181 writel(p2
, &dev
->IndexRegs
->Mailbox
[2]);
182 writel(p3
, &dev
->IndexRegs
->Mailbox
[3]);
183 writel(p4
, &dev
->IndexRegs
->Mailbox
[4]);
185 * Clear the synch command doorbell to start on a clean slate.
187 rx_writel(dev
, OutboundDoorbellReg
, OUTBOUNDDOORBELL_0
);
189 * Disable doorbell interrupts
191 rx_writeb(dev
, MUnit
.OIMR
, dev
->OIMR
= 0xff);
193 * Force the completion of the mask register write before issuing
196 rx_readb (dev
, MUnit
.OIMR
);
198 * Signal that there is a new synch command
200 rx_writel(dev
, InboundDoorbellReg
, INBOUNDDOORBELL_0
);
206 * Wait up to 30 seconds
208 while (time_before(jiffies
, start
+30*HZ
))
210 udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
212 * Mon960 will set doorbell0 bit when it has completed the command.
214 if (rx_readl(dev
, OutboundDoorbellReg
) & OUTBOUNDDOORBELL_0
) {
216 * Clear the doorbell.
218 rx_writel(dev
, OutboundDoorbellReg
, OUTBOUNDDOORBELL_0
);
223 * Yield the processor in case we are slow
227 if (unlikely(ok
!= 1)) {
229 * Restore interrupt mask even though we timed out
231 aac_adapter_enable_int(dev
);
235 * Pull the synch status from Mailbox 0.
238 *status
= readl(&dev
->IndexRegs
->Mailbox
[0]);
240 *r1
= readl(&dev
->IndexRegs
->Mailbox
[1]);
242 *r2
= readl(&dev
->IndexRegs
->Mailbox
[2]);
244 *r3
= readl(&dev
->IndexRegs
->Mailbox
[3]);
246 *r4
= readl(&dev
->IndexRegs
->Mailbox
[4]);
248 * Clear the synch command doorbell.
250 rx_writel(dev
, OutboundDoorbellReg
, OUTBOUNDDOORBELL_0
);
252 * Restore interrupt mask
254 aac_adapter_enable_int(dev
);
260 * aac_rx_interrupt_adapter - interrupt adapter
263 * Send an interrupt to the i960 and breakpoint it.
266 static void aac_rx_interrupt_adapter(struct aac_dev
*dev
)
268 rx_sync_cmd(dev
, BREAKPOINT_REQUEST
, 0, 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
272 * aac_rx_notify_adapter - send an event to the adapter
274 * @event: Event to send
276 * Notify the i960 that something it probably cares about has
280 static void aac_rx_notify_adapter(struct aac_dev
*dev
, u32 event
)
285 rx_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_1
);
287 case HostNormRespNotFull
:
288 rx_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_4
);
290 case AdapNormRespQue
:
291 rx_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_2
);
293 case HostNormCmdNotFull
:
294 rx_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_3
);
299 rx_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_6
);
302 rx_writel(dev
, MUnit
.IDR
,INBOUNDDOORBELL_5
);
311 * aac_rx_start_adapter - activate adapter
314 * Start up processing on an i960 based AAC adapter
317 static void aac_rx_start_adapter(struct aac_dev
*dev
)
319 union aac_init
*init
;
322 init
->r7
.host_elapsed_seconds
= cpu_to_le32(get_seconds());
323 // We can only use a 32 bit address here
324 rx_sync_cmd(dev
, INIT_STRUCT_BASE_ADDRESS
, (u32
)(ulong
)dev
->init_pa
,
325 0, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
);
329 * aac_rx_check_health
330 * @dev: device to check if healthy
332 * Will attempt to determine if the specified adapter is alive and
333 * capable of handling requests, returning 0 if alive.
335 static int aac_rx_check_health(struct aac_dev
*dev
)
337 u32 status
= rx_readl(dev
, MUnit
.OMRx
[0]);
340 * Check to see if the board failed any self tests.
342 if (unlikely(status
& SELF_TEST_FAILED
))
345 * Check to see if the board panic'd.
347 if (unlikely(status
& KERNEL_PANIC
)) {
353 dma_addr_t paddr
, baddr
;
356 if (likely((status
& 0xFF000000L
) == 0xBC000000L
))
357 return (status
>> 16) & 0xFF;
358 buffer
= pci_alloc_consistent(dev
->pdev
, 512, &baddr
);
360 if (unlikely(buffer
== NULL
))
362 post
= pci_alloc_consistent(dev
->pdev
,
363 sizeof(struct POSTSTATUS
), &paddr
);
364 if (unlikely(post
== NULL
)) {
365 pci_free_consistent(dev
->pdev
, 512, buffer
, baddr
);
368 memset(buffer
, 0, 512);
369 post
->Post_Command
= cpu_to_le32(COMMAND_POST_RESULTS
);
370 post
->Post_Address
= cpu_to_le32(baddr
);
371 rx_writel(dev
, MUnit
.IMRx
[0], paddr
);
372 rx_sync_cmd(dev
, COMMAND_POST_RESULTS
, baddr
, 0, 0, 0, 0, 0,
373 NULL
, NULL
, NULL
, NULL
, NULL
);
374 pci_free_consistent(dev
->pdev
, sizeof(struct POSTSTATUS
),
376 if (likely((buffer
[0] == '0') && ((buffer
[1] == 'x') || (buffer
[1] == 'X')))) {
377 ret
= (hex_to_bin(buffer
[2]) << 4) +
378 hex_to_bin(buffer
[3]);
380 pci_free_consistent(dev
->pdev
, 512, buffer
, baddr
);
384 * Wait for the adapter to be up and running.
386 if (unlikely(!(status
& KERNEL_UP_AND_RUNNING
)))
395 * aac_rx_deliver_producer
398 * Will send a fib, returning 0 if successful.
400 int aac_rx_deliver_producer(struct fib
* fib
)
402 struct aac_dev
*dev
= fib
->dev
;
403 struct aac_queue
*q
= &dev
->queues
->queue
[AdapNormCmdQueue
];
405 unsigned long nointr
= 0;
407 aac_queue_get( dev
, &Index
, AdapNormCmdQueue
, fib
->hw_fib_va
, 1, fib
, &nointr
);
409 atomic_inc(&q
->numpending
);
410 *(q
->headers
.producer
) = cpu_to_le32(Index
+ 1);
411 if (!(nointr
& aac_config
.irq_mod
))
412 aac_adapter_notify(dev
, AdapNormCmdQueue
);
418 * aac_rx_deliver_message
421 * Will send a fib, returning 0 if successful.
423 static int aac_rx_deliver_message(struct fib
* fib
)
425 struct aac_dev
*dev
= fib
->dev
;
426 struct aac_queue
*q
= &dev
->queues
->queue
[AdapNormCmdQueue
];
429 volatile void __iomem
*device
;
431 unsigned long count
= 10000000L; /* 50 seconds */
432 atomic_inc(&q
->numpending
);
434 Index
= rx_readl(dev
, MUnit
.InboundQueue
);
435 if (unlikely(Index
== 0xFFFFFFFFL
))
436 Index
= rx_readl(dev
, MUnit
.InboundQueue
);
437 if (likely(Index
!= 0xFFFFFFFFL
))
440 atomic_dec(&q
->numpending
);
445 device
= dev
->base
+ Index
;
446 addr
= fib
->hw_fib_pa
;
447 writel((u32
)(addr
& 0xffffffff), device
);
448 device
+= sizeof(u32
);
449 writel((u32
)(addr
>> 32), device
);
450 device
+= sizeof(u32
);
451 writel(le16_to_cpu(fib
->hw_fib_va
->header
.Size
), device
);
452 rx_writel(dev
, MUnit
.InboundQueue
, Index
);
458 * @size: mapping resize request
461 static int aac_rx_ioremap(struct aac_dev
* dev
, u32 size
)
464 iounmap(dev
->regs
.rx
);
467 dev
->base
= dev
->regs
.rx
= ioremap(dev
->base_start
, size
);
468 if (dev
->base
== NULL
)
470 dev
->IndexRegs
= &dev
->regs
.rx
->IndexRegs
;
474 static int aac_rx_restart_adapter(struct aac_dev
*dev
, int bled
, u8 reset_type
)
478 if (!(dev
->supplement_adapter_info
.supported_options2
&
479 AAC_OPTION_MU_RESET
) || (bled
>= 0) || (bled
== -2)) {
481 printk(KERN_ERR
"%s%d: adapter kernel panic'd %x.\n",
482 dev
->name
, dev
->id
, bled
);
484 bled
= aac_adapter_sync_cmd(dev
, IOP_RESET_ALWAYS
,
485 0, 0, 0, 0, 0, 0, &var
, NULL
, NULL
, NULL
, NULL
);
486 if (!bled
&& (var
!= 0x00000001) && (var
!= 0x3803000F))
489 if (bled
&& (bled
!= -ETIMEDOUT
))
490 bled
= aac_adapter_sync_cmd(dev
, IOP_RESET
,
491 0, 0, 0, 0, 0, 0, &var
, NULL
, NULL
, NULL
, NULL
);
493 if (bled
&& (bled
!= -ETIMEDOUT
))
496 if (bled
&& (var
== 0x3803000F)) { /* USE_OTHER_METHOD */
497 rx_writel(dev
, MUnit
.reserved2
, 3);
498 msleep(5000); /* Delay 5 seconds */
501 if (bled
&& (var
!= 0x00000001))
504 if (rx_readl(dev
, MUnit
.OMRx
[0]) & KERNEL_PANIC
)
506 if (startup_timeout
< 300)
507 startup_timeout
= 300;
512 * aac_rx_select_comm - Select communications method
514 * @comm: communications method
517 int aac_rx_select_comm(struct aac_dev
*dev
, int comm
)
520 case AAC_COMM_PRODUCER
:
521 dev
->a_ops
.adapter_enable_int
= aac_rx_enable_interrupt_producer
;
522 dev
->a_ops
.adapter_intr
= aac_rx_intr_producer
;
523 dev
->a_ops
.adapter_deliver
= aac_rx_deliver_producer
;
525 case AAC_COMM_MESSAGE
:
526 dev
->a_ops
.adapter_enable_int
= aac_rx_enable_interrupt_message
;
527 dev
->a_ops
.adapter_intr
= aac_rx_intr_message
;
528 dev
->a_ops
.adapter_deliver
= aac_rx_deliver_message
;
537 * aac_rx_init - initialize an i960 based AAC card
538 * @dev: device to configure
540 * Allocate and set up resources for the i960 based AAC variants. The
541 * device_interface in the commregion will be allocated and linked
542 * to the comm region.
545 int _aac_rx_init(struct aac_dev
*dev
)
548 unsigned long status
;
550 int instance
= dev
->id
;
551 const char * name
= dev
->name
;
553 if (aac_adapter_ioremap(dev
, dev
->base_size
)) {
554 printk(KERN_WARNING
"%s: unable to map adapter.\n", name
);
558 /* Failure to reset here is an option ... */
559 dev
->a_ops
.adapter_sync_cmd
= rx_sync_cmd
;
560 dev
->a_ops
.adapter_enable_int
= aac_rx_disable_interrupt
;
561 dev
->OIMR
= status
= rx_readb (dev
, MUnit
.OIMR
);
562 if ((((status
& 0x0c) != 0x0c) || aac_reset_devices
|| reset_devices
) &&
563 !aac_rx_restart_adapter(dev
, 0, IOP_HWSOFT_RESET
))
564 /* Make sure the Hardware FIFO is empty */
565 while ((++restart
< 512) &&
566 (rx_readl(dev
, MUnit
.OutboundQueue
) != 0xFFFFFFFFL
));
568 * Check to see if the board panic'd while booting.
570 status
= rx_readl(dev
, MUnit
.OMRx
[0]);
571 if (status
& KERNEL_PANIC
) {
572 if (aac_rx_restart_adapter(dev
,
573 aac_rx_check_health(dev
), IOP_HWSOFT_RESET
))
578 * Check to see if the board failed any self tests.
580 status
= rx_readl(dev
, MUnit
.OMRx
[0]);
581 if (status
& SELF_TEST_FAILED
) {
582 printk(KERN_ERR
"%s%d: adapter self-test failed.\n", dev
->name
, instance
);
586 * Check to see if the monitor panic'd while booting.
588 if (status
& MONITOR_PANIC
) {
589 printk(KERN_ERR
"%s%d: adapter monitor panic.\n", dev
->name
, instance
);
594 * Wait for the adapter to be up and running. Wait up to 3 minutes
596 while (!((status
= rx_readl(dev
, MUnit
.OMRx
[0])) & KERNEL_UP_AND_RUNNING
))
599 (status
& (KERNEL_PANIC
|SELF_TEST_FAILED
|MONITOR_PANIC
))) ||
600 time_after(jiffies
, start
+HZ
*startup_timeout
)) {
601 printk(KERN_ERR
"%s%d: adapter kernel failed to start, init status = %lx.\n",
602 dev
->name
, instance
, status
);
606 ((status
& (KERNEL_PANIC
|SELF_TEST_FAILED
|MONITOR_PANIC
)) ||
607 time_after(jiffies
, start
+ HZ
*
608 ((startup_timeout
> 60)
609 ? (startup_timeout
- 60)
610 : (startup_timeout
/ 2))))) {
611 if (likely(!aac_rx_restart_adapter(dev
,
612 aac_rx_check_health(dev
), IOP_HWSOFT_RESET
)))
618 if (restart
&& aac_commit
)
621 * Fill in the common function dispatch table.
623 dev
->a_ops
.adapter_interrupt
= aac_rx_interrupt_adapter
;
624 dev
->a_ops
.adapter_disable_int
= aac_rx_disable_interrupt
;
625 dev
->a_ops
.adapter_notify
= aac_rx_notify_adapter
;
626 dev
->a_ops
.adapter_sync_cmd
= rx_sync_cmd
;
627 dev
->a_ops
.adapter_check_health
= aac_rx_check_health
;
628 dev
->a_ops
.adapter_restart
= aac_rx_restart_adapter
;
629 dev
->a_ops
.adapter_start
= aac_rx_start_adapter
;
632 * First clear out all interrupts. Then enable the one's that we
635 aac_adapter_comm(dev
, AAC_COMM_PRODUCER
);
636 aac_adapter_disable_int(dev
);
637 rx_writel(dev
, MUnit
.ODR
, 0xffffffff);
638 aac_adapter_enable_int(dev
);
640 if (aac_init_adapter(dev
) == NULL
)
642 aac_adapter_comm(dev
, dev
->comm_interface
);
643 dev
->sync_mode
= 0; /* sync. mode not supported */
644 dev
->msi
= aac_msi
&& !pci_enable_msi(dev
->pdev
);
645 if (request_irq(dev
->pdev
->irq
, dev
->a_ops
.adapter_intr
,
646 IRQF_SHARED
, "aacraid", dev
) < 0) {
648 pci_disable_msi(dev
->pdev
);
649 printk(KERN_ERR
"%s%d: Interrupt unavailable.\n",
653 dev
->dbg_base
= dev
->base_start
;
654 dev
->dbg_base_mapped
= dev
->base
;
655 dev
->dbg_size
= dev
->base_size
;
657 aac_adapter_enable_int(dev
);
659 * Tell the adapter that all is configured, and it can
660 * start accepting requests
662 aac_rx_start_adapter(dev
);
671 int aac_rx_init(struct aac_dev
*dev
)
674 * Fill in the function dispatch table.
676 dev
->a_ops
.adapter_ioremap
= aac_rx_ioremap
;
677 dev
->a_ops
.adapter_comm
= aac_rx_select_comm
;
679 return _aac_rx_init(dev
);