blob: 073208b0f622cf6148d86418f384bbf5fa8f3f5c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
4 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Salyzyn, Mark912d4e82007-03-26 09:21:14 -04008 * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
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)
13 * any later version.
14 *
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.
19 *
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.
23 *
24 * Module Name:
25 * rx.c
26 *
27 * Abstract: Hardware miniport for Drawbridge specific hardware functions.
28 *
29 */
30
31#include <linux/kernel.h>
32#include <linux/init.h>
33#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/pci.h>
35#include <linux/spinlock.h>
36#include <linux/slab.h>
37#include <linux/blkdev.h>
38#include <linux/delay.h>
39#include <linux/completion.h>
40#include <linux/time.h>
41#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <scsi/scsi_host.h>
44
45#include "aacraid.h"
46
Mark Haverkamp28713322007-01-23 14:59:20 -080047static irqreturn_t aac_rx_intr_producer(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
49 struct aac_dev *dev = dev_id;
Mark Haverkamp28713322007-01-23 14:59:20 -080050 unsigned long bellbits;
51 u8 intstat = rx_readb(dev, MUnit.OISR);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -070052
Mark Haverkamp28713322007-01-23 14:59:20 -080053 /*
54 * Read mask and invert because drawbridge is reversed.
55 * This allows us to only service interrupts that have
56 * been enabled.
57 * Check to see if this is our interrupt. If it isn't just return
58 */
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040059 if (likely(intstat & ~(dev->OIMR))) {
Mark Haverkamp28713322007-01-23 14:59:20 -080060 bellbits = rx_readl(dev, OutboundDoorbellReg);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040061 if (unlikely(bellbits & DoorBellPrintfReady)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080062 aac_printf(dev, readl (&dev->IndexRegs->Mailbox[5]));
63 rx_writel(dev, MUnit.ODR,DoorBellPrintfReady);
64 rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
65 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040066 else if (unlikely(bellbits & DoorBellAdapterNormCmdReady)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080067 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
68 aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
69 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040070 else if (likely(bellbits & DoorBellAdapterNormRespReady)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080071 rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
72 aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
73 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040074 else if (unlikely(bellbits & DoorBellAdapterNormCmdNotFull)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080075 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
76 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040077 else if (unlikely(bellbits & DoorBellAdapterNormRespNotFull)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080078 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
79 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
80 }
81 return IRQ_HANDLED;
82 }
83 return IRQ_NONE;
84}
85
86static irqreturn_t aac_rx_intr_message(int irq, void *dev_id)
87{
88 struct aac_dev *dev = dev_id;
89 u32 Index = rx_readl(dev, MUnit.OutboundQueue);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040090 if (unlikely(Index == 0xFFFFFFFFL))
Mark Haverkamp28713322007-01-23 14:59:20 -080091 Index = rx_readl(dev, MUnit.OutboundQueue);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040092 if (likely(Index != 0xFFFFFFFFL)) {
Mark Haverkamp28713322007-01-23 14:59:20 -080093 do {
Salyzyn, Mark912d4e82007-03-26 09:21:14 -040094 if (unlikely(aac_intr_normal(dev, Index))) {
Mark Haverkamp28713322007-01-23 14:59:20 -080095 rx_writel(dev, MUnit.OutboundQueue, Index);
96 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespReady);
97 }
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -070098 Index = rx_readl(dev, MUnit.OutboundQueue);
Mark Haverkamp28713322007-01-23 14:59:20 -080099 } while (Index != 0xFFFFFFFFL);
100 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }
102 return IRQ_NONE;
103}
104
105/**
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700106 * aac_rx_disable_interrupt - Disable interrupts
107 * @dev: Adapter
108 */
109
110static void aac_rx_disable_interrupt(struct aac_dev *dev)
111{
112 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
113}
114
115/**
Mark Haverkamp28713322007-01-23 14:59:20 -0800116 * aac_rx_enable_interrupt_producer - Enable interrupts
117 * @dev: Adapter
118 */
119
120static void aac_rx_enable_interrupt_producer(struct aac_dev *dev)
121{
122 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
123}
124
125/**
126 * aac_rx_enable_interrupt_message - Enable interrupts
127 * @dev: Adapter
128 */
129
130static void aac_rx_enable_interrupt_message(struct aac_dev *dev)
131{
132 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
133}
134
135/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 * rx_sync_cmd - send a command and wait
137 * @dev: Adapter
138 * @command: Command to execute
139 * @p1: first parameter
140 * @ret: adapter status
141 *
142 * This routine will send a synchronous command to the adapter and wait
143 * for its completion.
144 */
145
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700146static int rx_sync_cmd(struct aac_dev *dev, u32 command,
147 u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
148 u32 *status, u32 * r1, u32 * r2, u32 * r3, u32 * r4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 unsigned long start;
151 int ok;
152 /*
153 * Write the command into Mailbox 0
154 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700155 writel(command, &dev->IndexRegs->Mailbox[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700157 * Write the parameters into Mailboxes 1 - 6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700159 writel(p1, &dev->IndexRegs->Mailbox[1]);
160 writel(p2, &dev->IndexRegs->Mailbox[2]);
161 writel(p3, &dev->IndexRegs->Mailbox[3]);
162 writel(p4, &dev->IndexRegs->Mailbox[4]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /*
164 * Clear the synch command doorbell to start on a clean slate.
165 */
166 rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
167 /*
168 * Disable doorbell interrupts
169 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700170 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 /*
172 * Force the completion of the mask register write before issuing
173 * the interrupt.
174 */
175 rx_readb (dev, MUnit.OIMR);
176 /*
177 * Signal that there is a new synch command
178 */
179 rx_writel(dev, InboundDoorbellReg, INBOUNDDOORBELL_0);
180
181 ok = 0;
182 start = jiffies;
183
184 /*
185 * Wait up to 30 seconds
186 */
187 while (time_before(jiffies, start+30*HZ))
188 {
189 udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
190 /*
191 * Mon960 will set doorbell0 bit when it has completed the command.
192 */
193 if (rx_readl(dev, OutboundDoorbellReg) & OUTBOUNDDOORBELL_0) {
194 /*
195 * Clear the doorbell.
196 */
197 rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
198 ok = 1;
199 break;
200 }
201 /*
202 * Yield the processor in case we are slow
203 */
Mark Haverkamp1241f352006-03-27 09:44:23 -0800204 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400206 if (unlikely(ok != 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 /*
208 * Restore interrupt mask even though we timed out
209 */
Mark Haverkamp28713322007-01-23 14:59:20 -0800210 aac_adapter_enable_int(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return -ETIMEDOUT;
212 }
213 /*
214 * Pull the synch status from Mailbox 0.
215 */
216 if (status)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700217 *status = readl(&dev->IndexRegs->Mailbox[0]);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700218 if (r1)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700219 *r1 = readl(&dev->IndexRegs->Mailbox[1]);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700220 if (r2)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700221 *r2 = readl(&dev->IndexRegs->Mailbox[2]);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700222 if (r3)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700223 *r3 = readl(&dev->IndexRegs->Mailbox[3]);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700224 if (r4)
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700225 *r4 = readl(&dev->IndexRegs->Mailbox[4]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 /*
227 * Clear the synch command doorbell.
228 */
229 rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
230 /*
231 * Restore interrupt mask
232 */
Mark Haverkamp28713322007-01-23 14:59:20 -0800233 aac_adapter_enable_int(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return 0;
235
236}
237
238/**
239 * aac_rx_interrupt_adapter - interrupt adapter
240 * @dev: Adapter
241 *
242 * Send an interrupt to the i960 and breakpoint it.
243 */
244
245static void aac_rx_interrupt_adapter(struct aac_dev *dev)
246{
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700247 rx_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
250/**
251 * aac_rx_notify_adapter - send an event to the adapter
252 * @dev: Adapter
253 * @event: Event to send
254 *
255 * Notify the i960 that something it probably cares about has
256 * happened.
257 */
258
259static void aac_rx_notify_adapter(struct aac_dev *dev, u32 event)
260{
261 switch (event) {
262
263 case AdapNormCmdQue:
264 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_1);
265 break;
266 case HostNormRespNotFull:
267 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_4);
268 break;
269 case AdapNormRespQue:
270 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_2);
271 break;
272 case HostNormCmdNotFull:
273 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3);
274 break;
275 case HostShutdown:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 break;
277 case FastIo:
278 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6);
279 break;
280 case AdapPrintfDone:
281 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_5);
282 break;
283 default:
284 BUG();
285 break;
286 }
287}
288
289/**
290 * aac_rx_start_adapter - activate adapter
291 * @dev: Adapter
292 *
293 * Start up processing on an i960 based AAC adapter
294 */
295
Adrian Bunk9695a252007-03-26 21:59:35 -0800296static void aac_rx_start_adapter(struct aac_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 struct aac_init *init;
299
300 init = dev->init;
301 init->HostElapsedSeconds = cpu_to_le32(get_seconds());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 // We can only use a 32 bit address here
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700303 rx_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
304 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306
307/**
308 * aac_rx_check_health
309 * @dev: device to check if healthy
310 *
311 * Will attempt to determine if the specified adapter is alive and
312 * capable of handling requests, returning 0 if alive.
313 */
314static int aac_rx_check_health(struct aac_dev *dev)
315{
316 u32 status = rx_readl(dev, MUnit.OMRx[0]);
317
318 /*
319 * Check to see if the board failed any self tests.
320 */
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400321 if (unlikely(status & SELF_TEST_FAILED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 return -1;
323 /*
324 * Check to see if the board panic'd.
325 */
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400326 if (unlikely(status & KERNEL_PANIC)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 char * buffer;
328 struct POSTSTATUS {
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700329 __le32 Post_Command;
330 __le32 Post_Address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 } * post;
332 dma_addr_t paddr, baddr;
333 int ret;
334
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400335 if (likely((status & 0xFF000000L) == 0xBC000000L))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return (status >> 16) & 0xFF;
337 buffer = pci_alloc_consistent(dev->pdev, 512, &baddr);
338 ret = -2;
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400339 if (unlikely(buffer == NULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return ret;
341 post = pci_alloc_consistent(dev->pdev,
342 sizeof(struct POSTSTATUS), &paddr);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400343 if (unlikely(post == NULL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 pci_free_consistent(dev->pdev, 512, buffer, baddr);
345 return ret;
346 }
347 memset(buffer, 0, 512);
348 post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS);
349 post->Post_Address = cpu_to_le32(baddr);
350 rx_writel(dev, MUnit.IMRx[0], paddr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700351 rx_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0,
352 NULL, NULL, NULL, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
354 post, paddr);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400355 if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10);
357 ret <<= 4;
358 ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
359 }
360 pci_free_consistent(dev->pdev, 512, buffer, baddr);
361 return ret;
362 }
363 /*
364 * Wait for the adapter to be up and running.
365 */
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400366 if (unlikely(!(status & KERNEL_UP_AND_RUNNING)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 return -3;
368 /*
369 * Everything is OK
370 */
371 return 0;
372}
373
374/**
Mark Haverkamp28713322007-01-23 14:59:20 -0800375 * aac_rx_deliver_producer
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700376 * @fib: fib to issue
377 *
378 * Will send a fib, returning 0 if successful.
379 */
Salyzyn, Mark2ab01ef2007-05-15 09:14:21 -0400380int aac_rx_deliver_producer(struct fib * fib)
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700381{
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700382 struct aac_dev *dev = fib->dev;
Mark Haverkamp28713322007-01-23 14:59:20 -0800383 struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
384 unsigned long qflags;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700385 u32 Index;
Mark Haverkamp28713322007-01-23 14:59:20 -0800386 unsigned long nointr = 0;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700387
Mark Haverkamp28713322007-01-23 14:59:20 -0800388 spin_lock_irqsave(q->lock, qflags);
Mark Haverkampa8166a52007-03-15 10:26:22 -0700389 aac_queue_get( dev, &Index, AdapNormCmdQueue, fib->hw_fib_va, 1, fib, &nointr);
Mark Haverkamp28713322007-01-23 14:59:20 -0800390
391 q->numpending++;
392 *(q->headers.producer) = cpu_to_le32(Index + 1);
393 spin_unlock_irqrestore(q->lock, qflags);
394 if (!(nointr & aac_config.irq_mod))
395 aac_adapter_notify(dev, AdapNormCmdQueue);
396
397 return 0;
398}
399
400/**
401 * aac_rx_deliver_message
402 * @fib: fib to issue
403 *
404 * Will send a fib, returning 0 if successful.
405 */
406static int aac_rx_deliver_message(struct fib * fib)
407{
408 struct aac_dev *dev = fib->dev;
409 struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
410 unsigned long qflags;
411 u32 Index;
412 u64 addr;
413 volatile void __iomem *device;
414
415 unsigned long count = 10000000L; /* 50 seconds */
416 spin_lock_irqsave(q->lock, qflags);
417 q->numpending++;
418 spin_unlock_irqrestore(q->lock, qflags);
419 for(;;) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700420 Index = rx_readl(dev, MUnit.InboundQueue);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400421 if (unlikely(Index == 0xFFFFFFFFL))
Mark Haverkamp28713322007-01-23 14:59:20 -0800422 Index = rx_readl(dev, MUnit.InboundQueue);
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400423 if (likely(Index != 0xFFFFFFFFL))
Mark Haverkamp28713322007-01-23 14:59:20 -0800424 break;
425 if (--count == 0) {
426 spin_lock_irqsave(q->lock, qflags);
427 q->numpending--;
428 spin_unlock_irqrestore(q->lock, qflags);
429 return -ETIMEDOUT;
430 }
431 udelay(5);
432 }
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700433 device = dev->base + Index;
Mark Haverkamp28713322007-01-23 14:59:20 -0800434 addr = fib->hw_fib_pa;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700435 writel((u32)(addr & 0xffffffff), device);
436 device += sizeof(u32);
437 writel((u32)(addr >> 32), device);
438 device += sizeof(u32);
Mark Haverkampa8166a52007-03-15 10:26:22 -0700439 writel(le16_to_cpu(fib->hw_fib_va->header.Size), device);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700440 rx_writel(dev, MUnit.InboundQueue, Index);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700441 return 0;
442}
443
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700444/**
445 * aac_rx_ioremap
446 * @size: mapping resize request
447 *
448 */
449static int aac_rx_ioremap(struct aac_dev * dev, u32 size)
450{
451 if (!size) {
452 iounmap(dev->regs.rx);
453 return 0;
454 }
455 dev->base = dev->regs.rx = ioremap(dev->scsi_host_ptr->base, size);
456 if (dev->base == NULL)
457 return -1;
458 dev->IndexRegs = &dev->regs.rx->IndexRegs;
459 return 0;
460}
461
Mark Haverkamp84188522007-03-15 10:26:05 -0700462static int aac_rx_restart_adapter(struct aac_dev *dev, int bled)
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700463{
464 u32 var;
465
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400466 if (!(dev->supplement_adapter_info.SupportedOptions2 &
Salyzyn, Marka3940da2008-01-08 12:48:25 -0800467 AAC_OPTION_MU_RESET) || (bled >= 0) || (bled == -2)) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400468 if (bled)
469 printk(KERN_ERR "%s%d: adapter kernel panic'd %x.\n",
470 dev->name, dev->id, bled);
471 else {
472 bled = aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS,
473 0, 0, 0, 0, 0, 0, &var, NULL, NULL, NULL, NULL);
Salyzyn, Mark9859c1a2007-07-27 10:29:26 -0400474 if (!bled && (var != 0x00000001) && (var != 0x3803000F))
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400475 bled = -EINVAL;
476 }
477 if (bled && (bled != -ETIMEDOUT))
478 bled = aac_adapter_sync_cmd(dev, IOP_RESET,
479 0, 0, 0, 0, 0, 0, &var, NULL, NULL, NULL, NULL);
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700480
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400481 if (bled && (bled != -ETIMEDOUT))
482 return -EINVAL;
483 }
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400484 if (bled || (var == 0x3803000F)) { /* USE_OTHER_METHOD */
Mark Haverkamp84188522007-03-15 10:26:05 -0700485 rx_writel(dev, MUnit.reserved2, 3);
486 msleep(5000); /* Delay 5 seconds */
487 var = 0x00000001;
488 }
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700489 if (var != 0x00000001)
Mark Haverkamp84188522007-03-15 10:26:05 -0700490 return -EINVAL;
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700491 if (rx_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC)
Mark Haverkamp84188522007-03-15 10:26:05 -0700492 return -ENODEV;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400493 if (startup_timeout < 300)
494 startup_timeout = 300;
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700495 return 0;
496}
497
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700498/**
Mark Haverkamp28713322007-01-23 14:59:20 -0800499 * aac_rx_select_comm - Select communications method
500 * @dev: Adapter
501 * @comm: communications method
502 */
503
504int aac_rx_select_comm(struct aac_dev *dev, int comm)
505{
506 switch (comm) {
507 case AAC_COMM_PRODUCER:
508 dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_producer;
509 dev->a_ops.adapter_intr = aac_rx_intr_producer;
510 dev->a_ops.adapter_deliver = aac_rx_deliver_producer;
511 break;
512 case AAC_COMM_MESSAGE:
513 dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_message;
514 dev->a_ops.adapter_intr = aac_rx_intr_message;
515 dev->a_ops.adapter_deliver = aac_rx_deliver_message;
516 break;
517 default:
518 return 1;
519 }
520 return 0;
521}
522
523/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 * aac_rx_init - initialize an i960 based AAC card
525 * @dev: device to configure
526 *
527 * Allocate and set up resources for the i960 based AAC variants. The
528 * device_interface in the commregion will be allocated and linked
529 * to the comm region.
530 */
531
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700532int _aac_rx_init(struct aac_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533{
534 unsigned long start;
535 unsigned long status;
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400536 int restart = 0;
Salyzyn, Mark912d4e82007-03-26 09:21:14 -0400537 int instance = dev->id;
538 const char * name = dev->name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700540 if (aac_adapter_ioremap(dev, dev->base_size)) {
541 printk(KERN_WARNING "%s: unable to map adapter.\n", name);
542 goto error_iounmap;
543 }
544
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400545 /* Failure to reset here is an option ... */
Salyzyn, Marka5694ec2007-04-30 13:22:24 -0400546 dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
547 dev->a_ops.adapter_enable_int = aac_rx_disable_interrupt;
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400548 dev->OIMR = status = rx_readb (dev, MUnit.OIMR);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400549 if ((((status & 0x0c) != 0x0c) || aac_reset_devices || reset_devices) &&
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400550 !aac_rx_restart_adapter(dev, 0))
Salyzyn, Markf8583172007-10-30 15:50:49 -0400551 /* Make sure the Hardware FIFO is empty */
552 while ((++restart < 512) &&
553 (rx_readl(dev, MUnit.OutboundQueue) != 0xFFFFFFFFL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 /*
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700555 * Check to see if the board panic'd while booting.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700557 status = rx_readl(dev, MUnit.OMRx[0]);
Mark Haverkamp84188522007-03-15 10:26:05 -0700558 if (status & KERNEL_PANIC) {
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400559 if (aac_rx_restart_adapter(dev, aac_rx_check_health(dev)))
Mark Haverkamp8c23cd72006-08-08 08:52:14 -0700560 goto error_iounmap;
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400561 ++restart;
Mark Haverkamp84188522007-03-15 10:26:05 -0700562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 /*
564 * Check to see if the board failed any self tests.
565 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700566 status = rx_readl(dev, MUnit.OMRx[0]);
567 if (status & SELF_TEST_FAILED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
569 goto error_iounmap;
570 }
571 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 * Check to see if the monitor panic'd while booting.
573 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700574 if (status & MONITOR_PANIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance);
576 goto error_iounmap;
577 }
578 start = jiffies;
579 /*
580 * Wait for the adapter to be up and running. Wait up to 3 minutes
581 */
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700582 while (!((status = rx_readl(dev, MUnit.OMRx[0])) & KERNEL_UP_AND_RUNNING))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 {
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400584 if ((restart &&
585 (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) ||
586 time_after(jiffies, start+HZ*startup_timeout)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
588 dev->name, instance, status);
589 goto error_iounmap;
590 }
Salyzyn, Mark18a65982007-03-30 10:30:48 -0400591 if (!restart &&
592 ((status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC)) ||
593 time_after(jiffies, start + HZ *
594 ((startup_timeout > 60)
595 ? (startup_timeout - 60)
596 : (startup_timeout / 2))))) {
597 if (likely(!aac_rx_restart_adapter(dev, aac_rx_check_health(dev))))
598 start = jiffies;
599 ++restart;
600 }
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700601 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 }
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400603 if (restart && aac_commit)
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400604 aac_commit = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /*
Mark Haverkamp28713322007-01-23 14:59:20 -0800606 * Fill in the common function dispatch table.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 */
608 dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter;
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700609 dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 dev->a_ops.adapter_notify = aac_rx_notify_adapter;
611 dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
612 dev->a_ops.adapter_check_health = aac_rx_check_health;
Mark Haverkamp84188522007-03-15 10:26:05 -0700613 dev->a_ops.adapter_restart = aac_rx_restart_adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700615 /*
616 * First clear out all interrupts. Then enable the one's that we
617 * can handle.
618 */
Mark Haverkamp28713322007-01-23 14:59:20 -0800619 aac_adapter_comm(dev, AAC_COMM_PRODUCER);
620 aac_adapter_disable_int(dev);
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700621 rx_writel(dev, MUnit.ODR, 0xffffffff);
Mark Haverkamp28713322007-01-23 14:59:20 -0800622 aac_adapter_enable_int(dev);
Mark Haverkampbd1aac82005-08-03 15:39:01 -0700623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (aac_init_adapter(dev) == NULL)
Mark Haverkamp28713322007-01-23 14:59:20 -0800625 goto error_iounmap;
626 aac_adapter_comm(dev, dev->comm_interface);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800627 dev->msi = aac_msi && !pci_enable_msi(dev->pdev);
628 if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
Mark Haverkamp28713322007-01-23 14:59:20 -0800629 IRQF_SHARED|IRQF_DISABLED, "aacraid", dev) < 0) {
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800630 if (dev->msi)
631 pci_disable_msi(dev->pdev);
Mark Haverkamp28713322007-01-23 14:59:20 -0800632 printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
633 name, instance);
634 goto error_iounmap;
635 }
636 aac_adapter_enable_int(dev);
637 /*
638 * Tell the adapter that all is configured, and it can
639 * start accepting requests
640 */
641 aac_rx_start_adapter(dev);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 return 0;
644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645error_iounmap:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 return -1;
648}
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700649
650int aac_rx_init(struct aac_dev *dev)
651{
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700652 /*
653 * Fill in the function dispatch table.
654 */
655 dev->a_ops.adapter_ioremap = aac_rx_ioremap;
Mark Haverkamp28713322007-01-23 14:59:20 -0800656 dev->a_ops.adapter_comm = aac_rx_select_comm;
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700657
Mark Haverkamp28713322007-01-23 14:59:20 -0800658 return _aac_rx_init(dev);
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -0700659}