2 * seagate.c Copyright (C) 1992, 1993 Drew Eckhardt
3 * low level scsi driver for ST01/ST02, Future Domain TMC-885,
4 * TMC-950 by Drew Eckhardt <drew@colorado.edu>
6 * Note : TMC-880 boards don't work because they have two bits in
7 * the status register flipped, I'll fix this "RSN"
8 * [why do I have strong feeling that above message is from 1993? :-) pavel@ucw.cz]
10 * This card does all the I/O via memory mapped I/O, so there is no need
11 * to check or allocate a region of the I/O address space.
14 /* 1996 - to use new read{b,w,l}, write{b,w,l}, and phys_to_virt
15 * macros, replaced assembler routines with C. There's probably a
16 * performance hit, but I only have a cdrom and can't tell. Define
17 * SEAGATE_USE_ASM if you want the old assembler code -- SJT
19 * 1998-jul-29 - created DPRINTK macros and made it work under
20 * linux 2.1.112, simplified some #defines etc. <pavel@ucw.cz>
25 * To use without BIOS -DOVERRIDE=base_address -DCONTROLLER=FD or SEAGATE
26 * -DIRQ will override the default of 5.
27 * Note: You can now set these options from the kernel's "command line".
30 * st0x=ADDRESS,IRQ (for a Seagate controller)
32 * tmc8xx=ADDRESS,IRQ (for a TMC-8xx or TMC-950 controller)
36 * will configure the driver for a TMC-8xx style controller using IRQ 15
37 * with a base address of 0xC8000.
40 * Will cause the host adapter to arbitrate for the
41 * bus for better SCSI-II compatibility, rather than just
42 * waiting for BUS FREE and then doing its thing. Should
43 * let us do one command per Lun when I integrate my
44 * reorganization changes into the distribution sources.
47 * Will activate debug code.
50 * Will use blind transfers where possible
53 * This will enable parity.
56 * Will use older seagate assembly code. should be (very small amount)
60 * Will allow compatibility with broken devices that don't
61 * handshake fast enough (ie, some CD ROM's) for the Seagate
64 * 50 is some number, It will let you specify a default
65 * transfer rate if handshaking isn't working correctly.
67 * -DOLDCNTDATASCEME There is a new sceme to set the CONTROL
68 * and DATA reigsters which complies more closely
69 * with the SCSI2 standard. This hopefully eliminates
70 * the need to swap the order these registers are
71 * 'messed' with. It makes the following two options
72 * obsolete. To reenable the old sceme define this.
74 * The following to options are patches from the SCSI.HOWTO
76 * -DSWAPSTAT This will swap the definitions for STAT_MSG and STAT_CD.
78 * -DSWAPCNTDATA This will swap the order that seagate.c messes with
79 * the CONTROL an DATA registers.
82 #include <linux/module.h>
85 #include <asm/system.h>
86 #include <asm/spinlock.h>
87 #include <linux/signal.h>
88 #include <linux/sched.h>
89 #include <linux/string.h>
90 #include <linux/config.h>
91 #include <linux/proc_fs.h>
92 #include <linux/init.h>
94 #include <linux/blk.h>
98 #include "constants.h"
99 #include <linux/stat.h>
100 #include <asm/uaccess.h>
102 #include <scsi/scsi_ioctl.h>
103 #include <asm/delay.h>
106 #define DPRINTK( when, msg... ) do { if ( (DEBUG & (when)) == (when) ) printk( msg ); } while (0)
108 #define DPRINTK( when, msg... ) do { } while (0)
110 #define DANY( msg... ) DPRINTK( 0xffff, msg );
112 static struct proc_dir_entry proc_scsi_seagate
=
114 PROC_SCSI_SEAGATE
, 7, "seagate",
115 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2
126 #undef LINKED /* Linked commands are currently broken! */
128 #if defined(OVERRIDE) && !defined(CONTROLLER)
129 #error Please use -DCONTROLLER=SEAGATE or -DCONTROLLER=FD to override controller type
133 Thanks to Brian Antoine for the example code in his Messy-Loss ST-01
134 driver, and Mitsugu Suzuki for information on the ST-01
145 #define CMD_ATTN 0x08
146 #define CMD_START_ARB 0x10
147 #define CMD_EN_PARITY 0x20
148 #define CMD_INTR 0x40
149 #define CMD_DRVR_ENABLE 0x80
155 #define STAT_MSG 0x08
158 #define STAT_MSG 0x02
162 #define STAT_BSY 0x01
164 #define STAT_REQ 0x10
165 #define STAT_SEL 0x20
166 #define STAT_PARITY 0x40
167 #define STAT_ARB_CMPL 0x80
173 #define REQ_MASK (STAT_CD | STAT_IO | STAT_MSG)
174 #define REQ_DATAOUT 0
175 #define REQ_DATAIN STAT_IO
176 #define REQ_CMDOUT STAT_CD
177 #define REQ_STATIN (STAT_CD | STAT_IO)
178 #define REQ_MSGOUT (STAT_MSG | STAT_CD)
179 #define REQ_MSGIN (STAT_MSG | STAT_CD | STAT_IO)
181 extern volatile int seagate_st0x_timeout
;
184 #define BASE_CMD CMD_EN_PARITY
193 #define PHASE_BUS_FREE 1
194 #define PHASE_ARBITRATION 2
195 #define PHASE_SELECTION 4
196 #define PHASE_DATAIN 8
197 #define PHASE_DATAOUT 0x10
198 #define PHASE_CMDOUT 0x20
199 #define PHASE_MSGIN 0x40
200 #define PHASE_MSGOUT 0x80
201 #define PHASE_STATUSIN 0x100
202 #define PHASE_ETC (PHASE_DATAIN | PHASE_DATAOUT | PHASE_CMDOUT | PHASE_MSGIN | PHASE_MSGOUT | PHASE_STATUSIN)
203 #define PRINT_COMMAND 0x200
204 #define PHASE_EXIT 0x400
205 #define PHASE_RESELECT 0x800
206 #define DEBUG_FAST 0x1000
207 #define DEBUG_SG 0x2000
208 #define DEBUG_LINKED 0x4000
209 #define DEBUG_BORKEN 0x8000
212 * Control options - these are timeouts specified in .01 seconds.
216 #define ST0X_BUS_FREE_DELAY 25
217 #define ST0X_SELECTION_DELAY 25
219 #define SEAGATE 1 /* these determine the type of the controller */
222 #define ST0X_ID_STR "Seagate ST-01/ST-02"
223 #define FD_ID_STR "TMC-8XX/TMC-950"
226 static int internal_command (unsigned char target
, unsigned char lun
,
228 void *buff
, int bufflen
, int reselect
);
230 static int incommand
; /* set if arbitration has finished
231 and we are in some command phase. */
233 static unsigned int base_address
= 0; /* Where the card ROM starts, used to
234 calculate memory mapped register
237 static unsigned long st0x_cr_sr
; /* control register write, status
238 register read. 256 bytes in
240 Read is status of SCSI BUS, as per
243 static unsigned long st0x_dr
; /* data register, read write 256
246 static volatile int st0x_aborted
= 0; /* set when we are aborted, ie by a
249 static unsigned char controller_type
= 0; /* set to SEAGATE for ST0x
250 boards or FD for TMC-8xx
252 static int irq
= IRQ
;
254 #define retcode(result) (((result) << 16) | (message << 8) | status)
255 #define STATUS ((u8) readb(st0x_cr_sr))
256 #define DATA ((u8) readb(st0x_dr))
257 #define WRITE_CONTROL(d) { writeb((d), st0x_cr_sr); }
258 #define WRITE_DATA(d) { writeb((d), st0x_dr); }
260 void st0x_setup (char *str
, int *ints
)
262 controller_type
= SEAGATE
;
263 base_address
= ints
[1];
267 void tmc8xx_setup (char *str
, int *ints
)
269 controller_type
= FD
;
270 base_address
= ints
[1];
275 static unsigned int seagate_bases
[] =
277 0xc8000, 0xca000, 0xcc000,
278 0xce000, 0xdc000, 0xde000
283 const unsigned char *signature
;
290 static const Signature __initdata signatures
[] =
292 {"ST01 v1.7 (C) Copyright 1987 Seagate", 15, 37, SEAGATE
},
293 {"SCSI BIOS 2.00 (C) Copyright 1987 Seagate", 15, 40, SEAGATE
},
296 * The following two lines are NOT mistakes. One detects ROM revision
297 * 3.0.0, the other 3.2. Since seagate has only one type of SCSI adapter,
298 * and this is not going to change, the "SEAGATE" and "SCSI" together
299 * are probably "good enough"
302 {"SEAGATE SCSI BIOS ", 16, 17, SEAGATE
},
303 {"SEAGATE SCSI BIOS ", 17, 17, SEAGATE
},
306 * However, future domain makes several incompatible SCSI boards, so specific
307 * signatures must be used.
310 {"FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89", 5, 46, FD
},
311 {"FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89", 5, 46, FD
},
312 {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90", 5, 47, FD
},
313 {"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90", 5, 47, FD
},
314 {"FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90", 5, 46, FD
},
315 {"FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92", 5, 44, FD
},
316 {"IBM F1 BIOS V1.1004/30/92", 5, 25, FD
},
317 {"FUTURE DOMAIN TMC-950", 5, 21, FD
},
320 #define NUM_SIGNATURES (sizeof(signatures) / sizeof(Signature))
321 #endif /* n OVERRIDE */
324 * hostno stores the hostnumber, as told to us by the init routine.
327 static int hostno
= -1;
328 static void seagate_reconnect_intr (int, void *, struct pt_regs
*);
329 static void do_seagate_reconnect_intr (int, void *, struct pt_regs
*);
339 * Support for broken devices :
340 * The Seagate board has a handshaking problem. Namely, a lack
341 * thereof for slow devices. You can blast 600K/second through
342 * it if you are polling for each byte, more if you do a blind
343 * transfer. In the first case, with a fast device, REQ will
344 * transition high-low or high-low-high before your loop restarts
345 * and you'll have no problems. In the second case, the board
346 * will insert wait states for up to 13.2 usecs for REQ to
347 * transition low->high, and everything will work.
349 * However, there's nothing in the state machine that says
350 * you *HAVE* to see a high-low-high set of transitions before
351 * sending the next byte, and slow things like the Trantor CD ROMS
352 * will break because of this.
354 * So, we need to slow things down, which isn't as simple as it
355 * seems. We can't slow things down period, because then people
356 * who don't recompile their kernels will shoot me for ruining
357 * their performance. We need to do it on a case per case basis.
359 * The best for performance will be to, only for borken devices
360 * (this is stored on a per-target basis in the scsi_devices array)
362 * Wait for a low->high transition before continuing with that
363 * transfer. If we timeout, continue anyways. We don't need
364 * a long timeout, because REQ should only be asserted until the
365 * corresponding ACK is received and processed.
367 * Note that we can't use the system timer for this, because of
368 * resolution, and we *really* can't use the timer chip since
369 * gettimeofday() and the beeper routines use that. So,
370 * the best thing for us to do will be to calibrate a timing
371 * loop in the initialization code using the timer chip before
372 * gettimeofday() can screw with it.
374 * FIXME: this is broken (not borken :-). Empty loop costs less than
375 * loop with ISA access in it! -- pavel@ucw.cz
378 static int borken_calibration
= 0;
379 static void __init
borken_init (void)
381 register int count
= 0, start
= jiffies
+ 1, stop
= start
+ 25;
383 while (jiffies
< start
) ;
384 for (; jiffies
< stop
; ++count
) ;
387 * Ok, we now have a count for .25 seconds. Convert to a
388 * count per second and divide by transfer rate in K. */
390 borken_calibration
= (count
* 4) / (SLOW_RATE
* 1024);
392 if (borken_calibration
< 1)
393 borken_calibration
= 1;
396 static inline void borken_wait (void)
400 for (count
= borken_calibration
; count
&& (STATUS
& STAT_REQ
); --count
) ;
401 #if (DEBUG & DEBUG_BORKEN)
403 printk ("scsi%d : borken timeout\n", hostno
);
407 #endif /* def SLOW_RATE */
409 /* These beasts only live on ISA, and ISA means 8MHz. Each ULOOP()
410 * contains at least one ISA access, which takes more than 0.125
411 * usec. So if we loop 8 times time in usec, we are safe.
414 #define ULOOP( i ) for (clock = i*8;;)
415 #define TIMEOUT (!(clock--))
417 int __init
seagate_st0x_detect (Scsi_Host_Template
* tpnt
)
419 struct Scsi_Host
*instance
;
422 tpnt
->proc_dir
= &proc_scsi_seagate
;
424 * First, we try for the manual override. */
425 DANY ("Autodetecting ST0x / TMC-8xx\n");
428 printk (KERN_ERR
"seagate_st0x_detect() called twice?!\n");
432 /* If the user specified the controller type from the command line,
433 controller_type will be non-zero, so don't try to detect one */
435 if (!controller_type
)
438 base_address
= OVERRIDE
;
439 controller_type
= CONTROLLER
;
441 DANY("Base address overridden to %x, controller type is %s\n",
442 base_address
, controller_type
== SEAGATE
? "SEAGATE" : "FD");
445 * To detect this card, we simply look for the signature
446 * from the BIOS version notice in all the possible locations
447 * of the ROM's. This has a nice side effect of not trashing
448 * any register locations that might be used by something else.
450 * XXX - note that we probably should be probing the address
451 * space for the on-board RAM instead.
454 for (i
= 0; i
< (sizeof (seagate_bases
) / sizeof (unsigned int)); ++i
)
456 for (j
= 0; !base_address
&& j
< NUM_SIGNATURES
; ++j
)
457 if (check_signature (seagate_bases
[i
] + signatures
[j
].offset
,
458 signatures
[j
].signature
, signatures
[j
].length
))
460 base_address
= seagate_bases
[i
];
461 controller_type
= signatures
[j
].type
;
463 #endif /* OVERRIDE */
464 } /* (! controller_type) */
466 tpnt
->this_id
= (controller_type
== SEAGATE
) ? 7 : 6;
467 tpnt
->name
= (controller_type
== SEAGATE
) ? ST0X_ID_STR
: FD_ID_STR
;
470 DANY ("ST0x / TMC-8xx not detected.\n");
474 st0x_cr_sr
= base_address
+ (controller_type
== SEAGATE
? 0x1a00 : 0x1c00);
475 st0x_dr
= st0x_cr_sr
+ 0x200;
477 DANY ("%s detected. Base address = %x, cr = %x, dr = %x\n",
478 tpnt
->name
, base_address
, st0x_cr_sr
, st0x_dr
);
481 * At all times, we will use IRQ 5. Should also check for IRQ3 if we
482 * loose our first interrupt.
484 instance
= scsi_register (tpnt
, 0);
485 hostno
= instance
->host_no
;
486 if (request_irq (irq
, do_seagate_reconnect_intr
, SA_INTERRUPT
,
487 (controller_type
== SEAGATE
) ? "seagate" : "tmc-8xx", NULL
)) {
488 printk ("scsi%d : unable to allocate IRQ%d\n", hostno
, irq
);
492 instance
->io_port
= base_address
;
494 printk( "Calibrating borken timer... " );
496 printk( " %d cycles per transfer\n", borken_calibration
);
499 printk( "This is one second... " );
502 ULOOP( 1*1000*1000 ) {
503 volatile int x
= STATUS
;
508 printk ("done, %s options:"
527 #ifdef SEAGATE_USE_ASM
543 const char *seagate_st0x_info (struct Scsi_Host
*shpnt
)
545 static char buffer
[64];
547 sprintf (buffer
, "%s at irq %d, address 0x%05X",
548 (controller_type
== SEAGATE
) ? ST0X_ID_STR
: FD_ID_STR
,
554 * These are our saved pointers for the outstanding command that is
555 * waiting for a reconnect
558 static unsigned char current_target
, current_lun
;
559 static unsigned char *current_cmnd
, *current_data
;
560 static int current_nobuffs
;
561 static struct scatterlist
*current_buffer
;
562 static int current_bufflen
;
566 * linked_connected indicates whether or not we are currently connected to
567 * linked_target, linked_lun and in an INFORMATION TRANSFER phase,
568 * using linked commands.
571 static int linked_connected
= 0;
572 static unsigned char linked_target
, linked_lun
;
575 static void (*done_fn
) (Scsi_Cmnd
*) = NULL
;
576 static Scsi_Cmnd
*SCint
= NULL
;
579 * These control whether or not disconnect / reconnect will be attempted,
580 * or are being attempted.
583 #define NO_RECONNECT 0
584 #define RECONNECT_NOW 1
585 #define CAN_RECONNECT 2
588 * LINKED_RIGHT indicates that we are currently connected to the correct target
589 * for this command, LINKED_WRONG indicates that we are connected to the wrong
590 * target. Note that these imply CAN_RECONNECT and require defined(LINKED).
593 #define LINKED_RIGHT 3
594 #define LINKED_WRONG 4
597 * This determines if we are expecting to reconnect or not.
600 static int should_reconnect
= 0;
603 * The seagate_reconnect_intr routine is called when a target reselects the
604 * host adapter. This occurs on the interrupt triggered by the target
608 static void do_seagate_reconnect_intr (int irq
, void *dev_id
, struct pt_regs
*regs
)
612 spin_lock_irqsave(&io_request_lock
, flags
);
613 seagate_reconnect_intr(irq
, dev_id
, regs
);
614 spin_unlock_irqrestore(&io_request_lock
, flags
);
617 static void seagate_reconnect_intr (int irq
, void *dev_id
, struct pt_regs
*regs
)
622 DPRINTK (PHASE_RESELECT
, "scsi%d : seagate_reconnect_intr() called\n", hostno
);
624 if (!should_reconnect
)
625 printk ("scsi%d: unexpected interrupt.\n", hostno
);
628 should_reconnect
= 0;
630 DPRINTK (PHASE_RESELECT
, "scsi%d : internal_command("
631 "%d, %08x, %08x, RECONNECT_NOW\n", hostno
,
632 current_target
, current_data
, current_bufflen
);
634 temp
= internal_command (current_target
, current_lun
, current_cmnd
,
635 current_data
, current_bufflen
, RECONNECT_NOW
);
637 if (msg_byte (temp
) != DISCONNECT
)
641 DPRINTK (PHASE_RESELECT
, "scsi%d : done_fn(%d,%08x)", hostno
,
644 panic ("SCint == NULL in seagate");
647 SCtmp
->result
= temp
;
651 printk ("done_fn() not defined.\n");
657 * The seagate_st0x_queue_command() function provides a queued interface
658 * to the seagate SCSI driver. Basically, it just passes control onto the
659 * seagate_command() function, after fixing it so that the done_fn()
660 * is set to the one passed to the function. We have to be very careful,
661 * because there are some commands on some devices that do not disconnect,
662 * and if we simply call the done_fn when the command is done then another
663 * command is started and queue_command is called again... We end up
664 * overflowing the kernel stack, and this tends not to be such a good idea.
667 static int recursion_depth
= 0;
669 int seagate_st0x_queue_command (Scsi_Cmnd
* SCpnt
, void (*done
) (Scsi_Cmnd
*))
671 int result
, reconnect
;
674 DANY( "seagate: que_command" );
676 current_target
= SCpnt
->target
;
677 current_lun
= SCpnt
->lun
;
678 (const void *) current_cmnd
= SCpnt
->cmnd
;
679 current_data
= (unsigned char *) SCpnt
->request_buffer
;
680 current_bufflen
= SCpnt
->request_bufflen
;
682 if (recursion_depth
) return 0;
688 * Set linked command bit in control field of SCSI command.
691 current_cmnd
[SCpnt
->cmd_len
] |= 0x01;
692 if (linked_connected
)
694 DPRINTK (DEBUG_LINKED
,
695 "scsi%d : using linked commands, current I_T_L nexus is ", hostno
);
696 if ((linked_target
== current_target
) && (linked_lun
== current_lun
))
698 DPRINTK (DEBUG_LINKED
, "correct\n");
699 reconnect
= LINKED_RIGHT
;
703 DPRINTK (DEBUG_LINKED
, "incorrect\n");
704 reconnect
= LINKED_WRONG
;
709 reconnect
= CAN_RECONNECT
;
711 result
= internal_command (SCint
->target
, SCint
->lun
, SCint
->cmnd
,
712 SCint
->request_buffer
, SCint
->request_bufflen
, reconnect
);
713 if (msg_byte (result
) == DISCONNECT
) break;
716 SCtmp
->result
= result
;
724 int seagate_st0x_command (Scsi_Cmnd
* SCpnt
)
726 return internal_command (SCpnt
->target
, SCpnt
->lun
, SCpnt
->cmnd
,
727 SCpnt
->request_buffer
, SCpnt
->request_bufflen
,
731 static int internal_command (unsigned char target
, unsigned char lun
,
732 const void *cmnd
, void *buff
, int bufflen
, int reselect
)
734 unsigned char *data
= NULL
;
735 struct scatterlist
*buffer
= NULL
;
736 int clock
, temp
, nobuffs
= 0, done
= 0, len
= 0;
740 int transfered
= 0, phase
= 0, newphase
;
743 register unsigned char status_read
;
744 unsigned char tmp_data
, tmp_control
, status
= 0, message
= 0;
746 unsigned transfersize
= 0, underflow
= 0;
749 int borken
= (int) SCint
->device
->borken
; /* Does the current target require
756 #if (DEBUG & PRINT_COMMAND)
757 printk ("scsi%d : target = %d, command = ", hostno
, target
);
758 print_command ((unsigned char *) cmnd
);
761 #if (DEBUG & PHASE_RESELECT)
765 printk ("scsi%d : reconnecting\n", hostno
);
769 printk ("scsi%d : connected, can reconnect\n", hostno
);
772 printk ("scsi%d : connected to wrong target, can reconnect\n", hostno
);
776 printk ("scsi%d : allowed to reconnect\n", hostno
);
779 printk ("scsi%d : not allowed to reconnect\n", hostno
);
783 if (target
== (controller_type
== SEAGATE
? 7 : 6))
784 return DID_BAD_TARGET
;
787 * We work it differently depending on if this is is "the first time,"
788 * or a reconnect. If this is a reselect phase, then SEL will
789 * be asserted, and we must skip selection / arbitration phases.
795 DPRINTK ( PHASE_RESELECT
, "scsi%d : phase RESELECT \n", hostno
);
798 * At this point, we should find the logical or of our ID and the original
799 * target's ID on the BUS, with BSY, SEL, and I/O signals asserted.
801 * After ARBITRATION phase is completed, only SEL, BSY, and the
802 * target ID are asserted. A valid initiator ID is not on the bus
803 * until IO is asserted, so we must wait for that.
807 if ((temp
& STAT_IO
) && !(temp
& STAT_BSY
))
811 DPRINTK (PHASE_RESELECT
,
812 "scsi%d : RESELECT timed out while waiting for IO .\n", hostno
);
813 return (DID_BAD_INTR
<< 16);
818 * After I/O is asserted by the target, we can read our ID and its
822 if (!((temp
= DATA
) & (controller_type
== SEAGATE
? 0x80 : 0x40)))
824 DPRINTK (PHASE_RESELECT
,
825 "scsi%d : detected reconnect request to different target.\n"
826 "\tData bus = %d\n", hostno
, temp
);
827 return (DID_BAD_INTR
<< 16);
830 if (!(temp
& (1 << current_target
)))
832 printk ("scsi%d : Unexpected reselect interrupt. Data bus = %d\n",
834 return (DID_BAD_INTR
<< 16);
837 buffer
= current_buffer
;
838 cmnd
= current_cmnd
; /* WDE add */
839 data
= current_data
; /* WDE add */
840 len
= current_bufflen
; /* WDE add */
841 nobuffs
= current_nobuffs
;
844 * We have determined that we have been selected. At this point,
845 * we must respond to the reselection by asserting BSY ourselves
849 WRITE_CONTROL (BASE_CMD
| CMD_DRVR_ENABLE
| CMD_BSY
);
851 WRITE_CONTROL (BASE_CMD
| CMD_BSY
);
855 * The target will drop SEL, and raise BSY, at which time we must drop
860 if (!(STATUS
& STAT_SEL
)) break;
862 WRITE_CONTROL (BASE_CMD
| CMD_INTR
);
863 DPRINTK (PHASE_RESELECT
,
864 "scsi%d : RESELECT timed out while waiting for SEL.\n", hostno
);
865 return (DID_BAD_INTR
<< 16);
869 WRITE_CONTROL (BASE_CMD
);
872 * At this point, we have connected with the target and can get
880 * This is a bletcherous hack, just as bad as the Unix #! interpreter stuff.
881 * If it turns out we are using the wrong I_T_L nexus, the easiest way to deal
882 * with it is to go into our INFORMATION TRANSFER PHASE code, send a ABORT
883 * message on MESSAGE OUT phase, and then loop back to here.
890 DPRINTK (PHASE_BUS_FREE
, "scsi%d : phase = BUS FREE \n", hostno
);
895 * On entry, we make sure that the BUS is in a BUS FREE
896 * phase, by insuring that both BSY and SEL are low for
897 * at least one bus settle delay. Several reads help
898 * eliminate wire glitch.
902 #error FIXME: this is broken: we may not use jiffies here - we are under cli(). It will hardlock.
903 clock
= jiffies
+ ST0X_BUS_FREE_DELAY
;
905 while (((STATUS
| STATUS
| STATUS
) &
906 (STAT_BSY
| STAT_SEL
)) &&
907 (!st0x_aborted
) && (jiffies
< clock
));
910 return retcode (DID_BUS_BUSY
);
911 else if (st0x_aborted
)
912 return retcode (st0x_aborted
);
915 DPRINTK (PHASE_SELECTION
, "scsi%d : phase = SELECTION\n", hostno
);
917 clock
= jiffies
+ ST0X_SELECTION_DELAY
;
920 * Arbitration/selection procedure :
922 * 2. Write HOST adapter address bit
923 * 3. Set start arbitration.
924 * 4. We get either ARBITRATION COMPLETE or SELECT at this
926 * 5. OR our ID and targets on bus.
927 * 6. Enable SCSI drivers and asserted SEL and ATTN
934 WRITE_DATA ((controller_type
== SEAGATE
) ? 0x80 : 0x40);
935 WRITE_CONTROL (CMD_START_ARB
);
936 restore_flags (flags
);
938 ULOOP( ST0X_SELECTION_DELAY
* 10000 ) {
939 status_read
= STATUS
;
940 if (status_read
& STAT_ARB_CMPL
) break;
941 if (st0x_aborted
) /* FIXME: What? We are going to do something even after abort? */
943 if (TIMEOUT
|| (status_read
& STAT_SEL
)) {
944 printk( "scsi%d : arbitration lost or timeout.\n", hostno
);
945 WRITE_CONTROL (BASE_CMD
);
946 return retcode (DID_NO_CONNECT
);
950 DPRINTK (PHASE_SELECTION
, "scsi%d : arbitration complete\n", hostno
);
954 * When the SCSI device decides that we're gawking at it, it will
955 * respond by asserting BUSY on the bus.
957 * Note : the Seagate ST-01/02 product manual says that we should
958 * twiddle the DATA register before the control register. However,
959 * this does not work reliably so we do it the other way around.
961 * Probably could be a problem with arbitration too, we really should
962 * try this with a SCSI protocol or logic analyzer to see what is
965 tmp_data
= (unsigned char) ((1 << target
) | (controller_type
== SEAGATE
? 0x80 : 0x40));
966 tmp_control
= BASE_CMD
| CMD_DRVR_ENABLE
| CMD_SEL
| (reselect
? CMD_ATTN
: 0);
970 #ifdef OLDCNTDATASCEME
972 WRITE_CONTROL (tmp_control
);
973 WRITE_DATA (tmp_data
);
975 WRITE_DATA (tmp_data
);
976 WRITE_CONTROL (tmp_control
);
979 tmp_control
^= CMD_BSY
; /* This is guesswork. What used to be in driver */
980 WRITE_CONTROL (tmp_control
); /* could never work: it sent data into control */
981 WRITE_DATA (tmp_data
); /* register and control info into data. Hopefully */
982 tmp_control
^= CMD_BSY
; /* fixed, but order of first two may be wrong. */
983 WRITE_CONTROL (tmp_control
); /* -- pavel@ucw.cz */
987 restore_flags (flags
);
992 * If we have been aborted, and we have a command in progress, IE the
993 * target still has BSY asserted, then we will reset the bus, and
994 * notify the midlevel driver to expect sense.
997 WRITE_CONTROL (BASE_CMD
);
998 if (STATUS
& STAT_BSY
) {
999 printk ("scsi%d : BST asserted after we've been aborted.\n", hostno
);
1000 seagate_st0x_reset (NULL
, 0);
1001 return retcode (DID_RESET
);
1003 return retcode (st0x_aborted
);
1005 if (STATUS
& STAT_BSY
) break;
1007 DPRINTK (PHASE_SELECTION
, "scsi%d : NO CONNECT with target %d, stat = %x \n",
1008 hostno
, target
, STATUS
);
1009 return retcode (DID_NO_CONNECT
);
1013 /* Establish current pointers. Take into account scatter / gather */
1015 if ((nobuffs
= SCint
->use_sg
))
1017 #if (DEBUG & DEBUG_SG)
1021 printk ("scsi%d : scatter gather requested, using %d buffers.\n",
1023 for (i
= 0; i
< nobuffs
; ++i
)
1024 printk ("scsi%d : buffer %d address = %08x length = %d\n",
1025 hostno
, i
, buffer
[i
].address
, buffer
[i
].length
);
1029 buffer
= (struct scatterlist
*) SCint
->buffer
;
1030 len
= buffer
->length
;
1031 data
= (unsigned char *) buffer
->address
;
1035 DPRINTK (DEBUG_SG
, "scsi%d : scatter gather not requested.\n", hostno
);
1037 len
= SCint
->request_bufflen
;
1038 data
= (unsigned char *) SCint
->request_buffer
;
1041 DPRINTK (PHASE_DATAIN
| PHASE_DATAOUT
, "scsi%d : len = %d\n", hostno
, len
);
1050 } /* end of switch(reselect) */
1053 * There are several conditions under which we wish to send a message :
1054 * 1. When we are allowing disconnect / reconnect, and need to establish
1055 * the I_T_L nexus via an IDENTIFY with the DiscPriv bit set.
1057 * 2. When we are doing linked commands, are have the wrong I_T_L nexus
1058 * established and want to send an ABORT message.
1061 /* GCC does not like an ifdef inside a macro, so do it the hard way. */
1063 WRITE_CONTROL (BASE_CMD
| CMD_DRVR_ENABLE
|
1064 (((reselect
== CAN_RECONNECT
)
1065 || (reselect
== LINKED_WRONG
)
1068 WRITE_CONTROL (BASE_CMD
| CMD_DRVR_ENABLE
|
1069 (((reselect
== CAN_RECONNECT
)
1074 * INFORMATION TRANSFER PHASE
1076 * The nasty looking read / write inline assembler loops we use for
1077 * DATAIN and DATAOUT phases are approximately 4-5 times as fast as
1078 * the 'C' versions - since we're moving 1024 bytes of data, this
1081 * SJT: The nasty-looking assembler is gone, so it's slower.
1085 DPRINTK (PHASE_ETC
, "scsi%d : phase = INFORMATION TRANSFER\n", hostno
);
1088 transfersize
= SCint
->transfersize
;
1089 underflow
= SCint
->underflow
;
1092 * Now, we poll the device for status information,
1093 * and handle any requests it makes. Note that since we are unsure of
1094 * how much data will be flowing across the system, etc and cannot
1095 * make reasonable timeouts, that we will instead have the midlevel
1096 * driver handle any timeouts that occur in this phase.
1099 while (((status_read
= STATUS
) & STAT_BSY
) && !st0x_aborted
&& !done
)
1102 if (status_read
& STAT_PARITY
)
1104 printk ("scsi%d : got parity error\n", hostno
);
1105 st0x_aborted
= DID_PARITY
;
1109 if (status_read
& STAT_REQ
)
1111 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
1112 if ((newphase
= (status_read
& REQ_MASK
)) != phase
)
1118 printk ("scsi%d : phase = DATA OUT\n", hostno
);
1121 printk ("scsi%d : phase = DATA IN\n", hostno
);
1124 printk ("scsi%d : phase = COMMAND OUT\n", hostno
);
1127 printk ("scsi%d : phase = STATUS IN\n", hostno
);
1130 printk ("scsi%d : phase = MESSAGE OUT\n", hostno
);
1133 printk ("scsi%d : phase = MESSAGE IN\n", hostno
);
1136 printk ("scsi%d : phase = UNKNOWN\n", hostno
);
1137 st0x_aborted
= DID_ERROR
;
1141 switch (status_read
& REQ_MASK
)
1145 * If we are in fast mode, then we simply splat the data out
1146 * in word-sized chunks as fast as we can.
1152 printk ("scsi%d: underflow to target %d lun %d \n", hostno
, target
, lun
);
1153 st0x_aborted
= DID_ERROR
;
1159 if (fast
&& transfersize
&& !(len
% transfersize
)
1160 && (len
>= transfersize
)
1162 && !(transfersize
% 4)
1166 DPRINTK (DEBUG_FAST
,
1167 "scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
1168 " len = %d, data = %08x\n",
1169 hostno
, SCint
->underflow
, SCint
->transfersize
, len
, data
);
1171 /* SJT: Start. Fast Write */
1172 #ifdef SEAGATE_USE_ASM
1179 "movl %%eax, (%%edi)\n\t"
1183 "movb %%al, (%%edi)\n\t"
1187 /* input */ : "D" (phys_to_virt(st0x_dr
)), "S" (data
), "c" (SCint
->transfersize
)
1188 /* clobbered */ : "eax", "ecx", "esi" );
1189 #else /* SEAGATE_USE_ASM */
1192 unsigned int *iop
= phys_to_virt (st0x_dr
);
1193 const unsigned int *dp
= (unsigned int *) data
;
1194 int xferlen
= transfersize
>> 2;
1196 unsigned char *iop
= phys_to_virt (st0x_dr
);
1197 const unsigned char *dp
= data
;
1198 int xferlen
= transfersize
;
1200 for (; xferlen
; --xferlen
)
1203 #endif /* SEAGATE_USE_ASM */
1205 len
-= transfersize
;
1206 data
+= transfersize
;
1207 DPRINTK (DEBUG_FAST
,
1208 "scsi%d : FAST transfer complete len = %d data = %08x\n",
1214 * We loop as long as we are in a data out phase, there is data to send,
1215 * and BSY is still active.
1218 /* SJT: Start. Slow Write. */
1219 #ifdef SEAGATE_USE_ASM
1221 * We loop as long as we are in a data out phase, there is data to send,
1222 * and BSY is still active.
1224 /* Local variables : len = ecx , data = esi,
1225 st0x_cr_sr = ebx, st0x_dr = edi
1228 /* Test for any data here at all. */
1229 "orl %%ecx, %%ecx\n\t"
1232 /* "movl " SYMBOL_NAME_STR(st0x_cr_sr) ", %%ebx\n\t" */
1233 /* "movl " SYMBOL_NAME_STR(st0x_dr) ", %%edi\n\t" */
1235 "movb (%%ebx), %%al\n\t"
1239 /* Test for data out phase - STATUS & REQ_MASK should be
1240 REQ_DATAOUT, which is 0. */
1241 "test $0xe, %%al\n\t"
1244 "test $0x10, %%al\n\t"
1247 "movb %%al, (%%edi)\n\t"
1250 /* output */ : "=S" (data
), "=c" (len
)
1251 /* input */ : "0" (data
), "1" (len
), "b" (phys_to_virt(st0x_cr_sr
)), "D" (phys_to_virt(st0x_dr
))
1252 /* clobbered */ : "eax", "ebx", "edi");
1253 #else /* SEAGATE_USE_ASM */
1259 if (!(stat
& STAT_BSY
) || ((stat
& REQ_MASK
) != REQ_DATAOUT
))
1261 if (stat
& STAT_REQ
)
1263 WRITE_DATA (*data
++);
1267 #endif /* SEAGATE_USE_ASM */
1271 if (!len
&& nobuffs
)
1275 len
= buffer
->length
;
1276 data
= (unsigned char *) buffer
->address
;
1278 "scsi%d : next scatter-gather buffer len = %d address = %08x\n",
1287 #if (DEBUG & (PHASE_DATAIN))
1291 len
&& (STATUS
& (REQ_MASK
| STAT_REQ
)) == (REQ_DATAIN
|
1298 #if (DEBUG & (PHASE_DATAIN))
1305 if (fast
&& transfersize
&& !(len
% transfersize
) &&
1306 (len
>= transfersize
)
1308 && !(transfersize
% 4)
1312 DPRINTK (DEBUG_FAST
,
1313 "scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
1314 " len = %d, data = %08x\n",
1315 hostno
, SCint
->underflow
, SCint
->transfersize
, len
, data
);
1317 /* SJT: Start. Fast Read */
1318 #ifdef SEAGATE_USE_ASM
1324 "movl (%%esi), %%eax\n\t"
1328 "movb (%%esi), %%al\n\t"
1333 /* input */ : "S" (phys_to_virt(st0x_dr
)), "D" (data
), "c" (SCint
->transfersize
)
1334 /* clobbered */ : "eax", "ecx", "edi");
1335 #else /* SEAGATE_USE_ASM */
1338 const unsigned int *iop
= phys_to_virt (st0x_dr
);
1339 unsigned int *dp
= (unsigned int *) data
;
1340 int xferlen
= len
>> 2;
1342 const unsigned char *iop
= phys_to_virt (st0x_dr
);
1343 unsigned char *dp
= data
;
1346 for (; xferlen
; --xferlen
)
1349 #endif /* SEAGATE_USE_ASM */
1351 len
-= transfersize
;
1352 data
+= transfersize
;
1353 #if (DEBUG & PHASE_DATAIN)
1354 printk ("scsi%d: transfered += %d\n", hostno
, transfersize
);
1355 transfered
+= transfersize
;
1358 DPRINTK (DEBUG_FAST
,
1359 "scsi%d : FAST transfer complete len = %d data = %08x\n",
1365 #if (DEBUG & PHASE_DATAIN)
1366 printk ("scsi%d: transfered += %d\n", hostno
, len
);
1367 transfered
+= len
; /* Assume we'll transfer it all, then
1368 subtract what we *didn't* transfer */
1372 * We loop as long as we are in a data in phase, there is room to read,
1373 * and BSY is still active
1377 #ifdef SEAGATE_USE_ASM
1379 * We loop as long as we are in a data in phase, there is room to read,
1380 * and BSY is still active
1382 /* Local variables : ecx = len, edi = data
1383 esi = st0x_cr_sr, ebx = st0x_dr */
1385 /* Test for room to read */
1386 "orl %%ecx, %%ecx\n\t"
1389 /* "movl " SYMBOL_NAME_STR(st0x_cr_sr) ", %%esi\n\t" */
1390 /* "movl " SYMBOL_NAME_STR(st0x_dr) ", %%ebx\n\t" */
1392 "movb (%%esi), %%al\n\t"
1396 /* Test for data in phase - STATUS & REQ_MASK should be REQ_DATAIN,
1397 = STAT_IO, which is 4. */
1398 "movb $0xe, %%ah\n\t"
1399 "andb %%al, %%ah\n\t"
1400 "cmpb $0x04, %%ah\n\t"
1403 "test $0x10, %%al\n\t"
1405 "movb (%%ebx), %%al\n\t"
1409 /* output */ : "=D" (data
), "=c" (len
)
1410 /* input */ : "0" (data
), "1" (len
), "S" (phys_to_virt(st0x_cr_sr
)), "b" (phys_to_virt(st0x_dr
))
1411 /* clobbered */ : "eax","ebx", "esi");
1412 #else /* SEAGATE_USE_ASM */
1418 if (!(stat
& STAT_BSY
) || ((stat
& REQ_MASK
) != REQ_DATAIN
))
1420 if (stat
& STAT_REQ
)
1426 #endif /* SEAGATE_USE_ASM */
1428 #if (DEBUG & PHASE_DATAIN)
1429 printk ("scsi%d: transfered -= %d\n", hostno
, len
);
1430 transfered
-= len
; /* Since we assumed all of Len got *
1431 transfered, correct our mistake */
1435 if (!len
&& nobuffs
)
1439 len
= buffer
->length
;
1440 data
= (unsigned char *) buffer
->address
;
1442 "scsi%d : next scatter-gather buffer len = %d address = %08x\n",
1449 while (((status_read
= STATUS
) & STAT_BSY
) &&
1450 ((status_read
& REQ_MASK
) == REQ_CMDOUT
))
1451 if (status_read
& STAT_REQ
)
1453 WRITE_DATA (*(const unsigned char *) cmnd
);
1454 cmnd
= 1 + (const unsigned char *) cmnd
;
1468 * We can only have sent a MSG OUT if we requested to do this
1469 * by raising ATTN. So, we must drop ATTN.
1472 WRITE_CONTROL (BASE_CMD
| CMD_DRVR_ENABLE
);
1474 * If we are reconnecting, then we must send an IDENTIFY message in
1475 * response to MSGOUT.
1480 WRITE_DATA (IDENTIFY (1, lun
));
1482 DPRINTK (PHASE_RESELECT
| PHASE_MSGOUT
, "scsi%d : sent IDENTIFY message.\n", hostno
);
1487 linked_connected
= 0;
1488 reselect
= CAN_RECONNECT
;
1490 DPRINTK (PHASE_MSGOUT
| DEBUG_LINKED
,
1491 "scsi%d : sent ABORT message to cancel incorrect I_T_L nexus.\n", hostno
);
1493 DPRINTK (DEBUG_LINKED
, "correct\n");
1496 printk ("scsi%d : target %d requested MSGOUT, sent NOP message.\n", hostno
, target
);
1501 switch (message
= DATA
)
1504 DANY ("seagate: deciding to disconnect\n");
1505 should_reconnect
= 1;
1506 current_data
= data
; /* WDE add */
1507 current_buffer
= buffer
;
1508 current_bufflen
= len
; /* WDE add */
1509 current_nobuffs
= nobuffs
;
1511 linked_connected
= 0;
1514 DPRINTK ((PHASE_RESELECT
| PHASE_MSGIN
), "scsi%d : disconnected.\n", hostno
);
1518 case LINKED_CMD_COMPLETE
:
1519 case LINKED_FLG_CMD_COMPLETE
:
1521 case COMMAND_COMPLETE
:
1523 * Note : we should check for underflow here.
1525 DPRINTK (PHASE_MSGIN
, "scsi%d : command complete.\n", hostno
);
1529 DPRINTK (PHASE_MSGIN
, "scsi%d : abort message.\n", hostno
);
1533 current_buffer
= buffer
;
1534 current_bufflen
= len
; /* WDE add */
1535 current_data
= data
; /* WDE mod */
1536 current_nobuffs
= nobuffs
;
1537 DPRINTK (PHASE_MSGIN
, "scsi%d : pointers saved.\n", hostno
);
1539 case RESTORE_POINTERS
:
1540 buffer
= current_buffer
;
1541 cmnd
= current_cmnd
;
1542 data
= current_data
; /* WDE mod */
1543 len
= current_bufflen
;
1544 nobuffs
= current_nobuffs
;
1545 DPRINTK (PHASE_MSGIN
, "scsi%d : pointers restored.\n", hostno
);
1550 * IDENTIFY distinguishes itself from the other messages by setting the
1551 * high byte. [FIXME: should not this read "the high bit"? - pavel@ucw.cz]
1553 * Note : we need to handle at least one outstanding command per LUN,
1554 * and need to hash the SCSI command for that I_T_L nexus based on the
1555 * known ID (at this point) and LUN.
1560 DPRINTK (PHASE_MSGIN
, "scsi%d : IDENTIFY message received from id %d, lun %d.\n",
1561 hostno
, target
, message
& 7);
1567 * We should go into a MESSAGE OUT phase, and send a MESSAGE_REJECT
1568 * if we run into a message that we don't like. The seagate driver
1569 * needs some serious restructuring first though.
1572 DPRINTK (PHASE_MSGIN
,
1573 "scsi%d : unknown message %d from target %d.\n", hostno
, message
, target
);
1579 printk ("scsi%d : unknown phase.\n", hostno
);
1580 st0x_aborted
= DID_ERROR
;
1581 } /* end of switch (status_read &
1586 * I really don't care to deal with borken devices in each single
1587 * byte transfer case (ie, message in, message out, status), so
1588 * I'll do the wait here if necessary.
1594 } /* if(status_read & STAT_REQ) ends */
1595 } /* while(((status_read = STATUS)...)
1598 DPRINTK (PHASE_DATAIN
| PHASE_DATAOUT
| PHASE_EXIT
,
1599 "scsi%d : Transfered %d bytes\n", hostno
, transfered
);
1601 #if (DEBUG & PHASE_EXIT)
1602 #if 0 /* Doesn't work for scatter/gather */
1603 printk ("Buffer : \n");
1604 for (i
= 0; i
< 20; ++i
)
1605 printk ("%02x ", ((unsigned char *) data
)[i
]); /* WDE mod */
1608 printk ("scsi%d : status = ", hostno
);
1609 print_status (status
);
1610 printk ("message = %02x\n", message
);
1613 /* We shouldn't reach this until *after* BSY has been deasserted */
1619 * Fix the message byte so that unsuspecting high level drivers don't
1620 * puke when they see a LINKED COMMAND message in place of the COMMAND
1621 * COMPLETE they may be expecting. Shouldn't be necessary, but it's
1622 * better to be on the safe side.
1624 * A non LINKED* message byte will indicate that the command completed,
1625 * and we are now disconnected.
1630 case LINKED_CMD_COMPLETE
:
1631 case LINKED_FLG_CMD_COMPLETE
:
1632 message
= COMMAND_COMPLETE
;
1633 linked_target
= current_target
;
1634 linked_lun
= current_lun
;
1635 linked_connected
= 1;
1636 DPRINTK (DEBUG_LINKED
, "scsi%d : keeping I_T_L nexus established"
1637 "for linked command.\n", hostno
);
1638 /* We also will need to adjust status to accommodate intermediate
1640 if ((status
== INTERMEDIATE_GOOD
) ||
1641 (status
== INTERMEDIATE_C_GOOD
))
1646 * We should also handle what are "normal" termination messages
1647 * here (ABORT, BUS_DEVICE_RESET?, and COMMAND_COMPLETE individually,
1648 * and flake if things aren't right.
1651 DPRINTK (DEBUG_LINKED
, "scsi%d : closing I_T_L nexus.\n", hostno
);
1652 linked_connected
= 0;
1657 if (should_reconnect
)
1659 DPRINTK (PHASE_RESELECT
, "scsi%d : exiting seagate_st0x_queue_command()"
1660 "with reconnect enabled.\n", hostno
);
1661 WRITE_CONTROL (BASE_CMD
| CMD_INTR
);
1664 WRITE_CONTROL (BASE_CMD
);
1666 return retcode (st0x_aborted
);
1667 } /* end of internal_command */
1669 int seagate_st0x_abort (Scsi_Cmnd
* SCpnt
)
1671 st0x_aborted
= DID_ABORT
;
1672 return SCSI_ABORT_PENDING
;
1678 * the seagate_st0x_reset function resets the SCSI bus
1681 int seagate_st0x_reset (Scsi_Cmnd
* SCpnt
, unsigned int reset_flags
)
1683 /* No timeouts - this command is going to fail because it was reset. */
1684 DANY ("scsi%d: Reseting bus... ", hostno
);
1686 /* assert RESET signal on SCSI bus. */
1687 WRITE_CONTROL (BASE_CMD
| CMD_RST
);
1691 WRITE_CONTROL (BASE_CMD
);
1692 st0x_aborted
= DID_RESET
;
1695 return SCSI_RESET_WAKEUP
;
1699 int seagate_st0x_biosparam (Disk
* disk
, kdev_t dev
, int *ip
)
1701 unsigned char buf
[256 + sizeof (Scsi_Ioctl_Command
)],
1702 cmd
[6], *data
, *page
;
1703 Scsi_Ioctl_Command
*sic
= (Scsi_Ioctl_Command
*) buf
;
1704 int result
, formatted_sectors
, total_sectors
;
1705 int cylinders
, heads
, sectors
;
1709 * Only SCSI-I CCS drives and later implement the necessary mode sense
1713 if (disk
->device
->scsi_level
< 2)
1718 cmd
[0] = MODE_SENSE
;
1719 cmd
[1] = (disk
->device
->lun
<< 5) & 0xe5;
1720 cmd
[2] = 0x04; /* Read page 4, rigid disk geometry
1721 page current values */
1727 * We are transferring 0 bytes in the out direction, and expect to get back
1728 * 24 bytes for each mode page.
1733 memcpy (data
, cmd
, 6);
1735 if (!(result
= kernel_scsi_ioctl (disk
->device
, SCSI_IOCTL_SEND_COMMAND
,
1739 * The mode page lies beyond the MODE SENSE header, with length 4, and
1740 * the BLOCK DESCRIPTOR, with length header[3].
1742 page
= data
+ 4 + data
[3];
1743 heads
= (int) page
[5];
1744 cylinders
= (page
[2] << 16) | (page
[3] << 8) | page
[4];
1746 cmd
[2] = 0x03; /* Read page 3, format page current
1748 memcpy (data
, cmd
, 6);
1750 if (!(result
= kernel_scsi_ioctl (disk
->device
, SCSI_IOCTL_SEND_COMMAND
,
1753 page
= data
+ 4 + data
[3];
1754 sectors
= (page
[10] << 8) | page
[11];
1756 * Get the total number of formatted sectors from the block descriptor,
1757 * so we can tell how many are being used for alternates.
1759 formatted_sectors
= (data
[4 + 1] << 16) | (data
[4 + 2] << 8)
1762 total_sectors
= (heads
* cylinders
* sectors
);
1765 * Adjust the real geometry by subtracting
1766 * (spare sectors / (heads * tracks)) cylinders from the number of cylinders.
1768 * It appears that the CE cylinder CAN be a partial cylinder.
1771 printk ("scsi%d : heads = %d cylinders = %d sectors = %d total = %d formatted = %d\n",
1772 hostno
, heads
, cylinders
, sectors
, total_sectors
,
1775 if (!heads
|| !sectors
|| !cylinders
)
1778 cylinders
-= ((total_sectors
- formatted_sectors
) / (heads
* sectors
));
1781 * Now, we need to do a sanity check on the geometry to see if it is
1782 * BIOS compatible. The maximum BIOS geometry is 1024 cylinders *
1783 * 256 heads * 64 sectors.
1786 if ((cylinders
> 1024) || (sectors
> 64))
1788 /* The Seagate's seem to have some mapping. Multiply
1789 heads*sectors*cyl to get capacity. Then start rounding down.
1791 capacity
= heads
* sectors
* cylinders
;
1793 /* Old MFM Drives use this, so does the Seagate */
1796 capacity
= capacity
/ sectors
;
1797 while (cylinders
> 1024)
1799 heads
*= 2; /* For some reason, they go in
1801 cylinders
= capacity
/ heads
;
1808 * There should be an alternate mapping for things the seagate doesn't
1809 * understand, but I couldn't say what it is with reasonable certainty.
1818 /* Eventually this will go into an include file, but this will be later */
1819 Scsi_Host_Template driver_template
= SEAGATE_ST0X
;
1821 #include "scsi_module.c"