This source file includes following definitions.
- aha1740_makecode
- aha1740_test_port
- aha1740_info
- aha1740_intr_handle
- aha1740_queuecommand
- internal_done
- aha1740_command
- aha1740_getconfig
- aha1740_detect
- aha1740_abort
- aha1740_reset
- aha1740_biosparam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <linux/kernel.h>
21 #include <linux/head.h>
22 #include <linux/types.h>
23 #include <linux/string.h>
24 #include <linux/ioport.h>
25
26 #include <linux/sched.h>
27 #include <asm/dma.h>
28
29 #include <asm/system.h>
30 #include <asm/io.h>
31 #include "../block/blk.h"
32 #include "scsi.h"
33 #include "hosts.h"
34
35 #include "aha1740.h"
36
37
38
39
40
41 #ifdef DEBUG
42 #define DEB(x) x
43 #else
44 #define DEB(x)
45 #endif
46
47
48
49
50
51 static unsigned int slot, base;
52 static unsigned char irq_level;
53
54 static struct ecb ecb[AHA1740_ECBS];
55
56 static int aha1740_last_ecb_used = 0;
57
58 int aha1740_makecode(unchar *sense, unchar *status)
59 {
60 struct statusword
61 {
62 ushort don:1,
63 du:1,
64 :1, qf:1,
65 sc:1,
66 dor:1,
67 ch:1,
68 intr:1,
69 asa:1,
70 sns:1,
71 :1, ini:1,
72 me:1,
73 :1, eca:1,
74 :1;
75 } status_word;
76 int retval = DID_OK;
77
78 status_word = * (struct statusword *) status;
79 #ifdef DEBUG
80 printk("makecode from %x,%x,%x,%x %x,%x,%x,%x",status[0],status[1],status[2],status[3],
81 sense[0],sense[1],sense[2],sense[3]);
82 #endif
83 if (!status_word.don)
84 {
85 if ( (status[1]&0x18) || status_word.sc )
86 {
87
88 switch ( status[2] )
89 {
90 case 0x12:
91 if ( status_word.dor )
92 retval=DID_ERROR;
93
94 case 0x00:
95 break;
96 case 0x11:
97 case 0x21:
98 retval=DID_TIME_OUT;
99 break;
100 case 0x0a:
101 retval=DID_BAD_TARGET;
102 break;
103 case 0x04:
104 case 0x05:
105 retval=DID_ABORT;
106
107 break;
108 default:
109 retval=DID_ERROR;
110 }
111 }
112 else
113 {
114 if ( status_word.qf )
115 {
116 retval = DID_TIME_OUT;
117
118 printk("aha1740.c: WARNING: AHA1740 queue overflow!\n");
119 }
120 else if ( status[0]&0x60 )
121 {
122 retval = DID_ERROR;
123 }
124
125
126
127 }
128 }
129
130 return status[3] | retval << 16;
131 }
132
133 int aha1740_test_port(void)
134 {
135 char name[4],tmp;
136
137
138 name[0]= 'A' -1 + ((tmp = inb(HID0)) >> 2);
139 name[1]= 'A' -1 + ((tmp & 3) << 3);
140 name[1]+= ((tmp = inb(HID1)) >> 5)&0x7;
141 name[2]= 'A' -1 + (tmp & 0x1f);
142 name[3]=0;
143 tmp = inb(HID2);
144 if ( strcmp ( name, HID_MFG ) || inb(HID2) != HID_PRD )
145 return 0;
146
147
148
149
150
151 if ( inb(EBCNTRL) != EBCNTRL_VALUE )
152 {
153 printk("aha1740: Board detected, but EBCNTRL = %x, so disabled it.\n",
154 inb(EBCNTRL));
155 return 0;
156 }
157
158 if ( inb(PORTADR) & PORTADDR_ENH )
159 return 1;
160
161 printk("aha1740: Board detected, but not in enhanced mode, so disabled it.\n");
162 return 0;
163 }
164
165 const char *aha1740_info(void)
166 {
167 static char buffer[] = "Adaptec 174x (EISA)";
168 return buffer;
169 }
170
171
172 void aha1740_intr_handle(int foo)
173 {
174 void (*my_done)(Scsi_Cmnd *);
175 int errstatus, adapstat;
176 int number_serviced;
177 struct ecb *ecbptr;
178 Scsi_Cmnd *SCtmp;
179
180 number_serviced = 0;
181
182 while(inb(G2STAT) & G2STAT_INTPEND)
183 {
184 DEB(printk("aha1740_intr top of loop.\n"));
185 adapstat = inb(G2INTST);
186 outb(G2CNTRL_IRST,G2CNTRL);
187
188 switch ( adapstat & G2INTST_MASK )
189 {
190 case G2INTST_CCBRETRY:
191 case G2INTST_CCBERROR:
192 case G2INTST_CCBGOOD:
193 ecbptr = (struct ecb *) ( ((ulong) inb(MBOXIN0)) +
194 ((ulong) inb(MBOXIN1) <<8) +
195 ((ulong) inb(MBOXIN2) <<16) +
196 ((ulong) inb(MBOXIN3) <<24) );
197 outb(G2CNTRL_HRDY,G2CNTRL);
198 SCtmp = ecbptr->SCpnt;
199 if (SCtmp->host_scribble)
200 scsi_free(SCtmp->host_scribble, 512);
201
202
203
204 if ( (adapstat & G2INTST_MASK) == G2INTST_CCBERROR )
205 {
206 memcpy(SCtmp->sense_buffer, ecbptr->sense,
207 sizeof(SCtmp->sense_buffer));
208 errstatus = aha1740_makecode(ecbptr->sense,ecbptr->status);
209 }
210 else
211 errstatus = 0;
212 DEB(if (errstatus) printk("aha1740_intr_handle: returning %6x\n", errstatus));
213 SCtmp->result = errstatus;
214 my_done = ecbptr->done;
215 memset(ecbptr,0,sizeof(struct ecb));
216 if ( my_done )
217 my_done(SCtmp);
218 break;
219 case G2INTST_HARDFAIL:
220 printk("aha1740 hardware failure!\n");
221 panic("aha1740.c");
222 case G2INTST_ASNEVENT:
223 printk("aha1740 asynchronous event: %02x %02x %02x %02x %02x\n",adapstat,
224 inb(MBOXIN0),inb(MBOXIN1),inb(MBOXIN2),inb(MBOXIN3));
225 outb(G2CNTRL_HRDY,G2CNTRL);
226 break;
227 case G2INTST_CMDGOOD:
228
229 break;
230 case G2INTST_CMDERROR:
231
232 break;
233 }
234 number_serviced++;
235 };
236 }
237
238 int aha1740_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
239 {
240 unchar direction;
241 unchar *cmd = (unchar *) SCpnt->cmnd;
242 unchar target = SCpnt->target;
243 void *buff = SCpnt->request_buffer;
244 int bufflen = SCpnt->request_bufflen;
245 int ecbno;
246 DEB(int i);
247
248
249 if(*cmd == REQUEST_SENSE)
250 {
251 if (bufflen != sizeof(SCpnt->sense_buffer))
252 {
253 printk("Wrong buffer length supplied for request sense (%d)\n",bufflen);
254 }
255 SCpnt->result = 0;
256 done(SCpnt);
257 return 0;
258 }
259
260 #ifdef DEBUG
261 if (*cmd == READ_10 || *cmd == WRITE_10)
262 i = xscsi2int(cmd+2);
263 else if (*cmd == READ_6 || *cmd == WRITE_6)
264 i = scsi2int(cmd+2);
265 else
266 i = -1;
267 printk("aha1740_queuecommand: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
268 printk("scsi cmd:");
269 for (i = 0; i < (COMMAND_SIZE(*cmd)); i++) printk("%02x ", cmd[i]);
270 printk("\n");
271 #endif
272
273
274
275 cli();
276 ecbno = aha1740_last_ecb_used + 1;
277 if (ecbno >= AHA1740_ECBS) ecbno = 0;
278
279 do{
280 if( ! ecb[ecbno].cmdw )
281 break;
282 ecbno++;
283 if (ecbno >= AHA1740_ECBS ) ecbno = 0;
284 } while (ecbno != aha1740_last_ecb_used);
285
286 if( ecb[ecbno].cmdw )
287 panic("Unable to find empty ecb for aha1740.\n");
288
289 ecb[ecbno].cmdw = AHA1740CMD_INIT;
290
291 aha1740_last_ecb_used = ecbno;
292 sti();
293
294 #ifdef DEBUG
295 printk("Sending command (%d %x)...",ecbno, done);
296 #endif
297
298 ecb[ecbno].cdblen = COMMAND_SIZE(*cmd);
299
300 direction = 0;
301 if (*cmd == READ_10 || *cmd == READ_6)
302 direction = 1;
303 else if (*cmd == WRITE_10 || *cmd == WRITE_6)
304 direction = 0;
305
306 memcpy(ecb[ecbno].cdb, cmd, ecb[ecbno].cdblen);
307
308 if (SCpnt->use_sg)
309 {
310 struct scatterlist * sgpnt;
311 struct aha1740_chain * cptr;
312 int i;
313 #ifdef DEBUG
314 unsigned char * ptr;
315 #endif
316 ecb[ecbno].sg = 1;
317 SCpnt->host_scribble = (unsigned char *) scsi_malloc(512);
318 sgpnt = (struct scatterlist *) SCpnt->request_buffer;
319 cptr = (struct aha1740_chain *) SCpnt->host_scribble;
320 if (cptr == NULL) panic("aha1740.c: unable to allocate DMA memory\n");
321 for(i=0; i<SCpnt->use_sg; i++)
322 {
323 cptr[i].dataptr = (long) sgpnt[i].address;
324 cptr[i].datalen = sgpnt[i].length;
325 }
326 ecb[ecbno].datalen = SCpnt->use_sg * sizeof(struct aha1740_chain);
327 ecb[ecbno].dataptr = (long) cptr;
328 #ifdef DEBUG
329 printk("cptr %x: ",cptr);
330 ptr = (unsigned char *) cptr;
331 for(i=0;i<24;i++) printk("%02x ", ptr[i]);
332 #endif
333 }
334 else
335 {
336 SCpnt->host_scribble = NULL;
337 ecb[ecbno].datalen = bufflen;
338 ecb[ecbno].dataptr = (long) buff;
339 }
340 ecb[ecbno].lun = SCpnt->lun;
341 ecb[ecbno].ses = 1;
342 ecb[ecbno].dir= direction;
343 ecb[ecbno].ars=1;
344 ecb[ecbno].senselen = 12;
345 ecb[ecbno].senseptr = (long) ecb[ecbno].sense;
346 ecb[ecbno].statusptr = (long) ecb[ecbno].status;
347 ecb[ecbno].done = done;
348 ecb[ecbno].SCpnt = SCpnt;
349 #ifdef DEBUG
350 {
351 int i;
352 printk("aha1740_command: sending.. ");
353 for (i = 0; i < sizeof(ecb[ecbno])-10; i++)
354 printk("%02x ", ((unchar *)&ecb[ecbno])[i]);
355 }
356 printk("\n");
357 #endif
358 if (done)
359 {
360
361
362
363
364
365
366
367
368 ulong adrs;
369
370 DEB(printk("aha1740[%d] critical section\n",ecbno));
371 cli();
372 if ( ! (inb(G2STAT) & G2STAT_MBXOUT) )
373 {
374 printk("aha1740[%d]_mbxout wait!\n",ecbno);
375 cli();
376 }
377 while ( ! (inb(G2STAT) & G2STAT_MBXOUT) );
378 adrs = (ulong) &(ecb[ecbno]);
379 outb((char) (adrs&0xff), MBOXOUT0);
380 outb((char) ((adrs>>8)&0xff), MBOXOUT1);
381 outb((char) ((adrs>>16)&0xff), MBOXOUT2);
382 outb((char) ((adrs>>24)&0xff), MBOXOUT3);
383 if ( inb(G2STAT) & G2STAT_BUSY )
384 {
385 printk("aha1740[%d]_attn wait!\n",ecbno);
386 cli();
387 }
388 while ( inb(G2STAT) & G2STAT_BUSY );
389 outb(ATTN_START | (target & 7), ATTN);
390 sti();
391 DEB(printk("aha1740[%d] request queued.\n",ecbno));
392 }
393 else
394 printk("aha1740_queuecommand: done can't be NULL\n");
395
396 return 0;
397 }
398
399 static volatile int internal_done_flag = 0;
400 static volatile int internal_done_errcode = 0;
401
402 static void internal_done(Scsi_Cmnd * SCpnt)
403 {
404 internal_done_errcode = SCpnt->result;
405 ++internal_done_flag;
406 }
407
408 int aha1740_command(Scsi_Cmnd * SCpnt)
409 {
410 aha1740_queuecommand(SCpnt, internal_done);
411
412 while (!internal_done_flag);
413 internal_done_flag = 0;
414 return internal_done_errcode;
415 }
416
417
418
419
420 void aha1740_getconfig(void)
421 {
422 static int intab[] = { 9,10,11,12,0,14,15,0 };
423
424 irq_level = intab [ inb(INTDEF)&0x7 ];
425 }
426
427 int aha1740_detect(int hostnum)
428 {
429 memset(&ecb, 0, sizeof(struct ecb));
430 DEB(printk("aha1740_detect: \n"));
431
432 for ( slot=MINEISA; slot <= MAXEISA; slot++ )
433 {
434 base = SLOTBASE(slot);
435
436
437
438
439
440 if(check_region(base, 0x5c)) continue;
441 if ( aha1740_test_port()) break;
442 }
443 if ( slot > MAXEISA )
444 return 0;
445
446 aha1740_getconfig();
447
448 if ( (inb(G2STAT) & (G2STAT_MBXOUT | G2STAT_BUSY) ) != G2STAT_MBXOUT )
449 {
450 outb(G2CNTRL_HRST,G2CNTRL);
451 outb(0,G2CNTRL);
452 }
453
454 printk("Configuring Adaptec at IO:%x, IRQ %d\n",base,
455 irq_level);
456
457 DEB(printk("aha1740_detect: enable interrupt channel %d\n", irq_level));
458
459 if (request_irq(irq_level,aha1740_intr_handle))
460 {
461 printk("Unable to allocate IRQ for adaptec controller.\n");
462 return 0;
463 }
464 snarf_region(base, 0x5c);
465 return 1;
466 }
467
468
469
470
471
472
473
474
475
476 int aha1740_abort(Scsi_Cmnd * SCpnt)
477 {
478 DEB(printk("aha1740_abort called\n"));
479 return SCSI_ABORT_SNOOZE;
480 }
481
482
483
484
485
486 int aha1740_reset(Scsi_Cmnd * SCpnt)
487 {
488 DEB(printk("aha1740_reset called\n"));
489 return SCSI_RESET_PUNT;
490 }
491
492 int aha1740_biosparam(int size, int dev, int* ip)
493 {
494 DEB(printk("aha1740_biosparam\n"));
495 ip[0] = 64;
496 ip[1] = 32;
497 ip[2] = size >> 11;
498
499 return 0;
500 }
501
502
503
504