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