This source file includes following definitions.
- aac_sa_intr
- aac_sa_disable_interrupt
- aac_sa_enable_interrupt
- aac_sa_notify_adapter
- sa_sync_cmd
- aac_sa_interrupt_adapter
- aac_sa_start_adapter
- aac_sa_restart_adapter
- aac_sa_check_health
- aac_sa_ioremap
- aac_sa_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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>
29
30 #include <scsi/scsi_host.h>
31
32 #include "aacraid.h"
33
34 static irqreturn_t aac_sa_intr(int irq, void *dev_id)
35 {
36 struct aac_dev *dev = dev_id;
37 unsigned short intstat, mask;
38
39 intstat = sa_readw(dev, DoorbellReg_p);
40
41
42
43
44 mask = ~(sa_readw(dev, SaDbCSR.PRISETIRQMASK));
45
46
47
48 if (intstat & mask) {
49 if (intstat & PrintfReady) {
50 aac_printf(dev, sa_readl(dev, Mailbox5));
51 sa_writew(dev, DoorbellClrReg_p, PrintfReady);
52 sa_writew(dev, DoorbellReg_s, PrintfDone);
53 } else if (intstat & DOORBELL_1) {
54 sa_writew(dev, DoorbellClrReg_p, DOORBELL_1);
55 aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
56 } else if (intstat & DOORBELL_2) {
57 sa_writew(dev, DoorbellClrReg_p, DOORBELL_2);
58 aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
59 } else if (intstat & DOORBELL_3) {
60 sa_writew(dev, DoorbellClrReg_p, DOORBELL_3);
61 } else if (intstat & DOORBELL_4) {
62 sa_writew(dev, DoorbellClrReg_p, DOORBELL_4);
63 }
64 return IRQ_HANDLED;
65 }
66 return IRQ_NONE;
67 }
68
69
70
71
72
73
74 static void aac_sa_disable_interrupt (struct aac_dev *dev)
75 {
76 sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
77 }
78
79
80
81
82
83
84 static void aac_sa_enable_interrupt (struct aac_dev *dev)
85 {
86 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 |
87 DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
88 }
89
90
91
92
93
94
95
96
97
98 static void aac_sa_notify_adapter(struct aac_dev *dev, u32 event)
99 {
100 switch (event) {
101
102 case AdapNormCmdQue:
103 sa_writew(dev, DoorbellReg_s,DOORBELL_1);
104 break;
105 case HostNormRespNotFull:
106 sa_writew(dev, DoorbellReg_s,DOORBELL_4);
107 break;
108 case AdapNormRespQue:
109 sa_writew(dev, DoorbellReg_s,DOORBELL_2);
110 break;
111 case HostNormCmdNotFull:
112 sa_writew(dev, DoorbellReg_s,DOORBELL_3);
113 break;
114 case HostShutdown:
115
116
117
118
119 break;
120 case FastIo:
121 sa_writew(dev, DoorbellReg_s,DOORBELL_6);
122 break;
123 case AdapPrintfDone:
124 sa_writew(dev, DoorbellReg_s,DOORBELL_5);
125 break;
126 default:
127 BUG();
128 break;
129 }
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
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)
147 {
148 unsigned long start;
149 int ok;
150
151
152
153 sa_writel(dev, Mailbox0, command);
154
155
156
157 sa_writel(dev, Mailbox1, p1);
158 sa_writel(dev, Mailbox2, p2);
159 sa_writel(dev, Mailbox3, p3);
160 sa_writel(dev, Mailbox4, p4);
161
162
163
164
165 sa_writew(dev, DoorbellClrReg_p, DOORBELL_0);
166
167
168
169 sa_writew(dev, DoorbellReg_s, DOORBELL_0);
170
171 ok = 0;
172 start = jiffies;
173
174 while(time_before(jiffies, start+30*HZ))
175 {
176
177
178
179 udelay(5);
180
181
182
183
184 if(sa_readw(dev, DoorbellReg_p) & DOORBELL_0) {
185 ok = 1;
186 break;
187 }
188 msleep(1);
189 }
190
191 if (ok != 1)
192 return -ETIMEDOUT;
193
194
195
196 sa_writew(dev, DoorbellClrReg_p, DOORBELL_0);
197
198
199
200 if (ret)
201 *ret = sa_readl(dev, Mailbox0);
202 if (r1)
203 *r1 = sa_readl(dev, Mailbox1);
204 if (r2)
205 *r2 = sa_readl(dev, Mailbox2);
206 if (r3)
207 *r3 = sa_readl(dev, Mailbox3);
208 if (r4)
209 *r4 = sa_readl(dev, Mailbox4);
210 return 0;
211 }
212
213
214
215
216
217
218
219
220 static void aac_sa_interrupt_adapter (struct aac_dev *dev)
221 {
222 sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
223 NULL, NULL, NULL, NULL, NULL);
224 }
225
226
227
228
229
230
231
232
233 static void aac_sa_start_adapter(struct aac_dev *dev)
234 {
235 union aac_init *init;
236
237
238
239 init = dev->init;
240 init->r7.host_elapsed_seconds = cpu_to_le32(ktime_get_real_seconds());
241
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);
245 }
246
247 static int aac_sa_restart_adapter(struct aac_dev *dev, int bled, u8 reset_type)
248 {
249 return -EINVAL;
250 }
251
252
253
254
255
256
257
258
259 static int aac_sa_check_health(struct aac_dev *dev)
260 {
261 long status = sa_readl(dev, Mailbox7);
262
263
264
265
266 if (status & SELF_TEST_FAILED)
267 return -1;
268
269
270
271 if (status & KERNEL_PANIC)
272 return -2;
273
274
275
276 if (!(status & KERNEL_UP_AND_RUNNING))
277 return -3;
278
279
280
281 return 0;
282 }
283
284
285
286
287
288
289 static int aac_sa_ioremap(struct aac_dev * dev, u32 size)
290 {
291 if (!size) {
292 iounmap(dev->regs.sa);
293 return 0;
294 }
295 dev->base = dev->regs.sa = ioremap(dev->base_start, size);
296 return (dev->base == NULL) ? -1 : 0;
297 }
298
299
300
301
302
303
304
305
306
307
308 int aac_sa_init(struct aac_dev *dev)
309 {
310 unsigned long start;
311 unsigned long status;
312 int instance;
313 const char *name;
314
315 instance = dev->id;
316 name = dev->name;
317
318
319
320
321
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;
333
334 if (aac_sa_ioremap(dev, dev->base_size)) {
335 printk(KERN_WARNING "%s: unable to map adapter.\n", name);
336 goto error_iounmap;
337 }
338
339
340
341
342 if (sa_readl(dev, Mailbox7) & SELF_TEST_FAILED) {
343 printk(KERN_WARNING "%s%d: adapter self-test failed.\n", name, instance);
344 goto error_iounmap;
345 }
346
347
348
349 if (sa_readl(dev, Mailbox7) & KERNEL_PANIC) {
350 printk(KERN_WARNING "%s%d: adapter kernel panic'd.\n", name, instance);
351 goto error_iounmap;
352 }
353 start = jiffies;
354
355
356
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);
362 goto error_iounmap;
363 }
364 msleep(1);
365 }
366
367
368
369
370
371 aac_adapter_disable_int(dev);
372 aac_adapter_enable_int(dev);
373
374 if(aac_init_adapter(dev) == NULL)
375 goto error_irq;
376 dev->sync_mode = 0;
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",
380 name, instance);
381 goto error_iounmap;
382 }
383 dev->dbg_base = dev->base_start;
384 dev->dbg_base_mapped = dev->base;
385 dev->dbg_size = dev->base_size;
386
387 aac_adapter_enable_int(dev);
388
389
390
391
392
393 aac_sa_start_adapter(dev);
394 return 0;
395
396 error_irq:
397 aac_sa_disable_interrupt(dev);
398 free_irq(dev->pdev->irq, (void *)dev);
399
400 error_iounmap:
401
402 return -1;
403 }
404