This source file includes following definitions.
- st0x_setup
- tmc8xx_setup
- borken_init
- borken_wait
- seagate_st0x_detect
- seagate_st0x_info
- seagate_reconnect_intr
- seagate_st0x_queue_command
- seagate_st0x_command
- internal_command
- seagate_st0x_abort
- seagate_st0x_reset
- seagate_st0x_biosparam
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 #include <asm/io.h>
51 #include <asm/system.h>
52 #include <linux/signal.h>
53 #include <linux/sched.h>
54 #include <linux/string.h>
55 #include <linux/config.h>
56
57 #include "../block/blk.h"
58 #include "scsi.h"
59 #include "hosts.h"
60 #include "seagate.h"
61 #include "constants.h"
62
63
64 #ifndef IRQ
65 #define IRQ 5
66 #endif
67
68 #if (defined(FAST32) && !defined(FAST))
69 #define FAST
70 #endif
71
72 #if defined(SLOW_RATE) && !defined(SLOW_HANDSHAKE)
73 #define SLOW_HANDSHAKE
74 #endif
75
76 #if defined(SLOW_HANDSHAKE) && !defined(SLOW_RATE)
77 #define SLOW_RATE 50
78 #endif
79
80
81 #if defined(LINKED)
82 #undef LINKED
83 #endif
84
85 static int internal_command(unsigned char target, unsigned char lun,
86 const void *cmnd,
87 void *buff, int bufflen, int reselect);
88
89 static int incommand;
90
91
92
93
94 static void *base_address = NULL;
95
96
97
98
99 #ifdef notyet
100 static volatile int abort_confirm = 0;
101 #endif
102
103 static volatile void *st0x_cr_sr;
104
105
106
107
108
109
110
111
112
113
114 static volatile void *st0x_dr;
115
116
117
118
119
120 static volatile int st0x_aborted=0;
121
122
123
124 static unsigned char controller_type = 0;
125 static unsigned char irq = IRQ;
126
127 #define retcode(result) (((result) << 16) | (message << 8) | status)
128 #define STATUS (*(volatile unsigned char *) st0x_cr_sr)
129 #define CONTROL STATUS
130 #define DATA (*(volatile unsigned char *) st0x_dr)
131
132 void st0x_setup (char *str, int *ints) {
133 controller_type = SEAGATE;
134 base_address = (void *) ints[1];
135 irq = ints[2];
136 }
137
138 void tmc8xx_setup (char *str, int *ints) {
139 controller_type = FD;
140 base_address = (void *) ints[1];
141 irq = ints[2];
142 }
143
144
145 #ifndef OVERRIDE
146 static const char * seagate_bases[] = {
147 (char *) 0xc8000, (char *) 0xca000, (char *) 0xcc000,
148 (char *) 0xce000, (char *) 0xdc000, (char *) 0xde000
149 };
150
151 typedef struct {
152 char *signature ;
153 unsigned offset;
154 unsigned length;
155 unsigned char type;
156 } Signature;
157
158 static const Signature signatures[] = {
159 #ifdef CONFIG_SCSI_SEAGATE
160 {"ST01 v1.7 (C) Copyright 1987 Seagate", 15, 37, SEAGATE},
161 {"SCSI BIOS 2.00 (C) Copyright 1987 Seagate", 15, 40, SEAGATE},
162
163
164
165
166
167
168
169
170 {"SEAGATE SCSI BIOS ",16, 17, SEAGATE},
171 {"SEAGATE SCSI BIOS ",17, 17, SEAGATE},
172
173
174
175
176
177
178 {"FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89", 5, 46, FD},
179 {"FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89", 5, 46, FD},
180 {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90",5, 47, FD},
181 {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90",5, 47, FD},
182 {"FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90", 5, 46, FD},
183 {"FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92", 5, 44, FD},
184 {"FUTURE DOMAIN TMC-950", 5, 21, FD},
185 #endif
186 }
187 ;
188
189 #define NUM_SIGNATURES (sizeof(signatures) / sizeof(Signature))
190 #endif
191
192
193
194
195
196 static int hostno = -1;
197 static void seagate_reconnect_intr(int, struct pt_regs *);
198
199 #ifdef FAST
200 static int fast = 1;
201 #endif
202
203 #ifdef SLOW_HANDSHAKE
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241 static int borken_calibration = 0;
242 static void borken_init (void) {
243 register int count = 0, start = jiffies + 1, stop = start + 25;
244
245 while (jiffies < start);
246 for (;jiffies < stop; ++count);
247
248
249
250
251
252
253 borken_calibration = (count * 4) / (SLOW_RATE*1024);
254
255 if (borken_calibration < 1)
256 borken_calibration = 1;
257 #if (DEBUG & DEBUG_BORKEN)
258 printk("scsi%d : borken calibrated to %dK/sec, %d cycles per transfer\n",
259 hostno, BORKEN_RATE, borken_calibration);
260 #endif
261 }
262
263 static inline void borken_wait(void) {
264 register int count;
265 for (count = borken_calibration; count && (STATUS & STAT_REQ);
266 --count);
267 #if (DEBUG & DEBUG_BORKEN)
268 if (count)
269 printk("scsi%d : borken timeout\n", hostno);
270 #endif
271 }
272
273 #endif
274
275 int seagate_st0x_detect (Scsi_Host_Template * tpnt)
276 {
277 struct Scsi_Host *instance;
278 #ifndef OVERRIDE
279 int i,j;
280 #endif
281
282
283
284
285 #ifdef DEBUG
286 printk("Autodetecting seagate ST0x\n");
287 #endif
288
289 if (hostno != -1)
290 {
291 printk ("ERROR : seagate_st0x_detect() called twice.\n");
292 return 0;
293 }
294
295
296
297
298 if (!controller_type) {
299 #ifdef OVERRIDE
300 base_address = (void *) OVERRIDE;
301
302
303 #ifdef CONTROLLER
304 controller_type = CONTROLLER;
305 #else
306 #error Please use -DCONTROLLER=SEAGATE or -DCONTROLLER=FD to override controller type
307 #endif
308 #ifdef DEBUG
309 printk("Base address overridden to %x, controller type is %s\n",
310 base_address,controller_type == SEAGATE ? "SEAGATE" : "FD");
311 #endif
312 #else
313
314
315
316
317
318
319
320
321
322
323 for (i = 0; i < (sizeof (seagate_bases) / sizeof (char * )); ++i)
324 for (j = 0; !base_address && j < NUM_SIGNATURES; ++j)
325 if (!memcmp ((void *) (seagate_bases[i] +
326 signatures[j].offset), (void *) signatures[j].signature,
327 signatures[j].length)) {
328 base_address = (void *) seagate_bases[i];
329 controller_type = signatures[j].type;
330 }
331 #endif
332 }
333
334 tpnt->this_id = (controller_type == SEAGATE) ? 7 : 6;
335 tpnt->name = (controller_type == SEAGATE) ? ST0X_ID_STR : FD_ID_STR;
336
337 if (base_address)
338 {
339 st0x_cr_sr =(void *) (((unsigned char *) base_address) + (controller_type == SEAGATE ? 0x1a00 : 0x1c00));
340 st0x_dr = (void *) (((unsigned char *) base_address ) + (controller_type == SEAGATE ? 0x1c00 : 0x1e00));
341 #ifdef DEBUG
342 printk("%s detected. Base address = %x, cr = %x, dr = %x\n", tpnt->name, base_address, st0x_cr_sr, st0x_dr);
343 #endif
344
345
346
347
348 instance = scsi_register(tpnt, 0);
349 hostno = instance->host_no;
350 if (request_irq((int) irq, seagate_reconnect_intr, SA_INTERRUPT, "seagate")) {
351 printk("scsi%d : unable to allocate IRQ%d\n",
352 hostno, (int) irq);
353 return 0;
354 }
355 #ifdef SLOW_HANDSHAKE
356 borken_init();
357 #endif
358
359 return 1;
360 }
361 else
362 {
363 #ifdef DEBUG
364 printk("ST0x not detected.\n");
365 #endif
366 return 0;
367 }
368 }
369
370 const char *seagate_st0x_info(struct Scsi_Host * shpnt) {
371 static char buffer[256];
372 sprintf(buffer, "scsi%d : %s at irq %d address %p options :"
373 #ifdef ARBITRATE
374 " ARBITRATE"
375 #endif
376 #ifdef SLOW_HANDSHAKE
377 " SLOW_HANDSHAKE"
378 #endif
379 #ifdef FAST
380 #ifdef FAST32
381 " FAST32"
382 #else
383 " FAST"
384 #endif
385 #endif
386
387 #ifdef LINKED
388 " LINKED"
389 #endif
390 "\n", hostno, (controller_type == SEAGATE) ? ST0X_ID_STR :
391 FD_ID_STR, irq, base_address);
392 return buffer;
393 }
394
395
396
397
398
399
400 static unsigned char current_target, current_lun;
401 static unsigned char *current_cmnd, *current_data;
402 static int current_nobuffs;
403 static struct scatterlist *current_buffer;
404 static int current_bufflen;
405
406 #ifdef LINKED
407
408
409
410
411
412
413
414 static int linked_connected = 0;
415 static unsigned char linked_target, linked_lun;
416 #endif
417
418
419 static void (*done_fn)(Scsi_Cmnd *) = NULL;
420 static Scsi_Cmnd * SCint = NULL;
421
422
423
424
425
426
427 #define NO_RECONNECT 0
428 #define RECONNECT_NOW 1
429 #define CAN_RECONNECT 2
430
431 #ifdef LINKED
432
433
434
435
436
437
438
439 #define LINKED_RIGHT 3
440 #define LINKED_WRONG 4
441 #endif
442
443
444
445
446
447 static int should_reconnect = 0;
448
449
450
451
452
453
454
455 static void seagate_reconnect_intr(int irq, struct pt_regs * regs)
456 {
457 int temp;
458 Scsi_Cmnd * SCtmp;
459
460
461 sti();
462 #if (DEBUG & PHASE_RESELECT)
463 printk("scsi%d : seagate_reconnect_intr() called\n", hostno);
464 #endif
465
466 if (!should_reconnect)
467 printk("scsi%d: unexpected interrupt.\n", hostno);
468 else {
469 should_reconnect = 0;
470
471 #if (DEBUG & PHASE_RESELECT)
472 printk("scsi%d : internal_command("
473 "%d, %08x, %08x, %d, RECONNECT_NOW\n", hostno,
474 current_target, current_data, current_bufflen);
475 #endif
476
477 temp = internal_command (current_target, current_lun,
478 current_cmnd, current_data, current_bufflen,
479 RECONNECT_NOW);
480
481 if (msg_byte(temp) != DISCONNECT) {
482 if (done_fn) {
483 #if (DEBUG & PHASE_RESELECT)
484 printk("scsi%d : done_fn(%d,%08x)", hostno,
485 hostno, temp);
486 #endif
487 if(!SCint) panic("SCint == NULL in seagate");
488 SCtmp = SCint;
489 SCint = NULL;
490 SCtmp->result = temp;
491 done_fn (SCtmp);
492 } else
493 printk("done_fn() not defined.\n");
494 }
495 }
496 }
497
498
499
500
501
502
503
504
505
506
507
508
509 static int recursion_depth = 0;
510
511 int seagate_st0x_queue_command (Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
512 {
513 int result, reconnect;
514 Scsi_Cmnd * SCtmp;
515
516 done_fn = done;
517 current_target = SCpnt->target;
518 current_lun = SCpnt->lun;
519 (const void *) current_cmnd = SCpnt->cmnd;
520 current_data = (unsigned char *) SCpnt->request_buffer;
521 current_bufflen = SCpnt->request_bufflen;
522 SCint = SCpnt;
523 if(recursion_depth) {
524 return 0;
525 };
526 recursion_depth++;
527 do{
528 #ifdef LINKED
529
530
531
532
533 current_cmnd[SCpnt->cmd_len] |= 0x01;
534 if (linked_connected) {
535 #if (DEBUG & DEBUG_LINKED)
536 printk("scsi%d : using linked commands, current I_T_L nexus is ",
537 hostno);
538 #endif
539 if ((linked_target == current_target) &&
540 (linked_lun == current_lun)) {
541 #if (DEBUG & DEBUG_LINKED)
542 printk("correct\n");
543 #endif
544 reconnect = LINKED_RIGHT;
545 } else {
546 #if (DEBUG & DEBUG_LINKED)
547 printk("incorrect\n");
548 #endif
549 reconnect = LINKED_WRONG;
550 }
551 } else
552 #endif
553 reconnect = CAN_RECONNECT;
554
555
556
557
558
559 result = internal_command (SCint->target, SCint->lun, SCint->cmnd, SCint->request_buffer,
560 SCint->request_bufflen,
561 reconnect);
562 if (msg_byte(result) == DISCONNECT) break;
563 SCtmp = SCint;
564 SCint = NULL;
565 SCtmp->result = result;
566 done_fn (SCtmp);
567 } while(SCint);
568 recursion_depth--;
569 return 0;
570 }
571
572 int seagate_st0x_command (Scsi_Cmnd * SCpnt) {
573 return internal_command (SCpnt->target, SCpnt->lun, SCpnt->cmnd, SCpnt->request_buffer,
574 SCpnt->request_bufflen,
575 (int) NO_RECONNECT);
576 }
577
578 static int internal_command(unsigned char target, unsigned char lun, const void *cmnd,
579 void *buff, int bufflen, int reselect) {
580 int len = 0;
581 unsigned char *data = NULL;
582 struct scatterlist *buffer = NULL;
583 int nobuffs = 0;
584 int clock;
585 int temp;
586 #ifdef SLOW_HANDSHAKE
587 int borken;
588 #endif
589
590
591 #if (DEBUG & PHASE_DATAIN) || (DEBUG & PHASE_DATOUT)
592 int transfered = 0;
593 #endif
594
595 #if (((DEBUG & PHASE_ETC) == PHASE_ETC) || (DEBUG & PRINT_COMMAND) || \
596 (DEBUG & PHASE_EXIT))
597 int i;
598 #endif
599
600 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
601 int phase=0, newphase;
602 #endif
603
604 int done = 0;
605 unsigned char status = 0;
606 unsigned char message = 0;
607 register unsigned char status_read;
608
609 unsigned transfersize = 0, underflow = 0;
610
611 incommand = 0;
612 st0x_aborted = 0;
613
614 #ifdef SLOW_HANDSHAKE
615 borken = (int) SCint->device->borken;
616 #endif
617
618 #if (DEBUG & PRINT_COMMAND)
619 printk ("scsi%d : target = %d, command = ", hostno, target);
620 print_command((unsigned char *) cmnd);
621 printk("\n");
622 #endif
623
624 #if (DEBUG & PHASE_RESELECT)
625 switch (reselect) {
626 case RECONNECT_NOW :
627 printk("scsi%d : reconnecting\n", hostno);
628 break;
629 #ifdef LINKED
630 case LINKED_RIGHT :
631 printk("scsi%d : connected, can reconnect\n", hostno);
632 break;
633 case LINKED_WRONG :
634 printk("scsi%d : connected to wrong target, can reconnect\n",
635 hostno);
636 break;
637 #endif
638 case CAN_RECONNECT :
639 printk("scsi%d : allowed to reconnect\n", hostno);
640 break;
641 default :
642 printk("scsi%d : not allowed to reconnect\n", hostno);
643 }
644 #endif
645
646
647 if (target == (controller_type == SEAGATE ? 7 : 6))
648 return DID_BAD_TARGET;
649
650
651
652
653
654
655
656 switch (reselect) {
657 case RECONNECT_NOW:
658 #if (DEBUG & PHASE_RESELECT)
659 printk("scsi%d : phase RESELECT \n", hostno);
660 #endif
661
662
663
664
665
666
667
668
669
670 clock = jiffies + 10;
671 for (;;) {
672 temp = STATUS;
673 if ((temp & STAT_IO) && !(temp & STAT_BSY))
674 break;
675
676 if (jiffies > clock) {
677 #if (DEBUG & PHASE_RESELECT)
678 printk("scsi%d : RESELECT timed out while waiting for IO .\n",
679 hostno);
680 #endif
681 return (DID_BAD_INTR << 16);
682 }
683 }
684
685
686
687
688
689
690 if (!((temp = DATA) & (controller_type == SEAGATE ? 0x80 : 0x40)))
691 {
692 #if (DEBUG & PHASE_RESELECT)
693 printk("scsi%d : detected reconnect request to different target.\n"
694 "\tData bus = %d\n", hostno, temp);
695 #endif
696 return (DID_BAD_INTR << 16);
697 }
698
699 if (!(temp & (1 << current_target)))
700 {
701 printk("scsi%d : Unexpected reselect interrupt. Data bus = %d\n",
702 hostno, temp);
703 return (DID_BAD_INTR << 16);
704 }
705
706 buffer=current_buffer;
707 cmnd=current_cmnd;
708 data=current_data;
709 len=current_bufflen;
710 nobuffs=current_nobuffs;
711
712
713
714
715
716
717 #if 1
718 CONTROL = (BASE_CMD | CMD_DRVR_ENABLE | CMD_BSY);
719 #else
720 CONTROL = (BASE_CMD | CMD_BSY);
721 #endif
722
723
724
725
726
727
728 for (clock = jiffies + 10; (jiffies < clock) && (STATUS & STAT_SEL););
729
730 if (jiffies >= clock)
731 {
732 CONTROL = (BASE_CMD | CMD_INTR);
733 #if (DEBUG & PHASE_RESELECT)
734 printk("scsi%d : RESELECT timed out while waiting for SEL.\n",
735 hostno);
736 #endif
737 return (DID_BAD_INTR << 16);
738 }
739
740 CONTROL = BASE_CMD;
741
742
743
744
745
746 break;
747 case CAN_RECONNECT:
748
749 #ifdef LINKED
750
751
752
753
754
755
756
757 connect_loop :
758
759 #endif
760
761 #if (DEBUG & PHASE_BUS_FREE)
762 printk ("scsi%d : phase = BUS FREE \n", hostno);
763 #endif
764
765
766
767
768
769
770
771
772
773
774 clock = jiffies + ST0X_BUS_FREE_DELAY;
775
776 #if !defined (ARBITRATE)
777 while (((STATUS | STATUS | STATUS) &
778 (STAT_BSY | STAT_SEL)) &&
779 (!st0x_aborted) && (jiffies < clock));
780
781 if (jiffies > clock)
782 return retcode(DID_BUS_BUSY);
783 else if (st0x_aborted)
784 return retcode(st0x_aborted);
785 #endif
786
787 #if (DEBUG & PHASE_SELECTION)
788 printk("scsi%d : phase = SELECTION\n", hostno);
789 #endif
790
791 clock = jiffies + ST0X_SELECTION_DELAY;
792
793
794
795
796
797
798
799
800
801
802
803
804 #if defined(ARBITRATE)
805 cli();
806 CONTROL = 0;
807 DATA = (controller_type == SEAGATE) ? 0x80 : 0x40;
808 CONTROL = CMD_START_ARB;
809 sti();
810 while (!((status_read = STATUS) & (STAT_ARB_CMPL | STAT_SEL)) &&
811 (jiffies < clock) && !st0x_aborted);
812
813 if (!(status_read & STAT_ARB_CMPL)) {
814 #if (DEBUG & PHASE_SELECTION)
815 if (status_read & STAT_SEL)
816 printk("scsi%d : arbitration lost\n", hostno);
817 else
818 printk("scsi%d : arbitration timeout.\n", hostno);
819 #endif
820 CONTROL = BASE_CMD;
821 return retcode(DID_NO_CONNECT);
822 };
823
824 #if (DEBUG & PHASE_SELECTION)
825 printk("scsi%d : arbitration complete\n", hostno);
826 #endif
827 #endif
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842 cli();
843 DATA = (unsigned char) ((1 << target) | (controller_type == SEAGATE ? 0x80 : 0x40));
844 CONTROL = BASE_CMD | CMD_DRVR_ENABLE | CMD_SEL |
845 (reselect ? CMD_ATTN : 0);
846 sti();
847 while (!((status_read = STATUS) & STAT_BSY) &&
848 (jiffies < clock) && !st0x_aborted)
849
850 #if 0 && (DEBUG & PHASE_SELECTION)
851 {
852 temp = clock - jiffies;
853
854 if (!(jiffies % 5))
855 printk("seagate_st0x_timeout : %d \r",temp);
856
857 }
858 printk("Done. \n");
859 printk("scsi%d : status = %02x, seagate_st0x_timeout = %d, aborted = %02x \n",
860 hostno, status_read, temp, st0x_aborted);
861 #else
862 ;
863 #endif
864
865
866 if ((jiffies >= clock) && !(status_read & STAT_BSY))
867 {
868 #if (DEBUG & PHASE_SELECTION)
869 printk ("scsi%d : NO CONNECT with target %d, status = %x \n",
870 hostno, target, STATUS);
871 #endif
872 return retcode(DID_NO_CONNECT);
873 }
874
875
876
877
878
879
880
881 if (st0x_aborted) {
882 CONTROL = BASE_CMD;
883 if (STATUS & STAT_BSY) {
884 printk("scsi%d : BST asserted after we've been aborted.\n",
885 hostno);
886 seagate_st0x_reset(NULL);
887 return retcode(DID_RESET);
888 }
889 return retcode(st0x_aborted);
890 }
891
892
893
894 if ((nobuffs = SCint->use_sg)) {
895 #if (DEBUG & DEBUG_SG)
896 {
897 int i;
898 printk("scsi%d : scatter gather requested, using %d buffers.\n",
899 hostno, nobuffs);
900 for (i = 0; i < nobuffs; ++i)
901 printk("scsi%d : buffer %d address = %08x length = %d\n",
902 hostno, i, buffer[i].address, buffer[i].length);
903 }
904 #endif
905
906 buffer = (struct scatterlist *) SCint->buffer;
907 len = buffer->length;
908 data = (unsigned char *) buffer->address;
909 } else {
910 #if (DEBUG & DEBUG_SG)
911 printk("scsi%d : scatter gather not requested.\n", hostno);
912 #endif
913 buffer = NULL;
914 len = SCint->request_bufflen;
915 data = (unsigned char *) SCint->request_buffer;
916 }
917
918 #if (DEBUG & (PHASE_DATAIN | PHASE_DATAOUT))
919 printk("scsi%d : len = %d\n", hostno, len);
920 #endif
921
922 break;
923 #ifdef LINKED
924 case LINKED_RIGHT:
925 break;
926 case LINKED_WRONG:
927 break;
928 #endif
929 }
930
931
932
933
934
935
936
937
938
939
940
941 CONTROL = BASE_CMD | CMD_DRVR_ENABLE |
942 (((reselect == CAN_RECONNECT)
943 #ifdef LINKED
944 || (reselect == LINKED_WRONG)
945 #endif
946 ) ? CMD_ATTN : 0) ;
947
948
949
950
951
952
953
954
955
956
957 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
958 printk("scsi%d : phase = INFORMATION TRANSFER\n", hostno);
959 #endif
960
961 incommand = 1;
962 transfersize = SCint->transfersize;
963 underflow = SCint->underflow;
964
965
966
967
968
969
970
971
972
973
974 while (((status_read = STATUS) & STAT_BSY) && !st0x_aborted && !done)
975 {
976 #ifdef PARITY
977 if (status_read & STAT_PARITY)
978 {
979 printk("scsi%d : got parity error\n", hostno);
980 st0x_aborted = DID_PARITY;
981 }
982 #endif
983
984 if (status_read & STAT_REQ)
985 {
986 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
987 if ((newphase = (status_read & REQ_MASK)) != phase)
988 {
989 phase = newphase;
990 switch (phase)
991 {
992 case REQ_DATAOUT:
993 printk("scsi%d : phase = DATA OUT\n",
994 hostno);
995 break;
996 case REQ_DATAIN :
997 printk("scsi%d : phase = DATA IN\n",
998 hostno);
999 break;
1000 case REQ_CMDOUT :
1001 printk("scsi%d : phase = COMMAND OUT\n",
1002 hostno);
1003 break;
1004 case REQ_STATIN :
1005 printk("scsi%d : phase = STATUS IN\n",
1006 hostno);
1007 break;
1008 case REQ_MSGOUT :
1009 printk("scsi%d : phase = MESSAGE OUT\n",
1010 hostno);
1011 break;
1012 case REQ_MSGIN :
1013 printk("scsi%d : phase = MESSAGE IN\n",
1014 hostno);
1015 break;
1016 default :
1017 printk("scsi%d : phase = UNKNOWN\n",
1018 hostno);
1019 st0x_aborted = DID_ERROR;
1020 }
1021 }
1022 #endif
1023 switch (status_read & REQ_MASK)
1024 {
1025 case REQ_DATAOUT :
1026
1027
1028
1029
1030
1031 #ifdef FAST
1032 if (!len) {
1033 #if 0
1034 printk("scsi%d: underflow to target %d lun %d \n",
1035 hostno, target, lun);
1036 st0x_aborted = DID_ERROR;
1037 fast = 0;
1038 #endif
1039 break;
1040 }
1041
1042 if (fast && transfersize && !(len % transfersize) && (len >= transfersize)
1043 #ifdef FAST32
1044 && !(transfersize % 4)
1045 #endif
1046 ) {
1047 #if (DEBUG & DEBUG_FAST)
1048 printk("scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
1049 " len = %d, data = %08x\n", hostno, SCint->underflow,
1050 SCint->transfersize, len, data);
1051 #endif
1052
1053 __asm__("
1054 cld;
1055 "
1056 #ifdef FAST32
1057 " shr $2, %%ecx;
1058 1: lodsl;
1059 movl %%eax, (%%edi);
1060 "
1061 #else
1062 "1: lodsb;
1063 movb %%al, (%%edi);
1064 "
1065 #endif
1066 " loop 1b;" : :
1067
1068 "D" (st0x_dr), "S" (data), "c" (SCint->transfersize) :
1069
1070 "eax", "ecx", "esi" );
1071
1072 len -= transfersize;
1073 data += transfersize;
1074
1075 #if (DEBUG & DEBUG_FAST)
1076 printk("scsi%d : FAST transfer complete len = %d data = %08x\n",
1077 hostno, len, data);
1078 #endif
1079
1080
1081 } else
1082 #endif
1083
1084 {
1085
1086
1087
1088
1089 __asm__ (
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100 "\torl %%ecx, %%ecx
1101 jz 2f
1102
1103 cld
1104
1105 movl _st0x_cr_sr, %%ebx
1106 movl _st0x_dr, %%edi
1107
1108 1: movb (%%ebx), %%al\n"
1109
1110
1111
1112
1113 "\ttest $1, %%al
1114 jz 2f\n"
1115
1116
1117
1118
1119 "\ttest $0xe, %%al
1120 jnz 2f \n"
1121
1122
1123
1124 "\ttest $0x10, %%al
1125 jz 1b
1126 lodsb
1127 movb %%al, (%%edi)
1128 loop 1b
1129
1130 2:
1131 ":
1132
1133 "=S" (data), "=c" (len) :
1134
1135 "0" (data), "1" (len) :
1136
1137 "eax", "ebx", "edi");
1138 }
1139
1140 if (!len && nobuffs) {
1141 --nobuffs;
1142 ++buffer;
1143 len = buffer->length;
1144 data = (unsigned char *) buffer->address;
1145 #if (DEBUG & DEBUG_SG)
1146 printk("scsi%d : next scatter-gather buffer len = %d address = %08x\n",
1147 hostno, len, data);
1148 #endif
1149 }
1150 break;
1151
1152 case REQ_DATAIN :
1153 #ifdef SLOW_HANDSHAKE
1154 if (borken) {
1155 #if (DEBUG & (PHASE_DATAIN))
1156 transfered += len;
1157 #endif
1158 for (; len && (STATUS & (REQ_MASK | STAT_REQ)) == (REQ_DATAIN |
1159 STAT_REQ); --len) {
1160 *data++ = DATA;
1161 borken_wait();
1162 }
1163 #if (DEBUG & (PHASE_DATAIN))
1164 transfered -= len;
1165 #endif
1166 } else
1167 #endif
1168 #ifdef FAST
1169 if (fast && transfersize && !(len % transfersize) && (len >= transfersize)
1170 #ifdef FAST32
1171 && !(transfersize % 4)
1172 #endif
1173 ) {
1174 #if (DEBUG & DEBUG_FAST)
1175 printk("scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
1176 " len = %d, data = %08x\n", hostno, SCint->underflow,
1177 SCint->transfersize, len, data);
1178 #endif
1179 __asm__("
1180 cld;
1181 "
1182 #ifdef FAST32
1183 " shr $2, %%ecx;
1184 1: movl (%%esi), %%eax;
1185 stosl;
1186 "
1187 #else
1188 "1: movb (%%esi), %%al;
1189 stosb;
1190 "
1191 #endif
1192
1193 " loop 1b;" : :
1194
1195 "S" (st0x_dr), "D" (data), "c" (SCint->transfersize) :
1196
1197 "eax", "ecx", "edi");
1198
1199 len -= transfersize;
1200 data += transfersize;
1201
1202 #if (DEBUG & PHASE_DATAIN)
1203 printk("scsi%d: transfered += %d\n", hostno, transfersize);
1204 transfered += transfersize;
1205 #endif
1206
1207 #if (DEBUG & DEBUG_FAST)
1208 printk("scsi%d : FAST transfer complete len = %d data = %08x\n",
1209 hostno, len, data);
1210 #endif
1211
1212 } else
1213 #endif
1214 {
1215
1216 #if (DEBUG & PHASE_DATAIN)
1217 printk("scsi%d: transfered += %d\n", hostno, len);
1218 transfered += len;
1219
1220 #endif
1221
1222
1223
1224
1225
1226
1227 __asm__ (
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237 "\torl %%ecx, %%ecx
1238 jz 2f
1239
1240 cld
1241 movl _st0x_cr_sr, %%esi
1242 movl _st0x_dr, %%ebx
1243
1244 1: movb (%%esi), %%al\n"
1245
1246
1247
1248
1249 "\ttest $1, %%al
1250 jz 2f\n"
1251
1252
1253
1254
1255 "\tmovb $0xe, %%ah
1256 andb %%al, %%ah
1257 cmpb $0x04, %%ah
1258 jne 2f\n"
1259
1260
1261
1262
1263 "\ttest $0x10, %%al
1264 jz 1b
1265
1266 movb (%%ebx), %%al
1267 stosb
1268 loop 1b\n"
1269
1270 "2:\n"
1271 :
1272
1273 "=D" (data), "=c" (len) :
1274
1275 "0" (data), "1" (len) :
1276
1277 "eax","ebx", "esi");
1278
1279 #if (DEBUG & PHASE_DATAIN)
1280 printk("scsi%d: transfered -= %d\n", hostno, len);
1281 transfered -= len;
1282
1283 #endif
1284 }
1285
1286 if (!len && nobuffs) {
1287 --nobuffs;
1288 ++buffer;
1289 len = buffer->length;
1290 data = (unsigned char *) buffer->address;
1291 #if (DEBUG & DEBUG_SG)
1292 printk("scsi%d : next scatter-gather buffer len = %d address = %08x\n",
1293 hostno, len, data);
1294 #endif
1295 }
1296
1297 break;
1298
1299 case REQ_CMDOUT :
1300 while (((status_read = STATUS) & STAT_BSY) &&
1301 ((status_read & REQ_MASK) == REQ_CMDOUT))
1302 if (status_read & STAT_REQ) {
1303 DATA = *(unsigned char *) cmnd;
1304 cmnd = 1+(unsigned char *) cmnd;
1305 #ifdef SLOW_HANDSHAKE
1306 if (borken)
1307 borken_wait();
1308 #endif
1309 }
1310 break;
1311
1312 case REQ_STATIN :
1313 status = DATA;
1314 break;
1315
1316 case REQ_MSGOUT :
1317
1318
1319
1320
1321
1322 CONTROL = BASE_CMD | CMD_DRVR_ENABLE;
1323
1324
1325
1326
1327 switch (reselect) {
1328 case CAN_RECONNECT:
1329 DATA = IDENTIFY(1, lun);
1330
1331 #if (DEBUG & (PHASE_RESELECT | PHASE_MSGOUT))
1332 printk("scsi%d : sent IDENTIFY message.\n", hostno);
1333 #endif
1334 break;
1335 #ifdef LINKED
1336 case LINKED_WRONG:
1337 DATA = ABORT;
1338 linked_connected = 0;
1339 reselect = CAN_RECONNECT;
1340 goto connect_loop;
1341 #if (DEBUG & (PHASE_MSGOUT | DEBUG_LINKED))
1342 printk("scsi%d : sent ABORT message to cancel incorrect I_T_L nexus.\n", hostno);
1343 #endif
1344 #endif
1345 #if (DEBUG & DEBUG_LINKED)
1346 printk("correct\n");
1347 #endif
1348 default:
1349 DATA = NOP;
1350 printk("scsi%d : target %d requested MSGOUT, sent NOP message.\n", hostno, target);
1351 }
1352 break;
1353
1354 case REQ_MSGIN :
1355 switch (message = DATA) {
1356 case DISCONNECT :
1357 should_reconnect = 1;
1358 current_data = data;
1359 current_buffer = buffer;
1360 current_bufflen = len;
1361 current_nobuffs = nobuffs;
1362 #ifdef LINKED
1363 linked_connected = 0;
1364 #endif
1365 done=1;
1366 #if (DEBUG & (PHASE_RESELECT | PHASE_MSGIN))
1367 printk("scsi%d : disconnected.\n", hostno);
1368 #endif
1369 break;
1370
1371 #ifdef LINKED
1372 case LINKED_CMD_COMPLETE:
1373 case LINKED_FLG_CMD_COMPLETE:
1374 #endif
1375 case COMMAND_COMPLETE :
1376
1377
1378
1379 #if (DEBUG & PHASE_MSGIN)
1380 printk("scsi%d : command complete.\n", hostno);
1381 #endif
1382 done = 1;
1383 break;
1384 case ABORT :
1385 #if (DEBUG & PHASE_MSGIN)
1386 printk("scsi%d : abort message.\n", hostno);
1387 #endif
1388 done=1;
1389 break;
1390 case SAVE_POINTERS :
1391 current_buffer = buffer;
1392 current_bufflen = len;
1393 current_data = data;
1394 current_nobuffs = nobuffs;
1395 #if (DEBUG & PHASE_MSGIN)
1396 printk("scsi%d : pointers saved.\n", hostno);
1397 #endif
1398 break;
1399 case RESTORE_POINTERS:
1400 buffer=current_buffer;
1401 cmnd=current_cmnd;
1402 data=current_data;
1403 len=current_bufflen;
1404 nobuffs=current_nobuffs;
1405 #if (DEBUG & PHASE_MSGIN)
1406 printk("scsi%d : pointers restored.\n", hostno);
1407 #endif
1408 break;
1409 default:
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420 if (message & 0x80) {
1421 #if (DEBUG & PHASE_MSGIN)
1422 printk("scsi%d : IDENTIFY message received from id %d, lun %d.\n",
1423 hostno, target, message & 7);
1424 #endif
1425 } else {
1426
1427
1428
1429
1430
1431
1432
1433 #if (DEBUG & PHASE_MSGIN)
1434 printk("scsi%d : unknown message %d from target %d.\n",
1435 hostno, message, target);
1436 #endif
1437 }
1438 }
1439 break;
1440
1441 default :
1442 printk("scsi%d : unknown phase.\n", hostno);
1443 st0x_aborted = DID_ERROR;
1444 }
1445
1446 #ifdef SLOW_HANDSHAKE
1447
1448
1449
1450
1451
1452 if (borken)
1453 borken_wait();
1454 #endif
1455
1456 }
1457 }
1458
1459 #if (DEBUG & (PHASE_DATAIN | PHASE_DATAOUT | PHASE_EXIT))
1460 printk("scsi%d : Transfered %d bytes\n", hostno, transfered);
1461 #endif
1462
1463 #if (DEBUG & PHASE_EXIT)
1464 #if 0
1465 printk("Buffer : \n");
1466 for (i = 0; i < 20; ++i)
1467 printk ("%02x ", ((unsigned char *) data)[i]);
1468 printk("\n");
1469 #endif
1470 printk("scsi%d : status = ", hostno);
1471 print_status(status);
1472 printk("message = %02x\n", message);
1473 #endif
1474
1475
1476
1477 #ifdef notyet
1478 if (st0x_aborted) {
1479 if (STATUS & STAT_BSY) {
1480 seagate_st0x_reset(NULL);
1481 st0x_aborted = DID_RESET;
1482 }
1483 abort_confirm = 1;
1484 }
1485 #endif
1486
1487 #ifdef LINKED
1488 else {
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499 switch (message) {
1500 case LINKED_CMD_COMPLETE :
1501 case LINKED_FLG_CMD_COMPLETE :
1502 message = COMMAND_COMPLETE;
1503 linked_target = current_target;
1504 linked_lun = current_lun;
1505 linked_connected = 1;
1506 #if (DEBUG & DEBUG_LINKED)
1507 printk("scsi%d : keeping I_T_L nexus established for linked command.\n",
1508 hostno);
1509 #endif
1510
1511
1512
1513 if ((status == INTERMEDIATE_GOOD) ||
1514 (status == INTERMEDIATE_C_GOOD))
1515 status = GOOD;
1516
1517 break;
1518
1519
1520
1521
1522
1523
1524 default :
1525 #if (DEBUG & DEBUG_LINKED)
1526 printk("scsi%d : closing I_T_L nexus.\n", hostno);
1527 #endif
1528 linked_connected = 0;
1529 }
1530 }
1531 #endif
1532
1533
1534
1535
1536 if (should_reconnect) {
1537 #if (DEBUG & PHASE_RESELECT)
1538 printk("scsi%d : exiting seagate_st0x_queue_command() with reconnect enabled.\n",
1539 hostno);
1540 #endif
1541 CONTROL = BASE_CMD | CMD_INTR ;
1542 } else
1543 CONTROL = BASE_CMD;
1544
1545 return retcode (st0x_aborted);
1546 }
1547
1548 int seagate_st0x_abort (Scsi_Cmnd * SCpnt)
1549 {
1550 st0x_aborted = DID_ABORT;
1551
1552 return SCSI_ABORT_PENDING;
1553 }
1554
1555
1556
1557
1558
1559 int seagate_st0x_reset (Scsi_Cmnd * SCpnt)
1560 {
1561 unsigned clock;
1562
1563
1564
1565
1566
1567 #ifdef DEBUG
1568 printk("In seagate_st0x_reset()\n");
1569 #endif
1570
1571
1572
1573
1574 CONTROL = BASE_CMD | CMD_RST;
1575 clock=jiffies+2;
1576
1577
1578
1579
1580 while (jiffies < clock);
1581
1582 CONTROL = BASE_CMD;
1583
1584 st0x_aborted = DID_RESET;
1585
1586 #ifdef DEBUG
1587 printk("SCSI bus reset.\n");
1588 #endif
1589 return SCSI_RESET_WAKEUP;
1590 }
1591
1592 #include <asm/segment.h>
1593 #include "sd.h"
1594 #include "scsi_ioctl.h"
1595
1596 int seagate_st0x_biosparam(Disk * disk, int dev, int* ip) {
1597 unsigned char buf[256 + sizeof(int) * 2], cmd[6], *data, *page;
1598 int *sizes, result, formatted_sectors, total_sectors;
1599 int cylinders, heads, sectors;
1600
1601
1602
1603
1604
1605
1606 if (disk->device->scsi_level < 2)
1607 return -1;
1608
1609 sizes = (int *) buf;
1610 data = (unsigned char *) (sizes + 2);
1611
1612 cmd[0] = MODE_SENSE;
1613 cmd[1] = (disk->device->lun << 5) & 0xe5;
1614 cmd[2] = 0x04;
1615 cmd[3] = 0;
1616 cmd[4] = 255;
1617 cmd[5] = 0;
1618
1619
1620
1621
1622
1623
1624 sizes[0] = 0;
1625 sizes[1] = 256;
1626
1627 memcpy (data, cmd, 6);
1628
1629 if (!(result = kernel_scsi_ioctl (disk->device, SCSI_IOCTL_SEND_COMMAND, (void *) buf))) {
1630
1631
1632
1633
1634
1635 page = data + 4 + data[3];
1636 heads = (int) page[5];
1637 cylinders = (page[2] << 16) | (page[3] << 8) | page[4];
1638
1639 cmd[2] = 0x03;
1640 memcpy (data, cmd, 6);
1641
1642 if (!(result = kernel_scsi_ioctl (disk->device, SCSI_IOCTL_SEND_COMMAND, (void *) buf))) {
1643 page = data + 4 + data[3];
1644 sectors = (page[10] << 8) | page[11];
1645
1646
1647
1648
1649
1650
1651
1652 formatted_sectors = (data[4 + 1] << 16) | (data[4 + 2] << 8) |
1653 data[4 + 3] ;
1654
1655 total_sectors = (heads * cylinders * sectors);
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665 printk("scsi%d : heads = %d cylinders = %d sectors = %d total = %d formatted = %d\n",
1666 hostno, heads, cylinders, sectors, total_sectors, formatted_sectors);
1667
1668 if (!heads || !sectors || !cylinders)
1669 result = -1;
1670 else
1671 cylinders -= ((total_sectors - formatted_sectors) / (heads * sectors));
1672
1673
1674
1675
1676
1677
1678
1679 if ((cylinders > 1024) || (sectors > 64))
1680 result = -1;
1681 else {
1682 ip[0] = heads;
1683 ip[1] = sectors;
1684 ip[2] = cylinders;
1685 }
1686
1687
1688
1689
1690
1691
1692 }
1693 }
1694
1695 return result;
1696 }