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