root/drivers/scsi/seagate.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. st0x_setup
  2. tmc8xx_setup
  3. borken_init
  4. borken_wait
  5. seagate_st0x_detect
  6. seagate_st0x_info
  7. seagate_reconnect_intr
  8. seagate_st0x_queue_command
  9. seagate_st0x_command
  10. internal_command
  11. seagate_st0x_abort
  12. seagate_st0x_reset
  13. seagate_st0x_biosparam

   1 /*
   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
   5  *
   6  *              Drew Eckhardt 
   7  *
   8  *      <drew@colorado.edu>
   9  *
  10  *      Note : TMC-880 boards don't work because they have two bits in 
  11  *              the status register flipped, I'll fix this "RSN"
  12  *
  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.
  15  */
  16 
  17 /*
  18  * Configuration : 
  19  * To use without BIOS -DOVERRIDE=base_address -DCONTROLLER=FD or SEAGATE
  20  * -DIRQ will override the default of 5.
  21  * Note: You can now set these options from the kernel's "command line".
  22  * The syntax is:
  23  *
  24  *     st0x=ADDRESS,IRQ                (for a Seagate controller)
  25  * or:
  26  *     tmc8xx=ADDRESS,IRQ              (for a TMC-8xx or TMC-950 controller)
  27  * eg:
  28  *     tmc8xx=0xC8000,15
  29  *
  30  * will configure the driver for a TMC-8xx style controller using IRQ 15
  31  * with a base address of 0xC8000.
  32  * 
  33  * -DFAST or -DFAST32 will use blind transfers where possible
  34  *
  35  * -DARBITRATE will cause the host adapter to arbitrate for the 
  36  *      bus for better SCSI-II compatibility, 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.
  40  *
  41  * -DSLOW_HANDSHAKE will allow compatibility with broken devices that don't 
  42  *      handshake fast enough (ie, some CD ROM's) for the Seagate
  43  *      code.
  44  *
  45  * -DSLOW_RATE=x, x some number will let you specify a default 
  46  *      transfer rate if handshaking isn't working correctly.
  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           /* Linked commands are currently broken ! */
  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                                                 set if arbitration has finished and we are 
  91                                                 in some command phase.
  92                                         */
  93 
  94 static void *base_address = NULL;       /*
  95                                                 Where the card ROM starts,
  96                                                 used to calculate memory mapped
  97                                                 register location.
  98                                         */
  99 #ifdef notyet
 100 static volatile int abort_confirm = 0;
 101 #endif
 102 
 103 static volatile void *st0x_cr_sr;       /*
 104                                                 control register write,
 105                                                 status register read.
 106                                                 256 bytes in length.
 107 
 108                                                 Read is status of SCSI BUS,
 109                                                 as per STAT masks.
 110 
 111                                         */
 112 
 113 
 114 static volatile void *st0x_dr;         /*
 115                                                 data register, read write
 116                                                 256 bytes in length.
 117                                         */
 118 
 119 
 120 static volatile int st0x_aborted=0;     /* 
 121                                                 set when we are aborted, ie by a time out, etc.
 122                                         */
 123 
 124 static unsigned char controller_type = 0; /* set to SEAGATE for ST0x boards or FD for TMC-8xx boards */
 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) {
     /* [previous][next][first][last][top][bottom][index][help] */
 133     controller_type = SEAGATE;
 134     base_address = (void *) ints[1];
 135     irq = ints[2];
 136 }
 137 
 138 void tmc8xx_setup (char *str, int *ints) {
     /* [previous][next][first][last][top][bottom][index][help] */
 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  * The following two lines are NOT mistakes.  One detects ROM revision 
 165  * 3.0.0, the other 3.2.  Since seagate has only one type of SCSI adapter, 
 166  * and this is not going to change, the "SEAGATE" and "SCSI" together
 167  * are probably "good enough"
 168  */
 169 
 170 {"SEAGATE SCSI BIOS ",16, 17, SEAGATE},
 171 {"SEAGATE SCSI BIOS ",17, 17, SEAGATE},
 172 
 173 /*
 174  * However, future domain makes several incompatible SCSI boards, so specific
 175  * signatures must be used.
 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 /* CONFIG_SCSI_SEAGATE */
 186 }
 187 ;
 188 
 189 #define NUM_SIGNATURES (sizeof(signatures) / sizeof(Signature))
 190 #endif /* n OVERRIDE */
 191 
 192 /*
 193  * hostno stores the hostnumber, as told to us by the init routine.
 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  * Support for broken devices : 
 206  * The Seagate board has a handshaking problem.  Namely, a lack 
 207  * thereof for slow devices.  You can blast 600K/second through 
 208  * it if you are polling for each byte, more if you do a blind 
 209  * transfer.  In the first case, with a fast device, REQ will 
 210  * transition high-low or high-low-high before your loop restarts 
 211  * and you'll have no problems.  In the second case, the board 
 212  * will insert wait states for up to 13.2 usecs for REQ to 
 213  * transition low->high, and everything will work.
 214  *
 215  * However, there's nothing in the state machine that says 
 216  * you *HAVE* to see a high-low-high set of transitions before
 217  * sending the next byte, and slow things like the Trantor CD ROMS
 218  * will break because of this.
 219  * 
 220  * So, we need to slow things down, which isn't as simple as it 
 221  * seems.  We can't slow things down period, because then people
 222  * who don't recompile their kernels will shoot me for ruining 
 223  * their performance.  We need to do it on a case per case basis.
 224  *
 225  * The best for performance will be to, only for borken devices 
 226  * (this is stored on a per-target basis in the scsi_devices array)
 227  * 
 228  * Wait for a low->high transition before continuing with that 
 229  * transfer.  If we timeout, continue anyways.  We don't need 
 230  * a long timeout, because REQ should only be asserted until the 
 231  * corresponding ACK is received and processed.
 232  *
 233  * Note that we can't use the system timer for this, because of 
 234  * resolution, and we *really* can't use the timer chip since 
 235  * gettimeofday() and the beeper routines use that.  So,
 236  * the best thing for us to do will be to calibrate a timing
 237  * loop in the initialization code using the timer chip before
 238  * gettimeofday() can screw with it.
 239  */
 240 
 241 static int borken_calibration = 0;
 242 static void borken_init (void) {
     /* [previous][next][first][last][top][bottom][index][help] */
 243   register int count = 0, start = jiffies + 1, stop = start + 25;
 244 
 245   while (jiffies < start);
 246   for (;jiffies < stop; ++count);
 247 
 248 /* 
 249  * Ok, we now have a count for .25 seconds.  Convert to a 
 250  * count per second and divide by transfer rate in K.
 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) {
     /* [previous][next][first][last][top][bottom][index][help] */
 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 /* def SLOW_HANDSHAKE */
 274 
 275 int seagate_st0x_detect (Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 276         {
 277      struct Scsi_Host *instance;
 278 #ifndef OVERRIDE
 279         int i,j;
 280 #endif 
 281 
 282 /*
 283  *      First, we try for the manual override.
 284  */
 285 #ifdef DEBUG 
 286         printk("Autodetecting seagate ST0x\n");
 287 #endif
 288         
 289         if (hostno != -1)
 290                 {
 291                 printk ("ERROR : seagate_st0x_detect() called twice.\n");
 292                 return 0;
 293                 }
 294 
 295       /* If the user specified the controller type from the command line,
 296          controller_type will be non-zero, so don't try and detect one */
 297 
 298         if (!controller_type) {
 299 #ifdef OVERRIDE
 300         base_address = (void *) OVERRIDE;
 301 
 302 /* CONTROLLER is used to override controller (SEAGATE or FD). PM: 07/01/93 */
 303 #ifdef CONTROLLER
 304         controller_type = CONTROLLER;
 305 #else
 306 #error Please use -DCONTROLLER=SEAGATE or -DCONTROLLER=FD to override controller type
 307 #endif /* CONTROLLER */
 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 /* OVERRIDE */    
 313 /*
 314  *      To detect this card, we simply look for the signature
 315  *      from the BIOS version notice in all the possible locations
 316  *      of the ROM's.  This has a nice side effect of not trashing
 317  *      any register locations that might be used by something else.
 318  *
 319  * XXX - note that we probably should be probing the address
 320  * space for the on-board RAM instead.
 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 /* OVERRIDE */
 332         } /* (! controller_type) */
 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  *      At all times, we will use IRQ 5.  Should also check for IRQ3 if we 
 346  *      loose our first interrupt.
 347  */
 348                 instance = scsi_register(tpnt, 0);
 349                 hostno = instance->host_no;
 350                 if (request_irq((int) irq, seagate_reconnect_intr, SA_INTERRUPT, "seagate")) {
 351                         printk("scsi%d : unable to allocate IRQ%d\n",
 352                                 hostno, (int) irq);
 353                         return 0;
 354                 }
 355 #ifdef SLOW_HANDSHAKE
 356                 borken_init();
 357 #endif
 358                 
 359                 return 1;
 360                 }
 361         else
 362                 {
 363 #ifdef DEBUG
 364                 printk("ST0x not detected.\n");
 365 #endif
 366                 return 0;
 367                 }
 368         }
 369          
 370 const char *seagate_st0x_info(struct Scsi_Host * shpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 371       static char buffer[256];
 372         sprintf(buffer, "scsi%d : %s at irq %d address %p options :"
 373 #ifdef ARBITRATE
 374 " ARBITRATE"
 375 #endif
 376 #ifdef SLOW_HANDSHAKE
 377 " SLOW_HANDSHAKE"
 378 #endif
 379 #ifdef FAST
 380 #ifdef FAST32
 381 " FAST32"
 382 #else
 383 " FAST"
 384 #endif
 385 #endif
 386  
 387 #ifdef LINKED
 388 " LINKED"
 389 #endif
 390               "\n", hostno, (controller_type == SEAGATE) ? ST0X_ID_STR : 
 391               FD_ID_STR, irq, base_address);
 392         return buffer;
 393 }
 394 
 395 /*
 396  * These are our saved pointers for the outstanding command that is 
 397  * waiting for a reconnect
 398  */
 399 
 400 static unsigned char current_target, current_lun;
 401 static unsigned char *current_cmnd, *current_data;
 402 static int current_nobuffs;
 403 static struct scatterlist *current_buffer;
 404 static int current_bufflen;
 405 
 406 #ifdef LINKED
 407 
 408 /* 
 409  * linked_connected indicates weather or not we are currently connected to 
 410  * linked_target, linked_lun and in an INFORMATION TRANSFER phase,
 411  * using linked commands.
 412  */
 413 
 414 static int linked_connected = 0;
 415 static unsigned char linked_target, linked_lun;
 416 #endif
 417 
 418 
 419 static void (*done_fn)(Scsi_Cmnd *) = NULL;
 420 static Scsi_Cmnd * SCint = NULL;
 421 
 422 /*
 423  * These control whether or not disconnect / reconnect will be attempted,
 424  * or are being attempted.
 425  */
 426 
 427 #define NO_RECONNECT    0
 428 #define RECONNECT_NOW   1
 429 #define CAN_RECONNECT   2
 430 
 431 #ifdef LINKED
 432 
 433 /*
 434  * LINKED_RIGHT indicates that we are currently connected to the correct target
 435  * for this command, LINKED_WRONG indicates that we are connected to the wrong 
 436  * target.  Note that these imply CAN_RECONNECT.
 437  */
 438 
 439 #define LINKED_RIGHT    3
 440 #define LINKED_WRONG    4
 441 #endif
 442 
 443 /*
 444  * This determines if we are expecting to reconnect or not.
 445  */
 446 
 447 static int should_reconnect = 0;
 448 
 449 /*
 450  * The seagate_reconnect_intr routine is called when a target reselects the 
 451  * host adapter.  This occurs on the interrupt triggered by the target 
 452  * asserting SEL.
 453  */
 454 
 455 static void seagate_reconnect_intr(int irq, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 456         {
 457         int temp;
 458         Scsi_Cmnd * SCtmp;
 459 
 460 /* enable all other interrupts. */      
 461         sti();
 462 #if (DEBUG & PHASE_RESELECT)
 463         printk("scsi%d : seagate_reconnect_intr() called\n", hostno);
 464 #endif
 465 
 466         if (!should_reconnect)
 467             printk("scsi%d: unexpected interrupt.\n", hostno);
 468         else {
 469                  should_reconnect = 0;
 470 
 471 #if (DEBUG & PHASE_RESELECT)
 472                 printk("scsi%d : internal_command("
 473                        "%d, %08x, %08x, %d, RECONNECT_NOW\n", hostno, 
 474                         current_target, current_data, current_bufflen);
 475 #endif
 476         
 477                 temp =  internal_command (current_target, current_lun,
 478                         current_cmnd, current_data, current_bufflen,
 479                         RECONNECT_NOW);
 480 
 481                 if (msg_byte(temp) != DISCONNECT) {
 482                         if (done_fn) {
 483 #if (DEBUG & PHASE_RESELECT)
 484                                 printk("scsi%d : done_fn(%d,%08x)", hostno, 
 485                                 hostno, temp);
 486 #endif
 487                                 if(!SCint) panic("SCint == NULL in seagate");
 488                                 SCtmp = SCint;
 489                                 SCint = NULL;
 490                                 SCtmp->result = temp;
 491                                 done_fn (SCtmp);
 492                         } else
 493                                 printk("done_fn() not defined.\n");
 494                         }
 495                 }
 496         } 
 497 
 498 /* 
 499  * The seagate_st0x_queue_command() function provides a queued interface
 500  * to the seagate SCSI driver.  Basically, it just passes control onto the
 501  * seagate_command() function, after fixing it so that the done_fn()
 502  * is set to the one passed to the function.  We have to be very careful,
 503  * because there are some commands on some devices that do not disconnect,
 504  * and if we simply call the done_fn when the command is done then another
 505  * command is started and queue_command is called again...  We end up
 506  * overflowing the kernel stack, and this tends not to be such a good idea.
 507  */
 508 
 509 static int recursion_depth = 0;
 510 
 511 int seagate_st0x_queue_command (Scsi_Cmnd * SCpnt,  void (*done)(Scsi_Cmnd *))
     /* [previous][next][first][last][top][bottom][index][help] */
 512         {
 513         int result, reconnect;
 514         Scsi_Cmnd * SCtmp;
 515 
 516         done_fn = done;
 517         current_target = SCpnt->target;
 518         current_lun = SCpnt->lun;
 519         (const void *) current_cmnd = SCpnt->cmnd;
 520         current_data = (unsigned char *) SCpnt->request_buffer;
 521         current_bufflen = SCpnt->request_bufflen;
 522         SCint = SCpnt;
 523         if(recursion_depth) {
 524           return 0;
 525         };
 526         recursion_depth++;
 527         do{
 528 #ifdef LINKED
 529 /*
 530  * Set linked command bit in control field of SCSI command.
 531  */
 532 
 533           current_cmnd[SCpnt->cmd_len] |= 0x01;
 534           if (linked_connected) {
 535 #if (DEBUG & DEBUG_LINKED) 
 536             printk("scsi%d : using linked commands, current I_T_L nexus is ",
 537               hostno);
 538 #endif
 539             if ((linked_target == current_target) && 
 540               (linked_lun == current_lun)) {
 541 #if (DEBUG & DEBUG_LINKED) 
 542             printk("correct\n");
 543 #endif
 544               reconnect = LINKED_RIGHT;
 545             } else {
 546 #if (DEBUG & DEBUG_LINKED) 
 547             printk("incorrect\n");
 548 #endif
 549               reconnect = LINKED_WRONG;
 550             }
 551           } else 
 552 #endif /* LINKED */
 553             reconnect = CAN_RECONNECT;
 554 
 555 
 556 
 557 
 558 
 559           result = internal_command (SCint->target, SCint->lun, SCint->cmnd, SCint->request_buffer,
 560                                      SCint->request_bufflen, 
 561                                      reconnect);
 562           if (msg_byte(result) == DISCONNECT)  break;
 563           SCtmp = SCint;
 564           SCint = NULL;
 565           SCtmp->result = result;
 566           done_fn (SCtmp);
 567         } while(SCint);
 568         recursion_depth--;
 569         return 0;
 570       }
 571 
 572 int seagate_st0x_command (Scsi_Cmnd * SCpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 573         return internal_command (SCpnt->target, SCpnt->lun, SCpnt->cmnd, SCpnt->request_buffer,
 574                                  SCpnt->request_bufflen, 
 575                                  (int) NO_RECONNECT);
 576 }
 577         
 578 static int internal_command(unsigned char target, unsigned char lun, const void *cmnd,
     /* [previous][next][first][last][top][bottom][index][help] */
 579                          void *buff, int bufflen, int reselect) {
 580         int len = 0;
 581         unsigned char *data = NULL;     
 582         struct scatterlist *buffer = NULL;
 583         int nobuffs = 0;
 584         int clock;                      
 585         int temp;
 586 #ifdef SLOW_HANDSHAKE
 587         int borken;     /* Does the current target require Very Slow I/O ? */
 588 #endif
 589 
 590 
 591 #if (DEBUG & PHASE_DATAIN) || (DEBUG & PHASE_DATOUT) 
 592         int transfered = 0;
 593 #endif
 594 
 595 #if (((DEBUG & PHASE_ETC) == PHASE_ETC) || (DEBUG & PRINT_COMMAND) || \
 596         (DEBUG & PHASE_EXIT))   
 597         int i;
 598 #endif
 599 
 600 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
 601         int phase=0, newphase;
 602 #endif
 603 
 604         int done = 0;
 605         unsigned char status = 0;       
 606         unsigned char message = 0;
 607         register unsigned char status_read;
 608 
 609         unsigned transfersize = 0, underflow = 0;
 610 
 611         incommand = 0;
 612         st0x_aborted = 0;
 613 
 614 #ifdef SLOW_HANDSHAKE
 615         borken = (int) SCint->device->borken;
 616 #endif
 617 
 618 #if (DEBUG & PRINT_COMMAND)
 619         printk ("scsi%d : target = %d, command = ", hostno, target);
 620         print_command((unsigned char *) cmnd);
 621         printk("\n");
 622 #endif
 623 
 624 #if (DEBUG & PHASE_RESELECT)
 625         switch (reselect) {
 626         case RECONNECT_NOW :
 627                 printk("scsi%d : reconnecting\n", hostno);
 628                 break;
 629 #ifdef LINKED
 630         case LINKED_RIGHT : 
 631                 printk("scsi%d : connected, can reconnect\n", hostno);
 632                 break;
 633         case LINKED_WRONG :
 634                 printk("scsi%d : connected to wrong target, can reconnect\n",
 635                         hostno);
 636                 break;          
 637 #endif
 638         case CAN_RECONNECT :
 639                 printk("scsi%d : allowed to reconnect\n", hostno);
 640                 break;
 641         default :
 642                 printk("scsi%d : not allowed to reconnect\n", hostno);
 643         }
 644 #endif
 645         
 646 
 647         if (target == (controller_type == SEAGATE ? 7 : 6))
 648                 return DID_BAD_TARGET;
 649 
 650 /*
 651  *      We work it differently depending on if this is is "the first time,"
 652  *      or a reconnect.  If this is a reselect phase, then SEL will 
 653  *      be asserted, and we must skip selection / arbitration phases.
 654  */
 655 
 656         switch (reselect) {
 657         case RECONNECT_NOW:
 658 #if (DEBUG & PHASE_RESELECT)
 659                 printk("scsi%d : phase RESELECT \n", hostno);
 660 #endif
 661 
 662 /*
 663  *      At this point, we should find the logical or of our ID and the original
 664  *      target's ID on the BUS, with BSY, SEL, and I/O signals asserted.
 665  *
 666  *      After ARBITRATION phase is completed, only SEL, BSY, and the 
 667  *      target ID are asserted.  A valid initiator ID is not on the bus
 668  *      until IO is asserted, so we must wait for that.
 669  */
 670                 clock = jiffies + 10;
 671                 for (;;) {
 672                         temp = STATUS;
 673                         if ((temp & STAT_IO) && !(temp & STAT_BSY))
 674                                 break;
 675 
 676                         if (jiffies > clock) {
 677 #if (DEBUG & PHASE_RESELECT)
 678                                 printk("scsi%d : RESELECT timed out while waiting for IO .\n",
 679                                         hostno);
 680 #endif
 681                                 return (DID_BAD_INTR << 16);
 682                         }
 683                 }
 684 
 685 /* 
 686  *      After I/O is asserted by the target, we can read our ID and its
 687  *      ID off of the BUS.
 688  */
 689  
 690                 if (!((temp = DATA) & (controller_type == SEAGATE ? 0x80 : 0x40)))
 691                         {
 692 #if (DEBUG & PHASE_RESELECT)
 693                         printk("scsi%d : detected reconnect request to different target.\n" 
 694                                "\tData bus = %d\n", hostno, temp);
 695 #endif
 696                         return (DID_BAD_INTR << 16);
 697                         }
 698 
 699                 if (!(temp & (1 << current_target)))
 700                         {
 701                         printk("scsi%d : Unexpected reselect interrupt.  Data bus = %d\n",
 702                                 hostno, temp);
 703                         return (DID_BAD_INTR << 16);
 704                         }
 705 
 706                 buffer=current_buffer;  
 707                 cmnd=current_cmnd;      /* WDE add */
 708                 data=current_data;      /* WDE add */
 709                 len=current_bufflen;    /* WDE add */
 710                 nobuffs=current_nobuffs;
 711 
 712 /*
 713  *      We have determined that we have been selected.  At this point, 
 714  *      we must respond to the reselection by asserting BSY ourselves
 715  */
 716 
 717 #if 1
 718                 CONTROL = (BASE_CMD | CMD_DRVR_ENABLE | CMD_BSY);
 719 #else
 720                 CONTROL = (BASE_CMD | CMD_BSY);
 721 #endif
 722 
 723 /*
 724  *      The target will drop SEL, and raise BSY, at which time we must drop
 725  *      BSY.
 726  */
 727 
 728                 for (clock = jiffies + 10; (jiffies < clock) &&  (STATUS & STAT_SEL););
 729 
 730                 if (jiffies >= clock)
 731                         { 
 732                         CONTROL = (BASE_CMD | CMD_INTR);
 733 #if (DEBUG & PHASE_RESELECT)
 734                         printk("scsi%d : RESELECT timed out while waiting for SEL.\n",
 735                                 hostno);
 736 #endif
 737                         return (DID_BAD_INTR << 16);                             
 738                         }
 739 
 740                 CONTROL = BASE_CMD;
 741 
 742 /*
 743  *      At this point, we have connected with the target and can get 
 744  *      on with our lives.
 745  */      
 746                 break;
 747         case CAN_RECONNECT:
 748 
 749 #ifdef LINKED
 750 /*
 751  * This is a bletcherous hack, just as bad as the Unix #! interpreter stuff.
 752  * If it turns out we are using the wrong I_T_L nexus, the easiest way to deal
 753  * with it is to go into our INFORMATION TRANSFER PHASE code, send a ABORT 
 754  * message on MESSAGE OUT phase, and then loop back to here.
 755  */
 756   
 757 connect_loop :
 758 
 759 #endif
 760 
 761 #if (DEBUG & PHASE_BUS_FREE)
 762                 printk ("scsi%d : phase = BUS FREE \n", hostno);
 763 #endif
 764 
 765 /*
 766  *      BUS FREE PHASE
 767  *
 768  *      On entry, we make sure that the BUS is in a BUS FREE
 769  *      phase, by insuring that both BSY and SEL are low for
 770  *      at least one bus settle delay.  Several reads help
 771  *      eliminate wire glitch.
 772  */
 773 
 774                 clock = jiffies + ST0X_BUS_FREE_DELAY;  
 775 
 776 #if !defined (ARBITRATE) 
 777                 while (((STATUS |  STATUS | STATUS) & 
 778                          (STAT_BSY | STAT_SEL)) && 
 779                          (!st0x_aborted) && (jiffies < clock));
 780 
 781                 if (jiffies > clock)
 782                         return retcode(DID_BUS_BUSY);
 783                 else if (st0x_aborted)
 784                         return retcode(st0x_aborted);
 785 #endif
 786 
 787 #if (DEBUG & PHASE_SELECTION)
 788                 printk("scsi%d : phase = SELECTION\n", hostno);
 789 #endif
 790 
 791                 clock = jiffies + ST0X_SELECTION_DELAY;
 792 
 793 /*
 794  * Arbitration/selection procedure : 
 795  * 1.  Disable drivers
 796  * 2.  Write HOST adapter address bit
 797  * 3.  Set start arbitration.
 798  * 4.  We get either ARBITRATION COMPLETE or SELECT at this
 799  *     point.
 800  * 5.  OR our ID and targets on bus.
 801  * 6.  Enable SCSI drivers and asserted SEL and ATTN
 802  */
 803                 
 804 #if defined(ARBITRATE)  
 805         cli();
 806         CONTROL = 0;
 807         DATA = (controller_type == SEAGATE) ? 0x80 : 0x40;
 808         CONTROL = CMD_START_ARB; 
 809         sti();
 810         while (!((status_read = STATUS) & (STAT_ARB_CMPL | STAT_SEL)) &&
 811                 (jiffies < clock) && !st0x_aborted);
 812 
 813         if (!(status_read & STAT_ARB_CMPL)) {
 814 #if (DEBUG & PHASE_SELECTION)
 815                 if (status_read & STAT_SEL) 
 816                         printk("scsi%d : arbitration lost\n", hostno);
 817                 else
 818                         printk("scsi%d : arbitration timeout.\n", hostno);
 819 #endif
 820                 CONTROL = BASE_CMD;
 821                 return retcode(DID_NO_CONNECT);
 822         };
 823 
 824 #if (DEBUG & PHASE_SELECTION)
 825         printk("scsi%d : arbitration complete\n", hostno);
 826 #endif
 827 #endif
 828 
 829 
 830 /*
 831  *      When the SCSI device decides that we're gawking at it, it will 
 832  *      respond by asserting BUSY on the bus.
 833  *
 834  *      Note : the Seagate ST-01/02 product manual says that we should 
 835  *      twiddle the DATA register before the control register.  However,
 836  *      this does not work reliably so we do it the other way around.
 837  *
 838  *      Probably could be a problem with arbitration too, we really should
 839  *      try this with a SCSI protocol or logic analyzer to see what is 
 840  *      going on.
 841  */
 842         cli();
 843         DATA = (unsigned char) ((1 << target) | (controller_type == SEAGATE ? 0x80 : 0x40));
 844         CONTROL = BASE_CMD | CMD_DRVR_ENABLE | CMD_SEL | 
 845                 (reselect ? CMD_ATTN : 0);
 846         sti();
 847                 while (!((status_read = STATUS) & STAT_BSY) && 
 848                         (jiffies < clock) && !st0x_aborted)
 849 
 850 #if 0 && (DEBUG & PHASE_SELECTION)
 851                 {
 852                 temp = clock - jiffies;
 853 
 854                 if (!(jiffies % 5))
 855                         printk("seagate_st0x_timeout : %d            \r",temp);
 856         
 857                 }
 858                 printk("Done.                                             \n");
 859                 printk("scsi%d : status = %02x, seagate_st0x_timeout = %d, aborted = %02x \n", 
 860                         hostno, status_read, temp, st0x_aborted);
 861 #else
 862                 ;
 863 #endif
 864         
 865 
 866                 if ((jiffies >= clock)  && !(status_read & STAT_BSY))
 867                         {
 868 #if (DEBUG & PHASE_SELECTION)
 869                         printk ("scsi%d : NO CONNECT with target %d, status = %x \n", 
 870                                 hostno, target, STATUS);
 871 #endif
 872                         return retcode(DID_NO_CONNECT);
 873                         }
 874 
 875 /*
 876  *      If we have been aborted, and we have a command in progress, IE the 
 877  *      target still has BSY asserted, then we will reset the bus, and 
 878  *      notify the midlevel driver to expect sense.
 879  */
 880 
 881                 if (st0x_aborted) {
 882                         CONTROL = BASE_CMD;
 883                         if (STATUS & STAT_BSY) {
 884                                 printk("scsi%d : BST asserted after we've been aborted.\n",
 885                                         hostno);
 886                                 seagate_st0x_reset(NULL);
 887                                 return retcode(DID_RESET);
 888                         }
 889                         return retcode(st0x_aborted);
 890                 }       
 891 
 892 /* Establish current pointers.  Take into account scatter / gather */
 893 
 894         if ((nobuffs = SCint->use_sg)) {
 895 #if (DEBUG & DEBUG_SG)
 896         {
 897         int i;
 898         printk("scsi%d : scatter gather requested, using %d buffers.\n",
 899                 hostno, nobuffs);
 900         for (i = 0; i < nobuffs; ++i)
 901                 printk("scsi%d : buffer %d address = %08x length = %d\n",
 902                         hostno, i, buffer[i].address, buffer[i].length);
 903         }
 904 #endif
 905                 
 906                 buffer = (struct scatterlist *) SCint->buffer;
 907                 len = buffer->length;
 908                 data = (unsigned char *) buffer->address;
 909         } else {
 910 #if (DEBUG & DEBUG_SG)
 911         printk("scsi%d : scatter gather not requested.\n", hostno);
 912 #endif
 913                 buffer = NULL;
 914                 len = SCint->request_bufflen;
 915                 data = (unsigned char *) SCint->request_buffer;
 916         }
 917 
 918 #if (DEBUG & (PHASE_DATAIN | PHASE_DATAOUT))
 919         printk("scsi%d : len = %d\n", hostno, len);
 920 #endif
 921 
 922                 break;
 923 #ifdef LINKED
 924         case LINKED_RIGHT:
 925                 break;
 926         case LINKED_WRONG:
 927                 break;
 928 #endif
 929         }
 930 
 931 /*
 932  *      There are several conditions under which we wish to send a message : 
 933  *      1.  When we are allowing disconnect / reconnect, and need to establish
 934  *          the I_T_L nexus via an IDENTIFY with the DiscPriv bit set.
 935  *
 936  *      2.  When we are doing linked commands, are have the wrong I_T_L nexus
 937  *          established and want to send an ABORT message.
 938  */
 939 
 940         
 941         CONTROL = BASE_CMD | CMD_DRVR_ENABLE | 
 942                 (((reselect == CAN_RECONNECT)
 943 #ifdef LINKED 
 944                 || (reselect == LINKED_WRONG)
 945 #endif 
 946                 )  ? CMD_ATTN : 0) ;
 947         
 948 /*
 949  *      INFORMATION TRANSFER PHASE
 950  *
 951  *      The nasty looking read / write inline assembler loops we use for 
 952  *      DATAIN and DATAOUT phases are approximately 4-5 times as fast as 
 953  *      the 'C' versions - since we're moving 1024 bytes of data, this
 954  *      really adds up.
 955  */
 956 
 957 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
 958         printk("scsi%d : phase = INFORMATION TRANSFER\n", hostno);
 959 #endif  
 960 
 961         incommand = 1;
 962         transfersize = SCint->transfersize;
 963         underflow = SCint->underflow;
 964 
 965 
 966 /*
 967  *      Now, we poll the device for status information,
 968  *      and handle any requests it makes.  Note that since we are unsure of 
 969  *      how much data will be flowing across the system, etc and cannot 
 970  *      make reasonable timeouts, that we will instead have the midlevel
 971  *      driver handle any timeouts that occur in this phase.
 972  */
 973 
 974         while (((status_read = STATUS) & STAT_BSY) && !st0x_aborted && !done) 
 975                 {
 976 #ifdef PARITY
 977                 if (status_read & STAT_PARITY)
 978                         {
 979                         printk("scsi%d : got parity error\n", hostno);
 980                         st0x_aborted = DID_PARITY;
 981                         }       
 982 #endif
 983 
 984                 if (status_read & STAT_REQ)
 985                         {
 986 #if ((DEBUG & PHASE_ETC) == PHASE_ETC)
 987                         if ((newphase = (status_read & REQ_MASK)) != phase)
 988                                 {
 989                                 phase = newphase;
 990                                 switch (phase)
 991                                 {
 992                                 case REQ_DATAOUT: 
 993                                         printk("scsi%d : phase = DATA OUT\n",
 994                                                 hostno); 
 995                                         break;
 996                                 case REQ_DATAIN : 
 997                                         printk("scsi%d : phase = DATA IN\n",
 998                                                 hostno); 
 999                                         break;
1000                                 case REQ_CMDOUT : 
1001                                         printk("scsi%d : phase = COMMAND OUT\n",
1002                                                 hostno); 
1003                                         break;
1004                                 case REQ_STATIN :
1005                                          printk("scsi%d : phase = STATUS IN\n",
1006                                                 hostno); 
1007                                         break;
1008                                 case REQ_MSGOUT :
1009                                         printk("scsi%d : phase = MESSAGE OUT\n",
1010                                                 hostno); 
1011                                         break;
1012                                 case REQ_MSGIN :
1013                                         printk("scsi%d : phase = MESSAGE IN\n",
1014                                                 hostno);
1015                                         break;
1016                                 default : 
1017                                         printk("scsi%d : phase = UNKNOWN\n",
1018                                                 hostno); 
1019                                         st0x_aborted = DID_ERROR; 
1020                                 }       
1021                                 }
1022 #endif
1023                 switch (status_read & REQ_MASK)
1024                 {                       
1025                 case REQ_DATAOUT : 
1026 /*
1027  * If we are in fast mode, then we simply splat the data out
1028  * in word-sized chunks as fast as we can.
1029  */
1030 
1031 #ifdef FAST 
1032 if (!len) {
1033 #if 0 
1034         printk("scsi%d: underflow to target %d lun %d \n", 
1035                 hostno, target, lun);
1036         st0x_aborted = DID_ERROR;
1037         fast = 0;
1038 #endif
1039         break;
1040 }
1041 
1042 if (fast && transfersize && !(len % transfersize) && (len >= transfersize)
1043 #ifdef FAST32
1044         && !(transfersize % 4)
1045 #endif
1046         ) {
1047 #if (DEBUG & DEBUG_FAST) 
1048         printk("scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
1049                "         len = %d, data = %08x\n", hostno, SCint->underflow, 
1050                SCint->transfersize, len, data);
1051 #endif
1052 
1053         __asm__("
1054         cld;
1055 "
1056 #ifdef FAST32
1057 "       shr $2, %%ecx;
1058 1:      lodsl;
1059         movl %%eax, (%%edi);
1060 "
1061 #else
1062 "1:     lodsb;
1063         movb %%al, (%%edi);
1064 "
1065 #endif
1066 "       loop 1b;" : :
1067         /* input */
1068         "D" (st0x_dr), "S" (data), "c" (SCint->transfersize) :
1069         /* clobbered */
1070         "eax", "ecx", "esi" );
1071 
1072         len -= transfersize;
1073         data += transfersize;
1074 
1075 #if (DEBUG & DEBUG_FAST)
1076         printk("scsi%d : FAST transfer complete len = %d data = %08x\n", 
1077                 hostno, len, data);
1078 #endif
1079 
1080 
1081 } else 
1082 #endif
1083 
1084 {
1085 /*
1086  *      We loop as long as we are in a data out phase, there is data to send, 
1087  *      and BSY is still active.
1088  */
1089                 __asm__ (
1090 
1091 /*
1092         Local variables : 
1093         len = ecx
1094         data = esi
1095         st0x_cr_sr = ebx
1096         st0x_dr =  edi
1097 
1098         Test for any data here at all.
1099 */
1100         "\torl %%ecx, %%ecx
1101         jz 2f
1102 
1103         cld
1104 
1105         movl _st0x_cr_sr, %%ebx
1106         movl _st0x_dr, %%edi
1107         
1108 1:      movb (%%ebx), %%al\n"
1109 /*
1110         Test for BSY
1111 */
1112 
1113         "\ttest $1, %%al
1114         jz 2f\n"
1115 
1116 /*
1117         Test for data out phase - STATUS & REQ_MASK should be REQ_DATAOUT, which is 0.
1118 */
1119         "\ttest $0xe, %%al
1120         jnz 2f  \n"
1121 /*
1122         Test for REQ
1123 */      
1124         "\ttest $0x10, %%al
1125         jz 1b
1126         lodsb
1127         movb %%al, (%%edi) 
1128         loop 1b
1129 
1130 2: 
1131                                                                         ":
1132 /* output */
1133 "=S" (data), "=c" (len) :
1134 /* input */
1135 "0" (data), "1" (len) :
1136 /* clobbered */
1137 "eax", "ebx", "edi"); 
1138 }
1139 
1140                         if (!len && nobuffs) {
1141                                 --nobuffs;
1142                                 ++buffer;
1143                                 len = buffer->length;
1144                                 data = (unsigned char *) buffer->address;
1145 #if (DEBUG & DEBUG_SG)
1146         printk("scsi%d : next scatter-gather buffer len = %d address = %08x\n",
1147                 hostno, len, data);
1148 #endif
1149                         }
1150                         break;
1151 
1152                 case REQ_DATAIN : 
1153 #ifdef SLOW_HANDSHAKE
1154         if (borken) {
1155 #if (DEBUG & (PHASE_DATAIN))
1156                 transfered += len;
1157 #endif
1158                 for (; len && (STATUS & (REQ_MASK | STAT_REQ)) == (REQ_DATAIN |
1159                         STAT_REQ); --len) {
1160                                 *data++ = DATA;
1161                                 borken_wait();
1162 }
1163 #if (DEBUG & (PHASE_DATAIN))
1164                 transfered -= len;
1165 #endif
1166         } else
1167 #endif
1168 #ifdef FAST
1169 if (fast && transfersize && !(len % transfersize) && (len >= transfersize)
1170 #ifdef FAST32
1171         && !(transfersize % 4)
1172 #endif
1173         ) {
1174 #if (DEBUG & DEBUG_FAST) 
1175         printk("scsi%d : FAST transfer, underflow = %d, transfersize = %d\n"
1176                "         len = %d, data = %08x\n", hostno, SCint->underflow, 
1177                SCint->transfersize, len, data);
1178 #endif
1179         __asm__("
1180         cld;
1181 "
1182 #ifdef FAST32
1183 "       shr $2, %%ecx;
1184 1:      movl (%%esi), %%eax;
1185         stosl;
1186 "
1187 #else
1188 "1:     movb (%%esi), %%al;
1189         stosb;
1190 "
1191 #endif
1192 
1193 "       loop 1b;" : :
1194         /* input */
1195         "S" (st0x_dr), "D" (data), "c" (SCint->transfersize) :
1196         /* clobbered */
1197         "eax", "ecx", "edi");
1198 
1199         len -= transfersize;
1200         data += transfersize;
1201 
1202 #if (DEBUG & PHASE_DATAIN)
1203         printk("scsi%d: transfered += %d\n", hostno, transfersize);
1204         transfered += transfersize;
1205 #endif
1206 
1207 #if (DEBUG & DEBUG_FAST)
1208         printk("scsi%d : FAST transfer complete len = %d data = %08x\n", 
1209                 hostno, len, data);
1210 #endif
1211 
1212 } else
1213 #endif
1214 {
1215 
1216 #if (DEBUG & PHASE_DATAIN)
1217         printk("scsi%d: transfered += %d\n", hostno, len);
1218         transfered += len;      /* Assume we'll transfer it all, then
1219                                    subtract what we *didn't* transfer */
1220 #endif
1221         
1222 /*
1223  *      We loop as long as we are in a data in phase, there is room to read, 
1224  *      and BSY is still active
1225  */
1226  
1227                         __asm__ (
1228 /*
1229         Local variables : 
1230         ecx = len
1231         edi = data
1232         esi = st0x_cr_sr
1233         ebx = st0x_dr
1234 
1235         Test for room to read
1236 */
1237         "\torl %%ecx, %%ecx
1238         jz 2f
1239 
1240         cld
1241         movl _st0x_cr_sr, %%esi
1242         movl _st0x_dr, %%ebx
1243 
1244 1:      movb (%%esi), %%al\n"
1245 /*
1246         Test for BSY
1247 */
1248 
1249         "\ttest $1, %%al 
1250         jz 2f\n"
1251 
1252 /*
1253         Test for data in phase - STATUS & REQ_MASK should be REQ_DATAIN, = STAT_IO, which is 4.
1254 */
1255         "\tmovb $0xe, %%ah      
1256         andb %%al, %%ah
1257         cmpb $0x04, %%ah
1258         jne 2f\n"
1259                 
1260 /*
1261         Test for REQ
1262 */      
1263         "\ttest $0x10, %%al
1264         jz 1b
1265 
1266         movb (%%ebx), %%al      
1267         stosb   
1268         loop 1b\n"
1269 
1270 "2:\n"
1271                                                                         :
1272 /* output */
1273 "=D" (data), "=c" (len) :
1274 /* input */
1275 "0" (data), "1" (len) :
1276 /* clobbered */
1277 "eax","ebx", "esi"); 
1278 
1279 #if (DEBUG & PHASE_DATAIN)
1280         printk("scsi%d: transfered -= %d\n", hostno, len);
1281         transfered -= len;              /* Since we assumed all of Len got 
1282                                          * transfered, correct our mistake */
1283 #endif
1284 }
1285         
1286                         if (!len && nobuffs) {
1287                                 --nobuffs;
1288                                 ++buffer;
1289                                 len = buffer->length;
1290                                 data = (unsigned char *) buffer->address;
1291 #if (DEBUG & DEBUG_SG)
1292         printk("scsi%d : next scatter-gather buffer len = %d address = %08x\n",
1293                 hostno, len, data);
1294 #endif
1295                         }
1296 
1297                         break;
1298 
1299                 case REQ_CMDOUT : 
1300                         while (((status_read = STATUS) & STAT_BSY) && 
1301                                ((status_read & REQ_MASK) == REQ_CMDOUT))
1302                                 if (status_read & STAT_REQ) {
1303                                         DATA = *(unsigned char *) cmnd;
1304                                         cmnd = 1+(unsigned char *) cmnd;
1305 #ifdef SLOW_HANDSHAKE
1306                                         if (borken) 
1307                                                 borken_wait();
1308 #endif
1309                                 }
1310                         break;
1311         
1312                 case REQ_STATIN : 
1313                         status = DATA;
1314                         break;
1315                                 
1316                 case REQ_MSGOUT : 
1317 /*
1318  *      We can only have sent a MSG OUT if we requested to do this 
1319  *      by raising ATTN.  So, we must drop ATTN.
1320  */
1321 
1322                         CONTROL = BASE_CMD | CMD_DRVR_ENABLE;
1323 /*
1324  *      If we are reconnecting, then we must send an IDENTIFY message in 
1325  *       response  to MSGOUT.
1326  */
1327                         switch (reselect) {
1328                         case CAN_RECONNECT:
1329                                 DATA = IDENTIFY(1, lun);
1330 
1331 #if (DEBUG & (PHASE_RESELECT | PHASE_MSGOUT)) 
1332                                 printk("scsi%d : sent IDENTIFY message.\n", hostno);
1333 #endif
1334                                 break;
1335 #ifdef LINKED
1336                         case LINKED_WRONG:
1337                                 DATA = ABORT;
1338                                 linked_connected = 0;
1339                                 reselect = CAN_RECONNECT;
1340                                 goto connect_loop;
1341 #if (DEBUG & (PHASE_MSGOUT | DEBUG_LINKED))
1342                                 printk("scsi%d : sent ABORT message to cancel incorrect I_T_L nexus.\n", hostno);
1343 #endif
1344 #endif /* LINKED */
1345 #if (DEBUG & DEBUG_LINKED) 
1346             printk("correct\n");
1347 #endif
1348                         default:
1349                                 DATA = NOP;
1350                                 printk("scsi%d : target %d requested MSGOUT, sent NOP message.\n", hostno, target);
1351                         }
1352                         break;
1353                                         
1354                 case REQ_MSGIN : 
1355                         switch (message = DATA) {
1356                         case DISCONNECT :
1357                                 should_reconnect = 1;
1358                                 current_data = data;    /* WDE add */
1359                                 current_buffer = buffer;
1360                                 current_bufflen = len;  /* WDE add */
1361                                 current_nobuffs = nobuffs;
1362 #ifdef LINKED
1363                                 linked_connected = 0;
1364 #endif
1365                                 done=1;
1366 #if (DEBUG & (PHASE_RESELECT | PHASE_MSGIN))
1367                                 printk("scsi%d : disconnected.\n", hostno);
1368 #endif
1369                                 break;
1370 
1371 #ifdef LINKED
1372                         case LINKED_CMD_COMPLETE:
1373                         case LINKED_FLG_CMD_COMPLETE:
1374 #endif
1375                         case COMMAND_COMPLETE :
1376 /*
1377  * Note : we should check for underflow here.   
1378  */
1379 #if (DEBUG & PHASE_MSGIN)       
1380                                 printk("scsi%d : command complete.\n", hostno);
1381 #endif
1382                                 done = 1;
1383                                 break;
1384                         case ABORT :
1385 #if (DEBUG & PHASE_MSGIN)
1386                                 printk("scsi%d : abort message.\n", hostno);
1387 #endif
1388                                 done=1;
1389                                 break;
1390                         case SAVE_POINTERS :
1391                                 current_buffer = buffer;
1392                                 current_bufflen = len;  /* WDE add */
1393                                 current_data = data;    /* WDE mod */
1394                                 current_nobuffs = nobuffs;
1395 #if (DEBUG & PHASE_MSGIN)
1396                                 printk("scsi%d : pointers saved.\n", hostno);
1397 #endif 
1398                                 break;
1399                         case RESTORE_POINTERS:
1400                                 buffer=current_buffer;
1401                                 cmnd=current_cmnd;
1402                                 data=current_data;      /* WDE mod */
1403                                 len=current_bufflen;
1404                                 nobuffs=current_nobuffs;
1405 #if (DEBUG & PHASE_MSGIN)
1406                                 printk("scsi%d : pointers restored.\n", hostno);
1407 #endif
1408                                 break;
1409                         default:
1410 
1411 /*
1412  *      IDENTIFY distinguishes itself from the other messages by setting the
1413  *      high byte.
1414  *      
1415  *      Note : we need to handle at least one outstanding command per LUN,
1416  *      and need to hash the SCSI command for that I_T_L nexus based on the 
1417  *      known ID (at this point) and LUN.
1418  */
1419 
1420                                 if (message & 0x80) {
1421 #if (DEBUG & PHASE_MSGIN)
1422                                         printk("scsi%d : IDENTIFY message received from id %d, lun %d.\n",
1423                                                 hostno, target, message & 7);
1424 #endif
1425                                 } else {
1426 
1427 /*
1428  *      We should go into a MESSAGE OUT phase, and send  a MESSAGE_REJECT 
1429  *      if we run into a message that we don't like.  The seagate driver 
1430  *      needs some serious restructuring first though.
1431  */
1432 
1433 #if (DEBUG & PHASE_MSGIN)
1434                                         printk("scsi%d : unknown message %d from target %d.\n",
1435                                                 hostno,  message,   target);
1436 #endif  
1437                                 }
1438                         }
1439                         break;
1440 
1441                 default : 
1442                         printk("scsi%d : unknown phase.\n", hostno); 
1443                         st0x_aborted = DID_ERROR; 
1444                 }       
1445 
1446 #ifdef SLOW_HANDSHAKE
1447 /*
1448  * I really don't care to deal with borken devices in each single 
1449  * byte transfer case (ie, message in, message out, status), so
1450  * I'll do the wait here if necessary.
1451  */
1452                 if (borken)
1453                         borken_wait();
1454 #endif
1455  
1456                 } /* if ends */
1457                 } /* while ends */
1458 
1459 #if (DEBUG & (PHASE_DATAIN | PHASE_DATAOUT | PHASE_EXIT))
1460         printk("scsi%d : Transfered %d bytes\n", hostno, transfered);
1461 #endif
1462 
1463 #if (DEBUG & PHASE_EXIT)
1464 #if 0           /* Doesn't work for scatter / gather */
1465         printk("Buffer : \n");
1466         for (i = 0; i < 20; ++i) 
1467                 printk ("%02x  ", ((unsigned char *) data)[i]); /* WDE mod */
1468         printk("\n");
1469 #endif
1470         printk("scsi%d : status = ", hostno);
1471         print_status(status);
1472         printk("message = %02x\n", message);
1473 #endif
1474 
1475 
1476 /* We shouldn't reach this until *after* BSY has been deasserted */
1477 #ifdef notyet
1478         if (st0x_aborted) {
1479                 if (STATUS & STAT_BSY) {        
1480                         seagate_st0x_reset(NULL);
1481                         st0x_aborted = DID_RESET;
1482                 } 
1483                 abort_confirm = 1;
1484         } 
1485 #endif
1486 
1487 #ifdef LINKED
1488 else {
1489 /*
1490  * Fix the message byte so that unsuspecting high level drivers don't 
1491  * puke when they see a LINKED COMMAND message in place of the COMMAND 
1492  * COMPLETE they may be expecting.  Shouldn't be necessary, but it's 
1493  * better to be on the safe side. 
1494  *
1495  * A non LINKED* message byte will indicate that the command completed, 
1496  * and we are now disconnected.
1497  */
1498 
1499                 switch (message) {
1500                 case LINKED_CMD_COMPLETE :
1501                 case LINKED_FLG_CMD_COMPLETE : 
1502                         message = COMMAND_COMPLETE;
1503                         linked_target = current_target;
1504                         linked_lun = current_lun;
1505                         linked_connected = 1;
1506 #if (DEBUG & DEBUG_LINKED)
1507                         printk("scsi%d : keeping I_T_L nexus established for linked command.\n", 
1508                                 hostno);
1509 #endif
1510 /*
1511  * We also will need to adjust status to accommodate intermediate conditions.
1512  */
1513                         if ((status == INTERMEDIATE_GOOD) ||
1514                                 (status == INTERMEDIATE_C_GOOD))
1515                                 status = GOOD;
1516                         
1517                         break;
1518 /*
1519  * We should also handle what are "normal" termination messages 
1520  * here (ABORT, BUS_DEVICE_RESET?, and COMMAND_COMPLETE individually, 
1521  * and flake if things aren't right.
1522  */
1523 
1524                 default :
1525 #if (DEBUG & DEBUG_LINKED)
1526                         printk("scsi%d : closing I_T_L nexus.\n", hostno);
1527 #endif
1528                         linked_connected = 0;
1529                 }
1530         }
1531 #endif /* LINKED */
1532 
1533 
1534 
1535 
1536         if (should_reconnect) {
1537 #if (DEBUG & PHASE_RESELECT)
1538                 printk("scsi%d : exiting seagate_st0x_queue_command() with reconnect enabled.\n",
1539                         hostno);
1540 #endif
1541                 CONTROL = BASE_CMD | CMD_INTR ;
1542         } else 
1543                 CONTROL = BASE_CMD;
1544 
1545         return retcode (st0x_aborted);
1546         }
1547 
1548 int seagate_st0x_abort (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1549         {
1550           st0x_aborted = DID_ABORT;
1551           
1552           return SCSI_ABORT_PENDING;
1553         }
1554 
1555 /*
1556         the seagate_st0x_reset function resets the SCSI bus
1557 */
1558         
1559 int seagate_st0x_reset (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1560         {
1561         unsigned clock;
1562         /*
1563                 No timeouts - this command is going to fail because 
1564                 it was reset.
1565         */
1566 
1567 #ifdef DEBUG
1568         printk("In seagate_st0x_reset()\n");
1569 #endif
1570 
1571 
1572         /* assert  RESET signal on SCSI bus.  */
1573                 
1574         CONTROL = BASE_CMD  | CMD_RST;
1575         clock=jiffies+2;
1576 
1577         
1578         /* Wait.  */
1579         
1580         while (jiffies < clock);
1581 
1582         CONTROL = BASE_CMD;
1583         
1584         st0x_aborted = DID_RESET;
1585 
1586 #ifdef DEBUG
1587         printk("SCSI bus reset.\n");
1588 #endif
1589         return SCSI_RESET_WAKEUP;
1590         }
1591 
1592 #include <asm/segment.h>
1593 #include "sd.h"
1594 #include "scsi_ioctl.h"
1595 
1596 int seagate_st0x_biosparam(Disk * disk, int dev, int* ip) {
     /* [previous][next][first][last][top][bottom][index][help] */
1597   unsigned char buf[256 + sizeof(int) * 2], cmd[6], *data, *page;
1598   int *sizes, result, formatted_sectors, total_sectors;
1599   int cylinders, heads, sectors;
1600 
1601 /*
1602  * Only SCSI-I CCS drives and later implement the necessary mode sense 
1603  * pages.  
1604  */
1605 
1606   if (disk->device->scsi_level < 2) 
1607         return -1;
1608 
1609   sizes = (int *) buf;
1610   data = (unsigned char *) (sizes + 2);
1611 
1612   cmd[0] = MODE_SENSE;
1613   cmd[1] = (disk->device->lun << 5) & 0xe5;
1614   cmd[2] = 0x04; /* Read page 4, rigid disk geometry page current values */
1615   cmd[3] = 0;
1616   cmd[4] = 255;
1617   cmd[5] = 0;
1618 
1619 /*
1620  * We are transferring 0 bytes in the out direction, and expect to get back
1621  * 24 bytes for each mode page.
1622  */
1623 
1624   sizes[0] = 0;
1625   sizes[1] = 256;
1626 
1627   memcpy (data, cmd, 6);
1628 
1629   if (!(result = kernel_scsi_ioctl (disk->device, SCSI_IOCTL_SEND_COMMAND, (void *) buf))) {
1630 /*
1631  * The mode page lies beyond the MODE SENSE header, with length 4, and 
1632  * the BLOCK DESCRIPTOR, with length header[3].
1633  */
1634 
1635     page = data + 4 + data[3];
1636     heads = (int) page[5];
1637     cylinders = (page[2] << 16) | (page[3] << 8) | page[4];
1638 
1639     cmd[2] = 0x03; /* Read page 3, format page current values */
1640     memcpy (data, cmd, 6);
1641 
1642     if (!(result = kernel_scsi_ioctl (disk->device, SCSI_IOCTL_SEND_COMMAND, (void *) buf))) {
1643       page = data + 4 + data[3];
1644       sectors = (page[10] << 8) | page[11];     
1645 
1646         
1647 /*
1648  * Get the total number of formatted sectors from the block descriptor, 
1649  * so we can tell how many are being used for alternates.  
1650  */
1651 
1652       formatted_sectors = (data[4 + 1] << 16) | (data[4 + 2] << 8) |
1653         data[4 + 3] ;
1654 
1655       total_sectors = (heads * cylinders * sectors);
1656 
1657 /*
1658  * Adjust the real geometry by subtracting 
1659  * (spare sectors / (heads * tracks)) cylinders from the number of cylinders.
1660  *
1661  * It appears that the CE cylinder CAN be a partial cylinder.
1662  */
1663 
1664      
1665 printk("scsi%d : heads = %d cylinders = %d sectors = %d total = %d formatted = %d\n",
1666     hostno, heads, cylinders, sectors, total_sectors, formatted_sectors);
1667 
1668       if (!heads || !sectors || !cylinders)
1669         result = -1;
1670       else
1671         cylinders -= ((total_sectors - formatted_sectors) / (heads * sectors));
1672 
1673 /*
1674  * Now, we need to do a sanity check on the geometry to see if it is 
1675  * BIOS compatible.  The maximum BIOS geometry is 1024 cylinders * 
1676  * 256 heads * 64 sectors. 
1677  */
1678 
1679       if ((cylinders > 1024) || (sectors > 64)) 
1680         result = -1;
1681       else {
1682         ip[0] = heads;
1683         ip[1] = sectors;
1684         ip[2] = cylinders;
1685       }
1686 
1687 /* 
1688  * There should be an alternate mapping for things the seagate doesn't
1689  * understand, but I couldn't say what it is with reasonable certainty.
1690  */
1691 
1692       }
1693     }
1694     
1695   return result;
1696 }

/* [previous][next][first][last][top][bottom][index][help] */