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