1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Adaptec AAC series RAID controller driver
4 * (c) Copyright 2001 Red Hat Inc.
6 * based on the old aacraid driver that is..
7 * Adaptec aacraid device driver for Linux.
9 * Copyright (c) 2000-2010 Adaptec, Inc.
10 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
16 * Abstract: Drawbridge specific support functions
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/types.h>
22 #include <linux/pci.h>
23 #include <linux/spinlock.h>
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/completion.h>
27 #include <linux/time.h>
28 #include <linux/interrupt.h>
30 #include <scsi/scsi_host.h>
34 static irqreturn_t
aac_sa_intr(int irq
, void *dev_id
)
36 struct aac_dev
*dev
= dev_id
;
37 unsigned short intstat
, mask
;
39 intstat
= sa_readw(dev
, DoorbellReg_p
);
41 * Read mask and invert because drawbridge is reversed.
42 * This allows us to only service interrupts that have been enabled.
44 mask
= ~(sa_readw(dev
, SaDbCSR
.PRISETIRQMASK
));
46 /* Check to see if this is our interrupt. If it isn't just return */
49 if (intstat
& PrintfReady
) {
50 aac_printf(dev
, sa_readl(dev
, Mailbox5
));
51 sa_writew(dev
, DoorbellClrReg_p
, PrintfReady
); /* clear PrintfReady */
52 sa_writew(dev
, DoorbellReg_s
, PrintfDone
);
53 } else if (intstat
& DOORBELL_1
) { // dev -> Host Normal Command Ready
54 sa_writew(dev
, DoorbellClrReg_p
, DOORBELL_1
);
55 aac_command_normal(&dev
->queues
->queue
[HostNormCmdQueue
]);
56 } else if (intstat
& DOORBELL_2
) { // dev -> Host Normal Response Ready
57 sa_writew(dev
, DoorbellClrReg_p
, DOORBELL_2
);
58 aac_response_normal(&dev
->queues
->queue
[HostNormRespQueue
]);
59 } else if (intstat
& DOORBELL_3
) { // dev -> Host Normal Command Not Full
60 sa_writew(dev
, DoorbellClrReg_p
, DOORBELL_3
);
61 } else if (intstat
& DOORBELL_4
) { // dev -> Host Normal Response Not Full
62 sa_writew(dev
, DoorbellClrReg_p
, DOORBELL_4
);
70 * aac_sa_disable_interrupt - disable interrupt
71 * @dev: Which adapter to enable.
74 static void aac_sa_disable_interrupt (struct aac_dev
*dev
)
76 sa_writew(dev
, SaDbCSR
.PRISETIRQMASK
, 0xffff);
80 * aac_sa_enable_interrupt - enable interrupt
81 * @dev: Which adapter to enable.
84 static void aac_sa_enable_interrupt (struct aac_dev
*dev
)
86 sa_writew(dev
, SaDbCSR
.PRICLEARIRQMASK
, (PrintfReady
| DOORBELL_1
|
87 DOORBELL_2
| DOORBELL_3
| DOORBELL_4
));
91 * aac_sa_notify_adapter - handle adapter notification
92 * @dev: Adapter that notification is for
93 * @event: Event to notidy
95 * Notify the adapter of an event
98 static void aac_sa_notify_adapter(struct aac_dev
*dev
, u32 event
)
103 sa_writew(dev
, DoorbellReg_s
,DOORBELL_1
);
105 case HostNormRespNotFull
:
106 sa_writew(dev
, DoorbellReg_s
,DOORBELL_4
);
108 case AdapNormRespQue
:
109 sa_writew(dev
, DoorbellReg_s
,DOORBELL_2
);
111 case HostNormCmdNotFull
:
112 sa_writew(dev
, DoorbellReg_s
,DOORBELL_3
);
116 sa_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
117 NULL, NULL, NULL, NULL, NULL);
121 sa_writew(dev
, DoorbellReg_s
,DOORBELL_6
);
124 sa_writew(dev
, DoorbellReg_s
,DOORBELL_5
);
134 * sa_sync_cmd - send a command and wait
136 * @command: Command to execute
137 * @p1: first parameter
138 * @ret: adapter status
140 * This routine will send a synchronous command to the adapter and wait
141 * for its completion.
144 static int sa_sync_cmd(struct aac_dev
*dev
, u32 command
,
145 u32 p1
, u32 p2
, u32 p3
, u32 p4
, u32 p5
, u32 p6
,
146 u32
*ret
, u32
*r1
, u32
*r2
, u32
*r3
, u32
*r4
)
151 * Write the Command into Mailbox 0
153 sa_writel(dev
, Mailbox0
, command
);
155 * Write the parameters into Mailboxes 1 - 4
157 sa_writel(dev
, Mailbox1
, p1
);
158 sa_writel(dev
, Mailbox2
, p2
);
159 sa_writel(dev
, Mailbox3
, p3
);
160 sa_writel(dev
, Mailbox4
, p4
);
163 * Clear the synch command doorbell to start on a clean slate.
165 sa_writew(dev
, DoorbellClrReg_p
, DOORBELL_0
);
167 * Signal that there is a new synch command
169 sa_writew(dev
, DoorbellReg_s
, DOORBELL_0
);
174 while(time_before(jiffies
, start
+30*HZ
))
177 * Delay 5uS so that the monitor gets access
181 * Mon110 will set doorbell0 bit when it has
182 * completed the command.
184 if(sa_readw(dev
, DoorbellReg_p
) & DOORBELL_0
) {
194 * Clear the synch command doorbell.
196 sa_writew(dev
, DoorbellClrReg_p
, DOORBELL_0
);
198 * Pull the synch status from Mailbox 0.
201 *ret
= sa_readl(dev
, Mailbox0
);
203 *r1
= sa_readl(dev
, Mailbox1
);
205 *r2
= sa_readl(dev
, Mailbox2
);
207 *r3
= sa_readl(dev
, Mailbox3
);
209 *r4
= sa_readl(dev
, Mailbox4
);
214 * aac_sa_interrupt_adapter - interrupt an adapter
215 * @dev: Which adapter to enable.
217 * Breakpoint an adapter.
220 static void aac_sa_interrupt_adapter (struct aac_dev
*dev
)
222 sa_sync_cmd(dev
, BREAKPOINT_REQUEST
, 0, 0, 0, 0, 0, 0,
223 NULL
, NULL
, NULL
, NULL
, NULL
);
227 * aac_sa_start_adapter - activate adapter
230 * Start up processing on an ARM based AAC adapter
233 static void aac_sa_start_adapter(struct aac_dev
*dev
)
235 union aac_init
*init
;
237 * Fill in the remaining pieces of the init.
240 init
->r7
.host_elapsed_seconds
= cpu_to_le32(ktime_get_real_seconds());
241 /* We can only use a 32 bit address here */
242 sa_sync_cmd(dev
, INIT_STRUCT_BASE_ADDRESS
,
243 (u32
)(ulong
)dev
->init_pa
, 0, 0, 0, 0, 0,
244 NULL
, NULL
, NULL
, NULL
, NULL
);
247 static int aac_sa_restart_adapter(struct aac_dev
*dev
, int bled
, u8 reset_type
)
253 * aac_sa_check_health
254 * @dev: device to check if healthy
256 * Will attempt to determine if the specified adapter is alive and
257 * capable of handling requests, returning 0 if alive.
259 static int aac_sa_check_health(struct aac_dev
*dev
)
261 long status
= sa_readl(dev
, Mailbox7
);
264 * Check to see if the board failed any self tests.
266 if (status
& SELF_TEST_FAILED
)
269 * Check to see if the board panic'd while booting.
271 if (status
& KERNEL_PANIC
)
274 * Wait for the adapter to be up and running. Wait up to 3 minutes
276 if (!(status
& KERNEL_UP_AND_RUNNING
))
286 * @size: mapping resize request
289 static int aac_sa_ioremap(struct aac_dev
* dev
, u32 size
)
292 iounmap(dev
->regs
.sa
);
295 dev
->base
= dev
->regs
.sa
= ioremap(dev
->base_start
, size
);
296 return (dev
->base
== NULL
) ? -1 : 0;
300 * aac_sa_init - initialize an ARM based AAC card
301 * @dev: device to configure
303 * Allocate and set up resources for the ARM based AAC variants. The
304 * device_interface in the commregion will be allocated and linked
305 * to the comm region.
308 int aac_sa_init(struct aac_dev
*dev
)
311 unsigned long status
;
319 * Fill in the function dispatch table.
322 dev
->a_ops
.adapter_interrupt
= aac_sa_interrupt_adapter
;
323 dev
->a_ops
.adapter_disable_int
= aac_sa_disable_interrupt
;
324 dev
->a_ops
.adapter_enable_int
= aac_sa_enable_interrupt
;
325 dev
->a_ops
.adapter_notify
= aac_sa_notify_adapter
;
326 dev
->a_ops
.adapter_sync_cmd
= sa_sync_cmd
;
327 dev
->a_ops
.adapter_check_health
= aac_sa_check_health
;
328 dev
->a_ops
.adapter_restart
= aac_sa_restart_adapter
;
329 dev
->a_ops
.adapter_start
= aac_sa_start_adapter
;
330 dev
->a_ops
.adapter_intr
= aac_sa_intr
;
331 dev
->a_ops
.adapter_deliver
= aac_rx_deliver_producer
;
332 dev
->a_ops
.adapter_ioremap
= aac_sa_ioremap
;
334 if (aac_sa_ioremap(dev
, dev
->base_size
)) {
335 printk(KERN_WARNING
"%s: unable to map adapter.\n", name
);
340 * Check to see if the board failed any self tests.
342 if (sa_readl(dev
, Mailbox7
) & SELF_TEST_FAILED
) {
343 printk(KERN_WARNING
"%s%d: adapter self-test failed.\n", name
, instance
);
347 * Check to see if the board panic'd while booting.
349 if (sa_readl(dev
, Mailbox7
) & KERNEL_PANIC
) {
350 printk(KERN_WARNING
"%s%d: adapter kernel panic'd.\n", name
, instance
);
355 * Wait for the adapter to be up and running. Wait up to 3 minutes.
357 while (!(sa_readl(dev
, Mailbox7
) & KERNEL_UP_AND_RUNNING
)) {
358 if (time_after(jiffies
, start
+startup_timeout
*HZ
)) {
359 status
= sa_readl(dev
, Mailbox7
);
360 printk(KERN_WARNING
"%s%d: adapter kernel failed to start, init status = %lx.\n",
361 name
, instance
, status
);
368 * First clear out all interrupts. Then enable the one's that
371 aac_adapter_disable_int(dev
);
372 aac_adapter_enable_int(dev
);
374 if(aac_init_adapter(dev
) == NULL
)
376 dev
->sync_mode
= 0; /* sync. mode not supported */
377 if (request_irq(dev
->pdev
->irq
, dev
->a_ops
.adapter_intr
,
378 IRQF_SHARED
, "aacraid", (void *)dev
) < 0) {
379 printk(KERN_WARNING
"%s%d: Interrupt unavailable.\n",
383 dev
->dbg_base
= dev
->base_start
;
384 dev
->dbg_base_mapped
= dev
->base
;
385 dev
->dbg_size
= dev
->base_size
;
387 aac_adapter_enable_int(dev
);
390 * Tell the adapter that all is configure, and it can start
393 aac_sa_start_adapter(dev
);
397 aac_sa_disable_interrupt(dev
);
398 free_irq(dev
->pdev
->irq
, (void *)dev
);