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