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

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