This source file includes following definitions.
- append_SC
- remove_first_SC
- remove_SC
- make_acklow
- getphase
- aha152x_setup
- aha152x_porttest
- aha152x_detect
- aha152x_info
- aha152x_queue
- aha152x_command
- aha152x_abort
- aha152x_reset_ports
- aha152x_reset
- aha152x_biosparam
- aha152x_done
- aha152x_intr
- aha152x_panic
- disp_ports
- disp_enintr
- enter_driver
- leave_driver
- show_command
- show_queues
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 #include <linux/sched.h>
185 #include <asm/io.h>
186 #include "../block/blk.h"
187 #include "scsi.h"
188 #include "sd.h"
189 #include "hosts.h"
190 #include "constants.h"
191 #include <asm/system.h>
192 #include <linux/errno.h>
193 #include <linux/string.h>
194 #include <linux/wait.h>
195 #include <linux/ioport.h>
196
197 #include "aha152x.h"
198
199
200
201
202
203
204 #if !defined(AUTOCONF)
205 #if !defined(IRQ)
206 #error undefined IRQ; define AUTOCONF or IRQ
207 #endif
208 #if !defined(SCSI_ID)
209 #error undefined SCSI_ID; define AUTOCONF or SCSI_ID
210 #endif
211 #if !defined(RECONNECT)
212 #error undefined RECONNECT; define AUTOCONF or RECONNECT
213 #endif
214 #if !defined(PARITY)
215 #error undefined PARITY; define AUTOCONF or PARITY
216 #endif
217 #endif
218
219
220 #define DEBUG_TIMING
221
222 #if defined(DEBUG_AHA152X)
223
224 #undef SKIP_PORTS
225
226 #undef DEBUG_QUEUE
227 #undef DEBUG_RESET
228 #undef DEBUG_INTR
229 #undef DEBUG_SELECTION
230 #undef DEBUG_MSGO
231 #undef DEBUG_MSGI
232 #undef DEBUG_STATUS
233 #undef DEBUG_CMD
234 #undef DEBUG_DATAI
235 #undef DEBUG_DATAO
236 #undef DEBUG_ABORT
237 #undef DEBUG_DONE
238 #undef DEBUG_BIOSPARAM
239
240 #undef DEBUG_RACE
241 #undef DEBUG_PHASES
242 #undef DEBUG_QUEUES
243
244
245 #if 0
246 #define DEBUG_PHASES
247 #define DEBUG_DATAI
248 #endif
249
250 #endif
251
252 #define DEBUG_RESET
253 #define DEBUG_ABORT
254
255
256
257
258 #define P_BUSFREE 1
259 #define P_PARITY 2
260
261 static char *aha152x_id = AHA152X_REVID;
262
263 static int port_base = 0;
264 static int this_host = 0;
265 static int can_disconnect = 0;
266 static int can_doparity = 0;
267 static int commands = 0;
268
269
270 static int setup_called = 0;
271 static int setup_portbase = 0;
272 static int setup_irq = 0;
273 static int setup_scsiid = 0;
274 static int setup_reconnect = 0;
275 static int setup_doparity = 0;
276
277 static char *setup_str = (char *)NULL;
278
279 enum {
280 not_issued = 0x01,
281 in_selection = 0x02,
282 disconnected = 0x04,
283 aborted = 0x08,
284 sent_ident = 0x10,
285 in_other = 0x20,
286 };
287
288
289
290
291
292
293
294 static Scsi_Cmnd *issue_SC = NULL;
295 static Scsi_Cmnd *current_SC = NULL;
296 static Scsi_Cmnd *disconnected_SC = NULL;
297
298 static struct wait_queue *abortion_complete;
299 static int abort_result;
300
301 void aha152x_intr( int irqno );
302 void aha152x_done( int error );
303 void aha152x_setup( char *str, int *ints );
304
305 static void aha152x_reset_ports(void);
306 static void aha152x_panic(char *msg);
307
308 static void disp_ports(void);
309 static void show_command(Scsi_Cmnd *ptr);
310 static void show_queues(void);
311 static void disp_enintr(void);
312
313 #if defined(DEBUG_RACE)
314 static void enter_driver(const char *);
315 static void leave_driver(const char *);
316 #endif
317
318
319 static void *addresses[] =
320 {
321 (void *) 0xdc000,
322 (void *) 0xc8000,
323 (void *) 0xcc000,
324 (void *) 0xd0000,
325 (void *) 0xd4000,
326 (void *) 0xd8000,
327 (void *) 0xe0000,
328 (void *) 0xf0000,
329 (void *) 0xeb800,
330 };
331 #define ADDRESS_COUNT (sizeof( addresses ) / sizeof( unsigned ))
332
333
334 static unsigned short ports[] =
335 {
336 0x340,
337 0x140
338 };
339 #define PORT_COUNT (sizeof( ports ) / sizeof( unsigned short ))
340
341
342 static unsigned short ints[] = { 9, 10, 11, 12 };
343
344
345
346
347
348
349
350
351 static struct signature {
352 char *signature;
353 int sig_offset;
354 int sig_length;
355 } signatures[] =
356 {
357 { "Adaptec AHA-1520 BIOS", 0x102e, 21 },
358 { "Adaptec ASW-B626 BIOS", 0x1029, 21 },
359 { "Adaptec BIOS: ASW-B626", 0x0f, 22 },
360 { "Adaptec ASW-B626 S2", 0x2e6c, 19 },
361 { "Adaptec BIOS:AIC-6360", 0xc, 21 },
362 { "ScsiPro SP-360 BIOS", 0x2873, 19 },
363 { "GA-400 LOCAL BUS SCSI BIOS", 0x102e, 26 },
364 };
365 #define SIGNATURE_COUNT (sizeof( signatures ) / sizeof( struct signature ))
366
367
368 static void do_pause( unsigned amount )
369 {
370 unsigned long the_time = jiffies + amount;
371
372 while (jiffies < the_time)
373 ;
374 }
375
376
377
378
379 static inline void append_SC( Scsi_Cmnd **SC, Scsi_Cmnd *new_SC)
380 {
381 Scsi_Cmnd *end;
382
383 new_SC->host_scribble = (unsigned char *) NULL;
384 if(!*SC)
385 *SC=new_SC;
386 else
387 {
388 for( end=*SC;
389 end->host_scribble;
390 end = (Scsi_Cmnd *) end->host_scribble )
391 ;
392 end->host_scribble = (unsigned char *) new_SC;
393 }
394 }
395
396 static inline Scsi_Cmnd *remove_first_SC( Scsi_Cmnd **SC )
397 {
398 Scsi_Cmnd *ptr;
399
400 ptr=*SC;
401 if(ptr)
402 *SC= (Scsi_Cmnd *) (*SC)->host_scribble;
403 return ptr;
404 }
405
406 static inline Scsi_Cmnd *remove_SC( Scsi_Cmnd **SC, int target, int lun )
407 {
408 Scsi_Cmnd *ptr, *prev;
409
410 for( ptr=*SC, prev=NULL;
411 ptr && ((ptr->target!=target) || (ptr->lun!=lun));
412 prev = ptr, ptr = (Scsi_Cmnd *) ptr->host_scribble )
413 ;
414
415 if(ptr)
416 if(prev)
417 prev->host_scribble = ptr->host_scribble;
418 else
419 *SC= (Scsi_Cmnd *) ptr->host_scribble;
420 return ptr;
421 }
422
423
424
425
426 static void make_acklow(void)
427 {
428 SETPORT( SXFRCTL0, CH1|SPIOEN );
429 GETPORT(SCSIDAT);
430 SETPORT( SXFRCTL0, CH1 );
431
432 while( TESTHI( SCSISIG, ACKI ) )
433 ;
434 }
435
436
437
438
439
440
441
442
443
444
445
446 static int getphase(void)
447 {
448 int phase, sstat1;
449
450 while( 1 )
451 {
452 do
453 {
454 while( !( ( sstat1 = GETPORT( SSTAT1 ) ) & (BUSFREE|SCSIRSTI|REQINIT ) ) )
455 ;
456 if( sstat1 & BUSFREE )
457 return P_BUSFREE;
458 if( sstat1 & SCSIRSTI )
459 {
460
461 printk("aha152x: RESET IN\n");
462 SETPORT( SSTAT1, SCSIRSTI );
463 }
464 }
465 while( TESTHI( SCSISIG, ACKI ) || TESTLO( SSTAT1, REQINIT ) );
466
467 SETPORT( SSTAT1, CLRSCSIPERR );
468
469 phase = GETPORT( SCSISIG ) & P_MASK ;
470
471 if( TESTHI( SSTAT1, SCSIPERR ) )
472 {
473 if( (phase & (CDO|MSGO))==0 )
474 return P_PARITY;
475
476 make_acklow();
477 }
478 else
479 return phase;
480 }
481 }
482
483
484 void aha152x_setup( char *str, int *ints)
485 {
486 if(setup_called)
487 panic("aha152x: aha152x_setup called twice.\n");
488
489 setup_called=ints[0];
490 setup_str=str;
491
492 setup_portbase = ints[0] >= 1 ? ints[1] : 0x340;
493 setup_irq = ints[0] >= 2 ? ints[2] : 11;
494 setup_scsiid = ints[0] >= 3 ? ints[3] : 7;
495 setup_reconnect = ints[0] >= 4 ? ints[4] : 1;
496 setup_doparity = ints[0] >= 5 ? ints[5] : 1;
497 }
498
499
500
501
502 static int aha152x_porttest(int port_base)
503 {
504 int i;
505
506 if(check_region(port_base, TEST-SCSISEQ))
507 return 0;
508
509 SETPORT( DMACNTRL1, 0 );
510 for(i=0; i<16; i++)
511 SETPORT( STACK, i );
512
513 SETPORT( DMACNTRL1, 0 );
514 for(i=0; i<16 && GETPORT(STACK)==i; i++)
515 ;
516
517 return(i==16);
518 }
519
520 int aha152x_detect(Scsi_Host_Template * tpnt)
521 {
522 int i, j, ok;
523 aha152x_config conf;
524 int interrupt_level;
525
526 if(setup_called)
527 {
528 printk("aha152x: processing commandline: ");
529
530 if(setup_called>5)
531 {
532 printk("\naha152x: %s\n", setup_str );
533 printk("aha152x: usage: aha152x=<PORTBASE>[,<IRQ>[,<SCSI ID>[,<RECONNECT>[,<PARITY>]]]]\n");
534 panic("aha152x panics in line %d", __LINE__);
535 }
536
537 port_base = setup_portbase;
538 interrupt_level = setup_irq;
539 this_host = setup_scsiid;
540 can_disconnect = setup_reconnect;
541 can_doparity = setup_doparity;
542
543 for( i=0; i<PORT_COUNT && (port_base != ports[i]); i++)
544 ;
545
546 if(i==PORT_COUNT)
547 {
548 printk("unknown portbase 0x%03x\n", port_base);
549 panic("aha152x panics in line %d", __LINE__);
550 }
551
552 if(!aha152x_porttest(port_base))
553 {
554 printk("portbase 0x%03x fails probe\n", port_base);
555 panic("aha152x panics in line %d", __LINE__);
556 }
557
558 i=0;
559 while(ints[i] && (interrupt_level!=ints[i]))
560 i++;
561 if(!ints[i])
562 {
563 printk("illegal IRQ %d\n", interrupt_level);
564 panic("aha152x panics in line %d", __LINE__);
565 }
566
567 if( (this_host < 0) || (this_host > 7) )
568 {
569 printk("illegal SCSI ID %d\n", this_host);
570 panic("aha152x panics in line %d", __LINE__);
571 }
572
573 if( (can_disconnect < 0) || (can_disconnect > 1) )
574 {
575 printk("reconnect %d should be 0 or 1\n", can_disconnect);
576 panic("aha152x panics in line %d", __LINE__);
577 }
578
579 if( (can_doparity < 0) || (can_doparity > 1) )
580 {
581 printk("parity %d should be 0 or 1\n", can_doparity);
582 panic("aha152x panics in line %d", __LINE__);
583 }
584 printk("ok\n");
585 }
586 else
587 {
588 #if !defined(SKIP_BIOSTEST)
589 ok=0;
590 for( i=0; i < ADDRESS_COUNT && !ok; i++)
591 for( j=0; (j < SIGNATURE_COUNT) && !ok; j++)
592 ok=!memcmp((void *) addresses[i]+signatures[j].sig_offset,
593 (void *) signatures[j].signature,
594 (int) signatures[j].sig_length);
595
596 if(!ok)
597 return 0;
598
599 printk("aha152x: BIOS test: passed, ");
600 #else
601 printk("aha152x: ");
602 #endif
603
604 #if !defined(PORTBASE)
605 printk("porttest: ");
606 for( i=0; i<PORT_COUNT && !aha152x_porttest(ports[i]); i++)
607 ;
608
609 if(i==PORT_COUNT)
610 {
611 printk("failed\n");
612 return 0;
613 }
614 else
615 port_base=ports[i];
616 printk("ok, ");
617 #else
618 port_base=PORTBASE;
619 #endif
620
621 #if defined(AUTOCONF)
622
623 conf.cf_port = (GETPORT(PORTA)<<8) + GETPORT(PORTB);
624
625 interrupt_level = ints[conf.cf_irq];
626 this_host = conf.cf_id;
627 can_disconnect = conf.cf_tardisc;
628 can_doparity = !conf.cf_parity;
629
630 printk("auto configuration: ok, ");
631
632 #endif
633
634 #if defined(IRQ)
635 interrupt_level = IRQ;
636 #endif
637
638 #if defined(SCSI_ID)
639 this_host = SCSI_ID;
640 #endif
641
642 #if defined(RECONNECT)
643 can_disconnect=RECONNECT;
644 #endif
645
646 #if defined(PARITY)
647 can_doparity=PARITY;
648 #endif
649 }
650
651 printk("detection complete\n");
652
653 ok = request_irq(interrupt_level, aha152x_intr, SA_INTERRUPT, "aha152x");
654
655 if(ok<0)
656 {
657 if(ok == -EINVAL)
658 {
659 printk("aha152x: bad IRQ %d.\n", interrupt_level);
660 printk(" Contact author.\n");
661 }
662 else
663 if( ok == -EBUSY)
664 printk( "aha152x: IRQ %d already in use. Configure another.\n",
665 interrupt_level);
666 else
667 {
668 printk( "\naha152x: Unexpected error code on requesting IRQ %d.\n",
669 interrupt_level);
670 printk(" Contact author.\n");
671 }
672 panic("aha152x: driver needs an IRQ.\n");
673 }
674
675 SETPORT( SCSIID, this_host << 4 );
676 tpnt->this_id=this_host;
677
678 if(can_disconnect)
679 tpnt->can_queue=AHA152X_MAXQUEUE;
680
681
682 SETBITS(SCSISEQ, SCSIRSTO );
683 do_pause(30);
684 CLRBITS(SCSISEQ, SCSIRSTO );
685 do_pause(60);
686
687 aha152x_reset(NULL);
688
689 printk("aha152x: vital data: PORTBASE=0x%03x, IRQ=%d, SCSI ID=%d, reconnect=%s, parity=%s\n",
690 port_base,
691 interrupt_level,
692 this_host,
693 can_disconnect ? "enabled" : "disabled",
694 can_doparity ? "enabled" : "disabled");
695
696 snarf_region(port_base, TEST-SCSISEQ);
697
698
699 SETPORT(SIMODE0, 0);
700 SETPORT(SIMODE1, 0);
701
702 SETBITS( DMACNTRL0, INTEN);
703 return 1;
704 }
705
706
707
708
709 const char *aha152x_info(void)
710 {
711 return(aha152x_id);
712 }
713
714
715
716
717 int aha152x_queue( Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
718 {
719 #if defined(DEBUG_RACE)
720 enter_driver("queue");
721 #else
722 #if defined(DEBUG_QUEUE)
723 printk("aha152x: queue(), ");
724 #endif
725 #endif
726
727
728 #if defined(DEBUG_QUEUE)
729 printk( "SCpnt (target = %d lun = %d cmnd = 0x%02x pieces = %d size = %u), ",
730 SCpnt->target,
731 SCpnt->lun,
732 *(unsigned char *)SCpnt->cmnd,
733 SCpnt->use_sg,
734 SCpnt->request_bufflen );
735 disp_ports();
736 #endif
737
738 SCpnt->scsi_done = done;
739
740
741
742
743
744
745
746 SCpnt->SCp.phase = not_issued;
747 if (SCpnt->use_sg)
748 {
749 SCpnt->SCp.buffer = (struct scatterlist *)SCpnt->request_buffer;
750 SCpnt->SCp.ptr = SCpnt->SCp.buffer->address;
751 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
752 SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
753 }
754 else
755 {
756 SCpnt->SCp.ptr = (char *)SCpnt->request_buffer;
757 SCpnt->SCp.this_residual = SCpnt->request_bufflen;
758 SCpnt->SCp.buffer = NULL;
759 SCpnt->SCp.buffers_residual = 0;
760 }
761
762 SCpnt->SCp.Status = CHECK_CONDITION;
763 SCpnt->SCp.Message = 0;
764 SCpnt->SCp.have_data_in = 0;
765 SCpnt->SCp.sent_command = 0;
766
767
768 cli();
769 commands++;
770 if(commands==1)
771 SETPORT( PORTA, 1 );
772
773 #if defined(DEBUG_QUEUES)
774 printk("i+ (%d), ", commands );
775 #endif
776 append_SC( &issue_SC, SCpnt);
777
778
779 if(!current_SC)
780 {
781 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
782 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
783 }
784 sti();
785
786 #if defined(DEBUG_RACE)
787 leave_driver("queue");
788 #endif
789
790 return 0;
791 }
792
793
794
795
796 int aha152x_command( Scsi_Cmnd *SCpnt )
797 {
798 printk( "aha152x: interrupt driven driver; use aha152x_queue()\n" );
799 return -1;
800 }
801
802
803
804
805
806 int aha152x_abort( Scsi_Cmnd *SCpnt)
807 {
808 Scsi_Cmnd *ptr, *prev;
809
810 cli();
811
812 #if defined(DEBUG_ABORT)
813 printk("aha152x: abort(), SCpnt=0x%08x, ", (unsigned int) SCpnt );
814 #endif
815
816 #if defined(DEBUG_ABORT)
817 show_queues();
818 #endif
819
820
821 for( ptr=issue_SC, prev=NULL;
822 ptr && ptr!=SCpnt;
823 prev=ptr, ptr=(Scsi_Cmnd *) ptr->host_scribble)
824 ;
825
826 if(ptr)
827 {
828
829 if(prev)
830 prev->host_scribble = ptr->host_scribble;
831 else
832 issue_SC = (Scsi_Cmnd *) ptr->host_scribble;
833 sti();
834
835 ptr->host_scribble = NULL;
836 ptr->result = DID_ABORT << 16;
837 ptr->done(ptr);
838 return SCSI_ABORT_SUCCESS;
839 }
840
841 if (!current_SC && TESTLO(SSTAT1, BUSFREE))
842 printk("bus busy w/o current command, ");
843
844 if (current_SC==SCpnt)
845 if( TESTLO(SSTAT1, BUSFREE) ) {
846
847 sti();
848 return SCSI_ABORT_BUSY;
849 }
850 else
851 {
852
853 sti();
854 current_SC->result = DID_ERROR << 16;
855 current_SC->done(current_SC);
856 current_SC = (Scsi_Cmnd *) NULL;
857 return SCSI_ABORT_SUCCESS;
858 }
859
860
861 for( ptr=disconnected_SC, prev=NULL;
862 ptr && ptr!=SCpnt;
863 prev=ptr, ptr=(Scsi_Cmnd *) ptr->host_scribble)
864 ;
865
866 if(ptr)
867 if( TESTHI(SSTAT1, BUSFREE) )
868 {
869
870 if(prev)
871 prev->host_scribble = ptr->host_scribble;
872 else
873 disconnected_SC = (Scsi_Cmnd *) ptr->host_scribble;
874
875
876
877 current_SC = ptr;
878 ptr->SCp.phase = in_selection|aborted;
879 SETPORT( SCSIID, (this_host << OID_) | current_SC->target );
880
881
882 SETPORT( SIMODE0, ENSELDO | (disconnected_SC ? ENSELDI : 0) );
883 SETPORT( SIMODE1, ENSELTIMO );
884
885
886 SETBITS(SCSISEQ, ENSELO | ENAUTOATNO );
887
888 SETBITS( DMACNTRL0, INTEN );
889 abort_result=SCSI_ABORT_SUCCESS;
890 sti();
891
892
893 sleep_on( &abortion_complete );
894 return abort_result;
895 }
896 else {
897
898 sti();
899 return SCSI_ABORT_BUSY;
900 }
901
902
903 printk("command not found\n");
904 sti();
905 return SCSI_ABORT_NOT_RUNNING;
906 }
907
908
909
910
911 static void aha152x_reset_ports(void)
912 {
913
914 SETPORT(DMACNTRL0, RSTFIFO);
915
916 SETPORT(SCSISEQ, 0);
917
918 SETPORT(SXFRCTL1, 0);
919 SETPORT( SCSISIG, 0);
920 SETPORT(SCSIRATE, 0);
921
922
923 SETPORT(SSTAT0, 0x7f);
924 SETPORT(SSTAT1, 0xef);
925
926 SETPORT(SSTAT4, SYNCERR|FWERR|FRERR);
927
928 SETPORT(DMACNTRL0, 0);
929 SETPORT(DMACNTRL1, 0);
930
931 SETPORT(BRSTCNTRL, 0xf1);
932
933
934 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
935 SETPORT(SXFRCTL0, CH1);
936
937
938 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
939 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
940 }
941
942
943
944
945
946 int aha152x_reset(Scsi_Cmnd * __unused)
947 {
948 Scsi_Cmnd *ptr, *prev, *next;
949
950 aha152x_reset_ports();
951
952
953 if( TESTLO( SSTAT1, BUSFREE ) )
954 {
955 CLRBITS( DMACNTRL0, INTEN );
956
957 #if defined( DEBUG_RESET )
958 printk("aha152x: reset(), bus not free: SCSI RESET OUT\n");
959 #endif
960
961 #if defined( DEBUG_RESET )
962 show_queues();
963 #endif
964
965 if(current_SC && !current_SC->device->soft_reset)
966 {
967 current_SC->host_scribble = NULL;
968 current_SC->result = DID_RESET << 16;
969 current_SC->done(current_SC);
970 current_SC=NULL;
971 }
972
973 cli();
974 prev=NULL; ptr=disconnected_SC;
975 while(ptr)
976 {
977 if(!ptr->device->soft_reset)
978 {
979 if(prev)
980 prev->host_scribble = ptr->host_scribble;
981 else
982 disconnected_SC = (Scsi_Cmnd *) ptr->host_scribble;
983
984 next = (Scsi_Cmnd *) ptr->host_scribble;
985
986 ptr->host_scribble = NULL;
987 ptr->result = DID_RESET << 16;
988 ptr->done(ptr);
989
990 ptr = next;
991 }
992 else
993 {
994 prev=ptr;
995 ptr = (Scsi_Cmnd *) ptr->host_scribble;
996 }
997 }
998 sti();
999
1000 #if defined( DEBUG_RESET )
1001 printk("commands on targets w/ soft-resets:\n");
1002 show_queues();
1003 #endif
1004
1005
1006 SETPORT(SCSISEQ, SCSIRSTO);
1007 do_pause(30);
1008 SETPORT(SCSISEQ, 0);
1009 do_pause(60);
1010
1011 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1012 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1013
1014 SETPORT( DMACNTRL0, INTEN );
1015 }
1016
1017 return SCSI_RESET_SUCCESS;
1018 }
1019
1020
1021
1022
1023 int aha152x_biosparam(Scsi_Disk * disk, int dev, int *info_array )
1024 {
1025 int size = disk->capacity;
1026 #if defined(DEBUG_BIOSPARAM)
1027 printk("aha152x_biosparam: dev=%x, size=%d, ", dev, size);
1028 #endif
1029
1030
1031
1032 info_array[0]=64;
1033 info_array[1]=32;
1034 info_array[2]=size>>11;
1035
1036 #if defined(DEBUG_BIOSPARAM)
1037 printk("bios geometry: head=%d, sec=%d, cyl=%d\n",
1038 info_array[0], info_array[1], info_array[2]);
1039 printk("WARNING: check, if the bios geometry is correct.\n");
1040 #endif
1041
1042 return 0;
1043 }
1044
1045
1046
1047
1048 void aha152x_done( int error )
1049 {
1050 Scsi_Cmnd *done_SC;
1051
1052 #if defined(DEBUG_DONE)
1053 printk("\naha152x: done(), ");
1054 disp_ports();
1055 #endif
1056
1057 if (current_SC)
1058 {
1059 #if defined(DEBUG_DONE)
1060 printk("done(%x), ", error);
1061 #endif
1062
1063 cli();
1064
1065 done_SC = current_SC;
1066 current_SC = NULL;
1067
1068
1069 commands--;
1070 if(!commands)
1071 SETPORT( PORTA, 0 );
1072
1073 #if defined(DEBUG_QUEUES)
1074 printk("ok (%d), ", commands);
1075 #endif
1076 sti();
1077
1078 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1079 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1080
1081 #if defined(DEBUG_PHASES)
1082 printk("BUS FREE loop, ");
1083 #endif
1084 while( TESTLO( SSTAT1, BUSFREE ) )
1085 ;
1086 #if defined(DEBUG_PHASES)
1087 printk("BUS FREE\n");
1088 #endif
1089
1090 done_SC->result = error;
1091 if(done_SC->scsi_done)
1092 {
1093 #if defined(DEBUG_DONE)
1094 printk("calling scsi_done, ");
1095 #endif
1096 done_SC->scsi_done( done_SC );
1097 #if defined(DEBUG_DONE)
1098 printk("done returned, ");
1099 #endif
1100 }
1101 else
1102 panic( "aha152x: current_SC->scsi_done() == NULL" );
1103 }
1104 else
1105 aha152x_panic( "done() called outside of command" );
1106 }
1107
1108
1109
1110
1111 void aha152x_intr( int irqno )
1112 {
1113 int done=0, phase;
1114
1115 #if defined(DEBUG_RACE)
1116 enter_driver("intr");
1117 #else
1118 #if defined(DEBUG_INTR)
1119 printk("\naha152x: intr(), ");
1120 #endif
1121 #endif
1122
1123
1124
1125
1126
1127 CLRBITS( DMACNTRL0, INTEN);
1128 sti();
1129
1130
1131
1132
1133
1134 if( TESTHI( SSTAT0, SELDI ) &&
1135 disconnected_SC &&
1136 ( !current_SC || ( current_SC->SCp.phase & in_selection ) )
1137 )
1138 {
1139 int identify_msg, target, i;
1140
1141
1142
1143 if(current_SC)
1144 {
1145 #if defined(DEBUG_QUEUES)
1146 printk("i+, ");
1147 #endif
1148 cli();
1149 append_SC( &issue_SC, current_SC);
1150 current_SC=NULL;
1151 sti();
1152 }
1153
1154
1155 SETPORT( SCSISEQ, 0 );
1156 SETPORT( SSTAT0, CLRSELDI );
1157 SETPORT( SSTAT1, CLRBUSFREE );
1158
1159 #if defined(DEBUG_QUEUES) || defined(DEBUG_PHASES)
1160 printk("reselected, ");
1161 #endif
1162
1163 i = GETPORT(SELID) & ~(1 << this_host);
1164 target=0;
1165 if(i)
1166 for( ; (i & 1)==0; target++, i>>=1)
1167 ;
1168 else
1169 aha152x_panic("reconnecting target unknown");
1170
1171 #if defined(DEBUG_QUEUES)
1172 printk("SELID=%02x, target=%d, ", GETPORT(SELID), target );
1173 #endif
1174 SETPORT( SCSIID, (this_host << OID_) | target );
1175 SETPORT( SCSISEQ, ENRESELI );
1176
1177 if(TESTLO( SSTAT0, SELDI ))
1178 aha152x_panic("RESELI failed");
1179
1180 SETPORT( SCSISIG, P_MSGI );
1181
1182
1183 if((i=getphase())!=P_MSGI)
1184 {
1185 printk("target doesn't enter MSGI to identify (phase=%02x)\n", i);
1186 aha152x_panic("unknown lun");
1187 }
1188 SETPORT( SCSISEQ, 0 );
1189
1190 SETPORT( SXFRCTL0, CH1);
1191
1192 identify_msg = GETPORT(SCSIBUS);
1193
1194 if(!(identify_msg & IDENTIFY_BASE))
1195 {
1196 printk("target=%d, inbound message (%02x) != IDENTIFY\n",
1197 target, identify_msg);
1198 aha152x_panic("unknown lun");
1199 }
1200
1201 make_acklow();
1202 getphase();
1203
1204 #if defined(DEBUG_QUEUES)
1205 printk("identify=%02x, lun=%d, ", identify_msg, identify_msg & 0x3f );
1206 #endif
1207
1208 cli();
1209 #if defined(DEBUG_QUEUES)
1210 printk("d-, ");
1211 #endif
1212 current_SC = remove_SC( &disconnected_SC,
1213 target,
1214 identify_msg & 0x3f );
1215
1216 if(!current_SC)
1217 {
1218 printk("lun=%d, ", identify_msg & 0x3f );
1219 aha152x_panic("no disconnected command for that lun");
1220 }
1221
1222 current_SC->SCp.phase &= ~disconnected;
1223 sti();
1224
1225 SETPORT( SIMODE0, 0 );
1226 SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
1227 #if defined(DEBUG_RACE)
1228 leave_driver("(reselected) intr");
1229 #endif
1230 SETBITS( DMACNTRL0, INTEN);
1231 return;
1232 }
1233
1234
1235 if(!current_SC)
1236 {
1237
1238 if(TESTHI( SSTAT1, BUSFREE) && issue_SC)
1239 {
1240 cli();
1241 #if defined(DEBUG_QUEUES)
1242 printk("i-, ");
1243 #endif
1244 current_SC = remove_first_SC( &issue_SC );
1245 sti();
1246
1247 #if defined(DEBUG_INTR) || defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1248 printk("issuing command, ");
1249 #endif
1250 current_SC->SCp.phase = in_selection;
1251
1252 #if defined(DEBUG_INTR) || defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1253 printk("selecting %d, ", current_SC->target);
1254 #endif
1255 SETPORT( SCSIID, (this_host << OID_) | current_SC->target );
1256
1257
1258 SETPORT( SXFRCTL1, can_doparity ? (ENSPCHK|ENSTIMER) : ENSTIMER);
1259
1260
1261 SETPORT( SIMODE0, ENSELDO | (disconnected_SC ? ENSELDI : 0) );
1262 SETPORT( SIMODE1, ENSELTIMO );
1263
1264
1265 SETBITS(SCSISEQ, ENSELO | ENAUTOATNO );
1266
1267 #if defined(DEBUG_RACE)
1268 leave_driver("(selecting) intr");
1269 #endif
1270 SETBITS( DMACNTRL0, INTEN );
1271 return;
1272 }
1273
1274
1275 printk("aha152x: ignoring spurious interrupt, nothing to do\n");
1276 return;
1277 }
1278
1279
1280
1281 #if defined(DEBUG_INTR)
1282 disp_ports();
1283 #endif
1284
1285
1286 if(current_SC->SCp.phase & in_selection)
1287 {
1288 if( TESTLO( SSTAT1, SELTO ) )
1289
1290 if( TESTHI( SSTAT0, SELDO ) )
1291 {
1292
1293 SETPORT( SSTAT1, CLRBUSFREE);
1294
1295
1296 CLRBITS(SCSISEQ, ENSELO|ENAUTOATNO );
1297
1298
1299 CLRBITS(SIMODE0, ENSELDO);
1300 CLRBITS(SIMODE1, ENSELTIMO);
1301
1302 if( TESTLO(SSTAT0, SELDO) )
1303 {
1304 printk("aha152x: passing bus free condition\n");
1305
1306 #if defined(DEBUG_RACE)
1307 leave_driver("(passing bus free) intr");
1308 #endif
1309 SETBITS( DMACNTRL0, INTEN);
1310
1311 if(current_SC->SCp.phase & aborted)
1312 {
1313 abort_result=SCSI_ABORT_ERROR;
1314 wake_up( &abortion_complete );
1315 }
1316
1317 aha152x_done( DID_NO_CONNECT << 16 );
1318 return;
1319 }
1320 #if defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1321 printk("SELDO (SELID=%x), ", GETPORT(SELID));
1322 #endif
1323
1324
1325 SETPORT( SSTAT0, CLRSELDO );
1326
1327 #if defined(DEBUG_ABORT)
1328 if(current_SC->SCp.phase & aborted)
1329 printk("(ABORT) target selected, ");
1330 #endif
1331
1332 current_SC->SCp.phase &= ~in_selection;
1333 current_SC->SCp.phase |= in_other;
1334
1335 #if defined(DEBUG_RACE)
1336 leave_driver("(SELDO) intr");
1337 #endif
1338
1339 SETPORT( SCSISIG, P_MSGO );
1340
1341 SETPORT( SIMODE0, 0 );
1342 SETPORT( SIMODE1, ENREQINIT|ENBUSFREE );
1343 SETBITS( DMACNTRL0, INTEN);
1344 return;
1345 }
1346 else
1347 aha152x_panic("neither timeout nor selection\007");
1348 else
1349 {
1350 #if defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1351 printk("SELTO, ");
1352 #endif
1353
1354 CLRBITS(SCSISEQ, ENSELO|ENAUTOATNO );
1355
1356
1357 SETPORT( SSTAT1, CLRSELTIMO );
1358
1359 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1360 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1361 SETBITS( DMACNTRL0, INTEN );
1362 #if defined(DEBUG_RACE)
1363 leave_driver("(SELTO) intr");
1364 #endif
1365
1366 if(current_SC->SCp.phase & aborted)
1367 {
1368 #if defined(DEBUG_ABORT)
1369 printk("(ABORT) selection timeout, ");
1370 #endif
1371 abort_result=SCSI_ABORT_ERROR;
1372 wake_up( &abortion_complete );
1373 }
1374
1375 if( TESTLO( SSTAT0, SELINGO ) )
1376
1377 aha152x_done( DID_BUS_BUSY << 16 );
1378 else
1379
1380 aha152x_done( DID_NO_CONNECT << 16 );
1381 return;
1382 }
1383 }
1384
1385
1386 phase = getphase();
1387 if(!(phase & ~P_MASK))
1388 SETPORT(SCSISIG, phase);
1389 SETPORT(SSTAT1, CLRPHASECHG);
1390 current_SC->SCp.phase =
1391 (current_SC->SCp.phase & ~((P_MASK|1)<<16)) | (phase << 16 );
1392
1393
1394 switch( phase )
1395 {
1396 case P_MSGO:
1397 {
1398 unsigned char message;
1399
1400 #if defined(DEBUG_INTR) || defined(DEBUG_MSGO) || defined(DEBUG_PHASES)
1401 printk("MESSAGE OUT, ");
1402 #endif
1403
1404 if( current_SC->SCp.phase & aborted )
1405 {
1406 #if defined(DEBUG_MSGO) || defined(DEBUG_ABORT)
1407 printk("ABORT, ");
1408 #endif
1409 message=ABORT;
1410 }
1411 else
1412
1413
1414
1415 if( !(current_SC->SCp.phase & sent_ident))
1416 {
1417 message=IDENTIFY(can_disconnect,current_SC->lun);
1418 #if defined(DEBUG_MSGO)
1419 printk("IDENTIFY (reconnect=%s;lun=%d), ",
1420 can_disconnect ? "enabled" : "disabled", current_SC->lun);
1421 #endif
1422 }
1423 else
1424 {
1425 message=MESSAGE_REJECT;
1426 #if defined(DEBUG_MSGO)
1427 printk("REJECT, ");
1428 #endif
1429 }
1430
1431 CLRBITS( SXFRCTL0, ENDMA);
1432
1433 SETPORT( SIMODE0, 0 );
1434 SETPORT( SIMODE1, ENPHASEMIS|ENREQINIT|ENBUSFREE );
1435
1436
1437 while( TESTLO( DMASTAT, INTSTAT ) )
1438 ;
1439
1440 if( TESTHI( SSTAT1, PHASEMIS ) )
1441 aha152x_panic("unable to send message");
1442
1443
1444 SETPORT( SSTAT1, CLRATNO);
1445
1446 SETPORT( SCSIDAT, message );
1447
1448 make_acklow();
1449 getphase();
1450
1451 if(message==IDENTIFY(can_disconnect,current_SC->lun))
1452 current_SC->SCp.phase |= sent_ident;
1453
1454 if(message==ABORT)
1455 {
1456
1457 abort_result=SCSI_ABORT_SUCCESS;
1458 wake_up( &abortion_complete );
1459
1460 current_SC->SCp.phase = (current_SC->SCp.phase & ~(P_MASK<<16));
1461
1462
1463 SETBITS( DMACNTRL0, INTEN );
1464 #if defined(DEBUG_RACE)
1465 leave_driver("(ABORT) intr");
1466 #endif
1467 aha152x_done(DID_ABORT<<16);
1468 return;
1469 }
1470 }
1471 break;
1472
1473 case P_CMD:
1474 #if defined(DEBUG_INTR) || defined(DEBUG_CMD) || defined(DEBUG_PHASES)
1475 printk("COMMAND, ");
1476 #endif
1477 if( !(current_SC->SCp.sent_command) )
1478 {
1479 if(GETPORT(FIFOSTAT) || GETPORT(SSTAT2) & (SFULL|SFCNT))
1480 printk("aha152x: P_CMD: %d(%d) bytes left in FIFO, resetting\n",
1481 GETPORT(FIFOSTAT), GETPORT(SSTAT2) & (SFULL|SFCNT));
1482
1483
1484 SETPORT(DMACNTRL0, WRITE_READ|RSTFIFO);
1485 SETPORT(DMACNTRL0, ENDMA|WRITE_READ);
1486
1487
1488 SETPORT(SXFRCTL0, CH1|CLRSTCNT|CLRCH1 );
1489 SETPORT(SXFRCTL0, SCSIEN|DMAEN|CH1);
1490
1491
1492 SETPORT( SIMODE0, 0 );
1493 SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
1494
1495 #if defined(DEBUG_CMD)
1496 printk("waiting, ");
1497 #endif
1498
1499 while( TESTLO ( DMASTAT, DFIFOEMP|INTSTAT ) )
1500 ;
1501
1502 if( TESTHI( SSTAT1, PHASEMIS ) )
1503 aha152x_panic("target left COMMAND phase");
1504
1505 #if defined(DEBUG_CMD)
1506 printk("DFIFOEMP, outsw (%d words), ",
1507 COMMAND_SIZE(current_SC->cmnd[0])>>1);
1508 disp_ports();
1509 #endif
1510
1511 outsw( DATAPORT,
1512 ¤t_SC->cmnd,
1513 COMMAND_SIZE(current_SC->cmnd[0])>>1 );
1514
1515 #if defined(DEBUG_CMD)
1516 printk("FCNT=%d, STCNT=%d, ", GETPORT(FIFOSTAT), GETSTCNT() );
1517 disp_ports();
1518 #endif
1519
1520
1521
1522 while( TESTLO ( SSTAT2, SEMPTY ) )
1523 ;
1524
1525 CLRBITS(SXFRCTL0, SCSIEN|DMAEN);
1526
1527 while( TESTHI( SXFRCTL0, SCSIEN ) )
1528 ;
1529
1530 CLRBITS(DMACNTRL0, ENDMA);
1531
1532 #if defined(DEBUG_CMD) || defined(DEBUG_INTR)
1533 printk("sent %d/%d command bytes, ", GETSTCNT(),
1534 COMMAND_SIZE(current_SC->cmnd[0]));
1535 #endif
1536
1537 }
1538 else
1539 aha152x_panic("Nothing to sent while in COMMAND OUT");
1540 break;
1541
1542 case P_MSGI:
1543 #if defined(DEBUG_INTR) || defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
1544 printk("MESSAGE IN, ");
1545 #endif
1546 SETPORT( SXFRCTL0, CH1);
1547
1548 SETPORT( SIMODE0, 0);
1549 SETPORT( SIMODE1, ENBUSFREE);
1550
1551 while( phase == P_MSGI )
1552 {
1553 current_SC->SCp.Message = GETPORT( SCSIBUS );
1554 switch(current_SC->SCp.Message)
1555 {
1556 case DISCONNECT:
1557 #if defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
1558 printk("target disconnected, ");
1559 #endif
1560 current_SC->SCp.Message = 0;
1561 current_SC->SCp.phase |= disconnected;
1562 if(!can_disconnect)
1563 aha152x_panic("target was not allowed to disconnect");
1564 break;
1565
1566 case COMMAND_COMPLETE:
1567 #if defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
1568 printk("inbound message ( COMMAND COMPLETE ), ");
1569 #endif
1570 done++;
1571 break;
1572
1573 case MESSAGE_REJECT:
1574 #if defined(DEBUG_MSGI) || defined(DEBUG_TIMING)
1575 printk("inbound message ( MESSAGE REJECT ), ");
1576 #endif
1577 break;
1578
1579 case SAVE_POINTERS:
1580 #if defined(DEBUG_MSGI)
1581 printk("inbound message ( SAVE DATA POINTERS ), ");
1582 #endif
1583 break;
1584
1585 case EXTENDED_MESSAGE:
1586 {
1587 int i, code;
1588
1589 #if defined(DEBUG_MSGI)
1590 printk("inbound message ( EXTENDED MESSAGE ), ");
1591 #endif
1592 make_acklow();
1593 if(getphase()!=P_MSGI)
1594 break;
1595
1596 i=GETPORT(SCSIBUS);
1597
1598 #if defined(DEBUG_MSGI)
1599 printk("length (%d), ", i);
1600 #endif
1601
1602 #if defined(DEBUG_MSGI)
1603 printk("code ( ");
1604 #endif
1605
1606 make_acklow();
1607 if(getphase()!=P_MSGI)
1608 break;
1609
1610 code = GETPORT(SCSIBUS);
1611
1612 switch( code )
1613 {
1614 case 0x00:
1615 #if defined(DEBUG_MSGI)
1616 printk("MODIFY DATA POINTER ");
1617 #endif
1618 SETPORT(SCSISIG, P_MSGI|ATNO);
1619 break;
1620 case 0x01:
1621 #if defined(DEBUG_MSGI)
1622 printk("SYNCHRONOUS DATA TRANSFER REQUEST ");
1623 #endif
1624 SETPORT(SCSISIG, P_MSGI|ATNO);
1625 break;
1626 case 0x02:
1627 #if defined(DEBUG_MSGI)
1628 printk("EXTENDED IDENTIFY ");
1629 #endif
1630 break;
1631 case 0x03:
1632 #if defined(DEBUG_MSGI)
1633 printk("WIDE DATA TRANSFER REQUEST ");
1634 #endif
1635 SETPORT(SCSISIG, P_MSGI|ATNO);
1636 break;
1637 default:
1638 #if defined(DEBUG_MSGI)
1639 if( code & 0x80 )
1640 printk("reserved (%d) ", code );
1641 else
1642 printk("vendor specific (%d) ", code);
1643 #endif
1644 SETPORT(SCSISIG, P_MSGI|ATNO);
1645 break;
1646 }
1647 #if defined(DEBUG_MSGI)
1648 printk(" ), data ( ");
1649 #endif
1650 while( --i && (make_acklow(), getphase()==P_MSGI))
1651 {
1652 #if defined(DEBUG_MSGI)
1653 printk("%x ", GETPORT(SCSIBUS) );
1654 #else
1655 GETPORT(SCSIBUS);
1656 #endif
1657 }
1658 #if defined(DEBUG_MSGI)
1659 printk(" ), ");
1660 #endif
1661
1662
1663
1664
1665 SETPORT(SCSISIG, P_MSGI|ATNO);
1666 }
1667 break;
1668
1669 default:
1670 printk("unsupported inbound message %x, ", current_SC->SCp.Message);
1671 break;
1672
1673 }
1674
1675 make_acklow();
1676 phase=getphase();
1677 }
1678
1679
1680 if(phase==P_BUSFREE)
1681 SETPORT(SXFRCTL0, CH1|CLRCH1);
1682
1683 if(current_SC->SCp.phase & disconnected)
1684 {
1685 cli();
1686 #if defined(DEBUG_QUEUES)
1687 printk("d+, ");
1688 #endif
1689 append_SC( &disconnected_SC, current_SC);
1690 current_SC = NULL;
1691 sti();
1692
1693 SETBITS( SCSISEQ, ENRESELI );
1694
1695 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1696 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1697
1698 SETBITS( DMACNTRL0, INTEN );
1699 return;
1700 }
1701 break;
1702
1703 case P_STATUS:
1704 #if defined(DEBUG_STATUS) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
1705 printk("STATUS, ");
1706 #endif
1707 SETPORT( SXFRCTL0, CH1);
1708
1709 SETPORT( SIMODE0, 0 );
1710 SETPORT( SIMODE1, ENREQINIT|ENBUSFREE );
1711
1712 if( TESTHI( SSTAT1, PHASEMIS ) )
1713 printk("aha152x: passing STATUS phase");
1714
1715 current_SC->SCp.Status = GETPORT( SCSIBUS );
1716 make_acklow();
1717 getphase();
1718
1719 #if defined(DEBUG_STATUS)
1720 printk("inbound status ");
1721 print_status( current_SC->SCp.Status );
1722 printk(", ");
1723 #endif
1724 break;
1725
1726 case P_DATAI:
1727 {
1728 int fifodata, data_count, done;
1729
1730 #if defined(DEBUG_DATAI) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
1731 printk("DATA IN, ");
1732 #endif
1733
1734 if(GETPORT(FIFOSTAT) || GETPORT(SSTAT2) & (SFULL|SFCNT))
1735 printk("aha152x: P_DATAI: %d(%d) bytes left in FIFO, resetting\n",
1736 GETPORT(FIFOSTAT), GETPORT(SSTAT2) & (SFULL|SFCNT));
1737
1738
1739 SETPORT(DMACNTRL0, RSTFIFO);
1740 SETPORT(DMACNTRL0, RSTFIFO|ENDMA);
1741
1742 SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN );
1743
1744 SETPORT( SIMODE0, 0 );
1745 SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
1746
1747
1748 done=0;
1749
1750
1751 while ( !done )
1752 {
1753 #if defined(DEBUG_DATAI)
1754 printk("expecting data, ");
1755 #endif
1756
1757 while( TESTLO ( DMASTAT, DFIFOFULL|INTSTAT ) )
1758 ;
1759
1760 if( TESTHI( DMASTAT, DFIFOFULL ) )
1761 fifodata=GETPORT(FIFOSTAT);
1762 else
1763 {
1764
1765 while( TESTLO( SSTAT2, SEMPTY ) )
1766 ;
1767
1768
1769 fifodata=GETPORT(FIFOSTAT);
1770 #if defined(DEBUG_DATAI)
1771 printk("last transfer, ");
1772 #endif
1773 done=1;
1774 }
1775
1776 #if defined(DEBUG_DATAI)
1777 printk("fifodata=%d, ", fifodata);
1778 #endif
1779
1780 while( fifodata && current_SC->SCp.this_residual )
1781 {
1782 data_count=fifodata;
1783
1784
1785 if (data_count > current_SC->SCp.this_residual)
1786 data_count = current_SC->SCp.this_residual;
1787
1788 fifodata -= data_count;
1789
1790 #if defined(DEBUG_DATAI)
1791 printk("data_count=%d, ", data_count);
1792 #endif
1793
1794 if(data_count == 1)
1795 {
1796
1797 SETBITS(DMACNTRL0, _8BIT );
1798 *current_SC->SCp.ptr++ = GETPORT( DATAPORT );
1799 current_SC->SCp.this_residual--;
1800 }
1801 else
1802 {
1803 CLRBITS(DMACNTRL0, _8BIT );
1804 data_count >>= 1;
1805 insw( DATAPORT, current_SC->SCp.ptr, data_count );
1806 #if defined(DEBUG_DATAI)
1807
1808 if(done)
1809 {
1810 int i;
1811 unsigned char *data;
1812
1813 printk("data on last transfer (%d bytes: ",
1814 2*data_count);
1815 data = (unsigned char *) current_SC->SCp.ptr;
1816 for( i=0; i<2*data_count; i++)
1817 printk("%2x ", *data++);
1818 printk("), ");
1819 }
1820 #endif
1821 current_SC->SCp.ptr += 2 * data_count;
1822 current_SC->SCp.this_residual -= 2 * data_count;
1823 }
1824
1825
1826 if (!current_SC->SCp.this_residual &&
1827 current_SC->SCp.buffers_residual)
1828 {
1829
1830 current_SC->SCp.buffers_residual--;
1831 current_SC->SCp.buffer++;
1832 current_SC->SCp.ptr =
1833 current_SC->SCp.buffer->address;
1834 current_SC->SCp.this_residual =
1835 current_SC->SCp.buffer->length;
1836 }
1837 }
1838
1839
1840
1841
1842 if(fifodata>0)
1843 {
1844 printk("aha152x: more data than expected (%d bytes)\n",
1845 GETPORT(FIFOSTAT));
1846 SETBITS(DMACNTRL0, _8BIT );
1847 printk("aha152x: data ( ");
1848 while(fifodata--)
1849 printk("%2x ", GETPORT( DATAPORT ));
1850 printk(")\n");
1851 }
1852
1853 #if defined(DEBUG_DATAI)
1854 if(!fifodata)
1855 printk("fifo empty, ");
1856 else
1857 printk("something left in fifo, ");
1858 #endif
1859 }
1860
1861 #if defined(DEBUG_DATAI)
1862 if(current_SC->SCp.buffers_residual || current_SC->SCp.this_residual)
1863 printk("left buffers (buffers=%d, bytes=%d), ",
1864 current_SC->SCp.buffers_residual,
1865 current_SC->SCp.this_residual);
1866 #endif
1867
1868 CLRBITS(SXFRCTL0, SCSIEN|DMAEN);
1869 while( TESTHI( SXFRCTL0, SCSIEN ) )
1870 ;
1871 CLRBITS(DMACNTRL0, ENDMA );
1872
1873 #if defined(DEBUG_DATAI) || defined(DEBUG_INTR)
1874 printk("got %d bytes, ", GETSTCNT());
1875 #endif
1876
1877 current_SC->SCp.have_data_in++;
1878 }
1879 break;
1880
1881 case P_DATAO:
1882 {
1883 int data_count;
1884
1885 #if defined(DEBUG_DATAO) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
1886 printk("DATA OUT, ");
1887 #endif
1888 #if defined(DEBUG_DATAO)
1889 printk("got data to send (bytes=%d, buffers=%d), ",
1890 current_SC->SCp.this_residual,
1891 current_SC->SCp.buffers_residual );
1892 #endif
1893
1894 if(GETPORT(FIFOSTAT) || GETPORT(SSTAT2) & (SFULL|SFCNT) )
1895 {
1896 printk("%d(%d) left in FIFO, ", GETPORT(FIFOSTAT), GETPORT(SSTAT2) & (SFULL|SFCNT) );
1897 aha152x_panic("FIFO should be empty");
1898 }
1899
1900 SETPORT(DMACNTRL0, WRITE_READ|RSTFIFO);
1901 SETPORT(DMACNTRL0, ENDMA|WRITE_READ);
1902
1903 SETPORT(SXFRCTL0, CH1|CLRSTCNT|CLRCH1 );
1904 SETPORT(SXFRCTL0, SCSIEN|DMAEN|CH1);
1905
1906 SETPORT( SIMODE0, 0 );
1907 SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
1908
1909
1910
1911 while( TESTLO( SSTAT1, PHASEMIS ) &&
1912 (current_SC->SCp.this_residual ||
1913 current_SC->SCp.buffers_residual) )
1914 {
1915 #if defined(DEBUG_DATAO)
1916 printk("sending data (left: bytes=%d, buffers=%d), waiting, ",
1917 current_SC->SCp.this_residual,
1918 current_SC->SCp.buffers_residual);
1919 #endif
1920
1921 data_count = current_SC->SCp.this_residual > 128 ?
1922 128 : current_SC->SCp.this_residual ;
1923
1924 #if defined(DEBUG_DATAO)
1925 printk("data_count=%d, ", data_count);
1926 #endif
1927
1928 if(data_count == 1)
1929 {
1930
1931 SETBITS(DMACNTRL0, _8BIT );
1932 SETPORT(DATAPORT, *current_SC->SCp.ptr++);
1933 current_SC->SCp.this_residual--;
1934 }
1935 else
1936 {
1937 CLRBITS(DMACNTRL0, _8BIT );
1938 data_count >>= 1;
1939 outsw( DATAPORT, current_SC->SCp.ptr, data_count );
1940 current_SC->SCp.ptr += 2 * data_count;
1941 current_SC->SCp.this_residual -= 2 * data_count;
1942 }
1943
1944
1945 while( TESTLO ( DMASTAT, DFIFOEMP|INTSTAT ) )
1946 ;
1947
1948 #if defined(DEBUG_DATAO)
1949 printk("fifo (%d bytes), transfered (%d bytes), ",
1950 GETPORT(FIFOSTAT), GETSTCNT() );
1951 #endif
1952
1953
1954 if ( TESTLO( SSTAT1, PHASEMIS ) &&
1955 !current_SC->SCp.this_residual &&
1956 current_SC->SCp.buffers_residual)
1957 {
1958
1959 current_SC->SCp.buffers_residual--;
1960 current_SC->SCp.buffer++;
1961 current_SC->SCp.ptr =
1962 current_SC->SCp.buffer->address;
1963 current_SC->SCp.this_residual =
1964 current_SC->SCp.buffer->length;
1965 }
1966 }
1967
1968 if ( current_SC->SCp.this_residual ||
1969 current_SC->SCp.buffers_residual )
1970 {
1971
1972
1973
1974
1975 data_count = GETPORT(SSTAT2) & (SFULL|SFCNT);
1976
1977 data_count += GETPORT(FIFOSTAT) ;
1978 current_SC->SCp.ptr -= data_count;
1979 current_SC->SCp.this_residual += data_count;
1980 #if defined(DEBUG_DATAO)
1981 printk("left data (bytes=%d, buffers=%d), fifos (bytes=%d), transfer incomplete, resetting fifo, ",
1982 current_SC->SCp.this_residual,
1983 current_SC->SCp.buffers_residual,
1984 data_count );
1985 #endif
1986 SETPORT(DMACNTRL0, WRITE_READ|RSTFIFO);
1987 CLRBITS(SXFRCTL0, SCSIEN|DMAEN );
1988 CLRBITS(DMACNTRL0, ENDMA);
1989 }
1990 else
1991 {
1992 #if defined(DEBUG_DATAO)
1993 printk("waiting for SCSI fifo to get empty, ");
1994 #endif
1995
1996 while( TESTLO( SSTAT2, SEMPTY ) )
1997 ;
1998 #if defined(DEBUG_DATAO)
1999 printk("ok, ");
2000 #endif
2001
2002 #if defined(DEBUG_DATAO)
2003 printk("left data (bytes=%d, buffers=%d) ",
2004 current_SC->SCp.this_residual,
2005 current_SC->SCp.buffers_residual);
2006 #endif
2007 CLRBITS(SXFRCTL0, SCSIEN|DMAEN);
2008
2009
2010 while( TESTHI( SXFRCTL0, SCSIEN ) )
2011 ;
2012
2013 CLRBITS(DMACNTRL0, ENDMA);
2014 }
2015
2016 #if defined(DEBUG_DATAO) || defined(DEBUG_INTR)
2017 printk("sent %d data bytes, ", GETSTCNT() );
2018 #endif
2019 }
2020 break;
2021
2022 case P_BUSFREE:
2023 #if defined(DEBUG_RACE)
2024 leave_driver("(BUSFREE) intr");
2025 #endif
2026 #if defined(DEBUG_PHASES)
2027 printk("unexpected BUS FREE, ");
2028 #endif
2029 current_SC->SCp.phase = (current_SC->SCp.phase & ~(P_MASK<<16));
2030
2031 aha152x_done( DID_ERROR << 16 );
2032 return;
2033 break;
2034
2035 case P_PARITY:
2036 #if defined(DEBUG_RACE)
2037 leave_driver("(DID_PARITY) intr");
2038 #endif
2039 printk("PARITY error in DATA phase, ");
2040
2041 current_SC->SCp.phase = (current_SC->SCp.phase & ~(P_MASK<<16));
2042
2043 SETBITS( DMACNTRL0, INTEN );
2044 aha152x_done( DID_PARITY << 16 );
2045 return;
2046 break;
2047
2048 default:
2049 printk("aha152x: unexpected phase\n");
2050 break;
2051 }
2052
2053 if(done)
2054 {
2055 #if defined(DEBUG_INTR)
2056 printk("command done.\n");
2057 #endif
2058 #if defined(DEBUG_RACE)
2059 leave_driver("(done) intr");
2060 #endif
2061
2062 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
2063 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
2064 SETPORT(SCSISEQ, disconnected_SC ? ENRESELI : 0 );
2065
2066 SETBITS( DMACNTRL0, INTEN );
2067
2068 aha152x_done( (current_SC->SCp.Status & 0xff)
2069 | ( (current_SC->SCp.Message & 0xff) << 8)
2070 | ( DID_OK << 16) );
2071
2072 #if defined(DEBUG_RACE)
2073 printk("done returned (DID_OK: Status=%x; Message=%x).\n",
2074 current_SC->SCp.Status, current_SC->SCp.Message);
2075 #endif
2076 return;
2077 }
2078
2079 if(current_SC)
2080 current_SC->SCp.phase |= 1<<16 ;
2081
2082 SETPORT( SIMODE0, 0 );
2083 SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
2084 #if defined(DEBUG_INTR)
2085 disp_enintr();
2086 #endif
2087 #if defined(DEBUG_RACE)
2088 leave_driver("(PHASEEND) intr");
2089 #endif
2090
2091 SETBITS( DMACNTRL0, INTEN);
2092 return;
2093 }
2094
2095
2096
2097
2098 static void aha152x_panic(char *msg)
2099 {
2100 printk("\naha152x_panic: %s\n", msg);
2101 show_queues();
2102 panic("aha152x panic");
2103 }
2104
2105
2106
2107
2108 static void disp_ports(void)
2109 {
2110 #if !defined(SKIP_PORTS)
2111 int s;
2112
2113 printk("\n%s: ", current_SC ? "on bus" : "waiting");
2114
2115 s=GETPORT(SCSISEQ);
2116 printk("SCSISEQ ( ");
2117 if( s & TEMODEO ) printk("TARGET MODE ");
2118 if( s & ENSELO ) printk("SELO ");
2119 if( s & ENSELI ) printk("SELI ");
2120 if( s & ENRESELI ) printk("RESELI ");
2121 if( s & ENAUTOATNO ) printk("AUTOATNO ");
2122 if( s & ENAUTOATNI ) printk("AUTOATNI ");
2123 if( s & ENAUTOATNP ) printk("AUTOATNP ");
2124 if( s & SCSIRSTO ) printk("SCSIRSTO ");
2125 printk(");");
2126
2127 printk(" SCSISIG ( ");
2128 s=GETPORT(SCSISIG);
2129 switch(s & P_MASK)
2130 {
2131 case P_DATAO:
2132 printk("DATA OUT");
2133 break;
2134 case P_DATAI:
2135 printk("DATA IN");
2136 break;
2137 case P_CMD:
2138 printk("COMMAND");
2139 break;
2140 case P_STATUS:
2141 printk("STATUS");
2142 break;
2143 case P_MSGO:
2144 printk("MESSAGE OUT");
2145 break;
2146 case P_MSGI:
2147 printk("MESSAGE IN");
2148 break;
2149 default:
2150 printk("*illegal*");
2151 break;
2152 }
2153
2154 printk(" ); ");
2155
2156 printk("INTSTAT ( %s ); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
2157
2158 printk("SSTAT ( ");
2159 s=GETPORT(SSTAT0);
2160 if( s & TARGET ) printk("TARGET ");
2161 if( s & SELDO ) printk("SELDO ");
2162 if( s & SELDI ) printk("SELDI ");
2163 if( s & SELINGO ) printk("SELINGO ");
2164 if( s & SWRAP ) printk("SWRAP ");
2165 if( s & SDONE ) printk("SDONE ");
2166 if( s & SPIORDY ) printk("SPIORDY ");
2167 if( s & DMADONE ) printk("DMADONE ");
2168
2169 s=GETPORT(SSTAT1);
2170 if( s & SELTO ) printk("SELTO ");
2171 if( s & ATNTARG ) printk("ATNTARG ");
2172 if( s & SCSIRSTI ) printk("SCSIRSTI ");
2173 if( s & PHASEMIS ) printk("PHASEMIS ");
2174 if( s & BUSFREE ) printk("BUSFREE ");
2175 if( s & SCSIPERR ) printk("SCSIPERR ");
2176 if( s & PHASECHG ) printk("PHASECHG ");
2177 if( s & REQINIT ) printk("REQINIT ");
2178 printk("); ");
2179
2180
2181 printk("SSTAT ( ");
2182
2183 s=GETPORT(SSTAT0) & GETPORT(SIMODE0);
2184
2185 if( s & TARGET ) printk("TARGET ");
2186 if( s & SELDO ) printk("SELDO ");
2187 if( s & SELDI ) printk("SELDI ");
2188 if( s & SELINGO ) printk("SELINGO ");
2189 if( s & SWRAP ) printk("SWRAP ");
2190 if( s & SDONE ) printk("SDONE ");
2191 if( s & SPIORDY ) printk("SPIORDY ");
2192 if( s & DMADONE ) printk("DMADONE ");
2193
2194 s=GETPORT(SSTAT1) & GETPORT(SIMODE1);
2195
2196 if( s & SELTO ) printk("SELTO ");
2197 if( s & ATNTARG ) printk("ATNTARG ");
2198 if( s & SCSIRSTI ) printk("SCSIRSTI ");
2199 if( s & PHASEMIS ) printk("PHASEMIS ");
2200 if( s & BUSFREE ) printk("BUSFREE ");
2201 if( s & SCSIPERR ) printk("SCSIPERR ");
2202 if( s & PHASECHG ) printk("PHASECHG ");
2203 if( s & REQINIT ) printk("REQINIT ");
2204 printk("); ");
2205
2206 printk("SXFRCTL0 ( ");
2207
2208 s=GETPORT(SXFRCTL0);
2209 if( s & SCSIEN ) printk("SCSIEN ");
2210 if( s & DMAEN ) printk("DMAEN ");
2211 if( s & CH1 ) printk("CH1 ");
2212 if( s & CLRSTCNT ) printk("CLRSTCNT ");
2213 if( s & SPIOEN ) printk("SPIOEN ");
2214 if( s & CLRCH1 ) printk("CLRCH1 ");
2215 printk("); ");
2216
2217 printk("SIGNAL ( ");
2218
2219 s=GETPORT(SCSISIG);
2220 if( s & ATNI ) printk("ATNI ");
2221 if( s & SELI ) printk("SELI ");
2222 if( s & BSYI ) printk("BSYI ");
2223 if( s & REQI ) printk("REQI ");
2224 if( s & ACKI ) printk("ACKI ");
2225 printk("); ");
2226
2227 printk("SELID ( %02x ), ", GETPORT(SELID) );
2228
2229 printk("SSTAT2 ( ");
2230
2231 s=GETPORT(SSTAT2);
2232 if( s & SOFFSET) printk("SOFFSET ");
2233 if( s & SEMPTY) printk("SEMPTY ");
2234 if( s & SFULL) printk("SFULL ");
2235 printk("); SFCNT ( %d ); ", s & (SFULL|SFCNT) );
2236
2237 #if 0
2238 printk("SSTAT4 ( ");
2239 s=GETPORT(SSTAT4);
2240 if( s & SYNCERR) printk("SYNCERR ");
2241 if( s & FWERR) printk("FWERR ");
2242 if( s & FRERR) printk("FRERR ");
2243 printk("); ");
2244 #endif
2245
2246 printk("FCNT ( %d ); ", GETPORT(FIFOSTAT) );
2247
2248 printk("DMACNTRL0 ( ");
2249 s=GETPORT(DMACNTRL0);
2250 printk( "%s ", s & _8BIT ? "8BIT" : "16BIT" );
2251 printk( "%s ", s & DMA ? "DMA" : "PIO" );
2252 printk( "%s ", s & WRITE_READ ? "WRITE" : "READ" );
2253 if( s & ENDMA ) printk("ENDMA ");
2254 if( s & INTEN ) printk("INTEN ");
2255 if( s & RSTFIFO ) printk("RSTFIFO ");
2256 if( s & SWINT ) printk("SWINT ");
2257 printk("); ");
2258
2259
2260 #if 0
2261 printk("DMACNTRL1 ( ");
2262
2263 s=GETPORT(DMACNTRL1);
2264 if( s & PWRDWN ) printk("PWRDN ");
2265 printk("); ");
2266
2267
2268 printk("STK ( %d ); ", s & 0xf);
2269
2270 printk("DMASTAT (");
2271 s=GETPORT(DMASTAT);
2272 if( s & ATDONE ) printk("ATDONE ");
2273 if( s & WORDRDY ) printk("WORDRDY ");
2274 if( s & DFIFOFULL ) printk("DFIFOFULL ");
2275 if( s & DFIFOEMP ) printk("DFIFOEMP ");
2276 printk(")");
2277
2278 #endif
2279
2280 printk("\n");
2281 #endif
2282 }
2283
2284
2285
2286
2287 static void disp_enintr(void)
2288 {
2289 int s;
2290
2291 printk("enabled interrupts ( ");
2292
2293 s=GETPORT(SIMODE0);
2294 if( s & ENSELDO ) printk("ENSELDO ");
2295 if( s & ENSELDI ) printk("ENSELDI ");
2296 if( s & ENSELINGO ) printk("ENSELINGO ");
2297 if( s & ENSWRAP ) printk("ENSWRAP ");
2298 if( s & ENSDONE ) printk("ENSDONE ");
2299 if( s & ENSPIORDY ) printk("ENSPIORDY ");
2300 if( s & ENDMADONE ) printk("ENDMADONE ");
2301
2302 s=GETPORT(SIMODE1);
2303 if( s & ENSELTIMO ) printk("ENSELTIMO ");
2304 if( s & ENATNTARG ) printk("ENATNTARG ");
2305 if( s & ENPHASEMIS ) printk("ENPHASEMIS ");
2306 if( s & ENBUSFREE ) printk("ENBUSFREE ");
2307 if( s & ENSCSIPERR ) printk("ENSCSIPERR ");
2308 if( s & ENPHASECHG ) printk("ENPHASECHG ");
2309 if( s & ENREQINIT ) printk("ENREQINIT ");
2310 printk(")\n");
2311 }
2312
2313 #if defined(DEBUG_RACE)
2314
2315 static const char *should_leave;
2316 static int in_driver=0;
2317
2318
2319
2320
2321 static void enter_driver(const char *func)
2322 {
2323 cli();
2324 printk("aha152x: entering %s() (%x)\n", func, jiffies);
2325 if(in_driver)
2326 {
2327 printk("%s should leave first.\n", should_leave);
2328 panic("aha152x: already in driver\n");
2329 }
2330
2331 in_driver++;
2332 should_leave=func;
2333 sti();
2334 }
2335
2336 static void leave_driver(const char *func)
2337 {
2338 cli();
2339 printk("\naha152x: leaving %s() (%x)\n", func, jiffies);
2340 if(!in_driver)
2341 {
2342 printk("aha152x: %s already left.\n", should_leave);
2343 panic("aha152x: %s already left driver.\n");
2344 }
2345
2346 in_driver--;
2347 should_leave=func;
2348 sti();
2349 }
2350 #endif
2351
2352
2353
2354
2355 static void show_command(Scsi_Cmnd *ptr)
2356 {
2357 int i;
2358
2359 printk("0x%08x: target=%d; lun=%d; cmnd=( ",
2360 (unsigned int) ptr, ptr->target, ptr->lun);
2361
2362 for(i=0; i<COMMAND_SIZE(ptr->cmnd[0]); i++)
2363 printk("%02x ", ptr->cmnd[i]);
2364
2365 printk("); residual=%d; buffers=%d; phase |",
2366 ptr->SCp.this_residual, ptr->SCp.buffers_residual);
2367
2368 if( ptr->SCp.phase & not_issued ) printk("not issued|");
2369 if( ptr->SCp.phase & in_selection ) printk("in selection|");
2370 if( ptr->SCp.phase & disconnected ) printk("disconnected|");
2371 if( ptr->SCp.phase & aborted ) printk("aborted|");
2372 if( ptr->SCp.phase & sent_ident ) printk("send_ident|");
2373 if( ptr->SCp.phase & in_other )
2374 {
2375 printk("; in other(");
2376 switch( (ptr->SCp.phase >> 16) & P_MASK )
2377 {
2378 case P_DATAO:
2379 printk("DATA OUT");
2380 break;
2381 case P_DATAI:
2382 printk("DATA IN");
2383 break;
2384 case P_CMD:
2385 printk("COMMAND");
2386 break;
2387 case P_STATUS:
2388 printk("STATUS");
2389 break;
2390 case P_MSGO:
2391 printk("MESSAGE OUT");
2392 break;
2393 case P_MSGI:
2394 printk("MESSAGE IN");
2395 break;
2396 default:
2397 printk("*illegal*");
2398 break;
2399 }
2400 printk(")");
2401 if(ptr->SCp.phase & (1<<16))
2402 printk("; phaseend");
2403 }
2404 printk("; next=0x%08x\n", (unsigned int) ptr->host_scribble);
2405 }
2406
2407
2408
2409
2410 static void show_queues(void)
2411 {
2412 Scsi_Cmnd *ptr;
2413
2414 cli();
2415 printk("QUEUE STATUS:\nissue_SC:\n");
2416 for(ptr=issue_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble )
2417 show_command(ptr);
2418
2419 printk("current_SC:\n");
2420 if(current_SC)
2421 show_command(current_SC);
2422 else
2423 printk("none\n");
2424
2425 printk("disconnected_SC:\n");
2426 for(ptr=disconnected_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble )
2427 show_command(ptr);
2428
2429 disp_ports();
2430 disp_enintr();
2431 sti();
2432 }