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