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