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