2 * seagate.c Copyright (C) 1992, 1993 Drew Eckhardt
3 * low level scsi driver for ST01/ST02, Future Domain TMC-885,
10 * Note : TMC-880 boards don't work because they have two bits in
11 * the status register flipped, I'll fix this "RSN"
13 * This card does all the I/O via memory mapped I/O, so there is no need
14 * to check or snarf a region of the I/O address space.
19 * To use without BIOS -DOVERRIDE=base_address -DCONTROLLER=FD or SEAGATE
20 * -DIRQ will overide the default of 5.
21 * Note: You can now set these options from the kernel's "command line".
24 * st0x=ADDRESS,IRQ (for a Seagate controller)
26 * tmc8xx=ADDRESS,IRQ (for a TMC-8xx or TMC-950 controller)
30 * will configure the driver for a TMC-8xx style controller using IRQ 15
31 * with a base address of 0xC8000.
33 * -DFAST or -DFAST32 will use blind transfers where possible
35 * -DARBITRATE will cause the host adapter to arbitrate for the
36 * bus for better SCSI-II compatability, rather than just
37 * waiting for BUS FREE and then doing its thing. Should
38 * let us do one command per Lun when I integrate my
39 * reorganization changes into the distribution sources.
41 * -DSLOW_HANDSHAKE will allow compatability with broken devices that don't
42 * handshake fast enough (ie, some CD ROM's) for the Seagate
45 * -DSLOW_RATE=x, x some number will let you specify a default
46 * transfer rate if handshaking isn't working correctly.
49 #include <linux/config.h>
51 #if defined(CONFIG_SCSI_SEAGATE) || defined(CONFIG_SCSI_FD_8xx)
53 #include <asm/system.h>
54 #include <linux/signal.h>
55 #include <linux/sched.h>
56 #include <linux/string.h>
57 #include "../block/blk.h"
61 #include "constants.h"
68 #if (defined(FAST32) && !defined(FAST))
72 #if defined(SLOW_RATE) && !defined(SLOW_HANDSHAKE)
73 #define SLOW_HANDSHAKE
76 #if defined(SLOW_HANDSHAKE) && !defined(SLOW_RATE)
82 #undef LINKED /* Linked commands are currently broken ! */
85 static int internal_command(unsigned char target
, unsigned char lun
,
87 void *buff
, int bufflen
, int reselect
);
89 static int incommand
; /*
90 set if arbitration has finished and we are
91 in some command phase.
94 static void *base_address
= NULL
; /*
95 Where the card ROM starts,
96 used to calculate memory mapped
99 static volatile int abort_confirm
= 0;
101 static volatile void *st0x_cr_sr
; /*
102 control register write,
103 status register read.
106 Read is status of SCSI BUS,
112 static volatile void *st0x_dr
; /*
113 data register, read write
118 static volatile int st0x_aborted
=0; /*
119 set when we are aborted, ie by a time out, etc.
122 static unsigned char controller_type
= 0; /* set to SEAGATE for ST0x boards or FD for TMC-8xx boards */
123 static unsigned char irq
= IRQ
;
125 #define retcode(result) (((result) << 16) | (message << 8) | status)
126 #define STATUS (*(volatile unsigned char *) st0x_cr_sr)
127 #define CONTROL STATUS
128 #define DATA (*(volatile unsigned char *) st0x_dr)
130 void st0x_setup (char *str
, int *ints
) {
131 controller_type
= SEAGATE
;
132 base_address
= (void *) ints
[1];
136 void tmc8xx_setup (char *str
, int *ints
) {
137 controller_type
= FD
;
138 base_address
= (void *) ints
[1];
144 static const char * seagate_bases
[] = {
145 (char *) 0xc8000, (char *) 0xca000, (char *) 0xcc000,
146 (char *) 0xce000, (char *) 0xdc000, (char *) 0xde000
156 static const Signature signatures
[] = {
157 #ifdef CONFIG_SCSI_SEAGATE
158 {"ST01 v1.7 (C) Copyright 1987 Seagate", 15, 37, SEAGATE
},
159 {"SCSI BIOS 2.00 (C) Copyright 1987 Seagate", 15, 40, SEAGATE
},
162 * The following two lines are NOT mistakes. One detects ROM revision
163 * 3.0.0, the other 3.2. Since seagate has only one type of SCSI adapter,
164 * and this is not going to change, the "SEAGATE" and "SCSI" together
165 * are probably "good enough"
168 {"SEAGATE SCSI BIOS ",16, 17, SEAGATE
},
169 {"SEAGATE SCSI BIOS ",17, 17, SEAGATE
},
172 * However, future domain makes several incompatable SCSI boards, so specific
173 * signatures must be used.
176 {"FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89", 5, 46, FD
},
177 {"FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89", 5, 46, FD
},
178 {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90",5, 47, FD
},
179 {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90",5, 47, FD
},
180 {"FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90", 5, 46, FD
},
181 {"FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92", 5, 44, FD
},
182 {"FUTURE DOMAIN TMC-950", 5, 21, FD
},
183 #endif /* CONFIG_SCSI_SEAGATE */
187 #define NUM_SIGNATURES (sizeof(signatures) / sizeof(Signature))
188 #endif /* n OVERRIDE */
191 * hostno stores the hostnumber, as told to us by the init routine.
194 static int hostno
= -1;
195 static void seagate_reconnect_intr(int);
201 #ifdef SLOW_HANDSHAKE
203 * Support for broken devices :
204 * The Seagate board has a handshaking problem. Namely, a lack
205 * thereof for slow devices. You can blast 600K/second through
206 * it if you are polling for each byte, more if you do a blind
207 * transfer. In the first case, with a fast device, REQ will
208 * transition high-low or high-low-high before your loop restarts
209 * and you'll have no problems. In the second case, the board
210 * will insert wait states for up to 13.2 usecs for REQ to
211 * transition low->high, and everything will work.
213 * However, there's nothing in the state machine that says
214 * you *HAVE* to see a high-low-high set of transitions before
215 * sending the next byte, and slow things like the Trantor CD ROMS
216 * will break because of this.
218 * So, we need to slow things down, which isn't as simple as it
219 * seems. We can't slow things down period, because then people
220 * who don't recompile their kernels will shoot me for ruining
221 * their performance. We need to do it on a case per case basis.
223 * The best for performance will be to, only for borken devices
224 * (this is stored on a per-target basis in the scsi_devices array)
226 * Wait for a low->high transition before continuing with that
227 * transfer. If we timeout, continue anyways. We don't need
228 * a long timeout, because REQ should only be asserted until the
229 * corresponding ACK is recieved and processed.
231 * Note that we can't use the system timer for this, because of
232 * resolution, and we *really* can't use the timer chip since
233 * gettimeofday() and the beeper routines use that. So,
234 * the best thing for us to do will be to calibrate a timing
235 * loop in the initialization code using the timer chip before
236 * gettimeofday() can screw with it.
239 static int borken_calibration
= 0;
240 static void borken_init (void) {
241 register int count
= 0, start
= jiffies
+ 1, stop
= start
+ 25;
243 while (jiffies
< start
);
244 for (;jiffies
< stop
; ++count
);
247 * Ok, we now have a count for .25 seconds. Convert to a
248 * count per second and divide by transer rate in K.
251 borken_calibration
= (count
* 4) / (SLOW_RATE
*1024);
253 if (borken_calibration
< 1)
254 borken_calibration
= 1;
255 #if (DEBUG & DEBUG_BORKEN)
256 printk("scsi%d : borken calibrated to %dK/sec, %d cycles per transfer\n",
257 hostno
, BORKEN_RATE
, borken_calibration
);
261 static inline void borken_wait(void) {
263 for (count
= borken_calibration
; count
&& (STATUS
& STAT_REQ
);
266 #if (DEBUG & DEBUG_BORKEN)
267 printk("scsi%d : borken timeout\n", hostno
);
273 #endif /* def SLOW_HANDSHAKE */
275 int seagate_st0x_detect (int hostnum
)
280 static struct sigaction seagate_sigaction
= {
281 &seagate_reconnect_intr
,
288 * First, we try for the manual override.
291 printk("Autodetecting seagate ST0x\n");
296 printk ("ERROR : seagate_st0x_detect() called twice.\n");
300 /* If the user specified the controller type from the command line,
301 controller_type will be non-zero, so don't try and detect one */
303 if (!controller_type
) {
305 base_address
= (void *) OVERRIDE
;
307 /* CONTROLLER is used to override controller (SEAGATE or FD). PM: 07/01/93 */
309 controller_type
= CONTROLLER
;
311 #error Please use -DCONTROLLER=SEAGATE or -DCONTROLLER=FD to override controller type
312 #endif /* CONTROLLER */
314 printk("Base address overridden to %x, controller type is %s\n",
315 base_address
,controller_type
== SEAGATE
? "SEAGATE" : "FD");
319 * To detect this card, we simply look for the signature
320 * from the BIOS version notice in all the possible locations
321 * of the ROM's. This has a nice sideeffect of not trashing
322 * any register locations that might be used by something else.
324 * XXX - note that we probably should be probing the address
325 * space for the on-board RAM instead.
328 for (i
= 0; i
< (sizeof (seagate_bases
) / sizeof (char * )); ++i
)
329 for (j
= 0; !base_address
&& j
< NUM_SIGNATURES
; ++j
)
330 if (!memcmp ((void *) (seagate_bases
[i
] +
331 signatures
[j
].offset
), (void *) signatures
[j
].signature
,
332 signatures
[j
].length
)) {
333 base_address
= (void *) seagate_bases
[i
];
334 controller_type
= signatures
[j
].type
;
337 } /* (! controller_type) */
339 scsi_hosts
[hostnum
].this_id
= (controller_type
== SEAGATE
) ? 7 : 6;
343 st0x_cr_sr
=(void *) (((unsigned char *) base_address
) + (controller_type
== SEAGATE
? 0x1a00 : 0x1c00));
344 st0x_dr
= (void *) (((unsigned char *) base_address
) + (controller_type
== SEAGATE
? 0x1c00 : 0x1e00));
346 printk("ST0x detected. Base address = %x, cr = %x, dr = %x\n", base_address
, st0x_cr_sr
, st0x_dr
);
349 * At all times, we will use IRQ 5. Should also check for IRQ3 if we
350 * loose our first interrupt.
353 if (irqaction((int) irq
, &seagate_sigaction
)) {
354 printk("scsi%d : unable to allocate IRQ%d\n",
358 #ifdef SLOW_HANDSHAKE
367 printk("ST0x not detected.\n");
373 const char *seagate_st0x_info(void) {
374 static char buffer
[256];
375 sprintf(buffer
, "scsi%d : %s at irq %d address %p options :"
379 #ifdef SLOW_HANDSHAKE
393 "\n", hostno
, (controller_type
== SEAGATE
) ? "seagate" :
394 "FD TMC-8xx", irq
, base_address
);
399 * These are our saved pointers for the outstanding command that is
400 * waiting for a reconnect
403 static unsigned char current_target
, current_lun
;
404 static unsigned char *current_cmnd
, *current_data
;
405 static int current_nobuffs
;
406 static struct scatterlist
*current_buffer
;
407 static int current_bufflen
;
412 * linked_connected indicates weather or not we are currently connected to
413 * linked_target, linked_lun and in an INFORMATION TRANSFER phase,
414 * using linked commands.
417 static int linked_connected
= 0;
418 static unsigned char linked_target
, linked_lun
;
422 static void (*done_fn
)(Scsi_Cmnd
*) = NULL
;
423 static Scsi_Cmnd
* SCint
= NULL
;
426 * These control whether or not disconnect / reconnect will be attempted,
427 * or are being attempted.
430 #define NO_RECONNECT 0
431 #define RECONNECT_NOW 1
432 #define CAN_RECONNECT 2
437 * LINKED_RIGHT indicates that we are currently connected to the correct target
438 * for this command, LINKED_WRONG indicates that we are connected to the wrong
439 * target. Note that these imply CAN_RECONNECT.
442 #define LINKED_RIGHT 3
443 #define LINKED_WRONG 4
447 * This determines if we are expecting to reconnect or not.
450 static int should_reconnect
= 0;
453 * The seagate_reconnect_intr routine is called when a target reselects the
454 * host adapter. This occurs on the interrupt triggered by the target
458 static void seagate_reconnect_intr (int unused
)
463 /* enable all other interrupts. */
465 #if (DEBUG & PHASE_RESELECT)
466 printk("scsi%d : seagate_reconnect_intr() called\n", hostno
);
469 if (!should_reconnect
)
470 printk("scsi%d: unexpected interrupt.\n", hostno
);
472 should_reconnect
= 0;
474 #if (DEBUG & PHASE_RESELECT)
475 printk("scsi%d : internal_command("
476 "%d, %08x, %08x, %d, RECONNECT_NOW\n", hostno
,
477 current_target
, current_data
, current_bufflen
);
480 temp
= internal_command (current_target
, current_lun
,
481 current_cmnd
, current_data
, current_bufflen
,
484 if (msg_byte(temp
) != DISCONNECT
) {
486 #if (DEBUG & PHASE_RESELECT)
487 printk("scsi%d : done_fn(%d,%08x)", hostno
,
490 if(!SCint
) panic("SCint == NULL in seagate");
493 SCtmp
->result
= temp
;
496 printk("done_fn() not defined.\n");
502 * The seagate_st0x_queue_command() function provides a queued interface
503 * to the seagate SCSI driver. Basically, it just passes control onto the
504 * seagate_command() function, after fixing it so that the done_fn()
505 * is set to the one passed to the function. We have to be very careful,
506 * because there are some commands on some devices that do not disconnect,
507 * and if we simply call the done_fn when the command is done then another
508 * command is started and queue_command is called again... We end up
509 * overflowing the kernel stack, and this tends not to be such a good idea.
512 static int recursion_depth
= 0;
514 int seagate_st0x_queue_command (Scsi_Cmnd
* SCpnt
, void (*done
)(Scsi_Cmnd
*))
516 int result
, reconnect
;
520 current_target
= SCpnt
->target
;
521 current_lun
= SCpnt
->lun
;
522 (const void *) current_cmnd
= SCpnt
->cmnd
;
523 current_data
= (unsigned char *) SCpnt
->request_buffer
;
524 current_bufflen
= SCpnt
->request_bufflen
;
526 if(recursion_depth
) {
533 * Set linked command bit in control field of SCSI command.
536 current_cmnd
[COMMAND_SIZE(current_cmnd
[0])] |= 0x01;
537 if (linked_connected
) {
538 #if (DEBUG & DEBUG_LINKED)
539 printk("scsi%d : using linked commands, current I_T_L nexus is ",
542 if ((linked_target
== current_target
) &&
543 (linked_lun
== current_lun
)) {
544 #if (DEBUG & DEBUG_LINKED)
547 reconnect
= LINKED_RIGHT
;
549 #if (DEBUG & DEBUG_LINKED)
550 printk("incorrect\n");
552 reconnect
= LINKED_WRONG
;
556 reconnect
= CAN_RECONNECT
;
562 result
= internal_command (SCint
->target
, SCint
->lun
, SCint
->cmnd
, SCint
->request_buffer
,
563 SCint
->request_bufflen
,
565 if (msg_byte(result
) == DISCONNECT
) break;
568 SCtmp
->result
= result
;
575 int seagate_st0x_command (Scsi_Cmnd
* SCpnt
) {
576 return internal_command (SCpnt
->target
, SCpnt
->lun
, SCpnt
->cmnd
, SCpnt
->request_buffer
,
577 SCpnt
->request_bufflen
,
581 static int internal_command(unsigned char target
, unsigned char lun
, const void *cmnd
,
582 void *buff
, int bufflen
, int reselect
) {
584 unsigned char *data
= NULL
;
585 struct scatterlist
*buffer
= NULL
;
589 #ifdef SLOW_HANDSHAKE
590 int borken
; /* Does the current target require Very Slow I/O ? */
594 #if (DEBUG & PHASE_DATAIN) || (DEBUG & PHASE_DATOUT)
598 #if (((DEBUG & PHASE_ETC) == PHASE_ETC) || (DEBUG & PRINT_COMMAND) || \
599 (DEBUG & PHASE_EXIT))
603 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
604 int phase
=0, newphase
;
608 unsigned char status
= 0;
609 unsigned char message
= 0;
610 register unsigned char status_read
;
612 unsigned transfersize
= 0, underflow
= 0;
617 #ifdef SLOW_HANDSHAKE
618 borken
= (int) scsi_devices
[SCint
->index
].borken
;
621 #if (DEBUG & PRINT_COMMAND)
622 printk ("scsi%d : target = %d, command = ", hostno
, target
);
623 print_command((unsigned char *) cmnd
);
627 #if (DEBUG & PHASE_RESELECT)
630 printk("scsi%d : reconnecting\n", hostno
);
634 printk("scsi%d : connected, can reconnect\n", hostno
);
637 printk("scsi%d : connected to wrong target, can reconnect\n",
642 printk("scsi%d : allowed to reconnect\n", hostno
);
645 printk("scsi%d : not allowed to reconnect\n", hostno
);
650 if (target
== (controller_type
== SEAGATE
? 7 : 6))
651 return DID_BAD_TARGET
;
654 * We work it differently depending on if this is is "the first time,"
655 * or a reconnect. If this is a reselct phase, then SEL will
656 * be asserted, and we must skip selection / arbitration phases.
661 #if (DEBUG & PHASE_RESELECT)
662 printk("scsi%d : phase RESELECT \n", hostno
);
666 * At this point, we should find the logical or of our ID and the original
667 * target's ID on the BUS, with BSY, SEL, and I/O signals asserted.
669 * After ARBITRATION phase is completed, only SEL, BSY, and the
670 * target ID are asserted. A valid initator ID is not on the bus
671 * until IO is asserted, so we must wait for that.
674 for (clock
= jiffies
+ 10, temp
= 0; (jiffies
< clock
) &&
675 !(STATUS
& STAT_IO
););
677 if (jiffies
>= clock
)
679 #if (DEBUG & PHASE_RESELECT)
680 printk("scsi%d : RESELECT timed out while waiting for IO .\n",
683 return (DID_BAD_INTR
<< 16);
687 * After I/O is asserted by the target, we can read our ID and its
691 if (!((temp
= DATA
) & (controller_type
== SEAGATE
? 0x80 : 0x40)))
693 #if (DEBUG & PHASE_RESELECT)
694 printk("scsi%d : detected reconnect request to different target.\n"
695 "\tData bus = %d\n", hostno
, temp
);
697 return (DID_BAD_INTR
<< 16);
700 if (!(temp
& (1 << current_target
)))
702 printk("scsi%d : Unexpected reselect interrupt. Data bus = %d\n",
704 return (DID_BAD_INTR
<< 16);
707 buffer
=current_buffer
;
708 cmnd
=current_cmnd
; /* WDE add */
709 data
=current_data
; /* WDE add */
710 len
=current_bufflen
; /* WDE add */
711 nobuffs
=current_nobuffs
;
714 * We have determined that we have been selected. At this point,
715 * we must respond to the reselection by asserting BSY ourselves
719 CONTROL
= (BASE_CMD
| CMD_DRVR_ENABLE
| CMD_BSY
);
721 CONTROL
= (BASE_CMD
| CMD_BSY
);
725 * The target will drop SEL, and raise BSY, at which time we must drop
729 for (clock
= jiffies
+ 10; (jiffies
< clock
) && (STATUS
& STAT_SEL
););
731 if (jiffies
>= clock
)
733 CONTROL
= (BASE_CMD
| CMD_INTR
);
734 #if (DEBUG & PHASE_RESELECT)
735 printk("scsi%d : RESELECT timed out while waiting for SEL.\n",
738 return (DID_BAD_INTR
<< 16);
744 * At this point, we have connected with the target and can get
752 * This is a bletcherous hack, just as bad as the Unix #! interpreter stuff.
753 * If it turns out we are using the wrong I_T_L nexus, the easiest way to deal
754 * with it is to go into our INFORMATION TRANSFER PHASE code, send a ABORT
755 * message on MESSAGE OUT phase, and then loop back to here.
762 #if (DEBUG & PHASE_BUS_FREE)
763 printk ("scsi%d : phase = BUS FREE \n", hostno
);
769 * On entry, we make sure that the BUS is in a BUS FREE
770 * phase, by insuring that both BSY and SEL are low for
771 * at least one bus settle delay. Several reads help
772 * eliminate wire glitch.
775 clock
= jiffies
+ ST0X_BUS_FREE_DELAY
;
777 #if !defined (ARBITRATE)
778 while (((STATUS
| STATUS
| STATUS
) &
779 (STAT_BSY
| STAT_SEL
)) &&
780 (!st0x_aborted
) && (jiffies
< clock
));
783 return retcode(DID_BUS_BUSY
);
784 else if (st0x_aborted
)
785 return retcode(st0x_aborted
);
788 #if (DEBUG & PHASE_SELECTION)
789 printk("scsi%d : phase = SELECTION\n", hostno
);
792 clock
= jiffies
+ ST0X_SELECTION_DELAY
;
795 * Arbitration/selection procedure :
797 * 2. Write HOST adapter address bit
798 * 3. Set start arbitration.
799 * 4. We get either ARBITRATION COMPLETE or SELECT at this
801 * 5. OR our ID and targets on bus.
802 * 6. Enable SCSI drivers and asserted SEL and ATTN
805 #if defined(ARBITRATE)
808 DATA
= (controller_type
== SEAGATE
) ? 0x80 : 0x40;
809 CONTROL
= CMD_START_ARB
;
811 while (!((status_read
= STATUS
) & (STAT_ARB_CMPL
| STAT_SEL
)) &&
812 (jiffies
< clock
) && !st0x_aborted
);
814 if (!(status_read
& STAT_ARB_CMPL
)) {
815 #if (DEBUG & PHASE_SELECTION)
816 if (status_read
& STAT_SEL
)
817 printk("scsi%d : arbitration lost\n", hostno
);
819 printk("scsi%d : arbitration timeout.\n", hostno
);
822 return retcode(DID_NO_CONNECT
);
825 #if (DEBUG & PHASE_SELECTION)
826 printk("scsi%d : arbitration complete\n", hostno
);
832 * When the SCSI device decides that we're gawking at it, it will
833 * respond by asserting BUSY on the bus.
835 * Note : the Seagate ST-01/02 product manual says that we should
836 * twiddle the DATA register before the control register. However,
837 * this does not work reliably so we do it the other way arround.
839 * Probably could be a problem with arbitration too, we really should
840 * try this with a SCSI protocol or logic analyzer to see what is
844 DATA
= (unsigned char) ((1 << target
) | (controller_type
== SEAGATE
? 0x80 : 0x40));
845 CONTROL
= BASE_CMD
| CMD_DRVR_ENABLE
| CMD_SEL
|
846 (reselect
? CMD_ATTN
: 0);
848 while (!((status_read
= STATUS
) & STAT_BSY
) &&
849 (jiffies
< clock
) && !st0x_aborted
)
851 #if 0 && (DEBUG & PHASE_SELECTION)
853 temp
= clock
- jiffies
;
856 printk("seagate_st0x_timeout : %d \r",temp
);
860 printk("scsi%d : status = %02x, seagate_st0x_timeout = %d, aborted = %02x \n",
861 hostno
, status_read
, temp
, st0x_aborted
);
867 if ((jiffies
>= clock
) && !(status_read
& STAT_BSY
))
869 #if (DEBUG & PHASE_SELECTION)
870 printk ("scsi%d : NO CONNECT with target %d, status = %x \n",
871 hostno
, target
, STATUS
);
873 return retcode(DID_NO_CONNECT
);
877 * If we have been aborted, and we have a command in progress, IE the
878 * target still has BSY asserted, then we will reset the bus, and
879 * notify the midlevel driver to expect sense.
884 if (STATUS
& STAT_BSY
) {
885 printk("scsi%d : BST asserted after we've been aborted.\n",
887 seagate_st0x_reset(NULL
);
888 return retcode(DID_RESET
);
890 return retcode(st0x_aborted
);
893 /* Establish current pointers. Take into account scatter / gather */
895 if ((nobuffs
= SCint
->use_sg
)) {
896 #if (DEBUG & DEBUG_SG)
899 printk("scsi%d : scatter gather requested, using %d buffers.\n",
901 for (i
= 0; i
< nobuffs
; ++i
)
902 printk("scsi%d : buffer %d address = %08x length = %d\n",
903 hostno
, i
, buffer
[i
].address
, buffer
[i
].length
);
907 buffer
= (struct scatterlist
*) SCint
->buffer
;
908 len
= buffer
->length
;
909 data
= (unsigned char *) buffer
->address
;
911 #if (DEBUG & DEBUG_SG)
912 printk("scsi%d : scatter gather not requested.\n", hostno
);
915 len
= SCint
->request_bufflen
;
916 data
= (unsigned char *) SCint
->request_buffer
;
919 #if (DEBUG & (PHASE_DATAIN | PHASE_DATAOUT))
920 printk("scsi%d : len = %d\n", hostno
, len
);
933 * There are several conditions under which we wish to send a message :
934 * 1. When we are allowing disconnect / reconnect, and need to establish
935 * the I_T_L nexus via an IDENTIFY with the DiscPriv bit set.
937 * 2. When we are doing linked commands, are have the wrong I_T_L nexus
938 * established and want to send an ABORT message.
942 CONTROL
= BASE_CMD
| CMD_DRVR_ENABLE
|
943 (((reselect
== CAN_RECONNECT
)
945 || (reselect
== LINKED_WRONG
)
950 * INFORMATION TRANSFER PHASE
952 * The nasty looking read / write inline assembler loops we use for
953 * DATAIN and DATAOUT phases are approximately 4-5 times as fast as
954 * the 'C' versions - since we're moving 1024 bytes of data, this
958 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
959 printk("scsi%d : phase = INFORMATION TRANSFER\n", hostno
);
963 transfersize
= SCint
->transfersize
;
964 underflow
= SCint
->underflow
;
968 * Now, we poll the device for status information,
969 * and handle any requests it makes. Note that since we are unsure of
970 * how much data will be flowing across the system, etc and cannot
971 * make reasonable timeouts, that we will instead have the midlevel
972 * driver handle any timeouts that occur in this phase.
975 while (((status_read
= STATUS
) & STAT_BSY
) && !st0x_aborted
&& !done
)
978 if (status_read
& STAT_PARITY
)
980 printk("scsi%d : got parity error\n", hostno
);
981 st0x_aborted
= DID_PARITY
;
985 if (status_read
& STAT_REQ
)
987 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
988 if ((newphase
= (status_read
& REQ_MASK
)) != phase
)
994 printk("scsi%d : phase = DATA OUT\n",
998 printk("scsi%d : phase = DATA IN\n",
1002 printk("scsi%d : phase = COMMAND OUT\n",
1006 printk("scsi%d : phase = STATUS IN\n",
1010 printk("scsi%d : phase = MESSAGE OUT\n",
1014 printk("scsi%d : phase = MESSAGE IN\n",
1018 printk("scsi%d : phase = UNKNOWN\n",
1020 st0x_aborted
= DID_ERROR
;
1024 switch (status_read
& REQ_MASK
)
1028 * If we are in fast mode, then we simply splat the data out
1029 * in word-sized chunks as fast as we can.
1035 printk("scsi%d: underflow to target %d lun %d \n",
1036 hostno
, target
, lun
);
1037 st0x_aborted
= DID_ERROR
;
1043 if (fast
&& transfersize
&& !(len
% transfersize
) && (len
>= transfersize
)
1045 && !(transfersize
% 4)
1048 #if (DEBUG & DEBUG_FAST)
1049 printk("scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
1050 " len = %d, data = %08x\n", hostno
, SCint
->underflow
,
1051 SCint
->transfersize
, len
, data
);
1060 movl %%eax, (%%edi);
1069 "D" (st0x_dr
), "S" (data
), "c" (SCint
->transfersize
) :
1071 "eax", "ecx", "esi" );
1073 len
-= transfersize
;
1074 data
+= transfersize
;
1076 #if (DEBUG & DEBUG_FAST)
1077 printk("scsi%d : FAST transfer complete len = %d data = %08x\n",
1087 * We loop as long as we are in a data out phase, there is data to send,
1088 * and BSY is still active.
1099 Test for any data here at all.
1106 movl _st0x_cr_sr, %%ebx
1107 movl _st0x_dr, %%edi
1109 1: movb (%%ebx), %%al\n"
1118 Test for data out phase - STATUS & REQ_MASK should be REQ_DATAOUT, which is 0.
1134 "=S" (data
), "=c" (len
) :
1136 "0" (data
), "1" (len
) :
1138 "eax", "ebx", "edi");
1141 if (!len
&& nobuffs
) {
1144 len
= buffer
->length
;
1145 data
= (unsigned char *) buffer
->address
;
1146 #if (DEBUG & DEBUG_SG)
1147 printk("scsi%d : next scatter-gather buffer len = %d address = %08x\n",
1154 #ifdef SLOW_HANDSHAKE
1156 #if (DEBUG & (PHASE_DATAIN))
1159 for (; len
&& (STATUS
& (REQ_MASK
| STAT_REQ
)) == (REQ_DATAIN
|
1164 #if (DEBUG & (PHASE_DATAIN))
1170 if (fast
&& transfersize
&& !(len
% transfersize
) && (len
>= transfersize
)
1172 && !(transfersize
% 4)
1175 #if (DEBUG & DEBUG_FAST)
1176 printk("scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
1177 " len = %d, data = %08x\n", hostno
, SCint
->underflow
,
1178 SCint
->transfersize
, len
, data
);
1185 1: movl (%%esi), %%eax;
1189 "1: movb (%%esi), %%al;
1196 "S" (st0x_dr
), "D" (data
), "c" (SCint
->transfersize
) :
1198 "eax", "ecx", "edi");
1200 len
-= transfersize
;
1201 data
+= transfersize
;
1203 #if (DEBUG & PHASE_DATAIN)
1204 printk("scsi%d: transfered += %d\n", hostno
, transfersize
);
1205 transfered
+= transfersize
;
1208 #if (DEBUG & DEBUG_FAST)
1209 printk("scsi%d : FAST transfer complete len = %d data = %08x\n",
1217 #if (DEBUG & PHASE_DATAIN)
1218 printk("scsi%d: transfered += %d\n", hostno
, len
);
1219 transfered
+= len
; /* Assume we'll transfer it all, then
1220 subtract what we *didn't* transfer */
1224 * We loop as long as we are in a data in phase, there is room to read,
1225 * and BSY is still active
1236 Test for room to read
1242 movl _st0x_cr_sr, %%esi
1243 movl _st0x_dr, %%ebx
1245 1: movb (%%esi), %%al\n"
1254 Test for data in phase - STATUS & REQ_MASK should be REQ_DATAIN, = STAT_IO, which is 4.
1274 "=D" (data
), "=c" (len
) :
1276 "0" (data
), "1" (len
) :
1278 "eax","ebx", "esi");
1280 #if (DEBUG & PHASE_DATAIN)
1281 printk("scsi%d: transfered -= %d\n", hostno
, len
);
1282 transfered
-= len
; /* Since we assumed all of Len got
1283 * transfered, correct our mistake */
1287 if (!len
&& nobuffs
) {
1290 len
= buffer
->length
;
1291 data
= (unsigned char *) buffer
->address
;
1292 #if (DEBUG & DEBUG_SG)
1293 printk("scsi%d : next scatter-gather buffer len = %d address = %08x\n",
1301 while (((status_read
= STATUS
) & STAT_BSY
) &&
1302 ((status_read
& REQ_MASK
) == REQ_CMDOUT
))
1303 if (status_read
& STAT_REQ
) {
1304 DATA
= *(unsigned char *) cmnd
;
1305 cmnd
= 1+(unsigned char *) cmnd
;
1306 #ifdef SLOW_HANDSHAKE
1319 * We can only have sent a MSG OUT if we requested to do this
1320 * by raising ATTN. So, we must drop ATTN.
1323 CONTROL
= BASE_CMD
| CMD_DRVR_ENABLE
;
1325 * If we are reconecting, then we must send an IDENTIFY message in
1326 * response to MSGOUT.
1330 DATA
= IDENTIFY(1, lun
);
1332 #if (DEBUG & (PHASE_RESELECT | PHASE_MSGOUT))
1333 printk("scsi%d : sent IDENTIFY message.\n", hostno
);
1339 linked_connected
= 0;
1340 reselect
= CAN_RECONNECT
;
1342 #if (DEBUG & (PHASE_MSGOUT | DEBUG_LINKED))
1343 printk("scsi%d : sent ABORT message to cancle incorrect I_T_L nexus.\n", hostno
);
1346 #if (DEBUG & DEBUG_LINKED)
1347 printk("correct\n");
1351 printk("scsi%d : target %d requested MSGOUT, sent NOP message.\n", hostno
, target
);
1356 switch (message
= DATA
) {
1358 should_reconnect
= 1;
1359 current_data
= data
; /* WDE add */
1360 current_buffer
= buffer
;
1361 current_bufflen
= len
; /* WDE add */
1362 current_nobuffs
= nobuffs
;
1364 linked_connected
= 0;
1367 #if (DEBUG & (PHASE_RESELECT | PHASE_MSGIN))
1368 printk("scsi%d : disconnected.\n", hostno
);
1373 case LINKED_CMD_COMPLETE
:
1374 case LINKED_FLG_CMD_COMPLETE
:
1376 case COMMAND_COMPLETE
:
1378 * Note : we should check for underflow here.
1380 #if (DEBUG & PHASE_MSGIN)
1381 printk("scsi%d : command complete.\n", hostno
);
1386 #if (DEBUG & PHASE_MSGIN)
1387 printk("scsi%d : abort message.\n", hostno
);
1391 case SAVE_POINTERS
:
1392 current_buffer
= buffer
;
1393 current_bufflen
= len
; /* WDE add */
1394 current_data
= data
; /* WDE mod */
1395 current_nobuffs
= nobuffs
;
1396 #if (DEBUG & PHASE_MSGIN)
1397 printk("scsi%d : pointers saved.\n", hostno
);
1400 case RESTORE_POINTERS
:
1401 buffer
=current_buffer
;
1403 data
=current_data
; /* WDE mod */
1404 len
=current_bufflen
;
1405 nobuffs
=current_nobuffs
;
1406 #if (DEBUG & PHASE_MSGIN)
1407 printk("scsi%d : pointers restored.\n", hostno
);
1413 * IDENTIFY distinguishes itself from the other messages by setting the
1416 * Note : we need to handle at least one outstanding command per LUN,
1417 * and need to hash the SCSI command for that I_T_L nexus based on the
1418 * known ID (at this point) and LUN.
1421 if (message
& 0x80) {
1422 #if (DEBUG & PHASE_MSGIN)
1423 printk("scsi%d : IDENTIFY message received from id %d, lun %d.\n",
1424 hostno
, target
, message
& 7);
1429 * We should go into a MESSAGE OUT phase, and send a MESSAGE_REJECT
1430 * if we run into a message that we don't like. The seagate driver
1431 * needs some serious restructuring first though.
1434 #if (DEBUG & PHASE_MSGIN)
1435 printk("scsi%d : unknown message %d from target %d.\n",
1436 hostno
, message
, target
);
1443 printk("scsi%d : unknown phase.\n", hostno
);
1444 st0x_aborted
= DID_ERROR
;
1447 #ifdef SLOW_HANDSHAKE
1449 * I really don't care to deal with borken devices in each single
1450 * byte transfer case (ie, message in, message out, status), so
1451 * I'll do the wait here if necessary.
1460 #if (DEBUG & (PHASE_DATAIN | PHASE_DATAOUT | PHASE_EXIT))
1461 printk("scsi%d : Transfered %d bytes\n", hostno
, transfered
);
1464 #if (DEBUG & PHASE_EXIT)
1465 #if 0 /* Doesn't work for scatter / gather */
1466 printk("Buffer : \n");
1467 for (i
= 0; i
< 20; ++i
)
1468 printk ("%02x ", ((unsigned char *) data
)[i
]); /* WDE mod */
1471 printk("scsi%d : status = ", hostno
);
1472 print_status(status
);
1473 printk("message = %02x\n", message
);
1477 /* We shouldn't reach this until *after* BSY has been deasserted */
1480 if (STATUS
& STAT_BSY
) {
1481 seagate_st0x_reset(NULL
);
1482 st0x_aborted
= DID_RESET
;
1491 * Fix the message byte so that unsuspecting high level drivers don't
1492 * puke when they see a LINKED COMMAND message in place of the COMMAND
1493 * COMPLETE they may be expecting. Shouldn't be necessary, but it's
1494 * better to be on the safe side.
1496 * A non LINKED* message byte will indicate that the command completed,
1497 * and we are now disconnected.
1501 case LINKED_CMD_COMPLETE
:
1502 case LINKED_FLG_CMD_COMPLETE
:
1503 message
= COMMAND_COMPLETE
;
1504 linked_target
= current_target
;
1505 linked_lun
= current_lun
;
1506 linked_connected
= 1;
1507 #if (DEBUG & DEBUG_LINKED)
1508 printk("scsi%d : keeping I_T_L nexus established for linked command.\n",
1512 * We also will need to adjust status to accomodate intermediate conditions.
1514 if ((status
== INTERMEDIATE_GOOD
) ||
1515 (status
== INTERMEDIATE_C_GOOD
))
1520 * We should also handle what are "normal" termination messages
1521 * here (ABORT, BUS_DEVICE_RESET?, and COMMAND_COMPLETE individually,
1522 * and flake if things aren't right.
1526 #if (DEBUG & DEBUG_LINKED)
1527 printk("scsi%d : closing I_T_L nexus.\n", hostno
);
1529 linked_connected
= 0;
1537 if (should_reconnect
) {
1538 #if (DEBUG & PHASE_RESELECT)
1539 printk("scsi%d : exiting seagate_st0x_queue_command() with reconnect enabled.\n",
1542 CONTROL
= BASE_CMD
| CMD_INTR
;
1546 return retcode (st0x_aborted
);
1549 int seagate_st0x_abort (Scsi_Cmnd
* SCpnt
, int code
)
1552 st0x_aborted
= code
;
1554 st0x_aborted
= DID_ABORT
;
1560 the seagate_st0x_reset function resets the SCSI bus
1563 int seagate_st0x_reset (Scsi_Cmnd
* SCpnt
)
1567 No timeouts - this command is going to fail because
1572 printk("In seagate_st0x_reset()\n");
1576 /* assert RESET signal on SCSI bus. */
1578 CONTROL
= BASE_CMD
| CMD_RST
;
1584 while (jiffies
< clock
);
1588 st0x_aborted
= DID_RESET
;
1591 printk("SCSI bus reset.\n");
1593 if(SCpnt
) SCpnt
->flags
|= NEEDS_JUMPSTART
;
1597 #ifdef CONFIG_BLK_DEV_SD
1599 #include <asm/segment.h>
1601 #include "scsi_ioctl.h"
1603 int seagate_st0x_biosparam(int size
, int dev
, int* ip
) {
1604 unsigned char buf
[256 + sizeof(int) * 2], cmd
[6], *data
, *page
;
1605 int *sizes
, result
, formatted_sectors
, total_sectors
;
1606 int cylinders
, heads
, sectors
;
1610 disk
= rscsi_disks
[MINOR(dev
) >> 4].device
;
1613 * Only SCSI-I CCS drives and later implement the necessary mode sense
1617 if (disk
->scsi_level
< 2)
1620 sizes
= (int *) buf
;
1621 data
= (unsigned char *) (sizes
+ 2);
1623 cmd
[0] = MODE_SENSE
;
1624 cmd
[1] = (disk
->lun
<< 5) & 0xe5;
1625 cmd
[2] = 0x04; /* Read page 4, rigid disk geometry page current values */
1631 * We are transfering 0 bytes in the out direction, and expect to get back
1632 * 24 bytes for each mode page.
1638 memcpy (data
, cmd
, 6);
1640 if (!(result
= kernel_scsi_ioctl (disk
, SCSI_IOCTL_SEND_COMMAND
, (void *) buf
))) {
1642 * The mode page lies beyond the MODE SENSE header, with length 4, and
1643 * the BLOCK DESCRIPTOR, with length header[3].
1646 page
= data
+ 4 + data
[3];
1647 heads
= (int) page
[5];
1648 cylinders
= (page
[2] << 16) | (page
[3] << 8) | page
[4];
1650 cmd
[2] = 0x03; /* Read page 3, format page current values */
1651 memcpy (data
, cmd
, 6);
1653 if (!(result
= kernel_scsi_ioctl (disk
, SCSI_IOCTL_SEND_COMMAND
, (void *) buf
))) {
1654 page
= data
+ 4 + data
[3];
1655 sectors
= (page
[10] << 8) | page
[11];
1659 * Get the total number of formatted sectors from the block descriptor,
1660 * so we can tell how many are being used for alternates.
1663 formatted_sectors
= (data
[4 + 1] << 16) | (data
[4 + 2] << 8) |
1666 total_sectors
= (heads
* cylinders
* sectors
);
1669 * Adjust the real geometry by subtracting
1670 * (spare sectors / (heads * tracks)) cylinders from the number of cylinders.
1672 * It appears that the CE cylinder CAN be a partial cylinder.
1676 printk("scsi%d : heads = %d cylinders = %d sectors = %d total = %d formatted = %d\n",
1677 hostno
, heads
, cylinders
, sectors
, total_sectors
, formatted_sectors
);
1679 if (!heads
|| !sectors
|| !cylinders
)
1682 cylinders
-= ((total_sectors
- formatted_sectors
) / (heads
* sectors
));
1685 * Now, we need to do a sanity check on the geometry to see if it is
1686 * BIOS compatable. The maximum BIOS geometry is 1024 cylinders *
1687 * 256 heads * 64 sectors.
1690 if ((cylinders
> 1024) || (sectors
> 64))
1699 * There should be an alternate mapping for things the seagate doesn't
1700 * understand, but I couldn't say what it is with reasonable certainty.
1708 #endif /* CONFIG_BLK_DEV_SD */
1710 #endif /* defined(CONFIG_SCSI_SEGATE) */