]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Adaptec AAC series RAID controller driver | |
fa195afe | 3 | * (c) Copyright 2001 Red Hat Inc. |
1da177e4 LT |
4 | * |
5 | * based on the old aacraid driver that is.. | |
6 | * Adaptec aacraid device driver for Linux. | |
7 | * | |
e8b12f0f | 8 | * Copyright (c) 2000-2010 Adaptec, Inc. |
1d4bcdad RAR |
9 | * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com) |
10 | * 2016-2017 Microsemi Corp. (aacraid@microsemi.com) | |
1da177e4 LT |
11 | * |
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) | |
15 | * any later version. | |
16 | * | |
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. | |
21 | * | |
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. | |
25 | * | |
26 | * Module Name: | |
27 | * rx.c | |
28 | * | |
29 | * Abstract: Hardware miniport for Drawbridge specific hardware functions. | |
30 | * | |
31 | */ | |
32 | ||
33 | #include <linux/kernel.h> | |
34 | #include <linux/init.h> | |
35 | #include <linux/types.h> | |
1da177e4 LT |
36 | #include <linux/pci.h> |
37 | #include <linux/spinlock.h> | |
1da177e4 LT |
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> | |
1da177e4 LT |
43 | |
44 | #include <scsi/scsi_host.h> | |
45 | ||
46 | #include "aacraid.h" | |
47 | ||
28713324 | 48 | static irqreturn_t aac_rx_intr_producer(int irq, void *dev_id) |
1da177e4 LT |
49 | { |
50 | struct aac_dev *dev = dev_id; | |
28713324 MH |
51 | unsigned long bellbits; |
52 | u8 intstat = rx_readb(dev, MUnit.OISR); | |
8e0c5ebd | 53 | |
28713324 MH |
54 | /* |
55 | * Read mask and invert because drawbridge is reversed. | |
56 | * This allows us to only service interrupts that have | |
57 | * been enabled. | |
58 | * Check to see if this is our interrupt. If it isn't just return | |
59 | */ | |
912d4e88 | 60 | if (likely(intstat & ~(dev->OIMR))) { |
28713324 | 61 | bellbits = rx_readl(dev, OutboundDoorbellReg); |
912d4e88 | 62 | if (unlikely(bellbits & DoorBellPrintfReady)) { |
28713324 MH |
63 | aac_printf(dev, readl (&dev->IndexRegs->Mailbox[5])); |
64 | rx_writel(dev, MUnit.ODR,DoorBellPrintfReady); | |
65 | rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone); | |
1da177e4 | 66 | } |
912d4e88 | 67 | else if (unlikely(bellbits & DoorBellAdapterNormCmdReady)) { |
28713324 MH |
68 | rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady); |
69 | aac_command_normal(&dev->queues->queue[HostNormCmdQueue]); | |
70 | } | |
912d4e88 | 71 | else if (likely(bellbits & DoorBellAdapterNormRespReady)) { |
28713324 MH |
72 | rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady); |
73 | aac_response_normal(&dev->queues->queue[HostNormRespQueue]); | |
74 | } | |
912d4e88 | 75 | else if (unlikely(bellbits & DoorBellAdapterNormCmdNotFull)) { |
28713324 | 76 | rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull); |
1da177e4 | 77 | } |
912d4e88 | 78 | else if (unlikely(bellbits & DoorBellAdapterNormRespNotFull)) { |
28713324 MH |
79 | rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull); |
80 | rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull); | |
81 | } | |
82 | return IRQ_HANDLED; | |
83 | } | |
84 | return IRQ_NONE; | |
85 | } | |
86 | ||
87 | static irqreturn_t aac_rx_intr_message(int irq, void *dev_id) | |
88 | { | |
e8b12f0f | 89 | int isAif, isFastResponse, isSpecial; |
28713324 MH |
90 | struct aac_dev *dev = dev_id; |
91 | u32 Index = rx_readl(dev, MUnit.OutboundQueue); | |
912d4e88 | 92 | if (unlikely(Index == 0xFFFFFFFFL)) |
28713324 | 93 | Index = rx_readl(dev, MUnit.OutboundQueue); |
912d4e88 | 94 | if (likely(Index != 0xFFFFFFFFL)) { |
28713324 | 95 | do { |
e8b12f0f MR |
96 | isAif = isFastResponse = isSpecial = 0; |
97 | if (Index & 0x00000002L) { | |
98 | isAif = 1; | |
99 | if (Index == 0xFFFFFFFEL) | |
100 | isSpecial = 1; | |
101 | Index &= ~0x00000002L; | |
102 | } else { | |
103 | if (Index & 0x00000001L) | |
104 | isFastResponse = 1; | |
105 | Index >>= 2; | |
106 | } | |
107 | if (!isSpecial) { | |
108 | if (unlikely(aac_intr_normal(dev, | |
109 | Index, isAif, | |
110 | isFastResponse, NULL))) { | |
111 | rx_writel(dev, | |
112 | MUnit.OutboundQueue, | |
113 | Index); | |
114 | rx_writel(dev, | |
115 | MUnit.ODR, | |
116 | DoorBellAdapterNormRespReady); | |
117 | } | |
28713324 MH |
118 | } |
119 | Index = rx_readl(dev, MUnit.OutboundQueue); | |
120 | } while (Index != 0xFFFFFFFFL); | |
121 | return IRQ_HANDLED; | |
1da177e4 LT |
122 | } |
123 | return IRQ_NONE; | |
124 | } | |
125 | ||
bd1aac80 MH |
126 | /** |
127 | * aac_rx_disable_interrupt - Disable interrupts | |
128 | * @dev: Adapter | |
129 | */ | |
130 | ||
131 | static void aac_rx_disable_interrupt(struct aac_dev *dev) | |
132 | { | |
133 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff); | |
134 | } | |
135 | ||
28713324 MH |
136 | /** |
137 | * aac_rx_enable_interrupt_producer - Enable interrupts | |
138 | * @dev: Adapter | |
139 | */ | |
140 | ||
141 | static void aac_rx_enable_interrupt_producer(struct aac_dev *dev) | |
142 | { | |
143 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb); | |
144 | } | |
145 | ||
146 | /** | |
147 | * aac_rx_enable_interrupt_message - Enable interrupts | |
148 | * @dev: Adapter | |
149 | */ | |
150 | ||
151 | static void aac_rx_enable_interrupt_message(struct aac_dev *dev) | |
152 | { | |
153 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7); | |
154 | } | |
155 | ||
1da177e4 LT |
156 | /** |
157 | * rx_sync_cmd - send a command and wait | |
158 | * @dev: Adapter | |
159 | * @command: Command to execute | |
160 | * @p1: first parameter | |
161 | * @ret: adapter status | |
162 | * | |
163 | * This routine will send a synchronous command to the adapter and wait | |
164 | * for its completion. | |
165 | */ | |
166 | ||
7c00ffa3 MH |
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) | |
1da177e4 LT |
170 | { |
171 | unsigned long start; | |
172 | int ok; | |
173 | /* | |
174 | * Write the command into Mailbox 0 | |
175 | */ | |
76a7f8fd | 176 | writel(command, &dev->IndexRegs->Mailbox[0]); |
1da177e4 | 177 | /* |
7c00ffa3 | 178 | * Write the parameters into Mailboxes 1 - 6 |
1da177e4 | 179 | */ |
76a7f8fd MH |
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]); | |
1da177e4 LT |
184 | /* |
185 | * Clear the synch command doorbell to start on a clean slate. | |
186 | */ | |
187 | rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0); | |
188 | /* | |
189 | * Disable doorbell interrupts | |
190 | */ | |
7c00ffa3 | 191 | rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff); |
1da177e4 LT |
192 | /* |
193 | * Force the completion of the mask register write before issuing | |
194 | * the interrupt. | |
195 | */ | |
196 | rx_readb (dev, MUnit.OIMR); | |
197 | /* | |
198 | * Signal that there is a new synch command | |
199 | */ | |
200 | rx_writel(dev, InboundDoorbellReg, INBOUNDDOORBELL_0); | |
201 | ||
202 | ok = 0; | |
203 | start = jiffies; | |
204 | ||
205 | /* | |
206 | * Wait up to 30 seconds | |
207 | */ | |
208 | while (time_before(jiffies, start+30*HZ)) | |
209 | { | |
210 | udelay(5); /* Delay 5 microseconds to let Mon960 get info. */ | |
211 | /* | |
212 | * Mon960 will set doorbell0 bit when it has completed the command. | |
213 | */ | |
214 | if (rx_readl(dev, OutboundDoorbellReg) & OUTBOUNDDOORBELL_0) { | |
215 | /* | |
216 | * Clear the doorbell. | |
217 | */ | |
218 | rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0); | |
219 | ok = 1; | |
220 | break; | |
221 | } | |
222 | /* | |
223 | * Yield the processor in case we are slow | |
224 | */ | |
1241f359 | 225 | msleep(1); |
1da177e4 | 226 | } |
912d4e88 | 227 | if (unlikely(ok != 1)) { |
1da177e4 LT |
228 | /* |
229 | * Restore interrupt mask even though we timed out | |
230 | */ | |
28713324 | 231 | aac_adapter_enable_int(dev); |
1da177e4 LT |
232 | return -ETIMEDOUT; |
233 | } | |
234 | /* | |
235 | * Pull the synch status from Mailbox 0. | |
236 | */ | |
237 | if (status) | |
76a7f8fd | 238 | *status = readl(&dev->IndexRegs->Mailbox[0]); |
7c00ffa3 | 239 | if (r1) |
76a7f8fd | 240 | *r1 = readl(&dev->IndexRegs->Mailbox[1]); |
7c00ffa3 | 241 | if (r2) |
76a7f8fd | 242 | *r2 = readl(&dev->IndexRegs->Mailbox[2]); |
7c00ffa3 | 243 | if (r3) |
76a7f8fd | 244 | *r3 = readl(&dev->IndexRegs->Mailbox[3]); |
7c00ffa3 | 245 | if (r4) |
76a7f8fd | 246 | *r4 = readl(&dev->IndexRegs->Mailbox[4]); |
1da177e4 LT |
247 | /* |
248 | * Clear the synch command doorbell. | |
249 | */ | |
250 | rx_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0); | |
251 | /* | |
252 | * Restore interrupt mask | |
253 | */ | |
28713324 | 254 | aac_adapter_enable_int(dev); |
1da177e4 LT |
255 | return 0; |
256 | ||
257 | } | |
258 | ||
259 | /** | |
260 | * aac_rx_interrupt_adapter - interrupt adapter | |
261 | * @dev: Adapter | |
262 | * | |
263 | * Send an interrupt to the i960 and breakpoint it. | |
264 | */ | |
265 | ||
266 | static void aac_rx_interrupt_adapter(struct aac_dev *dev) | |
267 | { | |
7c00ffa3 | 268 | rx_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL); |
1da177e4 LT |
269 | } |
270 | ||
271 | /** | |
272 | * aac_rx_notify_adapter - send an event to the adapter | |
273 | * @dev: Adapter | |
274 | * @event: Event to send | |
275 | * | |
276 | * Notify the i960 that something it probably cares about has | |
277 | * happened. | |
278 | */ | |
279 | ||
280 | static void aac_rx_notify_adapter(struct aac_dev *dev, u32 event) | |
281 | { | |
282 | switch (event) { | |
283 | ||
284 | case AdapNormCmdQue: | |
285 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_1); | |
286 | break; | |
287 | case HostNormRespNotFull: | |
288 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_4); | |
289 | break; | |
290 | case AdapNormRespQue: | |
291 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_2); | |
292 | break; | |
293 | case HostNormCmdNotFull: | |
294 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3); | |
295 | break; | |
296 | case HostShutdown: | |
1da177e4 LT |
297 | break; |
298 | case FastIo: | |
299 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6); | |
300 | break; | |
301 | case AdapPrintfDone: | |
302 | rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_5); | |
303 | break; | |
304 | default: | |
305 | BUG(); | |
306 | break; | |
307 | } | |
308 | } | |
309 | ||
310 | /** | |
311 | * aac_rx_start_adapter - activate adapter | |
312 | * @dev: Adapter | |
313 | * | |
314 | * Start up processing on an i960 based AAC adapter | |
315 | */ | |
316 | ||
9695a25d | 317 | static void aac_rx_start_adapter(struct aac_dev *dev) |
1da177e4 | 318 | { |
a1751cda | 319 | union aac_init *init; |
1da177e4 LT |
320 | |
321 | init = dev->init; | |
a1751cda | 322 | init->r7.host_elapsed_seconds = cpu_to_le32(get_seconds()); |
1da177e4 | 323 | // We can only use a 32 bit address here |
7c00ffa3 MH |
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); | |
1da177e4 LT |
326 | } |
327 | ||
328 | /** | |
329 | * aac_rx_check_health | |
330 | * @dev: device to check if healthy | |
331 | * | |
332 | * Will attempt to determine if the specified adapter is alive and | |
333 | * capable of handling requests, returning 0 if alive. | |
334 | */ | |
335 | static int aac_rx_check_health(struct aac_dev *dev) | |
336 | { | |
337 | u32 status = rx_readl(dev, MUnit.OMRx[0]); | |
338 | ||
339 | /* | |
340 | * Check to see if the board failed any self tests. | |
341 | */ | |
912d4e88 | 342 | if (unlikely(status & SELF_TEST_FAILED)) |
1da177e4 LT |
343 | return -1; |
344 | /* | |
345 | * Check to see if the board panic'd. | |
346 | */ | |
912d4e88 | 347 | if (unlikely(status & KERNEL_PANIC)) { |
1da177e4 LT |
348 | char * buffer; |
349 | struct POSTSTATUS { | |
56b58712 MH |
350 | __le32 Post_Command; |
351 | __le32 Post_Address; | |
1da177e4 LT |
352 | } * post; |
353 | dma_addr_t paddr, baddr; | |
354 | int ret; | |
355 | ||
912d4e88 | 356 | if (likely((status & 0xFF000000L) == 0xBC000000L)) |
1da177e4 LT |
357 | return (status >> 16) & 0xFF; |
358 | buffer = pci_alloc_consistent(dev->pdev, 512, &baddr); | |
359 | ret = -2; | |
912d4e88 | 360 | if (unlikely(buffer == NULL)) |
1da177e4 LT |
361 | return ret; |
362 | post = pci_alloc_consistent(dev->pdev, | |
363 | sizeof(struct POSTSTATUS), &paddr); | |
912d4e88 | 364 | if (unlikely(post == NULL)) { |
1da177e4 LT |
365 | pci_free_consistent(dev->pdev, 512, buffer, baddr); |
366 | return ret; | |
367 | } | |
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); | |
7c00ffa3 MH |
372 | rx_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0, |
373 | NULL, NULL, NULL, NULL, NULL); | |
1da177e4 LT |
374 | pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS), |
375 | post, paddr); | |
912d4e88 | 376 | if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) { |
ecc30990 AS |
377 | ret = (hex_to_bin(buffer[2]) << 4) + |
378 | hex_to_bin(buffer[3]); | |
1da177e4 LT |
379 | } |
380 | pci_free_consistent(dev->pdev, 512, buffer, baddr); | |
381 | return ret; | |
382 | } | |
383 | /* | |
384 | * Wait for the adapter to be up and running. | |
385 | */ | |
912d4e88 | 386 | if (unlikely(!(status & KERNEL_UP_AND_RUNNING))) |
1da177e4 LT |
387 | return -3; |
388 | /* | |
389 | * Everything is OK | |
390 | */ | |
391 | return 0; | |
392 | } | |
393 | ||
8e0c5ebd | 394 | /** |
28713324 | 395 | * aac_rx_deliver_producer |
8e0c5ebd MH |
396 | * @fib: fib to issue |
397 | * | |
398 | * Will send a fib, returning 0 if successful. | |
399 | */ | |
2ab01efd | 400 | int aac_rx_deliver_producer(struct fib * fib) |
8e0c5ebd | 401 | { |
8e0c5ebd | 402 | struct aac_dev *dev = fib->dev; |
28713324 | 403 | struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue]; |
8e0c5ebd | 404 | u32 Index; |
28713324 | 405 | unsigned long nointr = 0; |
8e0c5ebd | 406 | |
a8166a52 | 407 | aac_queue_get( dev, &Index, AdapNormCmdQueue, fib->hw_fib_va, 1, fib, &nointr); |
28713324 | 408 | |
ef616233 | 409 | atomic_inc(&q->numpending); |
28713324 | 410 | *(q->headers.producer) = cpu_to_le32(Index + 1); |
28713324 MH |
411 | if (!(nointr & aac_config.irq_mod)) |
412 | aac_adapter_notify(dev, AdapNormCmdQueue); | |
413 | ||
414 | return 0; | |
415 | } | |
416 | ||
417 | /** | |
418 | * aac_rx_deliver_message | |
419 | * @fib: fib to issue | |
420 | * | |
421 | * Will send a fib, returning 0 if successful. | |
422 | */ | |
423 | static int aac_rx_deliver_message(struct fib * fib) | |
424 | { | |
425 | struct aac_dev *dev = fib->dev; | |
426 | struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue]; | |
28713324 MH |
427 | u32 Index; |
428 | u64 addr; | |
429 | volatile void __iomem *device; | |
430 | ||
431 | unsigned long count = 10000000L; /* 50 seconds */ | |
ef616233 | 432 | atomic_inc(&q->numpending); |
28713324 | 433 | for(;;) { |
8e0c5ebd | 434 | Index = rx_readl(dev, MUnit.InboundQueue); |
912d4e88 | 435 | if (unlikely(Index == 0xFFFFFFFFL)) |
28713324 | 436 | Index = rx_readl(dev, MUnit.InboundQueue); |
912d4e88 | 437 | if (likely(Index != 0xFFFFFFFFL)) |
28713324 MH |
438 | break; |
439 | if (--count == 0) { | |
ef616233 | 440 | atomic_dec(&q->numpending); |
28713324 MH |
441 | return -ETIMEDOUT; |
442 | } | |
443 | udelay(5); | |
444 | } | |
76a7f8fd | 445 | device = dev->base + Index; |
28713324 | 446 | addr = fib->hw_fib_pa; |
8e0c5ebd MH |
447 | writel((u32)(addr & 0xffffffff), device); |
448 | device += sizeof(u32); | |
449 | writel((u32)(addr >> 32), device); | |
450 | device += sizeof(u32); | |
a8166a52 | 451 | writel(le16_to_cpu(fib->hw_fib_va->header.Size), device); |
8e0c5ebd | 452 | rx_writel(dev, MUnit.InboundQueue, Index); |
8e0c5ebd MH |
453 | return 0; |
454 | } | |
455 | ||
76a7f8fd MH |
456 | /** |
457 | * aac_rx_ioremap | |
458 | * @size: mapping resize request | |
459 | * | |
460 | */ | |
461 | static int aac_rx_ioremap(struct aac_dev * dev, u32 size) | |
462 | { | |
463 | if (!size) { | |
464 | iounmap(dev->regs.rx); | |
465 | return 0; | |
466 | } | |
ff08784b | 467 | dev->base = dev->regs.rx = ioremap(dev->base_start, size); |
76a7f8fd MH |
468 | if (dev->base == NULL) |
469 | return -1; | |
470 | dev->IndexRegs = &dev->regs.rx->IndexRegs; | |
471 | return 0; | |
472 | } | |
473 | ||
3a4c3699 | 474 | static int aac_rx_restart_adapter(struct aac_dev *dev, int bled, u8 reset_type) |
8c23cd74 | 475 | { |
6e40e5f0 | 476 | u32 var = 0; |
8c23cd74 | 477 | |
bca379d8 | 478 | if (!(dev->supplement_adapter_info.supported_options2 & |
a3940da5 | 479 | AAC_OPTION_MU_RESET) || (bled >= 0) || (bled == -2)) { |
29c97684 SM |
480 | if (bled) |
481 | printk(KERN_ERR "%s%d: adapter kernel panic'd %x.\n", | |
482 | dev->name, dev->id, bled); | |
483 | else { | |
484 | bled = aac_adapter_sync_cmd(dev, IOP_RESET_ALWAYS, | |
485 | 0, 0, 0, 0, 0, 0, &var, NULL, NULL, NULL, NULL); | |
9859c1aa | 486 | if (!bled && (var != 0x00000001) && (var != 0x3803000F)) |
29c97684 SM |
487 | bled = -EINVAL; |
488 | } | |
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); | |
8418852d | 492 | |
29c97684 SM |
493 | if (bled && (bled != -ETIMEDOUT)) |
494 | return -EINVAL; | |
495 | } | |
6e40e5f0 | 496 | if (bled && (var == 0x3803000F)) { /* USE_OTHER_METHOD */ |
8418852d MH |
497 | rx_writel(dev, MUnit.reserved2, 3); |
498 | msleep(5000); /* Delay 5 seconds */ | |
499 | var = 0x00000001; | |
500 | } | |
6e40e5f0 | 501 | if (bled && (var != 0x00000001)) |
8418852d | 502 | return -EINVAL; |
6e40e5f0 | 503 | ssleep(5); |
8c23cd74 | 504 | if (rx_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC) |
8418852d | 505 | return -ENODEV; |
1208bab5 SM |
506 | if (startup_timeout < 300) |
507 | startup_timeout = 300; | |
8c23cd74 MH |
508 | return 0; |
509 | } | |
510 | ||
28713324 MH |
511 | /** |
512 | * aac_rx_select_comm - Select communications method | |
513 | * @dev: Adapter | |
514 | * @comm: communications method | |
515 | */ | |
516 | ||
517 | int aac_rx_select_comm(struct aac_dev *dev, int comm) | |
518 | { | |
519 | switch (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; | |
524 | break; | |
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; | |
529 | break; | |
530 | default: | |
531 | return 1; | |
532 | } | |
533 | return 0; | |
534 | } | |
535 | ||
1da177e4 LT |
536 | /** |
537 | * aac_rx_init - initialize an i960 based AAC card | |
538 | * @dev: device to configure | |
539 | * | |
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. | |
543 | */ | |
544 | ||
76a7f8fd | 545 | int _aac_rx_init(struct aac_dev *dev) |
1da177e4 LT |
546 | { |
547 | unsigned long start; | |
548 | unsigned long status; | |
18a6598f | 549 | int restart = 0; |
912d4e88 SM |
550 | int instance = dev->id; |
551 | const char * name = dev->name; | |
1da177e4 | 552 | |
76a7f8fd MH |
553 | if (aac_adapter_ioremap(dev, dev->base_size)) { |
554 | printk(KERN_WARNING "%s: unable to map adapter.\n", name); | |
555 | goto error_iounmap; | |
556 | } | |
557 | ||
18a6598f | 558 | /* Failure to reset here is an option ... */ |
a5694ec5 SM |
559 | dev->a_ops.adapter_sync_cmd = rx_sync_cmd; |
560 | dev->a_ops.adapter_enable_int = aac_rx_disable_interrupt; | |
18a6598f | 561 | dev->OIMR = status = rx_readb (dev, MUnit.OIMR); |
1208bab5 | 562 | if ((((status & 0x0c) != 0x0c) || aac_reset_devices || reset_devices) && |
3a4c3699 | 563 | !aac_rx_restart_adapter(dev, 0, IOP_HWSOFT_RESET)) |
f858317d SM |
564 | /* Make sure the Hardware FIFO is empty */ |
565 | while ((++restart < 512) && | |
566 | (rx_readl(dev, MUnit.OutboundQueue) != 0xFFFFFFFFL)); | |
1da177e4 | 567 | /* |
8e0c5ebd | 568 | * Check to see if the board panic'd while booting. |
1da177e4 | 569 | */ |
76a7f8fd | 570 | status = rx_readl(dev, MUnit.OMRx[0]); |
8418852d | 571 | if (status & KERNEL_PANIC) { |
3a4c3699 RAR |
572 | if (aac_rx_restart_adapter(dev, |
573 | aac_rx_check_health(dev), IOP_HWSOFT_RESET)) | |
8418852d | 574 | goto error_iounmap; |
18a6598f | 575 | ++restart; |
8418852d | 576 | } |
1da177e4 LT |
577 | /* |
578 | * Check to see if the board failed any self tests. | |
579 | */ | |
76a7f8fd MH |
580 | status = rx_readl(dev, MUnit.OMRx[0]); |
581 | if (status & SELF_TEST_FAILED) { | |
1da177e4 LT |
582 | printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance); |
583 | goto error_iounmap; | |
584 | } | |
1da177e4 LT |
585 | /* |
586 | * Check to see if the monitor panic'd while booting. | |
587 | */ | |
76a7f8fd | 588 | if (status & MONITOR_PANIC) { |
1da177e4 LT |
589 | printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance); |
590 | goto error_iounmap; | |
591 | } | |
592 | start = jiffies; | |
593 | /* | |
594 | * Wait for the adapter to be up and running. Wait up to 3 minutes | |
595 | */ | |
76a7f8fd | 596 | while (!((status = rx_readl(dev, MUnit.OMRx[0])) & KERNEL_UP_AND_RUNNING)) |
1da177e4 | 597 | { |
18a6598f SM |
598 | if ((restart && |
599 | (status & (KERNEL_PANIC|SELF_TEST_FAILED|MONITOR_PANIC))) || | |
600 | time_after(jiffies, start+HZ*startup_timeout)) { | |
1da177e4 LT |
601 | printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n", |
602 | dev->name, instance, status); | |
603 | goto error_iounmap; | |
604 | } | |
18a6598f SM |
605 | if (!restart && |
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))))) { | |
3a4c3699 RAR |
611 | if (likely(!aac_rx_restart_adapter(dev, |
612 | aac_rx_check_health(dev), IOP_HWSOFT_RESET))) | |
18a6598f SM |
613 | start = jiffies; |
614 | ++restart; | |
615 | } | |
404d9a90 | 616 | msleep(1); |
1da177e4 | 617 | } |
29c97684 | 618 | if (restart && aac_commit) |
1208bab5 | 619 | aac_commit = 1; |
1da177e4 | 620 | /* |
28713324 | 621 | * Fill in the common function dispatch table. |
1da177e4 LT |
622 | */ |
623 | dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter; | |
bd1aac80 | 624 | dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt; |
1da177e4 LT |
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; | |
8418852d | 628 | dev->a_ops.adapter_restart = aac_rx_restart_adapter; |
de665f28 | 629 | dev->a_ops.adapter_start = aac_rx_start_adapter; |
1da177e4 | 630 | |
bd1aac80 MH |
631 | /* |
632 | * First clear out all interrupts. Then enable the one's that we | |
633 | * can handle. | |
634 | */ | |
28713324 MH |
635 | aac_adapter_comm(dev, AAC_COMM_PRODUCER); |
636 | aac_adapter_disable_int(dev); | |
bd1aac80 | 637 | rx_writel(dev, MUnit.ODR, 0xffffffff); |
28713324 | 638 | aac_adapter_enable_int(dev); |
bd1aac80 | 639 | |
1da177e4 | 640 | if (aac_init_adapter(dev) == NULL) |
28713324 MH |
641 | goto error_iounmap; |
642 | aac_adapter_comm(dev, dev->comm_interface); | |
11604612 | 643 | dev->sync_mode = 0; /* sync. mode not supported */ |
8ef22247 SM |
644 | dev->msi = aac_msi && !pci_enable_msi(dev->pdev); |
645 | if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr, | |
4909cc2b | 646 | IRQF_SHARED, "aacraid", dev) < 0) { |
8ef22247 SM |
647 | if (dev->msi) |
648 | pci_disable_msi(dev->pdev); | |
28713324 MH |
649 | printk(KERN_ERR "%s%d: Interrupt unavailable.\n", |
650 | name, instance); | |
651 | goto error_iounmap; | |
652 | } | |
ff08784b | 653 | dev->dbg_base = dev->base_start; |
e8b12f0f MR |
654 | dev->dbg_base_mapped = dev->base; |
655 | dev->dbg_size = dev->base_size; | |
656 | ||
28713324 MH |
657 | aac_adapter_enable_int(dev); |
658 | /* | |
659 | * Tell the adapter that all is configured, and it can | |
660 | * start accepting requests | |
661 | */ | |
662 | aac_rx_start_adapter(dev); | |
8e0c5ebd | 663 | |
1da177e4 LT |
664 | return 0; |
665 | ||
1da177e4 | 666 | error_iounmap: |
1da177e4 LT |
667 | |
668 | return -1; | |
669 | } | |
76a7f8fd MH |
670 | |
671 | int aac_rx_init(struct aac_dev *dev) | |
672 | { | |
76a7f8fd MH |
673 | /* |
674 | * Fill in the function dispatch table. | |
675 | */ | |
676 | dev->a_ops.adapter_ioremap = aac_rx_ioremap; | |
28713324 | 677 | dev->a_ops.adapter_comm = aac_rx_select_comm; |
76a7f8fd | 678 | |
28713324 | 679 | return _aac_rx_init(dev); |
76a7f8fd | 680 | } |