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