Import 2.3.18pre1
[davej-history.git] / drivers / scsi / fd_mcs.c
blob69c97f5881a41d507db19bee0becc5decb56fbd2
1 /* fd_mcs.c -- Future Domain MCS 600/700 (or IBM OEM) driver
3 * FutureDomain MCS-600/700 v0.2 03/11/1998 by ZP Gu (zpg@castle.net)
5 * This driver is cloned from fdomain.* to specifically support
6 * the Future Domain MCS 600/700 MCA SCSI adapters. Some PS/2s
7 * also equipped with IBM Fast SCSI Adapter/A which is an OEM
8 * of MCS 700.
10 * This driver also supports Reply SB16/SCSI card (the SCSI part).
12 * What makes this driver different is that this driver is MCA only
13 * and it supports multiple adapters in the same system, IRQ
14 * sharing, some driver statistics, and maps highest SCSI id to sda.
15 * All cards are auto-detected.
17 * Assumptions: TMC-1800/18C50/18C30, BIOS >= 3.4
19 * LILO command-line options:
20 * fd_mcs=<FIFO_COUNT>[,<FIFO_SIZE>]
22 * ********************************************************
23 * Please see Copyrights/Comments in fdomain.* for credits.
24 * Following is from fdomain.c for acknowledgement:
26 * Created: Sun May 3 18:53:19 1992 by faith@cs.unc.edu
27 * Revised: Wed Oct 2 11:10:55 1996 by r.faith@ieee.org
28 * Author: Rickard E. Faith, faith@cs.unc.edu
29 * Copyright 1992, 1993, 1994, 1995, 1996 Rickard E. Faith
31 * $Id: fdomain.c,v 5.45 1996/10/02 15:13:06 root Exp $
33 * This program is free software; you can redistribute it and/or modify it
34 * under the terms of the GNU General Public License as published by the
35 * Free Software Foundation; either version 2, or (at your option) any
36 * later version.
38 * This program is distributed in the hope that it will be useful, but
39 * WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41 * General Public License for more details.
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 675 Mass Ave, Cambridge, MA 02139, USA.
47 **************************************************************************
49 NOTES ON USER DEFINABLE OPTIONS:
51 DEBUG: This turns on the printing of various debug information.
53 ENABLE_PARITY: This turns on SCSI parity checking. With the current
54 driver, all attached devices must support SCSI parity. If none of your
55 devices support parity, then you can probably get the driver to work by
56 turning this option off. I have no way of testing this, however, and it
57 would appear that no one ever uses this option.
59 FIFO_COUNT: The host adapter has an 8K cache (host adapters based on the
60 18C30 chip have a 2k cache). When this many 512 byte blocks are filled by
61 the SCSI device, an interrupt will be raised. Therefore, this could be as
62 low as 0, or as high as 16. Note, however, that values which are too high
63 or too low seem to prevent any interrupts from occurring, and thereby lock
64 up the machine. I have found that 2 is a good number, but throughput may
65 be increased by changing this value to values which are close to 2.
66 Please let me know if you try any different values.
67 [*****Now a runtime option*****]
69 RESELECTION: This is no longer an option, since I gave up trying to
70 implement it in version 4.x of this driver. It did not improve
71 performance at all and made the driver unstable (because I never found one
72 of the two race conditions which were introduced by the multiple
73 outstanding command code). The instability seems a very high price to pay
74 just so that you don't have to wait for the tape to rewind. If you want
75 this feature implemented, send me patches. I'll be happy to send a copy
76 of my (broken) driver to anyone who would like to see a copy.
78 **************************************************************************/
80 #ifdef MODULE
81 #include <linux/module.h>
82 #endif
84 #include <linux/sched.h>
85 #include <linux/blk.h>
86 #include <linux/errno.h>
87 #include <linux/string.h>
88 #include <linux/ioport.h>
89 #include <linux/proc_fs.h>
90 #include <linux/delay.h>
91 #include <linux/mca.h>
92 #include <linux/spinlock.h>
93 #include <asm/io.h>
94 #include <asm/system.h>
96 #include "scsi.h"
97 #include "hosts.h"
98 #include "fd_mcs.h"
100 #define DRIVER_VERSION "v0.2 by ZP Gu<zpg@castle.net>"
102 struct proc_dir_entry proc_scsi_fd_mcs = {
103 PROC_SCSI_FD_MCS, 6, "fd_mcs",
104 S_IFDIR | S_IRUGO | S_IXUGO, 2
107 /* START OF USER DEFINABLE OPTIONS */
109 #define DEBUG 0 /* Enable debugging output */
110 #define ENABLE_PARITY 1 /* Enable SCSI Parity */
111 #define DO_DETECT 0 /* Do device detection here (see scsi.c) */
113 /* END OF USER DEFINABLE OPTIONS */
115 #if DEBUG
116 #define EVERY_ACCESS 0 /* Write a line on every scsi access */
117 #define ERRORS_ONLY 1 /* Only write a line if there is an error */
118 #define DEBUG_DETECT 1 /* Debug fd_mcs_detect() */
119 #define DEBUG_MESSAGES 1 /* Debug MESSAGE IN phase */
120 #define DEBUG_ABORT 1 /* Debug abort() routine */
121 #define DEBUG_RESET 1 /* Debug reset() routine */
122 #define DEBUG_RACE 1 /* Debug interrupt-driven race condition */
123 #else
124 #define EVERY_ACCESS 0 /* LEAVE THESE ALONE--CHANGE THE ONES ABOVE */
125 #define ERRORS_ONLY 0
126 #define DEBUG_DETECT 0
127 #define DEBUG_MESSAGES 0
128 #define DEBUG_ABORT 0
129 #define DEBUG_RESET 0
130 #define DEBUG_RACE 0
131 #endif
133 /* Errors are reported on the line, so we don't need to report them again */
134 #if EVERY_ACCESS
135 #undef ERRORS_ONLY
136 #define ERRORS_ONLY 0
137 #endif
139 #if ENABLE_PARITY
140 #define PARITY_MASK 0x08
141 #else
142 #define PARITY_MASK 0x00
143 #endif
145 enum chip_type {
146 unknown = 0x00,
147 tmc1800 = 0x01,
148 tmc18c50 = 0x02,
149 tmc18c30 = 0x03,
152 enum {
153 in_arbitration = 0x02,
154 in_selection = 0x04,
155 in_other = 0x08,
156 disconnect = 0x10,
157 aborted = 0x20,
158 sent_ident = 0x40,
161 enum in_port_type {
162 Read_SCSI_Data = 0,
163 SCSI_Status = 1,
164 TMC_Status = 2,
165 FIFO_Status = 3, /* tmc18c50/tmc18c30 only */
166 Interrupt_Cond = 4, /* tmc18c50/tmc18c30 only */
167 LSB_ID_Code = 5,
168 MSB_ID_Code = 6,
169 Read_Loopback = 7,
170 SCSI_Data_NoACK = 8,
171 Interrupt_Status = 9,
172 Configuration1 = 10,
173 Configuration2 = 11, /* tmc18c50/tmc18c30 only */
174 Read_FIFO = 12,
175 FIFO_Data_Count = 14
178 enum out_port_type {
179 Write_SCSI_Data = 0,
180 SCSI_Cntl = 1,
181 Interrupt_Cntl = 2,
182 SCSI_Mode_Cntl = 3,
183 TMC_Cntl = 4,
184 Memory_Cntl = 5, /* tmc18c50/tmc18c30 only */
185 Write_Loopback = 7,
186 IO_Control = 11, /* tmc18c30 only */
187 Write_FIFO = 12
190 struct fd_hostdata {
191 unsigned long _bios_base;
192 int _bios_major;
193 int _bios_minor;
194 volatile int _in_command;
195 Scsi_Cmnd *_current_SC;
196 enum chip_type _chip;
197 int _adapter_mask;
198 int _fifo_count; /* Number of 512 byte blocks before INTR */
200 char _adapter_name[64];
201 #if DEBUG_RACE
202 volatile int _in_interrupt_flag;
203 #endif
205 int _SCSI_Mode_Cntl_port;
206 int _FIFO_Data_Count_port;
207 int _Interrupt_Cntl_port;
208 int _Interrupt_Status_port;
209 int _Interrupt_Cond_port;
210 int _Read_FIFO_port;
211 int _Read_SCSI_Data_port;
212 int _SCSI_Cntl_port;
213 int _SCSI_Data_NoACK_port;
214 int _SCSI_Status_port;
215 int _TMC_Cntl_port;
216 int _TMC_Status_port;
217 int _Write_FIFO_port;
218 int _Write_SCSI_Data_port;
220 int _FIFO_Size; /* = 0x2000; 8k FIFO for
221 pre-tmc18c30 chips */
222 /* simple stats */
223 int _Bytes_Read;
224 int _Bytes_Written;
225 int _INTR_Processed;
228 #define FD_MAX_HOSTS 3 /* enough? */
230 #define HOSTDATA(shpnt) ((struct fd_hostdata *) shpnt->hostdata)
231 #define bios_base (HOSTDATA(shpnt)->_bios_base)
232 #define bios_major (HOSTDATA(shpnt)->_bios_major)
233 #define bios_minor (HOSTDATA(shpnt)->_bios_minor)
234 #define in_command (HOSTDATA(shpnt)->_in_command)
235 #define current_SC (HOSTDATA(shpnt)->_current_SC)
236 #define chip (HOSTDATA(shpnt)->_chip)
237 #define adapter_mask (HOSTDATA(shpnt)->_adapter_mask)
238 #define FIFO_COUNT (HOSTDATA(shpnt)->_fifo_count)
239 #define adapter_name (HOSTDATA(shpnt)->_adapter_name)
240 #if DEBUG_RACE
241 #define in_interrupt_flag (HOSTDATA(shpnt)->_in_interrupt_flag)
242 #endif
243 #define SCSI_Mode_Cntl_port (HOSTDATA(shpnt)->_SCSI_Mode_Cntl_port)
244 #define FIFO_Data_Count_port (HOSTDATA(shpnt)->_FIFO_Data_Count_port)
245 #define Interrupt_Cntl_port (HOSTDATA(shpnt)->_Interrupt_Cntl_port)
246 #define Interrupt_Status_port (HOSTDATA(shpnt)->_Interrupt_Status_port)
247 #define Interrupt_Cond_port (HOSTDATA(shpnt)->_Interrupt_Cond_port)
248 #define Read_FIFO_port (HOSTDATA(shpnt)->_Read_FIFO_port)
249 #define Read_SCSI_Data_port (HOSTDATA(shpnt)->_Read_SCSI_Data_port)
250 #define SCSI_Cntl_port (HOSTDATA(shpnt)->_SCSI_Cntl_port)
251 #define SCSI_Data_NoACK_port (HOSTDATA(shpnt)->_SCSI_Data_NoACK_port)
252 #define SCSI_Status_port (HOSTDATA(shpnt)->_SCSI_Status_port)
253 #define TMC_Cntl_port (HOSTDATA(shpnt)->_TMC_Cntl_port)
254 #define TMC_Status_port (HOSTDATA(shpnt)->_TMC_Status_port)
255 #define Write_FIFO_port (HOSTDATA(shpnt)->_Write_FIFO_port)
256 #define Write_SCSI_Data_port (HOSTDATA(shpnt)->_Write_SCSI_Data_port)
257 #define FIFO_Size (HOSTDATA(shpnt)->_FIFO_Size)
258 #define Bytes_Read (HOSTDATA(shpnt)->_Bytes_Read)
259 #define Bytes_Written (HOSTDATA(shpnt)->_Bytes_Written)
260 #define INTR_Processed (HOSTDATA(shpnt)->_INTR_Processed)
262 struct fd_mcs_adapters_struct {
263 char* name;
264 int id;
265 enum chip_type fd_chip;
266 int fifo_size;
267 int fifo_count;
270 #define REPLY_ID 0x5137
272 static struct fd_mcs_adapters_struct fd_mcs_adapters[] = {
273 { "Future Domain SCSI Adapter MCS-700(18C50)",
274 0x60e9,
275 tmc18c50,
276 0x2000,
277 4 },
278 { "Future Domain SCSI Adapter MCS-600/700(TMC-1800)",
279 0x6127,
280 tmc1800,
281 0x2000,
282 4 },
283 { "Reply Sound Blaster/SCSI Adapter",
284 REPLY_ID,
285 tmc18c30,
286 0x800,
287 2 },
290 #define FD_BRDS sizeof(fd_mcs_adapters)/sizeof(struct fd_mcs_adapters_struct)
292 static void fd_mcs_intr( int irq, void *dev_id, struct pt_regs * regs );
294 static unsigned long addresses[] = {0xc8000, 0xca000, 0xce000, 0xde000};
295 static unsigned short ports[] = { 0x140, 0x150, 0x160, 0x170 };
296 static unsigned short ints[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
298 /* host information */
299 static int found = 0;
300 static struct Scsi_Host *hosts[FD_MAX_HOSTS+1] = { NULL };
302 static int user_fifo_count = 0;
303 static int user_fifo_size = 0;
305 void fd_mcs_setup( char *str, int *ints )
307 static int done_setup = 0;
309 if (done_setup++ || ints[0] < 1 || ints[0] > 2 ||
310 ints[1] < 1 || ints[1] > 16) {
311 printk( "fd_mcs: usage: fd_mcs=FIFO_COUNT, FIFO_SIZE\n" );
314 user_fifo_count = ints[0] >= 1 ? ints[1] : 0;
315 user_fifo_size = ints[0] >= 2 ? ints[2] : 0;
318 static void print_banner( struct Scsi_Host *shpnt )
320 printk( "scsi%d <fd_mcs>: ", shpnt->host_no);
322 if (bios_base) {
323 printk( "BIOS at 0x%lX", bios_base);
324 } else {
325 printk( "No BIOS");
328 printk( ", HostID %d, %s Chip, IRQ %d, IO 0x%lX\n",
329 shpnt->this_id,
330 chip == tmc18c50 ? "TMC-18C50"
331 : (chip == tmc18c30 ? "TMC-18C30" :
332 (chip == tmc1800 ? "TMC-1800" : "Unknown")),
333 shpnt->irq,
334 shpnt->io_port );
338 static void do_pause( unsigned amount ) /* Pause for amount*10 milliseconds */
340 do {
341 udelay(10*1000);
342 } while (--amount);
345 inline static void fd_mcs_make_bus_idle( struct Scsi_Host *shpnt )
347 outb( 0, SCSI_Cntl_port );
348 outb( 0, SCSI_Mode_Cntl_port );
349 if (chip == tmc18c50 || chip == tmc18c30)
350 outb( 0x21 | PARITY_MASK, TMC_Cntl_port ); /* Clear forced intr. */
351 else
352 outb( 0x01 | PARITY_MASK, TMC_Cntl_port );
355 int fd_mcs_detect( Scsi_Host_Template *tpnt )
357 int loop;
358 struct Scsi_Host *shpnt;
360 /* get id, port, bios, irq */
361 int slot;
362 u_char pos2, pos3, pos4;
363 int id, port, irq;
364 unsigned long bios;
366 /* if not MCA machine, return */
367 if (!MCA_bus)
368 return 0;
370 /* changeable? */
371 id = 7;
373 for( loop = 0; loop < FD_BRDS; loop++ ) {
374 slot = 0;
375 while ( MCA_NOTFOUND !=
376 (slot = mca_find_adapter(fd_mcs_adapters[loop].id,
377 slot)) ) {
379 /* if we get this far, an adapter has been detected and is
380 enabled */
382 printk("scsi <fd_mcs>: %s at slot %d\n",
383 fd_mcs_adapters[loop].name, slot + 1 );
385 pos2 = mca_read_stored_pos( slot, 2 );
386 pos3 = mca_read_stored_pos( slot, 3 );
387 pos4 = mca_read_stored_pos( slot, 4);
389 /* ready for next probe */
390 slot++;
392 if (fd_mcs_adapters[loop].id == REPLY_ID) { /* reply card */
393 static int reply_irq[] = {10, 11, 14, 15};
395 bios = 0; /* no bios */
397 if (pos2 & 0x2)
398 port = ports[pos4 & 0x3];
399 else
400 continue;
402 /* can't really disable it, same as irq=10 */
403 irq = reply_irq[((pos4 >> 2) & 0x1) + 2*((pos4 >> 4) & 0x1)];
404 } else {
405 bios = addresses[pos2 >> 6];
406 port = ports[(pos2 >> 4) & 0x03];
407 irq = ints[(pos2 >> 1) & 0x07];
410 if (irq) {
411 /* claim the slot */
412 mca_set_adapter_name( slot-1, fd_mcs_adapters[loop].name );
414 /* check irq/region */
415 if (check_region(port, 0x10) ||
416 request_irq(irq, fd_mcs_intr,
417 SA_SHIRQ, "fd_mcs", hosts)) {
418 printk( "fd_mcs: check_region() || request_irq() failed, Skip it\n");
420 continue;
423 /* register */
424 if (!(shpnt = scsi_register(tpnt, sizeof(struct fd_hostdata)))) {
425 printk( "fd_mcs: scsi_register() failed\n");
426 continue;
429 /* request I/O region */
430 request_region( port, 0x10, "fd_mcs" );
432 /* save name */
433 strcpy(adapter_name, fd_mcs_adapters[loop].name);
435 /* chip/fifo */
436 chip = fd_mcs_adapters[loop].fd_chip;
437 /* use boot time value if available */
438 FIFO_COUNT =
439 user_fifo_count?user_fifo_count:fd_mcs_adapters[loop].fifo_count;
440 FIFO_Size =
441 user_fifo_size?user_fifo_size:fd_mcs_adapters[loop].fifo_size;
443 #ifdef NOT_USED
444 /* *************************************************** */
445 /* Try to toggle 32-bit mode. This only
446 works on an 18c30 chip. (User reports
447 say this works, so we should switch to
448 it in the near future.) */
449 outb( 0x80, port + IO_Control );
450 if ((inb( port + Configuration2 ) & 0x80) == 0x80) {
451 outb( 0x00, port + IO_Control );
452 if ((inb( port + Configuration2 ) & 0x80) == 0x00) {
453 chip = tmc18c30;
454 FIFO_Size = 0x800; /* 2k FIFO */
456 printk("FIRST: chip=%s, fifo_size=0x%x\n",
457 (chip == tmc18c30)?"tmc18c30":"tmc18c50", FIFO_Size);
461 /* That should have worked, but appears to
462 have problems. Let's assume it is an
463 18c30 if the RAM is disabled. */
465 if (inb( port + Configuration2 ) & 0x02) {
466 chip = tmc18c30;
467 FIFO_Size = 0x800; /* 2k FIFO */
469 printk("SECOND: chip=%s, fifo_size=0x%x\n",
470 (chip == tmc18c30)?"tmc18c30":"tmc18c50", FIFO_Size);
472 /* *************************************************** */
473 #endif
475 /* IBM/ANSI scsi scan ordering */
476 /* Stick this back in when the scsi.c changes are there */
477 shpnt->reverse_ordering = 1;
480 /* saving info */
481 hosts[found++] = shpnt;
483 shpnt->this_id = id;
484 shpnt->irq = irq;
485 shpnt->io_port = port;
486 shpnt->n_io_port = 0x10;
488 /* save */
489 bios_base = bios;
490 adapter_mask = (1 << id);
492 /* save more */
493 SCSI_Mode_Cntl_port = port + SCSI_Mode_Cntl;
494 FIFO_Data_Count_port = port + FIFO_Data_Count;
495 Interrupt_Cntl_port = port + Interrupt_Cntl;
496 Interrupt_Status_port = port + Interrupt_Status;
497 Interrupt_Cond_port = port + Interrupt_Cond;
498 Read_FIFO_port = port + Read_FIFO;
499 Read_SCSI_Data_port = port + Read_SCSI_Data;
500 SCSI_Cntl_port = port + SCSI_Cntl;
501 SCSI_Data_NoACK_port = port + SCSI_Data_NoACK;
502 SCSI_Status_port = port + SCSI_Status;
503 TMC_Cntl_port = port + TMC_Cntl;
504 TMC_Status_port = port + TMC_Status;
505 Write_FIFO_port = port + Write_FIFO;
506 Write_SCSI_Data_port = port + Write_SCSI_Data;
508 Bytes_Read = 0;
509 Bytes_Written = 0;
510 INTR_Processed = 0;
512 /* say something */
513 print_banner( shpnt );
515 /* reset */
516 outb( 1, SCSI_Cntl_port );
517 do_pause( 2 );
518 outb( 0, SCSI_Cntl_port );
519 do_pause( 115 );
520 outb( 0, SCSI_Mode_Cntl_port );
521 outb( PARITY_MASK, TMC_Cntl_port );
522 /* done reset */
524 #if DO_DETECT
525 /* scan devices attached */
527 const int buflen = 255;
528 int i, j, retcode;
529 Scsi_Cmnd SCinit;
530 unsigned char do_inquiry[] = { INQUIRY, 0, 0, 0, buflen, 0 };
531 unsigned char do_request_sense[] = { REQUEST_SENSE,
532 0, 0, 0, buflen, 0 };
533 unsigned char do_read_capacity[] = { READ_CAPACITY,
534 0, 0, 0, 0, 0, 0, 0, 0, 0 };
535 unsigned char buf[buflen];
537 SCinit.request_buffer = SCinit.buffer = buf;
538 SCinit.request_bufflen = SCinit.bufflen = sizeof(buf)-1;
539 SCinit.use_sg = 0;
540 SCinit.lun = 0;
541 SCinit.host = shpnt;
543 printk( "fd_mcs: detection routine scanning for devices:\n" );
544 for (i = 0; i < 8; i++) {
545 if (i == shpnt->this_id) /* Skip host adapter */
546 continue;
547 SCinit.target = i;
548 memcpy(SCinit.cmnd, do_request_sense,
549 sizeof(do_request_sense));
550 retcode = fd_mcs_command(&SCinit);
551 if (!retcode) {
552 memcpy(SCinit.cmnd, do_inquiry, sizeof(do_inquiry));
553 retcode = fd_mcs_command(&SCinit);
554 if (!retcode) {
555 printk( " SCSI ID %d: ", i );
556 for (j = 8; j < (buf[4] < 32 ? buf[4] : 32); j++)
557 printk( "%c", buf[j] >= 20 ? buf[j] : ' ' );
558 memcpy(SCinit.cmnd, do_read_capacity,
559 sizeof(do_read_capacity));
560 retcode = fd_mcs_command(&SCinit);
561 if (!retcode) {
562 unsigned long blocks, size, capacity;
564 blocks = (buf[0] << 24) | (buf[1] << 16)
565 | (buf[2] << 8) | buf[3];
566 size = (buf[4] << 24) | (buf[5] << 16) |
567 (buf[6] << 8) | buf[7];
568 capacity = +( +(blocks / 1024L) * +(size * 10L)) / 1024L;
570 printk( "%lu MB (%lu byte blocks)\n",
571 ((capacity + 5L) / 10L), size );
577 #endif
581 if (found == FD_MAX_HOSTS) {
582 printk( "fd_mcs: detecting reached max=%d host adapters.\n",
583 FD_MAX_HOSTS);
584 break;
588 return found;
591 const char *fd_mcs_info(struct Scsi_Host *shpnt)
593 return adapter_name;
596 static int TOTAL_INTR = 0;
599 * inout : decides on the direction of the dataflow and the meaning of the
600 * variables
601 * buffer: If inout==FALSE data is being written to it else read from it
602 * *start: If inout==FALSE start of the valid data in the buffer
603 * offset: If inout==FALSE offset from the beginning of the imaginary file
604 * from which we start writing into the buffer
605 * length: If inout==FALSE max number of bytes to be written into the buffer
606 * else number of bytes in the buffer
608 int fd_mcs_proc_info( char *buffer, char **start, off_t offset,
609 int length, int hostno, int inout )
611 struct Scsi_Host *shpnt;
612 int len = 0;
613 int i;
615 if (inout)
616 return(-ENOSYS);
618 *start = buffer + offset;
620 for (i = 0; hosts[i] && hosts[i]->host_no != hostno; i++);
621 shpnt = hosts[i];
623 if (!shpnt) {
624 return(-ENOENT);
625 } else {
626 len += sprintf(buffer+len, "Future Domain MCS-600/700 Driver %s\n",
627 DRIVER_VERSION);
629 len += sprintf(buffer+len, "HOST #%d: %s\n",
630 hostno, adapter_name);
632 len += sprintf(buffer+len, "FIFO Size=0x%x, FIFO Count=%d\n",
633 FIFO_Size, FIFO_COUNT);
635 len += sprintf(buffer+len, "DriverCalls=%d, Interrupts=%d, BytesRead=%d, BytesWrite=%d\n\n",
636 TOTAL_INTR, INTR_Processed, Bytes_Read, Bytes_Written);
639 if ((len -= offset) <= 0)
640 return 0;
641 if (len > length)
642 len = length;
643 return len;
646 static int fd_mcs_select(struct Scsi_Host *shpnt, int target )
648 int status;
649 unsigned long timeout;
651 outb( 0x82, SCSI_Cntl_port ); /* Bus Enable + Select */
652 outb( adapter_mask | (1 << target), SCSI_Data_NoACK_port );
654 /* Stop arbitration and enable parity */
655 outb( PARITY_MASK, TMC_Cntl_port );
657 timeout = 350; /* 350mS -- because of timeouts
658 (was 250mS) */
660 do {
661 status = inb( SCSI_Status_port ); /* Read adapter status */
662 if (status & 1) { /* Busy asserted */
663 /* Enable SCSI Bus (on error, should make bus idle with 0) */
664 outb( 0x80, SCSI_Cntl_port );
665 return 0;
667 udelay(1000); /* wait one msec */
668 } while (--timeout);
670 /* Make bus idle */
671 fd_mcs_make_bus_idle(shpnt);
672 #if EVERY_ACCESS
673 if (!target) printk( "Selection failed\n" );
674 #endif
675 #if ERRORS_ONLY
676 if (!target) {
677 static int flag = 0;
679 if (!flag) /* Skip first failure for all chips. */
680 ++flag;
681 else
682 printk( "fd_mcs: Selection failed\n" );
684 #endif
685 return 1;
688 static void my_done( struct Scsi_Host *shpnt, int error )
690 if (in_command) {
691 in_command = 0;
692 outb( 0x00, Interrupt_Cntl_port );
693 fd_mcs_make_bus_idle(shpnt);
694 current_SC->result = error;
695 current_SC->scsi_done( current_SC );
696 } else {
697 panic( "fd_mcs: my_done() called outside of command\n" );
699 #if DEBUG_RACE
700 in_interrupt_flag = 0;
701 #endif
704 /* only my_done needs to be protected */
705 static void fd_mcs_intr( int irq, void *dev_id, struct pt_regs * regs )
707 unsigned long flags;
708 int status;
709 int done = 0;
710 unsigned data_count, tmp_count;
712 int i = 0;
713 struct Scsi_Host *shpnt;
715 TOTAL_INTR++;
717 /* search for one adapter-response on shared interrupt */
718 while ((shpnt = hosts[i++])) {
719 if ((inb(TMC_Status_port)) & 1)
720 break;
723 /* return if some other device on this IRQ caused the interrupt */
724 if (!shpnt) {
725 return;
728 INTR_Processed++;
730 outb( 0x00, Interrupt_Cntl_port );
732 /* Abort calls my_done, so we do nothing here. */
733 if (current_SC->SCp.phase & aborted) {
734 #if DEBUG_ABORT
735 printk( "Interrupt after abort, ignoring\n" );
736 #endif
737 /* return; */
740 #if DEBUG_RACE
741 ++in_interrupt_flag;
742 #endif
744 if (current_SC->SCp.phase & in_arbitration) {
745 status = inb( TMC_Status_port ); /* Read adapter status */
746 if (!(status & 0x02)) {
747 #if EVERY_ACCESS
748 printk( " AFAIL " );
749 #endif
750 spin_lock_irqsave(&io_request_lock, flags);
751 my_done( shpnt, DID_BUS_BUSY << 16 );
752 spin_unlock_irqrestore(&io_request_lock, flags);
753 return;
755 current_SC->SCp.phase = in_selection;
757 outb( 0x40 | FIFO_COUNT, Interrupt_Cntl_port );
759 outb( 0x82, SCSI_Cntl_port ); /* Bus Enable + Select */
760 outb( adapter_mask | (1 << current_SC->target), SCSI_Data_NoACK_port );
762 /* Stop arbitration and enable parity */
763 outb( 0x10 | PARITY_MASK, TMC_Cntl_port );
764 #if DEBUG_RACE
765 in_interrupt_flag = 0;
766 #endif
767 return;
768 } else if (current_SC->SCp.phase & in_selection) {
769 status = inb( SCSI_Status_port );
770 if (!(status & 0x01)) {
771 /* Try again, for slow devices */
772 if (fd_mcs_select(shpnt, current_SC->target )) {
773 #if EVERY_ACCESS
774 printk( " SFAIL " );
775 #endif
776 spin_lock_irqsave(&io_request_lock, flags);
777 my_done( shpnt, DID_NO_CONNECT << 16 );
778 spin_unlock_irqrestore(&io_request_lock, flags);
779 return;
780 } else {
781 #if EVERY_ACCESS
782 printk( " AltSel " );
783 #endif
784 /* Stop arbitration and enable parity */
785 outb( 0x10 | PARITY_MASK, TMC_Cntl_port );
788 current_SC->SCp.phase = in_other;
789 outb( 0x90 | FIFO_COUNT, Interrupt_Cntl_port );
790 outb( 0x80, SCSI_Cntl_port );
791 #if DEBUG_RACE
792 in_interrupt_flag = 0;
793 #endif
794 return;
797 /* current_SC->SCp.phase == in_other: this is the body of the routine */
799 status = inb( SCSI_Status_port );
801 if (status & 0x10) { /* REQ */
803 switch (status & 0x0e) {
805 case 0x08: /* COMMAND OUT */
806 outb( current_SC->cmnd[current_SC->SCp.sent_command++],
807 Write_SCSI_Data_port );
808 #if EVERY_ACCESS
809 printk( "CMD = %x,",
810 current_SC->cmnd[ current_SC->SCp.sent_command - 1] );
811 #endif
812 break;
813 case 0x00: /* DATA OUT -- tmc18c50/tmc18c30 only */
814 if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
815 current_SC->SCp.have_data_in = -1;
816 outb( 0xd0 | PARITY_MASK, TMC_Cntl_port );
818 break;
819 case 0x04: /* DATA IN -- tmc18c50/tmc18c30 only */
820 if (chip != tmc1800 && !current_SC->SCp.have_data_in) {
821 current_SC->SCp.have_data_in = 1;
822 outb( 0x90 | PARITY_MASK, TMC_Cntl_port );
824 break;
825 case 0x0c: /* STATUS IN */
826 current_SC->SCp.Status = inb( Read_SCSI_Data_port );
827 #if EVERY_ACCESS
828 printk( "Status = %x, ", current_SC->SCp.Status );
829 #endif
830 #if ERRORS_ONLY
831 if (current_SC->SCp.Status
832 && current_SC->SCp.Status != 2
833 && current_SC->SCp.Status != 8) {
834 printk( "ERROR fd_mcs: target = %d, command = %x, status = %x\n",
835 current_SC->target,
836 current_SC->cmnd[0],
837 current_SC->SCp.Status );
839 #endif
840 break;
841 case 0x0a: /* MESSAGE OUT */
842 outb( MESSAGE_REJECT, Write_SCSI_Data_port ); /* Reject */
843 break;
844 case 0x0e: /* MESSAGE IN */
845 current_SC->SCp.Message = inb( Read_SCSI_Data_port );
846 #if EVERY_ACCESS
847 printk( "Message = %x, ", current_SC->SCp.Message );
848 #endif
849 if (!current_SC->SCp.Message) ++done;
850 #if DEBUG_MESSAGES || EVERY_ACCESS
851 if (current_SC->SCp.Message) {
852 printk( "fd_mcs: message = %x\n", current_SC->SCp.Message );
854 #endif
855 break;
859 if (chip == tmc1800
860 && !current_SC->SCp.have_data_in
861 && (current_SC->SCp.sent_command
862 >= current_SC->cmd_len)) {
863 /* We have to get the FIFO direction
864 correct, so I've made a table based
865 on the SCSI Standard of which commands
866 appear to require a DATA OUT phase.
869 p. 94: Command for all device types
870 CHANGE DEFINITION 40 DATA OUT
871 COMPARE 39 DATA OUT
872 COPY 18 DATA OUT
873 COPY AND VERIFY 3a DATA OUT
874 INQUIRY 12
875 LOG SELECT 4c DATA OUT
876 LOG SENSE 4d
877 MODE SELECT (6) 15 DATA OUT
878 MODE SELECT (10) 55 DATA OUT
879 MODE SENSE (6) 1a
880 MODE SENSE (10) 5a
881 READ BUFFER 3c
882 RECEIVE DIAGNOSTIC RESULTS 1c
883 REQUEST SENSE 03
884 SEND DIAGNOSTIC 1d DATA OUT
885 TEST UNIT READY 00
886 WRITE BUFFER 3b DATA OUT
888 p.178: Commands for direct-access devices (not listed on p. 94)
889 FORMAT UNIT 04 DATA OUT
890 LOCK-UNLOCK CACHE 36
891 PRE-FETCH 34
892 PREVENT-ALLOW MEDIUM REMOVAL 1e
893 READ (6)/RECEIVE 08
894 READ (10) 3c
895 READ CAPACITY 25
896 READ DEFECT DATA (10) 37
897 READ LONG 3e
898 REASSIGN BLOCKS 07 DATA OUT
899 RELEASE 17
900 RESERVE 16 DATA OUT
901 REZERO UNIT/REWIND 01
902 SEARCH DATA EQUAL (10) 31 DATA OUT
903 SEARCH DATA HIGH (10) 30 DATA OUT
904 SEARCH DATA LOW (10) 32 DATA OUT
905 SEEK (6) 0b
906 SEEK (10) 2b
907 SET LIMITS (10) 33
908 START STOP UNIT 1b
909 SYNCHRONIZE CACHE 35
910 VERIFY (10) 2f
911 WRITE (6)/PRINT/SEND 0a DATA OUT
912 WRITE (10)/SEND 2a DATA OUT
913 WRITE AND VERIFY (10) 2e DATA OUT
914 WRITE LONG 3f DATA OUT
915 WRITE SAME 41 DATA OUT ?
917 p. 261: Commands for sequential-access devices (not previously listed)
918 ERASE 19
919 LOAD UNLOAD 1b
920 LOCATE 2b
921 READ BLOCK LIMITS 05
922 READ POSITION 34
923 READ REVERSE 0f
924 RECOVER BUFFERED DATA 14
925 SPACE 11
926 WRITE FILEMARKS 10 ?
928 p. 298: Commands for printer devices (not previously listed)
929 ****** NOT SUPPORTED BY THIS DRIVER, since 0b is SEEK (6) *****
930 SLEW AND PRINT 0b DATA OUT -- same as seek
931 STOP PRINT 1b
932 SYNCHRONIZE BUFFER 10
934 p. 315: Commands for processor devices (not previously listed)
936 p. 321: Commands for write-once devices (not previously listed)
937 MEDIUM SCAN 38
938 READ (12) a8
939 SEARCH DATA EQUAL (12) b1 DATA OUT
940 SEARCH DATA HIGH (12) b0 DATA OUT
941 SEARCH DATA LOW (12) b2 DATA OUT
942 SET LIMITS (12) b3
943 VERIFY (12) af
944 WRITE (12) aa DATA OUT
945 WRITE AND VERIFY (12) ae DATA OUT
947 p. 332: Commands for CD-ROM devices (not previously listed)
948 PAUSE/RESUME 4b
949 PLAY AUDIO (10) 45
950 PLAY AUDIO (12) a5
951 PLAY AUDIO MSF 47
952 PLAY TRACK RELATIVE (10) 49
953 PLAY TRACK RELATIVE (12) a9
954 READ HEADER 44
955 READ SUB-CHANNEL 42
956 READ TOC 43
958 p. 370: Commands for scanner devices (not previously listed)
959 GET DATA BUFFER STATUS 34
960 GET WINDOW 25
961 OBJECT POSITION 31
962 SCAN 1b
963 SET WINDOW 24 DATA OUT
965 p. 391: Commands for optical memory devices (not listed)
966 ERASE (10) 2c
967 ERASE (12) ac
968 MEDIUM SCAN 38 DATA OUT
969 READ DEFECT DATA (12) b7
970 READ GENERATION 29
971 READ UPDATED BLOCK 2d
972 UPDATE BLOCK 3d DATA OUT
974 p. 419: Commands for medium changer devices (not listed)
975 EXCHANGE MEDIUM 46
976 INITIALIZE ELEMENT STATUS 07
977 MOVE MEDIUM a5
978 POSITION TO ELEMENT 2b
979 READ ELEMENT STATUS b8
980 REQUEST VOL. ELEMENT ADDRESS b5
981 SEND VOLUME TAG b6 DATA OUT
983 p. 454: Commands for communications devices (not listed previously)
984 GET MESSAGE (6) 08
985 GET MESSAGE (10) 28
986 GET MESSAGE (12) a8
989 switch (current_SC->cmnd[0]) {
990 case CHANGE_DEFINITION: case COMPARE: case COPY:
991 case COPY_VERIFY: case LOG_SELECT: case MODE_SELECT:
992 case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER:
994 case FORMAT_UNIT: case REASSIGN_BLOCKS: case RESERVE:
995 case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW:
996 case WRITE_6: case WRITE_10: case WRITE_VERIFY:
997 case 0x3f: case 0x41:
999 case 0xb1: case 0xb0: case 0xb2:
1000 case 0xaa: case 0xae:
1002 case 0x24:
1004 case 0x38: case 0x3d:
1006 case 0xb6:
1008 case 0xea: /* alternate number for WRITE LONG */
1010 current_SC->SCp.have_data_in = -1;
1011 outb( 0xd0 | PARITY_MASK, TMC_Cntl_port );
1012 break;
1014 case 0x00:
1015 default:
1017 current_SC->SCp.have_data_in = 1;
1018 outb( 0x90 | PARITY_MASK, TMC_Cntl_port );
1019 break;
1023 if (current_SC->SCp.have_data_in == -1) { /* DATA OUT */
1024 while ( (data_count = FIFO_Size - inw( FIFO_Data_Count_port )) > 512 ) {
1025 #if EVERY_ACCESS
1026 printk( "DC=%d, ", data_count ) ;
1027 #endif
1028 if (data_count > current_SC->SCp.this_residual)
1029 data_count = current_SC->SCp.this_residual;
1030 if (data_count > 0) {
1031 #if EVERY_ACCESS
1032 printk( "%d OUT, ", data_count );
1033 #endif
1034 if (data_count == 1) {
1035 Bytes_Written++;
1037 outb( *current_SC->SCp.ptr++, Write_FIFO_port );
1038 --current_SC->SCp.this_residual;
1039 } else {
1040 data_count >>= 1;
1041 tmp_count = data_count << 1;
1042 outsw( Write_FIFO_port, current_SC->SCp.ptr, data_count );
1043 current_SC->SCp.ptr += tmp_count;
1044 Bytes_Written += tmp_count;
1045 current_SC->SCp.this_residual -= tmp_count;
1048 if (!current_SC->SCp.this_residual) {
1049 if (current_SC->SCp.buffers_residual) {
1050 --current_SC->SCp.buffers_residual;
1051 ++current_SC->SCp.buffer;
1052 current_SC->SCp.ptr = current_SC->SCp.buffer->address;
1053 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1054 } else
1055 break;
1058 } else if (current_SC->SCp.have_data_in == 1) { /* DATA IN */
1059 while ((data_count = inw( FIFO_Data_Count_port )) > 0) {
1060 #if EVERY_ACCESS
1061 printk( "DC=%d, ", data_count );
1062 #endif
1063 if (data_count > current_SC->SCp.this_residual)
1064 data_count = current_SC->SCp.this_residual;
1065 if (data_count) {
1066 #if EVERY_ACCESS
1067 printk( "%d IN, ", data_count );
1068 #endif
1069 if (data_count == 1) {
1070 Bytes_Read++;
1071 *current_SC->SCp.ptr++ = inb( Read_FIFO_port );
1072 --current_SC->SCp.this_residual;
1073 } else {
1074 data_count >>= 1; /* Number of words */
1075 tmp_count = data_count << 1;
1076 insw( Read_FIFO_port, current_SC->SCp.ptr, data_count );
1077 current_SC->SCp.ptr += tmp_count;
1078 Bytes_Read += tmp_count;
1079 current_SC->SCp.this_residual -= tmp_count;
1082 if (!current_SC->SCp.this_residual
1083 && current_SC->SCp.buffers_residual) {
1084 --current_SC->SCp.buffers_residual;
1085 ++current_SC->SCp.buffer;
1086 current_SC->SCp.ptr = current_SC->SCp.buffer->address;
1087 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1092 if (done) {
1093 #if EVERY_ACCESS
1094 printk( " ** IN DONE %d ** ", current_SC->SCp.have_data_in );
1095 #endif
1097 #if ERRORS_ONLY
1098 if (current_SC->cmnd[0] == REQUEST_SENSE && !current_SC->SCp.Status) {
1099 if ((unsigned char)(*((char *)current_SC->request_buffer+2)) & 0x0f) {
1100 unsigned char key;
1101 unsigned char code;
1102 unsigned char qualifier;
1104 key = (unsigned char)(*((char *)current_SC->request_buffer + 2))
1105 & 0x0f;
1106 code = (unsigned char)(*((char *)current_SC->request_buffer + 12));
1107 qualifier = (unsigned char)(*((char *)current_SC->request_buffer
1108 + 13));
1110 if (key != UNIT_ATTENTION
1111 && !(key == NOT_READY
1112 && code == 0x04
1113 && (!qualifier || qualifier == 0x02 || qualifier == 0x01))
1114 && !(key == ILLEGAL_REQUEST && (code == 0x25
1115 || code == 0x24
1116 || !code)))
1118 printk( "fd_mcs: REQUEST SENSE "
1119 "Key = %x, Code = %x, Qualifier = %x\n",
1120 key, code, qualifier );
1123 #endif
1124 #if EVERY_ACCESS
1125 printk( "BEFORE MY_DONE. . ." );
1126 #endif
1127 spin_lock_irqsave(&io_request_lock, flags);
1128 my_done( shpnt,
1129 (current_SC->SCp.Status & 0xff)
1130 | ((current_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16) );
1131 spin_unlock_irqrestore(&io_request_lock, flags);
1132 #if EVERY_ACCESS
1133 printk( "RETURNING.\n" );
1134 #endif
1136 } else {
1137 if (current_SC->SCp.phase & disconnect) {
1138 outb( 0xd0 | FIFO_COUNT, Interrupt_Cntl_port );
1139 outb( 0x00, SCSI_Cntl_port );
1140 } else {
1141 outb( 0x90 | FIFO_COUNT, Interrupt_Cntl_port );
1144 #if DEBUG_RACE
1145 in_interrupt_flag = 0;
1146 #endif
1147 return;
1150 int fd_mcs_release(struct Scsi_Host *shpnt)
1152 int i, this_host, irq_usage;
1154 release_region(shpnt->io_port, shpnt->n_io_port);
1156 this_host = -1;
1157 irq_usage = 0;
1158 for (i = 0; i < found; i++) {
1159 if (shpnt == hosts[i])
1160 this_host = i;
1161 if (shpnt->irq == hosts[i]->irq)
1162 irq_usage++;
1165 /* only for the last one */
1166 if (1 == irq_usage)
1167 free_irq(shpnt->irq, hosts);
1169 found--;
1171 for (i = this_host; i < found; i++)
1172 hosts[i] = hosts[i+1];
1174 hosts[found] = NULL;
1176 return 0;
1179 int fd_mcs_queue( Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
1181 struct Scsi_Host *shpnt = SCpnt->host;
1183 if (in_command) {
1184 panic( "fd_mcs: fd_mcs_queue() NOT REENTRANT!\n" );
1186 #if EVERY_ACCESS
1187 printk( "queue: target = %d cmnd = 0x%02x pieces = %d size = %u\n",
1188 SCpnt->target,
1189 *(unsigned char *)SCpnt->cmnd,
1190 SCpnt->use_sg,
1191 SCpnt->request_bufflen );
1192 #endif
1194 fd_mcs_make_bus_idle(shpnt);
1196 SCpnt->scsi_done = done; /* Save this for the done function */
1197 current_SC = SCpnt;
1199 /* Initialize static data */
1201 if (current_SC->use_sg) {
1202 current_SC->SCp.buffer =
1203 (struct scatterlist *)current_SC->request_buffer;
1204 current_SC->SCp.ptr = current_SC->SCp.buffer->address;
1205 current_SC->SCp.this_residual = current_SC->SCp.buffer->length;
1206 current_SC->SCp.buffers_residual = current_SC->use_sg - 1;
1207 } else {
1208 current_SC->SCp.ptr = (char *)current_SC->request_buffer;
1209 current_SC->SCp.this_residual = current_SC->request_bufflen;
1210 current_SC->SCp.buffer = NULL;
1211 current_SC->SCp.buffers_residual = 0;
1215 current_SC->SCp.Status = 0;
1216 current_SC->SCp.Message = 0;
1217 current_SC->SCp.have_data_in = 0;
1218 current_SC->SCp.sent_command = 0;
1219 current_SC->SCp.phase = in_arbitration;
1221 /* Start arbitration */
1222 outb( 0x00, Interrupt_Cntl_port );
1223 outb( 0x00, SCSI_Cntl_port ); /* Disable data drivers */
1224 outb( adapter_mask, SCSI_Data_NoACK_port ); /* Set our id bit */
1225 in_command = 1;
1226 outb( 0x20, Interrupt_Cntl_port );
1227 outb( 0x14 | PARITY_MASK, TMC_Cntl_port ); /* Start arbitration */
1229 return 0;
1232 static void internal_done( Scsi_Cmnd *SCpnt )
1234 /* flag it done */
1235 SCpnt->host_scribble = (unsigned char *)1;
1238 int fd_mcs_command( Scsi_Cmnd *SCpnt )
1240 fd_mcs_queue( SCpnt, internal_done );
1241 /* host_scribble is used for status here */
1242 SCpnt->host_scribble = NULL;
1243 while (!SCpnt->host_scribble)
1244 barrier();
1245 return SCpnt->result;
1248 #if DEBUG_ABORT || DEBUG_RESET
1249 static void fd_mcs_print_info( Scsi_Cmnd *SCpnt )
1251 unsigned int imr;
1252 unsigned int irr;
1253 unsigned int isr;
1254 struct Scsi_Host *shpnt = SCpnt->host;
1256 if (!SCpnt || !SCpnt->host) {
1257 printk( "fd_mcs: cannot provide detailed information\n" );
1260 printk( "%s\n", fd_mcs_info( SCpnt->host ) );
1261 print_banner( SCpnt->host );
1262 switch (SCpnt->SCp.phase) {
1263 case in_arbitration: printk( "arbitration " ); break;
1264 case in_selection: printk( "selection " ); break;
1265 case in_other: printk( "other " ); break;
1266 default: printk( "unknown " ); break;
1269 printk( "(%d), target = %d cmnd = 0x%02x pieces = %d size = %u\n",
1270 SCpnt->SCp.phase,
1271 SCpnt->target,
1272 *(unsigned char *)SCpnt->cmnd,
1273 SCpnt->use_sg,
1274 SCpnt->request_bufflen );
1275 printk( "sent_command = %d, have_data_in = %d, timeout = %d\n",
1276 SCpnt->SCp.sent_command,
1277 SCpnt->SCp.have_data_in,
1278 SCpnt->timeout );
1279 #if DEBUG_RACE
1280 printk( "in_interrupt_flag = %d\n", in_interrupt_flag );
1281 #endif
1283 imr = (inb( 0x0a1 ) << 8) + inb( 0x21 );
1284 outb( 0x0a, 0xa0 );
1285 irr = inb( 0xa0 ) << 8;
1286 outb( 0x0a, 0x20 );
1287 irr += inb( 0x20 );
1288 outb( 0x0b, 0xa0 );
1289 isr = inb( 0xa0 ) << 8;
1290 outb( 0x0b, 0x20 );
1291 isr += inb( 0x20 );
1293 /* Print out interesting information */
1294 printk( "IMR = 0x%04x", imr );
1295 if (imr & (1 << shpnt->irq))
1296 printk( " (masked)" );
1297 printk( ", IRR = 0x%04x, ISR = 0x%04x\n", irr, isr );
1299 printk( "SCSI Status = 0x%02x\n", inb( SCSI_Status_port ) );
1300 printk( "TMC Status = 0x%02x", inb( TMC_Status_port ) );
1301 if (inb( TMC_Status_port ) & 1)
1302 printk( " (interrupt)" );
1303 printk( "\n" );
1304 printk( "Interrupt Status = 0x%02x", inb( Interrupt_Status_port ) );
1305 if (inb( Interrupt_Status_port ) & 0x08)
1306 printk( " (enabled)" );
1307 printk( "\n" );
1308 if (chip == tmc18c50 || chip == tmc18c30) {
1309 printk( "FIFO Status = 0x%02x\n", inb( shpnt->io_port + FIFO_Status ) );
1310 printk( "Int. Condition = 0x%02x\n",
1311 inb( shpnt->io_port + Interrupt_Cond ) );
1313 printk( "Configuration 1 = 0x%02x\n", inb( shpnt->io_port + Configuration1 ) );
1314 if (chip == tmc18c50 || chip == tmc18c30)
1315 printk( "Configuration 2 = 0x%02x\n",
1316 inb( shpnt->io_port + Configuration2 ) );
1318 #endif
1320 int fd_mcs_abort( Scsi_Cmnd *SCpnt)
1322 struct Scsi_Host *shpnt = SCpnt->host;
1324 unsigned long flags;
1325 #if EVERY_ACCESS || ERRORS_ONLY || DEBUG_ABORT
1326 printk( "fd_mcs: abort " );
1327 #endif
1329 save_flags( flags );
1330 cli();
1331 if (!in_command) {
1332 #if EVERY_ACCESS || ERRORS_ONLY
1333 printk( " (not in command)\n" );
1334 #endif
1335 restore_flags( flags );
1336 return SCSI_ABORT_NOT_RUNNING;
1337 } else printk( "\n" );
1339 #if DEBUG_ABORT
1340 fd_mcs_print_info( SCpnt );
1341 #endif
1343 fd_mcs_make_bus_idle(shpnt);
1345 current_SC->SCp.phase |= aborted;
1347 current_SC->result = DID_ABORT << 16;
1349 restore_flags( flags );
1351 /* Aborts are not done well. . . */
1352 spin_lock_irqsave(&io_request_lock, flags);
1353 my_done( shpnt, DID_ABORT << 16 );
1354 spin_unlock_irqrestore(&io_request_lock, flags);
1356 return SCSI_ABORT_SUCCESS;
1359 int fd_mcs_reset( Scsi_Cmnd *SCpnt, unsigned int reset_flags )
1361 struct Scsi_Host *shpnt = SCpnt->host;
1363 #if DEBUG_RESET
1364 static int called_once = 0;
1365 #endif
1367 #if ERRORS_ONLY
1368 if (SCpnt) printk( "fd_mcs: SCSI Bus Reset\n" );
1369 #endif
1371 #if DEBUG_RESET
1372 if (called_once) fd_mcs_print_info( current_SC );
1373 called_once = 1;
1374 #endif
1376 outb( 1, SCSI_Cntl_port );
1377 do_pause( 2 );
1378 outb( 0, SCSI_Cntl_port );
1379 do_pause( 115 );
1380 outb( 0, SCSI_Mode_Cntl_port );
1381 outb( PARITY_MASK, TMC_Cntl_port );
1383 /* Unless this is the very first call (i.e., SCPnt == NULL), everything
1384 is probably hosed at this point. We will, however, try to keep
1385 things going by informing the high-level code that we need help. */
1387 return SCSI_RESET_WAKEUP;
1390 #include "sd.h"
1391 #include <scsi/scsi_ioctl.h>
1393 int fd_mcs_biosparam( Scsi_Disk *disk, kdev_t dev, int *info_array )
1395 int drive;
1396 unsigned char buf[512 + sizeof( int ) * 2];
1397 int size = disk->capacity;
1398 int *sizes = (int *)buf;
1399 unsigned char *data = (unsigned char *)(sizes + 2);
1400 unsigned char do_read[] = { READ_6, 0, 0, 0, 1, 0 };
1401 int retcode;
1403 /* BIOS >= 3.4 for MCA cards */
1404 drive = MINOR(dev) / 16;
1406 /* This algorithm was provided by Future Domain (much thanks!). */
1408 sizes[0] = 0; /* zero bytes out */
1409 sizes[1] = 512; /* one sector in */
1410 memcpy( data, do_read, sizeof( do_read ) );
1411 retcode = kernel_scsi_ioctl( disk->device,
1412 SCSI_IOCTL_SEND_COMMAND,
1413 (void *)buf );
1414 if (!retcode /* SCSI command ok */
1415 && data[511] == 0xaa && data[510] == 0x55 /* Partition table valid */
1416 && data[0x1c2]) { /* Partition type */
1418 /* The partition table layout is as follows:
1420 Start: 0x1b3h
1421 Offset: 0 = partition status
1422 1 = starting head
1423 2 = starting sector and cylinder (word, encoded)
1424 4 = partition type
1425 5 = ending head
1426 6 = ending sector and cylinder (word, encoded)
1427 8 = starting absolute sector (double word)
1428 c = number of sectors (double word)
1429 Signature: 0x1fe = 0x55aa
1431 So, this algorithm assumes:
1432 1) the first partition table is in use,
1433 2) the data in the first entry is correct, and
1434 3) partitions never divide cylinders
1436 Note that (1) may be FALSE for NetBSD (and other BSD flavors),
1437 as well as for Linux. Note also, that Linux doesn't pay any
1438 attention to the fields that are used by this algorithm -- it
1439 only uses the absolute sector data. Recent versions of Linux's
1440 fdisk(1) will fill this data in correctly, and forthcoming
1441 versions will check for consistency.
1443 Checking for a non-zero partition type is not part of the
1444 Future Domain algorithm, but it seemed to be a reasonable thing
1445 to do, especially in the Linux and BSD worlds. */
1447 info_array[0] = data[0x1c3] + 1; /* heads */
1448 info_array[1] = data[0x1c4] & 0x3f; /* sectors */
1449 } else {
1451 /* Note that this new method guarantees that there will always be
1452 less than 1024 cylinders on a platter. This is good for drives
1453 up to approximately 7.85GB (where 1GB = 1024 * 1024 kB). */
1455 if ((unsigned int)size >= 0x7e0000U) {
1456 info_array[0] = 0xff; /* heads = 255 */
1457 info_array[1] = 0x3f; /* sectors = 63 */
1458 } else if ((unsigned int)size >= 0x200000U) {
1459 info_array[0] = 0x80; /* heads = 128 */
1460 info_array[1] = 0x3f; /* sectors = 63 */
1461 } else {
1462 info_array[0] = 0x40; /* heads = 64 */
1463 info_array[1] = 0x20; /* sectors = 32 */
1466 /* For both methods, compute the cylinders */
1467 info_array[2] = (unsigned int)size / (info_array[0] * info_array[1] );
1470 return 0;
1473 #ifdef MODULE
1474 /* Eventually this will go into an include file, but this will be later */
1475 Scsi_Host_Template driver_template = FD_MCS;
1477 #include "scsi_module.c"
1478 #endif