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