aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorMark Haverkamp <markh@osdl.org>2006-09-19 12:00:02 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-09-23 21:09:42 -0400
commit76a7f8fdc0c2381ae1ba55ef71837712223ecb3c (patch)
treeb6672be9f0c94d36841e56e6cf8a8636028268c5 /drivers/scsi
parent653ba58d55feb708c6f97e6f3e84901b3a03c9c0 (diff)
[SCSI] aacraid: merge rx and rkt code
Received from Mark Salyzyn: The only real difference between the rkt and rx platform modules is the offset of the message registers. This patch recognizes this similarity and simplifies the driver to reduce it's code footprint and to improve maintainability by reducing the code duplication. Visibly, the 'rkt.c' portion of this patch looks more complicated than it really is. View it as retaining the rkt-only specifics of the interface. Signed-off-by: Mark Haverkamp <markh@osdl.org> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/aacraid/aacraid.h14
-rw-r--r--drivers/scsi/aacraid/comminit.c11
-rw-r--r--drivers/scsi/aacraid/linit.c12
-rw-r--r--drivers/scsi/aacraid/rkt.c461
-rw-r--r--drivers/scsi/aacraid/rx.c90
-rw-r--r--drivers/scsi/aacraid/sa.c21
6 files changed, 112 insertions, 497 deletions
diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index e5f7be6f3cd6..eb3ed91bac79 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -494,6 +494,7 @@ struct adapter_ops
494 int (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4); 494 int (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4);
495 int (*adapter_check_health)(struct aac_dev *dev); 495 int (*adapter_check_health)(struct aac_dev *dev);
496 int (*adapter_send)(struct fib * fib); 496 int (*adapter_send)(struct fib * fib);
497 int (*adapter_ioremap)(struct aac_dev * dev, u32 size);
497}; 498};
498 499
499/* 500/*
@@ -682,14 +683,6 @@ struct rx_inbound {
682 __le32 Mailbox[8]; 683 __le32 Mailbox[8];
683}; 684};
684 685
685#define InboundMailbox0 IndexRegs.Mailbox[0]
686#define InboundMailbox1 IndexRegs.Mailbox[1]
687#define InboundMailbox2 IndexRegs.Mailbox[2]
688#define InboundMailbox3 IndexRegs.Mailbox[3]
689#define InboundMailbox4 IndexRegs.Mailbox[4]
690#define InboundMailbox5 IndexRegs.Mailbox[5]
691#define InboundMailbox6 IndexRegs.Mailbox[6]
692
693#define INBOUNDDOORBELL_0 0x00000001 686#define INBOUNDDOORBELL_0 0x00000001
694#define INBOUNDDOORBELL_1 0x00000002 687#define INBOUNDDOORBELL_1 0x00000002
695#define INBOUNDDOORBELL_2 0x00000004 688#define INBOUNDDOORBELL_2 0x00000004
@@ -1010,6 +1003,8 @@ struct aac_dev
1010 struct rx_registers __iomem *rx; 1003 struct rx_registers __iomem *rx;
1011 struct rkt_registers __iomem *rkt; 1004 struct rkt_registers __iomem *rkt;
1012 } regs; 1005 } regs;
1006 volatile void __iomem *base;
1007 volatile struct rx_inbound __iomem *IndexRegs;
1013 u32 OIMR; /* Mask Register Cache */ 1008 u32 OIMR; /* Mask Register Cache */
1014 /* 1009 /*
1015 * AIF thread states 1010 * AIF thread states
@@ -1050,6 +1045,9 @@ struct aac_dev
1050#define aac_adapter_send(fib) \ 1045#define aac_adapter_send(fib) \
1051 ((fib)->dev)->a_ops.adapter_send(fib) 1046 ((fib)->dev)->a_ops.adapter_send(fib)
1052 1047
1048#define aac_adapter_ioremap(dev, size) \
1049 (dev)->a_ops.adapter_ioremap(dev, size)
1050
1053#define FIB_CONTEXT_FLAG_TIMED_OUT (0x00000001) 1051#define FIB_CONTEXT_FLAG_TIMED_OUT (0x00000001)
1054 1052
1055/* 1053/*
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c
index 87a955096761..d5cf8b91a0e7 100644
--- a/drivers/scsi/aacraid/comminit.c
+++ b/drivers/scsi/aacraid/comminit.c
@@ -307,17 +307,12 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev)
307 if (status[1] & AAC_OPT_NEW_COMM) 307 if (status[1] & AAC_OPT_NEW_COMM)
308 dev->new_comm_interface = dev->a_ops.adapter_send != 0; 308 dev->new_comm_interface = dev->a_ops.adapter_send != 0;
309 if (dev->new_comm_interface && (status[2] > dev->base_size)) { 309 if (dev->new_comm_interface && (status[2] > dev->base_size)) {
310 iounmap(dev->regs.sa); 310 aac_adapter_ioremap(dev, 0);
311 dev->base_size = status[2]; 311 dev->base_size = status[2];
312 dprintk((KERN_DEBUG "ioremap(%lx,%d)\n", 312 if (aac_adapter_ioremap(dev, status[2])) {
313 host->base, status[2]));
314 dev->regs.sa = ioremap(host->base, status[2]);
315 if (dev->regs.sa == NULL) {
316 /* remap failed, go back ... */ 313 /* remap failed, go back ... */
317 dev->new_comm_interface = 0; 314 dev->new_comm_interface = 0;
318 dev->regs.sa = ioremap(host->base, 315 if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) {
319 AAC_MIN_FOOTPRINT_SIZE);
320 if (dev->regs.sa == NULL) {
321 printk(KERN_WARNING 316 printk(KERN_WARNING
322 "aacraid: unable to map adapter.\n"); 317 "aacraid: unable to map adapter.\n");
323 return NULL; 318 return NULL;
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 6e4eafa4ecee..359e7ddfdb47 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -867,13 +867,6 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
867 * Map in the registers from the adapter. 867 * Map in the registers from the adapter.
868 */ 868 */
869 aac->base_size = AAC_MIN_FOOTPRINT_SIZE; 869 aac->base_size = AAC_MIN_FOOTPRINT_SIZE;
870 if ((aac->regs.sa = ioremap(
871 (unsigned long)aac->scsi_host_ptr->base, AAC_MIN_FOOTPRINT_SIZE))
872 == NULL) {
873 printk(KERN_WARNING "%s: unable to map adapter.\n",
874 AAC_DRIVERNAME);
875 goto out_free_fibs;
876 }
877 if ((*aac_drivers[index].init)(aac)) 870 if ((*aac_drivers[index].init)(aac))
878 goto out_unmap; 871 goto out_unmap;
879 872
@@ -972,8 +965,7 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
972 aac_fib_map_free(aac); 965 aac_fib_map_free(aac);
973 pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, aac->comm_phys); 966 pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, aac->comm_phys);
974 kfree(aac->queues); 967 kfree(aac->queues);
975 iounmap(aac->regs.sa); 968 aac_adapter_ioremap(aac, 0);
976 out_free_fibs:
977 kfree(aac->fibs); 969 kfree(aac->fibs);
978 kfree(aac->fsa_dev); 970 kfree(aac->fsa_dev);
979 out_free_host: 971 out_free_host:
@@ -1008,7 +1000,7 @@ static void __devexit aac_remove_one(struct pci_dev *pdev)
1008 kfree(aac->queues); 1000 kfree(aac->queues);
1009 1001
1010 free_irq(pdev->irq, aac); 1002 free_irq(pdev->irq, aac);
1011 iounmap(aac->regs.sa); 1003 aac_adapter_ioremap(aac, 0);
1012 1004
1013 kfree(aac->fibs); 1005 kfree(aac->fibs);
1014 kfree(aac->fsa_dev); 1006 kfree(aac->fsa_dev);
diff --git a/drivers/scsi/aacraid/rkt.c b/drivers/scsi/aacraid/rkt.c
index f850c3a7cce9..643f23b5ded8 100644
--- a/drivers/scsi/aacraid/rkt.c
+++ b/drivers/scsi/aacraid/rkt.c
@@ -28,389 +28,27 @@
28 * 28 *
29 */ 29 */
30 30
31#include <linux/kernel.h>
32#include <linux/init.h>
33#include <linux/types.h>
34#include <linux/sched.h>
35#include <linux/pci.h>
36#include <linux/spinlock.h>
37#include <linux/slab.h>
38#include <linux/blkdev.h> 31#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 <asm/semaphore.h>
44 32
45#include <scsi/scsi_host.h> 33#include <scsi/scsi_host.h>
46 34
47#include "aacraid.h" 35#include "aacraid.h"
48 36
49static irqreturn_t aac_rkt_intr(int irq, void *dev_id, struct pt_regs *regs)
50{
51 struct aac_dev *dev = dev_id;
52
53 if (dev->new_comm_interface) {
54 u32 Index = rkt_readl(dev, MUnit.OutboundQueue);
55 if (Index == 0xFFFFFFFFL)
56 Index = rkt_readl(dev, MUnit.OutboundQueue);
57 if (Index != 0xFFFFFFFFL) {
58 do {
59 if (aac_intr_normal(dev, Index)) {
60 rkt_writel(dev, MUnit.OutboundQueue, Index);
61 rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormRespReady);
62 }
63 Index = rkt_readl(dev, MUnit.OutboundQueue);
64 } while (Index != 0xFFFFFFFFL);
65 return IRQ_HANDLED;
66 }
67 } else {
68 unsigned long bellbits;
69 u8 intstat;
70 intstat = rkt_readb(dev, MUnit.OISR);
71 /*
72 * Read mask and invert because drawbridge is reversed.
73 * This allows us to only service interrupts that have
74 * been enabled.
75 * Check to see if this is our interrupt. If it isn't just return
76 */
77 if (intstat & ~(dev->OIMR))
78 {
79 bellbits = rkt_readl(dev, OutboundDoorbellReg);
80 if (bellbits & DoorBellPrintfReady) {
81 aac_printf(dev, rkt_readl (dev, IndexRegs.Mailbox[5]));
82 rkt_writel(dev, MUnit.ODR,DoorBellPrintfReady);
83 rkt_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
84 }
85 else if (bellbits & DoorBellAdapterNormCmdReady) {
86 rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
87 aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
88// rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
89 }
90 else if (bellbits & DoorBellAdapterNormRespReady) {
91 rkt_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
92 aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
93 }
94 else if (bellbits & DoorBellAdapterNormCmdNotFull) {
95 rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
96 }
97 else if (bellbits & DoorBellAdapterNormRespNotFull) {
98 rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
99 rkt_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
100 }
101 return IRQ_HANDLED;
102 }
103 }
104 return IRQ_NONE;
105}
106
107/**
108 * aac_rkt_disable_interrupt - Disable interrupts
109 * @dev: Adapter
110 */
111
112static void aac_rkt_disable_interrupt(struct aac_dev *dev)
113{
114 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
115}
116
117/**
118 * rkt_sync_cmd - send a command and wait
119 * @dev: Adapter
120 * @command: Command to execute
121 * @p1: first parameter
122 * @ret: adapter status
123 *
124 * This routine will send a synchronous command to the adapter and wait
125 * for its completion.
126 */
127
128static int rkt_sync_cmd(struct aac_dev *dev, u32 command,
129 u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6,
130 u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4)
131{
132 unsigned long start;
133 int ok;
134 /*
135 * Write the command into Mailbox 0
136 */
137 rkt_writel(dev, InboundMailbox0, command);
138 /*
139 * Write the parameters into Mailboxes 1 - 6
140 */
141 rkt_writel(dev, InboundMailbox1, p1);
142 rkt_writel(dev, InboundMailbox2, p2);
143 rkt_writel(dev, InboundMailbox3, p3);
144 rkt_writel(dev, InboundMailbox4, p4);
145 /*
146 * Clear the synch command doorbell to start on a clean slate.
147 */
148 rkt_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
149 /*
150 * Disable doorbell interrupts
151 */
152 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
153 /*
154 * Force the completion of the mask register write before issuing
155 * the interrupt.
156 */
157 rkt_readb (dev, MUnit.OIMR);
158 /*
159 * Signal that there is a new synch command
160 */
161 rkt_writel(dev, InboundDoorbellReg, INBOUNDDOORBELL_0);
162
163 ok = 0;
164 start = jiffies;
165
166 /*
167 * Wait up to 30 seconds
168 */
169 while (time_before(jiffies, start+30*HZ))
170 {
171 udelay(5); /* Delay 5 microseconds to let Mon960 get info. */
172 /*
173 * Mon960 will set doorbell0 bit when it has completed the command.
174 */
175 if (rkt_readl(dev, OutboundDoorbellReg) & OUTBOUNDDOORBELL_0) {
176 /*
177 * Clear the doorbell.
178 */
179 rkt_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
180 ok = 1;
181 break;
182 }
183 /*
184 * Yield the processor in case we are slow
185 */
186 msleep(1);
187 }
188 if (ok != 1) {
189 /*
190 * Restore interrupt mask even though we timed out
191 */
192 if (dev->new_comm_interface)
193 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
194 else
195 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
196 return -ETIMEDOUT;
197 }
198 /*
199 * Pull the synch status from Mailbox 0.
200 */
201 if (status)
202 *status = rkt_readl(dev, IndexRegs.Mailbox[0]);
203 if (r1)
204 *r1 = rkt_readl(dev, IndexRegs.Mailbox[1]);
205 if (r2)
206 *r2 = rkt_readl(dev, IndexRegs.Mailbox[2]);
207 if (r3)
208 *r3 = rkt_readl(dev, IndexRegs.Mailbox[3]);
209 if (r4)
210 *r4 = rkt_readl(dev, IndexRegs.Mailbox[4]);
211 /*
212 * Clear the synch command doorbell.
213 */
214 rkt_writel(dev, OutboundDoorbellReg, OUTBOUNDDOORBELL_0);
215 /*
216 * Restore interrupt mask
217 */
218 if (dev->new_comm_interface)
219 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
220 else
221 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
222 return 0;
223
224}
225
226/**
227 * aac_rkt_interrupt_adapter - interrupt adapter
228 * @dev: Adapter
229 *
230 * Send an interrupt to the i960 and breakpoint it.
231 */
232
233static void aac_rkt_interrupt_adapter(struct aac_dev *dev)
234{
235 rkt_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
236 NULL, NULL, NULL, NULL, NULL);
237}
238
239/** 37/**
240 * aac_rkt_notify_adapter - send an event to the adapter 38 * aac_rkt_ioremap
241 * @dev: Adapter 39 * @size: mapping resize request
242 * @event: Event to send
243 * 40 *
244 * Notify the i960 that something it probably cares about has
245 * happened.
246 */ 41 */
247 42static int aac_rkt_ioremap(struct aac_dev * dev, u32 size)
248static void aac_rkt_notify_adapter(struct aac_dev *dev, u32 event)
249{ 43{
250 switch (event) { 44 if (!size) {
251 45 iounmap(dev->regs.rkt);
252 case AdapNormCmdQue: 46 return 0;
253 rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_1);
254 break;
255 case HostNormRespNotFull:
256 rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_4);
257 break;
258 case AdapNormRespQue:
259 rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_2);
260 break;
261 case HostNormCmdNotFull:
262 rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3);
263 break;
264 case HostShutdown:
265// rkt_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
266// NULL, NULL, NULL, NULL, NULL);
267 break;
268 case FastIo:
269 rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6);
270 break;
271 case AdapPrintfDone:
272 rkt_writel(dev, MUnit.IDR,INBOUNDDOORBELL_5);
273 break;
274 default:
275 BUG();
276 break;
277 } 47 }
278} 48 dev->base = dev->regs.rkt = ioremap(dev->scsi_host_ptr->base, size);
279 49 if (dev->base == NULL)
280/**
281 * aac_rkt_start_adapter - activate adapter
282 * @dev: Adapter
283 *
284 * Start up processing on an i960 based AAC adapter
285 */
286
287static void aac_rkt_start_adapter(struct aac_dev *dev)
288{
289 struct aac_init *init;
290
291 init = dev->init;
292 init->HostElapsedSeconds = cpu_to_le32(get_seconds());
293 // We can only use a 32 bit address here
294 rkt_sync_cmd(dev, INIT_STRUCT_BASE_ADDRESS, (u32)(ulong)dev->init_pa,
295 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL);
296}
297
298/**
299 * aac_rkt_check_health
300 * @dev: device to check if healthy
301 *
302 * Will attempt to determine if the specified adapter is alive and
303 * capable of handling requests, returning 0 if alive.
304 */
305static int aac_rkt_check_health(struct aac_dev *dev)
306{
307 u32 status = rkt_readl(dev, MUnit.OMRx[0]);
308
309 /*
310 * Check to see if the board failed any self tests.
311 */
312 if (status & SELF_TEST_FAILED)
313 return -1; 50 return -1;
314 /* 51 dev->IndexRegs = &dev->regs.rkt->IndexRegs;
315 * Check to see if the board panic'd.
316 */
317 if (status & KERNEL_PANIC) {
318 char * buffer;
319 struct POSTSTATUS {
320 __le32 Post_Command;
321 __le32 Post_Address;
322 } * post;
323 dma_addr_t paddr, baddr;
324 int ret;
325
326 if ((status & 0xFF000000L) == 0xBC000000L)
327 return (status >> 16) & 0xFF;
328 buffer = pci_alloc_consistent(dev->pdev, 512, &baddr);
329 ret = -2;
330 if (buffer == NULL)
331 return ret;
332 post = pci_alloc_consistent(dev->pdev,
333 sizeof(struct POSTSTATUS), &paddr);
334 if (post == NULL) {
335 pci_free_consistent(dev->pdev, 512, buffer, baddr);
336 return ret;
337 }
338 memset(buffer, 0, 512);
339 post->Post_Command = cpu_to_le32(COMMAND_POST_RESULTS);
340 post->Post_Address = cpu_to_le32(baddr);
341 rkt_writel(dev, MUnit.IMRx[0], paddr);
342 rkt_sync_cmd(dev, COMMAND_POST_RESULTS, baddr, 0, 0, 0, 0, 0,
343 NULL, NULL, NULL, NULL, NULL);
344 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
345 post, paddr);
346 if ((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X'))) {
347 ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10);
348 ret <<= 4;
349 ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
350 }
351 pci_free_consistent(dev->pdev, 512, buffer, baddr);
352 return ret;
353 }
354 /*
355 * Wait for the adapter to be up and running.
356 */
357 if (!(status & KERNEL_UP_AND_RUNNING))
358 return -3;
359 /*
360 * Everything is OK
361 */
362 return 0;
363}
364
365/**
366 * aac_rkt_send
367 * @fib: fib to issue
368 *
369 * Will send a fib, returning 0 if successful.
370 */
371static int aac_rkt_send(struct fib * fib)
372{
373 u64 addr = fib->hw_fib_pa;
374 struct aac_dev *dev = fib->dev;
375 volatile void __iomem *device = dev->regs.rkt;
376 u32 Index;
377
378 dprintk((KERN_DEBUG "%p->aac_rkt_send(%p->%llx)\n", dev, fib, addr));
379 Index = rkt_readl(dev, MUnit.InboundQueue);
380 if (Index == 0xFFFFFFFFL)
381 Index = rkt_readl(dev, MUnit.InboundQueue);
382 dprintk((KERN_DEBUG "Index = 0x%x\n", Index));
383 if (Index == 0xFFFFFFFFL)
384 return Index;
385 device += Index;
386 dprintk((KERN_DEBUG "entry = %x %x %u\n", (u32)(addr & 0xffffffff),
387 (u32)(addr >> 32), (u32)le16_to_cpu(fib->hw_fib->header.Size)));
388 writel((u32)(addr & 0xffffffff), device);
389 device += sizeof(u32);
390 writel((u32)(addr >> 32), device);
391 device += sizeof(u32);
392 writel(le16_to_cpu(fib->hw_fib->header.Size), device);
393 rkt_writel(dev, MUnit.InboundQueue, Index);
394 dprintk((KERN_DEBUG "aac_rkt_send - return 0\n"));
395 return 0;
396}
397
398static int aac_rkt_restart_adapter(struct aac_dev *dev)
399{
400 u32 var;
401
402 printk(KERN_ERR "%s%d: adapter kernel panic'd.\n",
403 dev->name, dev->id);
404
405 if (aac_rkt_check_health(dev) <= 0)
406 return 1;
407 if (rkt_sync_cmd(dev, IOP_RESET, 0, 0, 0, 0, 0, 0,
408 &var, NULL, NULL, NULL, NULL))
409 return 1;
410 if (var != 0x00000001)
411 return 1;
412 if (rkt_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC)
413 return 1;
414 return 0; 52 return 0;
415} 53}
416 54
@@ -425,74 +63,18 @@ static int aac_rkt_restart_adapter(struct aac_dev *dev)
425 63
426int aac_rkt_init(struct aac_dev *dev) 64int aac_rkt_init(struct aac_dev *dev)
427{ 65{
428 unsigned long start; 66 int retval;
429 unsigned long status; 67 extern int _aac_rx_init(struct aac_dev *dev);
430 int instance; 68 extern void aac_rx_start_adapter(struct aac_dev *dev);
431 const char * name;
432
433 instance = dev->id;
434 name = dev->name;
435 69
436 /* 70 /*
437 * Check to see if the board panic'd while booting.
438 */
439 if (rkt_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC)
440 if (aac_rkt_restart_adapter(dev))
441 goto error_iounmap;
442 /*
443 * Check to see if the board failed any self tests.
444 */
445 if (rkt_readl(dev, MUnit.OMRx[0]) & SELF_TEST_FAILED) {
446 printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
447 goto error_iounmap;
448 }
449 /*
450 * Check to see if the monitor panic'd while booting.
451 */
452 if (rkt_readl(dev, MUnit.OMRx[0]) & MONITOR_PANIC) {
453 printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance);
454 goto error_iounmap;
455 }
456 start = jiffies;
457 /*
458 * Wait for the adapter to be up and running. Wait up to 3 minutes
459 */
460 while (!(rkt_readl(dev, MUnit.OMRx[0]) & KERNEL_UP_AND_RUNNING))
461 {
462 if(time_after(jiffies, start+startup_timeout*HZ))
463 {
464 status = rkt_readl(dev, MUnit.OMRx[0]);
465 printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
466 dev->name, instance, status);
467 goto error_iounmap;
468 }
469 msleep(1);
470 }
471 if (request_irq(dev->scsi_host_ptr->irq, aac_rkt_intr, IRQF_SHARED|IRQF_DISABLED, "aacraid", (void *)dev)<0)
472 {
473 printk(KERN_ERR "%s%d: Interrupt unavailable.\n", name, instance);
474 goto error_iounmap;
475 }
476 /*
477 * Fill in the function dispatch table. 71 * Fill in the function dispatch table.
478 */ 72 */
479 dev->a_ops.adapter_interrupt = aac_rkt_interrupt_adapter; 73 dev->a_ops.adapter_ioremap = aac_rkt_ioremap;
480 dev->a_ops.adapter_disable_int = aac_rkt_disable_interrupt;
481 dev->a_ops.adapter_notify = aac_rkt_notify_adapter;
482 dev->a_ops.adapter_sync_cmd = rkt_sync_cmd;
483 dev->a_ops.adapter_check_health = aac_rkt_check_health;
484 dev->a_ops.adapter_send = aac_rkt_send;
485
486 /*
487 * First clear out all interrupts. Then enable the one's that we
488 * can handle.
489 */
490 rkt_writeb(dev, MUnit.OIMR, 0xff);
491 rkt_writel(dev, MUnit.ODR, 0xffffffff);
492 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
493 74
494 if (aac_init_adapter(dev) == NULL) 75 retval = _aac_rx_init(dev);
495 goto error_irq; 76 if (retval)
77 return retval;
496 if (dev->new_comm_interface) { 78 if (dev->new_comm_interface) {
497 /* 79 /*
498 * FIB Setup has already been done, but we can minimize the 80 * FIB Setup has already been done, but we can minimize the
@@ -509,20 +91,11 @@ int aac_rkt_init(struct aac_dev *dev)
509 dev->init->MaxIoCommands = cpu_to_le32(246); 91 dev->init->MaxIoCommands = cpu_to_le32(246);
510 dev->scsi_host_ptr->can_queue = 246 - AAC_NUM_MGT_FIB; 92 dev->scsi_host_ptr->can_queue = 246 - AAC_NUM_MGT_FIB;
511 } 93 }
512 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
513 } 94 }
514 /* 95 /*
515 * Tell the adapter that all is configured, and it can start 96 * Tell the adapter that all is configured, and it can start
516 * accepting requests 97 * accepting requests
517 */ 98 */
518 aac_rkt_start_adapter(dev); 99 aac_rx_start_adapter(dev);
519 return 0; 100 return 0;
520
521error_irq:
522 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
523 free_irq(dev->scsi_host_ptr->irq, (void *)dev);
524
525error_iounmap:
526
527 return -1;
528} 101}
diff --git a/drivers/scsi/aacraid/rx.c b/drivers/scsi/aacraid/rx.c
index c715c4b2442d..a1d214d770eb 100644
--- a/drivers/scsi/aacraid/rx.c
+++ b/drivers/scsi/aacraid/rx.c
@@ -79,7 +79,7 @@ static irqreturn_t aac_rx_intr(int irq, void *dev_id, struct pt_regs *regs)
79 { 79 {
80 bellbits = rx_readl(dev, OutboundDoorbellReg); 80 bellbits = rx_readl(dev, OutboundDoorbellReg);
81 if (bellbits & DoorBellPrintfReady) { 81 if (bellbits & DoorBellPrintfReady) {
82 aac_printf(dev, rx_readl (dev, IndexRegs.Mailbox[5])); 82 aac_printf(dev, readl (&dev->IndexRegs->Mailbox[5]));
83 rx_writel(dev, MUnit.ODR,DoorBellPrintfReady); 83 rx_writel(dev, MUnit.ODR,DoorBellPrintfReady);
84 rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone); 84 rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
85 } 85 }
@@ -134,14 +134,14 @@ static int rx_sync_cmd(struct aac_dev *dev, u32 command,
134 /* 134 /*
135 * Write the command into Mailbox 0 135 * Write the command into Mailbox 0
136 */ 136 */
137 rx_writel(dev, InboundMailbox0, command); 137 writel(command, &dev->IndexRegs->Mailbox[0]);
138 /* 138 /*
139 * Write the parameters into Mailboxes 1 - 6 139 * Write the parameters into Mailboxes 1 - 6
140 */ 140 */
141 rx_writel(dev, InboundMailbox1, p1); 141 writel(p1, &dev->IndexRegs->Mailbox[1]);
142 rx_writel(dev, InboundMailbox2, p2); 142 writel(p2, &dev->IndexRegs->Mailbox[2]);
143 rx_writel(dev, InboundMailbox3, p3); 143 writel(p3, &dev->IndexRegs->Mailbox[3]);
144 rx_writel(dev, InboundMailbox4, p4); 144 writel(p4, &dev->IndexRegs->Mailbox[4]);
145 /* 145 /*
146 * Clear the synch command doorbell to start on a clean slate. 146 * Clear the synch command doorbell to start on a clean slate.
147 */ 147 */
@@ -199,15 +199,15 @@ static int rx_sync_cmd(struct aac_dev *dev, u32 command,
199 * Pull the synch status from Mailbox 0. 199 * Pull the synch status from Mailbox 0.
200 */ 200 */
201 if (status) 201 if (status)
202 *status = rx_readl(dev, IndexRegs.Mailbox[0]); 202 *status = readl(&dev->IndexRegs->Mailbox[0]);
203 if (r1) 203 if (r1)
204 *r1 = rx_readl(dev, IndexRegs.Mailbox[1]); 204 *r1 = readl(&dev->IndexRegs->Mailbox[1]);
205 if (r2) 205 if (r2)
206 *r2 = rx_readl(dev, IndexRegs.Mailbox[2]); 206 *r2 = readl(&dev->IndexRegs->Mailbox[2]);
207 if (r3) 207 if (r3)
208 *r3 = rx_readl(dev, IndexRegs.Mailbox[3]); 208 *r3 = readl(&dev->IndexRegs->Mailbox[3]);
209 if (r4) 209 if (r4)
210 *r4 = rx_readl(dev, IndexRegs.Mailbox[4]); 210 *r4 = readl(&dev->IndexRegs->Mailbox[4]);
211 /* 211 /*
212 * Clear the synch command doorbell. 212 * Clear the synch command doorbell.
213 */ 213 */
@@ -261,8 +261,6 @@ static void aac_rx_notify_adapter(struct aac_dev *dev, u32 event)
261 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3); 261 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_3);
262 break; 262 break;
263 case HostShutdown: 263 case HostShutdown:
264// rx_sync_cmd(dev, HOST_CRASHING, 0, 0, 0, 0, 0, 0,
265// NULL, NULL, NULL, NULL, NULL);
266 break; 264 break;
267 case FastIo: 265 case FastIo:
268 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6); 266 rx_writel(dev, MUnit.IDR,INBOUNDDOORBELL_6);
@@ -283,7 +281,7 @@ static void aac_rx_notify_adapter(struct aac_dev *dev, u32 event)
283 * Start up processing on an i960 based AAC adapter 281 * Start up processing on an i960 based AAC adapter
284 */ 282 */
285 283
286static void aac_rx_start_adapter(struct aac_dev *dev) 284void aac_rx_start_adapter(struct aac_dev *dev)
287{ 285{
288 struct aac_init *init; 286 struct aac_init *init;
289 287
@@ -381,7 +379,7 @@ static int aac_rx_send(struct fib * fib)
381 dprintk((KERN_DEBUG "Index = 0x%x\n", Index)); 379 dprintk((KERN_DEBUG "Index = 0x%x\n", Index));
382 if (Index == 0xFFFFFFFFL) 380 if (Index == 0xFFFFFFFFL)
383 return Index; 381 return Index;
384 device += Index; 382 device = dev->base + Index;
385 dprintk((KERN_DEBUG "entry = %x %x %u\n", (u32)(addr & 0xffffffff), 383 dprintk((KERN_DEBUG "entry = %x %x %u\n", (u32)(addr & 0xffffffff),
386 (u32)(addr >> 32), (u32)le16_to_cpu(fib->hw_fib->header.Size))); 384 (u32)(addr >> 32), (u32)le16_to_cpu(fib->hw_fib->header.Size)));
387 writel((u32)(addr & 0xffffffff), device); 385 writel((u32)(addr & 0xffffffff), device);
@@ -394,6 +392,24 @@ static int aac_rx_send(struct fib * fib)
394 return 0; 392 return 0;
395} 393}
396 394
395/**
396 * aac_rx_ioremap
397 * @size: mapping resize request
398 *
399 */
400static int aac_rx_ioremap(struct aac_dev * dev, u32 size)
401{
402 if (!size) {
403 iounmap(dev->regs.rx);
404 return 0;
405 }
406 dev->base = dev->regs.rx = ioremap(dev->scsi_host_ptr->base, size);
407 if (dev->base == NULL)
408 return -1;
409 dev->IndexRegs = &dev->regs.rx->IndexRegs;
410 return 0;
411}
412
397static int aac_rx_restart_adapter(struct aac_dev *dev) 413static int aac_rx_restart_adapter(struct aac_dev *dev)
398{ 414{
399 u32 var; 415 u32 var;
@@ -422,7 +438,7 @@ static int aac_rx_restart_adapter(struct aac_dev *dev)
422 * to the comm region. 438 * to the comm region.
423 */ 439 */
424 440
425int aac_rx_init(struct aac_dev *dev) 441int _aac_rx_init(struct aac_dev *dev)
426{ 442{
427 unsigned long start; 443 unsigned long start;
428 unsigned long status; 444 unsigned long status;
@@ -432,23 +448,30 @@ int aac_rx_init(struct aac_dev *dev)
432 instance = dev->id; 448 instance = dev->id;
433 name = dev->name; 449 name = dev->name;
434 450
451 if (aac_adapter_ioremap(dev, dev->base_size)) {
452 printk(KERN_WARNING "%s: unable to map adapter.\n", name);
453 goto error_iounmap;
454 }
455
435 /* 456 /*
436 * Check to see if the board panic'd while booting. 457 * Check to see if the board panic'd while booting.
437 */ 458 */
438 if (rx_readl(dev, MUnit.OMRx[0]) & KERNEL_PANIC) 459 status = rx_readl(dev, MUnit.OMRx[0]);
460 if (status & KERNEL_PANIC)
439 if (aac_rx_restart_adapter(dev)) 461 if (aac_rx_restart_adapter(dev))
440 goto error_iounmap; 462 goto error_iounmap;
441 /* 463 /*
442 * Check to see if the board failed any self tests. 464 * Check to see if the board failed any self tests.
443 */ 465 */
444 if (rx_readl(dev, MUnit.OMRx[0]) & SELF_TEST_FAILED) { 466 status = rx_readl(dev, MUnit.OMRx[0]);
467 if (status & SELF_TEST_FAILED) {
445 printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance); 468 printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
446 goto error_iounmap; 469 goto error_iounmap;
447 } 470 }
448 /* 471 /*
449 * Check to see if the monitor panic'd while booting. 472 * Check to see if the monitor panic'd while booting.
450 */ 473 */
451 if (rx_readl(dev, MUnit.OMRx[0]) & MONITOR_PANIC) { 474 if (status & MONITOR_PANIC) {
452 printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance); 475 printk(KERN_ERR "%s%d: adapter monitor panic.\n", dev->name, instance);
453 goto error_iounmap; 476 goto error_iounmap;
454 } 477 }
@@ -456,12 +479,10 @@ int aac_rx_init(struct aac_dev *dev)
456 /* 479 /*
457 * Wait for the adapter to be up and running. Wait up to 3 minutes 480 * Wait for the adapter to be up and running. Wait up to 3 minutes
458 */ 481 */
459 while ((!(rx_readl(dev, IndexRegs.Mailbox[7]) & KERNEL_UP_AND_RUNNING)) 482 while (!((status = rx_readl(dev, MUnit.OMRx[0])) & KERNEL_UP_AND_RUNNING))
460 || (!(rx_readl(dev, MUnit.OMRx[0]) & KERNEL_UP_AND_RUNNING)))
461 { 483 {
462 if(time_after(jiffies, start+startup_timeout*HZ)) 484 if(time_after(jiffies, start+startup_timeout*HZ))
463 { 485 {
464 status = rx_readl(dev, IndexRegs.Mailbox[7]);
465 printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n", 486 printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %lx.\n",
466 dev->name, instance, status); 487 dev->name, instance, status);
467 goto error_iounmap; 488 goto error_iounmap;
@@ -496,11 +517,6 @@ int aac_rx_init(struct aac_dev *dev)
496 if (dev->new_comm_interface) 517 if (dev->new_comm_interface)
497 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7); 518 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
498 519
499 /*
500 * Tell the adapter that all is configured, and it can start
501 * accepting requests
502 */
503 aac_rx_start_adapter(dev);
504 return 0; 520 return 0;
505 521
506error_irq: 522error_irq:
@@ -511,3 +527,23 @@ error_iounmap:
511 527
512 return -1; 528 return -1;
513} 529}
530
531int aac_rx_init(struct aac_dev *dev)
532{
533 int retval;
534
535 /*
536 * Fill in the function dispatch table.
537 */
538 dev->a_ops.adapter_ioremap = aac_rx_ioremap;
539
540 retval = _aac_rx_init(dev);
541 if (!retval) {
542 /*
543 * Tell the adapter that all is configured, and it can
544 * start accepting requests
545 */
546 aac_rx_start_adapter(dev);
547 }
548 return retval;
549}
diff --git a/drivers/scsi/aacraid/sa.c b/drivers/scsi/aacraid/sa.c
index cd586cc8f9be..f906ead239dd 100644
--- a/drivers/scsi/aacraid/sa.c
+++ b/drivers/scsi/aacraid/sa.c
@@ -281,6 +281,21 @@ static int aac_sa_check_health(struct aac_dev *dev)
281} 281}
282 282
283/** 283/**
284 * aac_sa_ioremap
285 * @size: mapping resize request
286 *
287 */
288static int aac_sa_ioremap(struct aac_dev * dev, u32 size)
289{
290 if (!size) {
291 iounmap(dev->regs.sa);
292 return 0;
293 }
294 dev->base = dev->regs.sa = ioremap(dev->scsi_host_ptr->base, size);
295 return (dev->base == NULL) ? -1 : 0;
296}
297
298/**
284 * aac_sa_init - initialize an ARM based AAC card 299 * aac_sa_init - initialize an ARM based AAC card
285 * @dev: device to configure 300 * @dev: device to configure
286 * 301 *
@@ -299,6 +314,11 @@ int aac_sa_init(struct aac_dev *dev)
299 instance = dev->id; 314 instance = dev->id;
300 name = dev->name; 315 name = dev->name;
301 316
317 if (aac_sa_ioremap(dev, dev->base_size)) {
318 printk(KERN_WARNING "%s: unable to map adapter.\n", name);
319 goto error_iounmap;
320 }
321
302 /* 322 /*
303 * Check to see if the board failed any self tests. 323 * Check to see if the board failed any self tests.
304 */ 324 */
@@ -341,6 +361,7 @@ int aac_sa_init(struct aac_dev *dev)
341 dev->a_ops.adapter_notify = aac_sa_notify_adapter; 361 dev->a_ops.adapter_notify = aac_sa_notify_adapter;
342 dev->a_ops.adapter_sync_cmd = sa_sync_cmd; 362 dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
343 dev->a_ops.adapter_check_health = aac_sa_check_health; 363 dev->a_ops.adapter_check_health = aac_sa_check_health;
364 dev->a_ops.adapter_ioremap = aac_sa_ioremap;
344 365
345 /* 366 /*
346 * First clear out all interrupts. Then enable the one's that 367 * First clear out all interrupts. Then enable the one's that