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