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