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