Linux Audio

Check our new training course

Loading...
v3.1
   1/************************************************************
   2 *                                                          *
   3 *               Linux EATA SCSI PIO driver                 *
   4 *                                                          *
   5 *  based on the CAM document CAM/89-004 rev. 2.0c,         *
   6 *  DPT's driver kit, some internal documents and source,   *
   7 *  and several other Linux scsi drivers and kernel docs.   *
   8 *                                                          *
   9 *  The driver currently:                                   *
  10 *      -supports all EATA-PIO boards                       *
  11 *      -only supports DASD devices                         *
  12 *                                                          *
  13 *  (c)1993-96 Michael Neuffer, Alfred Arnold               *
  14 *             neuffer@goofy.zdv.uni-mainz.de               *
  15 *             a.arnold@kfa-juelich.de                      * 
  16 *                                                          *
  17 *  Updated 2002 by Alan Cox <alan@lxorguk.ukuu.org.uk> for *
  18 *   Linux 2.5.x and the newer locking and error handling   *
  19 *                                                          *
  20 *  This program is free software; you can redistribute it  *
  21 *  and/or modify it under the terms of the GNU General     *
  22 *  Public License as published by the Free Software        *
  23 *  Foundation; either version 2 of the License, or         *
  24 *  (at your option) any later version.                     *
  25 *                                                          *
  26 *  This program is distributed in the hope that it will be *
  27 *  useful, but WITHOUT ANY WARRANTY; without even the      *
  28 *  implied warranty of MERCHANTABILITY or FITNESS FOR A    *
  29 *  PARTICULAR PURPOSE.  See the GNU General Public License *
  30 *  for more details.                                       *
  31 *                                                          *
  32 *  You should have received a copy of the GNU General      *
  33 *  Public License along with this kernel; if not, write to *
  34 *  the Free Software Foundation, Inc., 675 Mass Ave,       *
  35 *  Cambridge, MA 02139, USA.                               *
  36 *							    *
  37 *  For the avoidance of doubt the "preferred form" of this *
  38 *  code is one which is in an open non patent encumbered   *
  39 *  format. Where cryptographic key signing forms part of   *
  40 *  the process of creating an executable the information   *
  41 *  including keys needed to generate an equivalently       *
  42 *  functional executable are deemed to be part of the 	    *
  43 *  source code are deemed to be part of the source code.   *
  44 *                                                          *
  45 ************************************************************
  46 *  last change: 2002/11/02               OS: Linux 2.5.45  *
  47 ************************************************************/
  48
  49#include <linux/module.h>
  50#include <linux/kernel.h>
  51#include <linux/string.h>
  52#include <linux/ioport.h>
  53#include <linux/in.h>
  54#include <linux/pci.h>
  55#include <linux/proc_fs.h>
  56#include <linux/interrupt.h>
  57#include <linux/blkdev.h>
  58#include <linux/spinlock.h>
  59#include <linux/delay.h>
  60
  61#include <asm/io.h>
  62
  63#include <scsi/scsi.h>
  64#include <scsi/scsi_cmnd.h>
  65#include <scsi/scsi_device.h>
  66#include <scsi/scsi_host.h>
  67
  68#include "eata_generic.h"
  69#include "eata_pio.h"
  70
  71
  72static unsigned int ISAbases[MAXISA] =	{
  73	 0x1F0, 0x170, 0x330, 0x230
  74};
  75
  76static unsigned int ISAirqs[MAXISA] = {
  77	14, 12, 15, 11
  78};
  79
  80static unsigned char EISAbases[] = { 
  81	1, 1, 1, 1, 1, 1, 1, 1,
  82	1, 1, 1, 1, 1, 1, 1, 1 
  83};
  84
  85static unsigned int registered_HBAs;
  86static struct Scsi_Host *last_HBA;
  87static struct Scsi_Host *first_HBA;
  88static unsigned char reg_IRQ[16];
  89static unsigned char reg_IRQL[16];
  90static unsigned long int_counter;
  91static unsigned long queue_counter;
  92
  93static struct scsi_host_template driver_template;
  94
  95/*
  96 * eata_proc_info
  97 * inout : decides on the direction of the dataflow and the meaning of the 
  98 *         variables
  99 * buffer: If inout==FALSE data is being written to it else read from it
 100 * *start: If inout==FALSE start of the valid data in the buffer
 101 * offset: If inout==FALSE offset from the beginning of the imaginary file 
 102 *         from which we start writing into the buffer
 103 * length: If inout==FALSE max number of bytes to be written into the buffer 
 104 *         else number of bytes in the buffer
 105 */
 106static int eata_pio_proc_info(struct Scsi_Host *shost, char *buffer, char **start, off_t offset,
 107			      int length, int rw)
 108{
 109	int len = 0;
 110	off_t begin = 0, pos = 0;
 111
 112	if (rw)
 113		return -ENOSYS;
 114
 115	len += sprintf(buffer+len, "EATA (Extended Attachment) PIO driver version: "
 116		   "%d.%d%s\n",VER_MAJOR, VER_MINOR, VER_SUB);
 117	len += sprintf(buffer + len, "queued commands:     %10ld\n"
 118		   "processed interrupts:%10ld\n", queue_counter, int_counter);
 119	len += sprintf(buffer + len, "\nscsi%-2d: HBA %.10s\n",
 120		   shost->host_no, SD(shost)->name);
 121	len += sprintf(buffer + len, "Firmware revision: v%s\n",
 122		   SD(shost)->revision);
 123	len += sprintf(buffer + len, "IO: PIO\n");
 124	len += sprintf(buffer + len, "Base IO : %#.4x\n", (u32) shost->base);
 125	len += sprintf(buffer + len, "Host Bus: %s\n",
 126		   (SD(shost)->bustype == 'P')?"PCI ":
 127		   (SD(shost)->bustype == 'E')?"EISA":"ISA ");
 128    
 129	pos = begin + len;
 130    
 131	if (pos < offset) {
 132		len = 0;
 133		begin = pos;
 134	}
 135	if (pos > offset + length)
 136		goto stop_output;
 137    
 138stop_output:
 139	DBG(DBG_PROC, printk("2pos: %ld offset: %ld len: %d\n", pos, offset, len));
 140	*start = buffer + (offset - begin);   /* Start of wanted data */
 141	len -= (offset - begin);            /* Start slop */
 142	if (len > length)
 143		len = length;               /* Ending slop */
 144	DBG(DBG_PROC, printk("3pos: %ld offset: %ld len: %d\n", pos, offset, len));
 145    
 146	return len;
 147}
 148
 149static int eata_pio_release(struct Scsi_Host *sh)
 150{
 151	hostdata *hd = SD(sh);
 152	if (sh->irq && reg_IRQ[sh->irq] == 1)
 153		free_irq(sh->irq, NULL);
 154	else
 155		reg_IRQ[sh->irq]--;
 156	if (SD(sh)->channel == 0) {
 157		if (sh->io_port && sh->n_io_port)
 158			release_region(sh->io_port, sh->n_io_port);
 159	}
 160	/* At this point the PCI reference can go */
 161	if (hd->pdev)
 162		pci_dev_put(hd->pdev);
 163	return 1;
 164}
 165
 166static void IncStat(struct scsi_pointer *SCp, unsigned int Increment)
 167{
 168	SCp->ptr += Increment;
 169	if ((SCp->this_residual -= Increment) == 0) {
 170		if ((--SCp->buffers_residual) == 0)
 171			SCp->Status = 0;
 172		else {
 173			SCp->buffer++;
 174			SCp->ptr = sg_virt(SCp->buffer);
 175			SCp->this_residual = SCp->buffer->length;
 176		}
 177	}
 178}
 179
 180static irqreturn_t eata_pio_int_handler(int irq, void *dev_id);
 181
 182static irqreturn_t do_eata_pio_int_handler(int irq, void *dev_id)
 183{
 184	unsigned long flags;
 185	struct Scsi_Host *dev = dev_id;
 186	irqreturn_t ret;
 187
 188	spin_lock_irqsave(dev->host_lock, flags);
 189	ret = eata_pio_int_handler(irq, dev_id);
 190	spin_unlock_irqrestore(dev->host_lock, flags);
 191	return ret;
 192}
 193
 194static irqreturn_t eata_pio_int_handler(int irq, void *dev_id)
 195{
 196	unsigned int eata_stat = 0xfffff;
 197	struct scsi_cmnd *cmd;
 198	hostdata *hd;
 199	struct eata_ccb *cp;
 200	unsigned long base;
 201	unsigned int x, z;
 202	struct Scsi_Host *sh;
 203	unsigned short zwickel = 0;
 204	unsigned char stat, odd;
 205	irqreturn_t ret = IRQ_NONE;
 206
 207	for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) 
 208	{
 209		if (sh->irq != irq)
 210			continue;
 211		if (inb(sh->base + HA_RSTATUS) & HA_SBUSY)
 212			continue;
 213
 214		int_counter++;
 215		ret = IRQ_HANDLED;
 216
 217		hd = SD(sh);
 218
 219		cp = &hd->ccb[0];
 220		cmd = cp->cmd;
 221		base = cmd->device->host->base;
 222
 223		do {
 224			stat = inb(base + HA_RSTATUS);
 225			if (stat & HA_SDRQ) {
 226				if (cp->DataIn) {
 227					z = 256;
 228					odd = 0;
 229					while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
 230						if (odd) {
 231							*(cmd->SCp.ptr) = zwickel >> 8;
 232							IncStat(&cmd->SCp, 1);
 233							odd = 0;
 234						}
 235						x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
 236						insw(base + HA_RDATA, cmd->SCp.ptr, x);
 237						z -= x;
 238						IncStat(&cmd->SCp, 2 * x);
 239						if ((z > 0) && (cmd->SCp.this_residual == 1)) {
 240							zwickel = inw(base + HA_RDATA);
 241							*(cmd->SCp.ptr) = zwickel & 0xff;
 242							IncStat(&cmd->SCp, 1);
 243							z--;
 244							odd = 1;
 245						}
 246					}
 247					while (z > 0) {
 248						zwickel = inw(base + HA_RDATA);
 249						z--;
 250					}
 251				} else {	/* cp->DataOut */
 252
 253					odd = 0;
 254					z = 256;
 255					while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
 256						if (odd) {
 257							zwickel += *(cmd->SCp.ptr) << 8;
 258							IncStat(&cmd->SCp, 1);
 259							outw(zwickel, base + HA_RDATA);
 260							z--;
 261							odd = 0;
 262						}
 263						x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
 264						outsw(base + HA_RDATA, cmd->SCp.ptr, x);
 265						z -= x;
 266						IncStat(&cmd->SCp, 2 * x);
 267						if ((z > 0) && (cmd->SCp.this_residual == 1)) {
 268							zwickel = *(cmd->SCp.ptr);
 269							zwickel &= 0xff;
 270							IncStat(&cmd->SCp, 1);
 271							odd = 1;
 272						}
 273					}
 274					while (z > 0 || odd) {
 275						outw(zwickel, base + HA_RDATA);
 276						z--;
 277						odd = 0;
 278					}
 279				}
 280			}
 281		}
 282		while ((stat & HA_SDRQ) || ((stat & HA_SMORE) && hd->moresupport));
 283
 284		/* terminate handler if HBA goes busy again, i.e. transfers
 285		 * more data */
 286
 287		if (stat & HA_SBUSY)
 288			break;
 289
 290		/* OK, this is quite stupid, but I haven't found any correct
 291		 * way to get HBA&SCSI status so far */
 292
 293		if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {
 294			cmd->result = (DID_OK << 16);
 295			hd->devflags |= (1 << cp->cp_id);
 296		} else if (hd->devflags & (1 << cp->cp_id))
 297			cmd->result = (DID_OK << 16) + 0x02;
 298		else
 299			cmd->result = (DID_NO_CONNECT << 16);
 300
 301		if (cp->status == LOCKED) {
 302			cp->status = FREE;
 303			eata_stat = inb(base + HA_RSTATUS);
 304			printk(KERN_CRIT "eata_pio: int_handler, freeing locked " "queueslot\n");
 305			return ret;
 306		}
 307#if DBG_INTR2
 308		if (stat != 0x50)
 309			printk(KERN_DEBUG "stat: %#.2x, result: %#.8x\n", stat, cmd->result);
 310#endif
 311
 312		cp->status = FREE;	/* now we can release the slot  */
 313
 314		cmd->scsi_done(cmd);
 315	}
 316
 317	return ret;
 318}
 319
 320static inline unsigned int eata_pio_send_command(unsigned long base, unsigned char command)
 321{
 322	unsigned int loop = 50;
 323
 324	while (inb(base + HA_RSTATUS) & HA_SBUSY)
 325		if (--loop == 0)
 326			return 1;
 327
 328	/* Enable interrupts for HBA.  It is not the best way to do it at this
 329	 * place, but I hope that it doesn't interfere with the IDE driver 
 330	 * initialization this way */
 331
 332	outb(HA_CTRL_8HEADS, base + HA_CTRLREG);
 333
 334	outb(command, base + HA_WCOMMAND);
 335	return 0;
 336}
 337
 338static int eata_pio_queue_lck(struct scsi_cmnd *cmd,
 339		void (*done)(struct scsi_cmnd *))
 340{
 341	unsigned int x, y;
 342	unsigned long base;
 343
 344	hostdata *hd;
 345	struct Scsi_Host *sh;
 346	struct eata_ccb *cp;
 347
 348	queue_counter++;
 349
 350	hd = HD(cmd);
 351	sh = cmd->device->host;
 352	base = sh->base;
 353
 354	/* use only slot 0, as 2001 can handle only one cmd at a time */
 355
 356	y = x = 0;
 357
 358	if (hd->ccb[y].status != FREE) {
 359
 360		DBG(DBG_QUEUE, printk(KERN_EMERG "can_queue %d, x %d, y %d\n", sh->can_queue, x, y));
 361#if DEBUG_EATA
 362		panic(KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld " "intrno: %ld\n", queue_counter, int_counter);
 363#else
 364		panic(KERN_EMERG "eata_pio: run out of queue slots....\n");
 365#endif
 366	}
 367
 368	cp = &hd->ccb[y];
 369
 370	memset(cp, 0, sizeof(struct eata_ccb));
 371
 372	cp->status = USED;	/* claim free slot */
 373
 374	DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,
 375		"eata_pio_queue 0x%p, y %d\n", cmd, y));
 376
 377	cmd->scsi_done = (void *) done;
 378
 379	if (cmd->sc_data_direction == DMA_TO_DEVICE)
 380		cp->DataOut = 1;	/* Output mode */
 381	else
 382		cp->DataIn = 0;	/* Input mode  */
 383
 384	cp->Interpret = (cmd->device->id == hd->hostid);
 385	cp->cp_datalen = cpu_to_be32(scsi_bufflen(cmd));
 386	cp->Auto_Req_Sen = 0;
 387	cp->cp_reqDMA = 0;
 388	cp->reqlen = 0;
 389
 390	cp->cp_id = cmd->device->id;
 391	cp->cp_lun = cmd->device->lun;
 392	cp->cp_dispri = 0;
 393	cp->cp_identify = 1;
 394	memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
 395
 396	cp->cp_statDMA = 0;
 397
 398	cp->cp_viraddr = cp;
 399	cp->cmd = cmd;
 400	cmd->host_scribble = (char *) &hd->ccb[y];
 401
 402	if (!scsi_bufflen(cmd)) {
 403		cmd->SCp.buffers_residual = 1;
 404		cmd->SCp.ptr = NULL;
 405		cmd->SCp.this_residual = 0;
 406		cmd->SCp.buffer = NULL;
 407	} else {
 408		cmd->SCp.buffer = scsi_sglist(cmd);
 409		cmd->SCp.buffers_residual = scsi_sg_count(cmd);
 410		cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
 411		cmd->SCp.this_residual = cmd->SCp.buffer->length;
 412	}
 413	cmd->SCp.Status = (cmd->SCp.this_residual != 0);	/* TRUE as long as bytes 
 414								 * are to transfer */
 415
 416	if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) {
 417		cmd->result = DID_BUS_BUSY << 16;
 418		scmd_printk(KERN_NOTICE, cmd,
 419			"eata_pio_queue pid 0x%p, HBA busy, "
 420			"returning DID_BUS_BUSY, done.\n", cmd);
 421		done(cmd);
 422		cp->status = FREE;
 423		return 0;
 424	}
 425	/* FIXME: timeout */
 426	while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
 427		cpu_relax();
 428	outsw(base + HA_RDATA, cp, hd->cplen);
 429	outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
 430	for (x = 0; x < hd->cppadlen; x++)
 431		outw(0, base + HA_RDATA);
 432
 433	DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,
 434		"Queued base %#.4lx cmd: 0x%p "
 435		"slot %d irq %d\n", sh->base, cmd, y, sh->irq));
 436
 437	return 0;
 438}
 439
 440static DEF_SCSI_QCMD(eata_pio_queue)
 441
 442static int eata_pio_abort(struct scsi_cmnd *cmd)
 443{
 444	unsigned int loop = 100;
 445
 446	DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,
 447		"eata_pio_abort called pid: 0x%p\n", cmd));
 448
 449	while (inb(cmd->device->host->base + HA_RAUXSTAT) & HA_ABUSY)
 450		if (--loop == 0) {
 451			printk(KERN_WARNING "eata_pio: abort, timeout error.\n");
 452			return FAILED;
 453		}
 454	if (CD(cmd)->status == FREE) {
 455		DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_NOT_RUNNING\n"));
 456		return FAILED;
 457	}
 458	if (CD(cmd)->status == USED) {
 459		DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_BUSY\n"));
 460		/* We want to sleep a bit more here */
 461		return FAILED;		/* SNOOZE */
 462	}
 463	if (CD(cmd)->status == RESET) {
 464		printk(KERN_WARNING "eata_pio: abort, command reset error.\n");
 465		return FAILED;
 466	}
 467	if (CD(cmd)->status == LOCKED) {
 468		DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio: abort, queue slot " "locked.\n"));
 469		return FAILED;
 470	}
 471	panic("eata_pio: abort: invalid slot status\n");
 472}
 473
 474static int eata_pio_host_reset(struct scsi_cmnd *cmd)
 475{
 476	unsigned int x, limit = 0;
 477	unsigned char success = 0;
 478	struct scsi_cmnd *sp;
 479	struct Scsi_Host *host = cmd->device->host;
 480
 481	DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,
 482		"eata_pio_reset called\n"));
 483
 484	spin_lock_irq(host->host_lock);
 485
 486	if (HD(cmd)->state == RESET) {
 487		printk(KERN_WARNING "eata_pio_reset: exit, already in reset.\n");
 488		spin_unlock_irq(host->host_lock);
 489		return FAILED;
 490	}
 491
 492	/* force all slots to be free */
 493
 494	for (x = 0; x < cmd->device->host->can_queue; x++) {
 495
 496		if (HD(cmd)->ccb[x].status == FREE)
 497			continue;
 498
 499		sp = HD(cmd)->ccb[x].cmd;
 500		HD(cmd)->ccb[x].status = RESET;
 501		printk(KERN_WARNING "eata_pio_reset: slot %d in reset.\n", x);
 502
 503		if (sp == NULL)
 504			panic("eata_pio_reset: slot %d, sp==NULL.\n", x);
 505	}
 506
 507	/* hard reset the HBA  */
 508	outb(EATA_CMD_RESET, cmd->device->host->base + HA_WCOMMAND);
 509
 510	DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: board reset done.\n"));
 511	HD(cmd)->state = RESET;
 512
 513	spin_unlock_irq(host->host_lock);
 514	msleep(3000);
 515	spin_lock_irq(host->host_lock);
 516
 517	DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: interrupts disabled, " "loops %d.\n", limit));
 518
 519	for (x = 0; x < cmd->device->host->can_queue; x++) {
 520
 521		/* Skip slots already set free by interrupt */
 522		if (HD(cmd)->ccb[x].status != RESET)
 523			continue;
 524
 525		sp = HD(cmd)->ccb[x].cmd;
 526		sp->result = DID_RESET << 16;
 527
 528		/* This mailbox is terminated */
 529		printk(KERN_WARNING "eata_pio_reset: reset ccb %d.\n", x);
 530		HD(cmd)->ccb[x].status = FREE;
 531
 532		sp->scsi_done(sp);
 533	}
 534
 535	HD(cmd)->state = 0;
 536
 537	spin_unlock_irq(host->host_lock);
 538
 539	if (success) {		/* hmmm... */
 540		DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, success.\n"));
 541		return SUCCESS;
 542	} else {
 543		DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, wakeup.\n"));
 544		return FAILED;
 545	}
 546}
 547
 548static char *get_pio_board_data(unsigned long base, unsigned int irq, unsigned int id, unsigned long cplen, unsigned short cppadlen)
 549{
 550	struct eata_ccb cp;
 551	static char buff[256];
 552	int z;
 553
 554	memset(&cp, 0, sizeof(struct eata_ccb));
 555	memset(buff, 0, sizeof(buff));
 556
 557	cp.DataIn = 1;
 558	cp.Interpret = 1;	/* Interpret command */
 559
 560	cp.cp_datalen = cpu_to_be32(254);
 561	cp.cp_dataDMA = cpu_to_be32(0);
 562
 563	cp.cp_id = id;
 564	cp.cp_lun = 0;
 565
 566	cp.cp_cdb[0] = INQUIRY;
 567	cp.cp_cdb[1] = 0;
 568	cp.cp_cdb[2] = 0;
 569	cp.cp_cdb[3] = 0;
 570	cp.cp_cdb[4] = 254;
 571	cp.cp_cdb[5] = 0;
 572
 573	if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP))
 574		return NULL;
 575
 576	while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
 577		cpu_relax();
 578
 579	outsw(base + HA_RDATA, &cp, cplen);
 580	outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
 581	for (z = 0; z < cppadlen; z++)
 582		outw(0, base + HA_RDATA);
 583
 584	while (inb(base + HA_RSTATUS) & HA_SBUSY)
 585		cpu_relax();
 586
 587	if (inb(base + HA_RSTATUS) & HA_SERROR)
 588		return NULL;
 589	else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))
 590		return NULL;
 591	else {
 592		insw(base + HA_RDATA, &buff, 127);
 593		while (inb(base + HA_RSTATUS) & HA_SDRQ)
 594			inw(base + HA_RDATA);
 595		return buff;
 596	}
 597}
 598
 599static int get_pio_conf_PIO(unsigned long base, struct get_conf *buf)
 600{
 601	unsigned long loop = HZ / 2;
 602	int z;
 603	unsigned short *p;
 604
 605	if (!request_region(base, 9, "eata_pio"))
 606		return 0;
 607
 608	memset(buf, 0, sizeof(struct get_conf));
 609
 610	while (inb(base + HA_RSTATUS) & HA_SBUSY)
 611		if (--loop == 0)
 612			goto fail;
 613
 614	DBG(DBG_PIO && DBG_PROBE, printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#lx\n", base));
 615	eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG);
 616
 617	loop = 50;
 618	for (p = (unsigned short *) buf; (long) p <= ((long) buf + (sizeof(struct get_conf) / 2)); p++) {
 619		while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
 620			if (--loop == 0)
 621				goto fail;
 622
 623		loop = 50;
 624		*p = inw(base + HA_RDATA);
 625	}
 626	if (inb(base + HA_RSTATUS) & HA_SERROR) {
 627		DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during "
 628					"transfer for HBA at %lx\n", base));
 629		goto fail;
 630	}
 631
 632	if (cpu_to_be32(EATA_SIGNATURE) != buf->signature)
 633		goto fail;
 634
 635	DBG(DBG_PIO && DBG_PROBE, printk(KERN_NOTICE "EATA Controller found "
 636				"at %#4lx EATA Level: %x\n",
 637				base, (unsigned int) (buf->version)));
 638
 639	while (inb(base + HA_RSTATUS) & HA_SDRQ)
 640		inw(base + HA_RDATA);
 641
 642	if (!ALLOW_DMA_BOARDS) {
 643		for (z = 0; z < MAXISA; z++)
 644			if (base == ISAbases[z]) {
 645				buf->IRQ = ISAirqs[z];
 646				break;
 647			}
 648	}
 649
 650	return 1;
 651
 652 fail:
 653	release_region(base, 9);
 654	return 0;
 655}
 656
 657static void print_pio_config(struct get_conf *gc)
 658{
 659	printk("Please check values: (read config data)\n");
 660	printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n", be32_to_cpu(gc->len), gc->version, gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support);
 661	printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n", gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2], gc->scsi_id[1], be16_to_cpu(gc->queuesiz), be16_to_cpu(gc->SGsiz), gc->SECOND);
 662	printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n", gc->IRQ, gc->IRQ_TR, gc->FORCADR, gc->MAX_CHAN, gc->ID_qest);
 663}
 664
 665static unsigned int print_selftest(unsigned int base)
 666{
 667	unsigned char buffer[512];
 668#ifdef VERBOSE_SETUP
 669	int z;
 670#endif
 671
 672	printk("eata_pio: executing controller self test & setup...\n");
 673	while (inb(base + HA_RSTATUS) & HA_SBUSY);
 674	outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND);
 675	do {
 676		while (inb(base + HA_RSTATUS) & HA_SBUSY)
 677			/* nothing */ ;
 678		if (inb(base + HA_RSTATUS) & HA_SDRQ) {
 679			insw(base + HA_RDATA, &buffer, 256);
 680#ifdef VERBOSE_SETUP
 681			/* no beeps please... */
 682			for (z = 0; z < 511 && buffer[z]; z++)
 683				if (buffer[z] != 7)
 684					printk("%c", buffer[z]);
 685#endif
 686		}
 687	} while (inb(base + HA_RSTATUS) & (HA_SBUSY | HA_SDRQ));
 688
 689	return (!(inb(base + HA_RSTATUS) & HA_SERROR));
 690}
 691
 692static int register_pio_HBA(long base, struct get_conf *gc, struct pci_dev *pdev)
 693{
 694	unsigned long size = 0;
 695	char *buff;
 696	unsigned long cplen;
 697	unsigned short cppadlen;
 698	struct Scsi_Host *sh;
 699	hostdata *hd;
 700
 701	DBG(DBG_REGISTER, print_pio_config(gc));
 702
 703	if (gc->DMA_support) {
 704		printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n", base);
 705		if (!ALLOW_DMA_BOARDS)
 706			return 0;
 707	}
 708
 709	if ((buff = get_pio_board_data(base, gc->IRQ, gc->scsi_id[3], cplen = (cpu_to_be32(gc->cplen) + 1) / 2, cppadlen = (cpu_to_be16(gc->cppadlen) + 1) / 2)) == NULL) {
 710		printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", base);
 711		return 0;
 712	}
 713
 714	if (!print_selftest(base) && !ALLOW_DMA_BOARDS) {
 715		printk("HBA at %#lx failed while performing self test & setup.\n", base);
 716		return 0;
 717	}
 718
 719	size = sizeof(hostdata) + (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz));
 720
 721	sh = scsi_register(&driver_template, size);
 722	if (sh == NULL)
 723		return 0;
 724
 725	if (!reg_IRQ[gc->IRQ]) {	/* Interrupt already registered ? */
 726		if (!request_irq(gc->IRQ, do_eata_pio_int_handler, IRQF_DISABLED, "EATA-PIO", sh)) {
 727			reg_IRQ[gc->IRQ]++;
 728			if (!gc->IRQ_TR)
 729				reg_IRQL[gc->IRQ] = 1;	/* IRQ is edge triggered */
 730		} else {
 731			printk("Couldn't allocate IRQ %d, Sorry.\n", gc->IRQ);
 732			return 0;
 733		}
 734	} else {		/* More than one HBA on this IRQ */
 735		if (reg_IRQL[gc->IRQ]) {
 736			printk("Can't support more than one HBA on this IRQ,\n" "  if the IRQ is edge triggered. Sorry.\n");
 737			return 0;
 738		} else
 739			reg_IRQ[gc->IRQ]++;
 740	}
 741
 742	hd = SD(sh);
 743
 744	memset(hd->ccb, 0, (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz)));
 745	memset(hd->reads, 0, sizeof(hd->reads));
 746
 747	strlcpy(SD(sh)->vendor, &buff[8], sizeof(SD(sh)->vendor));
 748	strlcpy(SD(sh)->name, &buff[16], sizeof(SD(sh)->name));
 749	SD(sh)->revision[0] = buff[32];
 750	SD(sh)->revision[1] = buff[33];
 751	SD(sh)->revision[2] = buff[34];
 752	SD(sh)->revision[3] = '.';
 753	SD(sh)->revision[4] = buff[35];
 754	SD(sh)->revision[5] = 0;
 755
 756	switch (be32_to_cpu(gc->len)) {
 757	case 0x1c:
 758		SD(sh)->EATA_revision = 'a';
 759		break;
 760	case 0x1e:
 761		SD(sh)->EATA_revision = 'b';
 762		break;
 763	case 0x22:
 764		SD(sh)->EATA_revision = 'c';
 765		break;
 766	case 0x24:
 767		SD(sh)->EATA_revision = 'z';
 768	default:
 769		SD(sh)->EATA_revision = '?';
 770	}
 771
 772	if (be32_to_cpu(gc->len) >= 0x22) {
 773		if (gc->is_PCI)
 774			hd->bustype = IS_PCI;
 775		else if (gc->is_EISA)
 776			hd->bustype = IS_EISA;
 777		else
 778			hd->bustype = IS_ISA;
 779	} else {
 780		if (buff[21] == '4')
 781			hd->bustype = IS_PCI;
 782		else if (buff[21] == '2')
 783			hd->bustype = IS_EISA;
 784		else
 785			hd->bustype = IS_ISA;
 786	}
 787
 788	SD(sh)->cplen = cplen;
 789	SD(sh)->cppadlen = cppadlen;
 790	SD(sh)->hostid = gc->scsi_id[3];
 791	SD(sh)->devflags = 1 << gc->scsi_id[3];
 792	SD(sh)->moresupport = gc->MORE_support;
 793	sh->unique_id = base;
 794	sh->base = base;
 795	sh->io_port = base;
 796	sh->n_io_port = 9;
 797	sh->irq = gc->IRQ;
 798	sh->dma_channel = PIO;
 799	sh->this_id = gc->scsi_id[3];
 800	sh->can_queue = 1;
 801	sh->cmd_per_lun = 1;
 802	sh->sg_tablesize = SG_ALL;
 803
 804	hd->channel = 0;
 805
 806	hd->pdev = pci_dev_get(pdev);	/* Keep a PCI reference */
 807
 808	sh->max_id = 8;
 809	sh->max_lun = 8;
 810
 811	if (gc->SECOND)
 812		hd->primary = 0;
 813	else
 814		hd->primary = 1;
 815
 816	hd->next = NULL;	/* build a linked list of all HBAs */
 817	hd->prev = last_HBA;
 818	if (hd->prev != NULL)
 819		SD(hd->prev)->next = sh;
 820	last_HBA = sh;
 821	if (first_HBA == NULL)
 822		first_HBA = sh;
 823	registered_HBAs++;
 824	return (1);
 825}
 826
 827static void find_pio_ISA(struct get_conf *buf)
 828{
 829	int i;
 830
 831	for (i = 0; i < MAXISA; i++) {
 832		if (!ISAbases[i])
 833			continue;
 834		if (!get_pio_conf_PIO(ISAbases[i], buf))
 835			continue;
 836		if (!register_pio_HBA(ISAbases[i], buf, NULL))
 837			release_region(ISAbases[i], 9);
 838		else
 839			ISAbases[i] = 0;
 840	}
 841	return;
 842}
 843
 844static void find_pio_EISA(struct get_conf *buf)
 845{
 846	u32 base;
 847	int i;
 848
 849#ifdef CHECKPAL
 850	u8 pal1, pal2, pal3;
 851#endif
 852
 853	for (i = 0; i < MAXEISA; i++) {
 854		if (EISAbases[i]) {	/* Still a possibility ?          */
 855
 856			base = 0x1c88 + (i * 0x1000);
 857#ifdef CHECKPAL
 858			pal1 = inb((u16) base - 8);
 859			pal2 = inb((u16) base - 7);
 860			pal3 = inb((u16) base - 6);
 861
 862			if (((pal1 == 0x12) && (pal2 == 0x14)) || ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) || ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
 863				DBG(DBG_PROBE, printk(KERN_NOTICE "EISA EATA id tags found: " "%x %x %x \n", (int) pal1, (int) pal2, (int) pal3));
 864#endif
 865				if (get_pio_conf_PIO(base, buf)) {
 866					DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));
 867					if (buf->IRQ) {
 868						if (!register_pio_HBA(base, buf, NULL))
 869							release_region(base, 9);
 870					} else {
 871						printk(KERN_NOTICE "eata_dma: No valid IRQ. HBA " "removed from list\n");
 872						release_region(base, 9);
 873					}
 874				}
 875				/* Nothing found here so we take it from the list */
 876				EISAbases[i] = 0;
 877#ifdef CHECKPAL
 878			}
 879#endif
 880		}
 881	}
 882	return;
 883}
 884
 885static void find_pio_PCI(struct get_conf *buf)
 886{
 887#ifndef CONFIG_PCI
 888	printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
 889#else
 890	struct pci_dev *dev = NULL;
 891	unsigned long base, x;
 892
 893	while ((dev = pci_get_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) {
 894		DBG(DBG_PROBE && DBG_PCI, printk("eata_pio: find_PCI, HBA at %s\n", pci_name(dev)));
 895		if (pci_enable_device(dev))
 896			continue;
 897		pci_set_master(dev);
 898		base = pci_resource_flags(dev, 0);
 899		if (base & IORESOURCE_MEM) {
 900			printk("eata_pio: invalid base address of device %s\n", pci_name(dev));
 901			continue;
 902		}
 903		base = pci_resource_start(dev, 0);
 904		/* EISA tag there ? */
 905		if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
 906			continue;	/* Jep, it's forced, so move on  */
 907		base += 0x10;	/* Now, THIS is the real address */
 908		if (base != 0x1f8) {
 909			/* We didn't find it in the primary search */
 910			if (get_pio_conf_PIO(base, buf)) {
 911				if (buf->FORCADR) {	/* If the address is forced */
 912					release_region(base, 9);
 913					continue;	/* we'll find it later      */
 914				}
 915
 916				/* OK. We made it till here, so we can go now  
 917				 * and register it. We  only have to check and 
 918				 * eventually remove it from the EISA and ISA list 
 919				 */
 920
 921				if (!register_pio_HBA(base, buf, dev)) {
 922					release_region(base, 9);
 923					continue;
 924				}
 925
 926				if (base < 0x1000) {
 927					for (x = 0; x < MAXISA; ++x) {
 928						if (ISAbases[x] == base) {
 929							ISAbases[x] = 0;
 930							break;
 931						}
 932					}
 933				} else if ((base & 0x0fff) == 0x0c88) {
 934					x = (base >> 12) & 0x0f;
 935					EISAbases[x] = 0;
 936				}
 937			}
 938#ifdef CHECK_BLINK
 939			else if (check_blink_state(base)) {
 940				printk("eata_pio: HBA is in BLINK state.\n" "Consult your HBAs manual to correct this.\n");
 941			}
 942#endif
 943		}
 944	}
 945#endif				/* #ifndef CONFIG_PCI */
 946}
 947
 948static int eata_pio_detect(struct scsi_host_template *tpnt)
 949{
 950	struct Scsi_Host *HBA_ptr;
 951	struct get_conf gc;
 952	int i;
 953
 954	find_pio_PCI(&gc);
 955	find_pio_EISA(&gc);
 956	find_pio_ISA(&gc);
 957
 958	for (i = 0; i <= MAXIRQ; i++)
 959		if (reg_IRQ[i])
 960			request_irq(i, do_eata_pio_int_handler, IRQF_DISABLED, "EATA-PIO", NULL);
 961
 962	HBA_ptr = first_HBA;
 963
 964	if (registered_HBAs != 0) {
 965		printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
 966		       "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n" "            Alfred Arnold,   a.arnold@kfa-juelich.de\n" "This release only supports DASD devices (harddisks)\n", VER_MAJOR, VER_MINOR, VER_SUB);
 967
 968		printk("Registered HBAs:\n");
 969		printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:" " QS: SG: CPL:\n");
 970		for (i = 1; i <= registered_HBAs; i++) {
 971			printk("scsi%-2d: %.10s v%s 2.0%c  %s %#.4lx   %2d   %d   %d   %c"
 972			       "  %2d  %2d  %2d\n",
 973			       HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
 974			       SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P') ?
 975			       "PCI " : (SD(HBA_ptr)->bustype == 'E') ? "EISA" : "ISA ",
 976			       HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, HBA_ptr->this_id,
 977			       SD(HBA_ptr)->primary ? 'Y' : 'N', HBA_ptr->can_queue,
 978			       HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);
 979			HBA_ptr = SD(HBA_ptr)->next;
 980		}
 981	}
 982	return (registered_HBAs);
 983}
 984
 985static struct scsi_host_template driver_template = {
 986	.proc_name		= "eata_pio",
 987	.name              	= "EATA (Extended Attachment) PIO driver",
 988	.proc_info         	= eata_pio_proc_info,
 989	.detect            	= eata_pio_detect,
 990	.release           	= eata_pio_release,
 991	.queuecommand      	= eata_pio_queue,
 992	.eh_abort_handler  	= eata_pio_abort,
 993	.eh_host_reset_handler	= eata_pio_host_reset,
 994	.use_clustering    	= ENABLE_CLUSTERING,
 995};
 996
 997MODULE_AUTHOR("Michael Neuffer, Alfred Arnold");
 998MODULE_DESCRIPTION("EATA SCSI PIO driver");
 999MODULE_LICENSE("GPL");
1000
1001#include "scsi_module.c"
v4.6
  1/************************************************************
  2 *                                                          *
  3 *               Linux EATA SCSI PIO driver                 *
  4 *                                                          *
  5 *  based on the CAM document CAM/89-004 rev. 2.0c,         *
  6 *  DPT's driver kit, some internal documents and source,   *
  7 *  and several other Linux scsi drivers and kernel docs.   *
  8 *                                                          *
  9 *  The driver currently:                                   *
 10 *      -supports all EATA-PIO boards                       *
 11 *      -only supports DASD devices                         *
 12 *                                                          *
 13 *  (c)1993-96 Michael Neuffer, Alfred Arnold               *
 14 *             neuffer@goofy.zdv.uni-mainz.de               *
 15 *             a.arnold@kfa-juelich.de                      * 
 16 *                                                          *
 17 *  Updated 2002 by Alan Cox <alan@lxorguk.ukuu.org.uk> for *
 18 *   Linux 2.5.x and the newer locking and error handling   *
 19 *                                                          *
 20 *  This program is free software; you can redistribute it  *
 21 *  and/or modify it under the terms of the GNU General     *
 22 *  Public License as published by the Free Software        *
 23 *  Foundation; either version 2 of the License, or         *
 24 *  (at your option) any later version.                     *
 25 *                                                          *
 26 *  This program is distributed in the hope that it will be *
 27 *  useful, but WITHOUT ANY WARRANTY; without even the      *
 28 *  implied warranty of MERCHANTABILITY or FITNESS FOR A    *
 29 *  PARTICULAR PURPOSE.  See the GNU General Public License *
 30 *  for more details.                                       *
 31 *                                                          *
 32 *  You should have received a copy of the GNU General      *
 33 *  Public License along with this kernel; if not, write to *
 34 *  the Free Software Foundation, Inc., 675 Mass Ave,       *
 35 *  Cambridge, MA 02139, USA.                               *
 36 *							    *
 37 *  For the avoidance of doubt the "preferred form" of this *
 38 *  code is one which is in an open non patent encumbered   *
 39 *  format. Where cryptographic key signing forms part of   *
 40 *  the process of creating an executable the information   *
 41 *  including keys needed to generate an equivalently       *
 42 *  functional executable are deemed to be part of the 	    *
 43 *  source code are deemed to be part of the source code.   *
 44 *                                                          *
 45 ************************************************************
 46 *  last change: 2002/11/02               OS: Linux 2.5.45  *
 47 ************************************************************/
 48
 49#include <linux/module.h>
 50#include <linux/kernel.h>
 51#include <linux/string.h>
 52#include <linux/ioport.h>
 53#include <linux/in.h>
 54#include <linux/pci.h>
 55#include <linux/proc_fs.h>
 56#include <linux/interrupt.h>
 57#include <linux/blkdev.h>
 58#include <linux/spinlock.h>
 59#include <linux/delay.h>
 60
 61#include <asm/io.h>
 62
 63#include <scsi/scsi.h>
 64#include <scsi/scsi_cmnd.h>
 65#include <scsi/scsi_device.h>
 66#include <scsi/scsi_host.h>
 67
 68#include "eata_generic.h"
 69#include "eata_pio.h"
 70
 71
 72static unsigned int ISAbases[MAXISA] =	{
 73	 0x1F0, 0x170, 0x330, 0x230
 74};
 75
 76static unsigned int ISAirqs[MAXISA] = {
 77	14, 12, 15, 11
 78};
 79
 80static unsigned char EISAbases[] = { 
 81	1, 1, 1, 1, 1, 1, 1, 1,
 82	1, 1, 1, 1, 1, 1, 1, 1 
 83};
 84
 85static unsigned int registered_HBAs;
 86static struct Scsi_Host *last_HBA;
 87static struct Scsi_Host *first_HBA;
 88static unsigned char reg_IRQ[16];
 89static unsigned char reg_IRQL[16];
 90static unsigned long int_counter;
 91static unsigned long queue_counter;
 92
 93static struct scsi_host_template driver_template;
 94
 95static int eata_pio_show_info(struct seq_file *m, struct Scsi_Host *shost)
 
 
 
 
 
 
 
 
 
 
 
 
 96{
 97	seq_printf(m, "EATA (Extended Attachment) PIO driver version: "
 
 
 
 
 
 
 98		   "%d.%d%s\n",VER_MAJOR, VER_MINOR, VER_SUB);
 99	seq_printf(m, "queued commands:     %10ld\n"
100		   "processed interrupts:%10ld\n", queue_counter, int_counter);
101	seq_printf(m, "\nscsi%-2d: HBA %.10s\n",
102		   shost->host_no, SD(shost)->name);
103	seq_printf(m, "Firmware revision: v%s\n",
104		   SD(shost)->revision);
105	seq_puts(m, "IO: PIO\n");
106	seq_printf(m, "Base IO : %#.4x\n", (u32) shost->base);
107	seq_printf(m, "Host Bus: %s\n",
108		   (SD(shost)->bustype == 'P')?"PCI ":
109		   (SD(shost)->bustype == 'E')?"EISA":"ISA ");
110	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111}
112
113static int eata_pio_release(struct Scsi_Host *sh)
114{
115	hostdata *hd = SD(sh);
116	if (sh->irq && reg_IRQ[sh->irq] == 1)
117		free_irq(sh->irq, NULL);
118	else
119		reg_IRQ[sh->irq]--;
120	if (SD(sh)->channel == 0) {
121		if (sh->io_port && sh->n_io_port)
122			release_region(sh->io_port, sh->n_io_port);
123	}
124	/* At this point the PCI reference can go */
125	if (hd->pdev)
126		pci_dev_put(hd->pdev);
127	return 1;
128}
129
130static void IncStat(struct scsi_pointer *SCp, unsigned int Increment)
131{
132	SCp->ptr += Increment;
133	if ((SCp->this_residual -= Increment) == 0) {
134		if ((--SCp->buffers_residual) == 0)
135			SCp->Status = 0;
136		else {
137			SCp->buffer++;
138			SCp->ptr = sg_virt(SCp->buffer);
139			SCp->this_residual = SCp->buffer->length;
140		}
141	}
142}
143
144static irqreturn_t eata_pio_int_handler(int irq, void *dev_id);
145
146static irqreturn_t do_eata_pio_int_handler(int irq, void *dev_id)
147{
148	unsigned long flags;
149	struct Scsi_Host *dev = dev_id;
150	irqreturn_t ret;
151
152	spin_lock_irqsave(dev->host_lock, flags);
153	ret = eata_pio_int_handler(irq, dev_id);
154	spin_unlock_irqrestore(dev->host_lock, flags);
155	return ret;
156}
157
158static irqreturn_t eata_pio_int_handler(int irq, void *dev_id)
159{
160	unsigned int eata_stat = 0xfffff;
161	struct scsi_cmnd *cmd;
162	hostdata *hd;
163	struct eata_ccb *cp;
164	unsigned long base;
165	unsigned int x, z;
166	struct Scsi_Host *sh;
167	unsigned short zwickel = 0;
168	unsigned char stat, odd;
169	irqreturn_t ret = IRQ_NONE;
170
171	for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) 
172	{
173		if (sh->irq != irq)
174			continue;
175		if (inb(sh->base + HA_RSTATUS) & HA_SBUSY)
176			continue;
177
178		int_counter++;
179		ret = IRQ_HANDLED;
180
181		hd = SD(sh);
182
183		cp = &hd->ccb[0];
184		cmd = cp->cmd;
185		base = cmd->device->host->base;
186
187		do {
188			stat = inb(base + HA_RSTATUS);
189			if (stat & HA_SDRQ) {
190				if (cp->DataIn) {
191					z = 256;
192					odd = 0;
193					while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
194						if (odd) {
195							*(cmd->SCp.ptr) = zwickel >> 8;
196							IncStat(&cmd->SCp, 1);
197							odd = 0;
198						}
199						x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
200						insw(base + HA_RDATA, cmd->SCp.ptr, x);
201						z -= x;
202						IncStat(&cmd->SCp, 2 * x);
203						if ((z > 0) && (cmd->SCp.this_residual == 1)) {
204							zwickel = inw(base + HA_RDATA);
205							*(cmd->SCp.ptr) = zwickel & 0xff;
206							IncStat(&cmd->SCp, 1);
207							z--;
208							odd = 1;
209						}
210					}
211					while (z > 0) {
212						zwickel = inw(base + HA_RDATA);
213						z--;
214					}
215				} else {	/* cp->DataOut */
216
217					odd = 0;
218					z = 256;
219					while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
220						if (odd) {
221							zwickel += *(cmd->SCp.ptr) << 8;
222							IncStat(&cmd->SCp, 1);
223							outw(zwickel, base + HA_RDATA);
224							z--;
225							odd = 0;
226						}
227						x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
228						outsw(base + HA_RDATA, cmd->SCp.ptr, x);
229						z -= x;
230						IncStat(&cmd->SCp, 2 * x);
231						if ((z > 0) && (cmd->SCp.this_residual == 1)) {
232							zwickel = *(cmd->SCp.ptr);
233							zwickel &= 0xff;
234							IncStat(&cmd->SCp, 1);
235							odd = 1;
236						}
237					}
238					while (z > 0 || odd) {
239						outw(zwickel, base + HA_RDATA);
240						z--;
241						odd = 0;
242					}
243				}
244			}
245		}
246		while ((stat & HA_SDRQ) || ((stat & HA_SMORE) && hd->moresupport));
247
248		/* terminate handler if HBA goes busy again, i.e. transfers
249		 * more data */
250
251		if (stat & HA_SBUSY)
252			break;
253
254		/* OK, this is quite stupid, but I haven't found any correct
255		 * way to get HBA&SCSI status so far */
256
257		if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {
258			cmd->result = (DID_OK << 16);
259			hd->devflags |= (1 << cp->cp_id);
260		} else if (hd->devflags & (1 << cp->cp_id))
261			cmd->result = (DID_OK << 16) + 0x02;
262		else
263			cmd->result = (DID_NO_CONNECT << 16);
264
265		if (cp->status == LOCKED) {
266			cp->status = FREE;
267			eata_stat = inb(base + HA_RSTATUS);
268			printk(KERN_CRIT "eata_pio: int_handler, freeing locked " "queueslot\n");
269			return ret;
270		}
271#if DBG_INTR2
272		if (stat != 0x50)
273			printk(KERN_DEBUG "stat: %#.2x, result: %#.8x\n", stat, cmd->result);
274#endif
275
276		cp->status = FREE;	/* now we can release the slot  */
277
278		cmd->scsi_done(cmd);
279	}
280
281	return ret;
282}
283
284static inline unsigned int eata_pio_send_command(unsigned long base, unsigned char command)
285{
286	unsigned int loop = 50;
287
288	while (inb(base + HA_RSTATUS) & HA_SBUSY)
289		if (--loop == 0)
290			return 1;
291
292	/* Enable interrupts for HBA.  It is not the best way to do it at this
293	 * place, but I hope that it doesn't interfere with the IDE driver 
294	 * initialization this way */
295
296	outb(HA_CTRL_8HEADS, base + HA_CTRLREG);
297
298	outb(command, base + HA_WCOMMAND);
299	return 0;
300}
301
302static int eata_pio_queue_lck(struct scsi_cmnd *cmd,
303		void (*done)(struct scsi_cmnd *))
304{
305	unsigned int x, y;
306	unsigned long base;
307
308	hostdata *hd;
309	struct Scsi_Host *sh;
310	struct eata_ccb *cp;
311
312	queue_counter++;
313
314	hd = HD(cmd);
315	sh = cmd->device->host;
316	base = sh->base;
317
318	/* use only slot 0, as 2001 can handle only one cmd at a time */
319
320	y = x = 0;
321
322	if (hd->ccb[y].status != FREE) {
323
324		DBG(DBG_QUEUE, printk(KERN_EMERG "can_queue %d, x %d, y %d\n", sh->can_queue, x, y));
325#if DEBUG_EATA
326		panic(KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld " "intrno: %ld\n", queue_counter, int_counter);
327#else
328		panic(KERN_EMERG "eata_pio: run out of queue slots....\n");
329#endif
330	}
331
332	cp = &hd->ccb[y];
333
334	memset(cp, 0, sizeof(struct eata_ccb));
335
336	cp->status = USED;	/* claim free slot */
337
338	DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,
339		"eata_pio_queue 0x%p, y %d\n", cmd, y));
340
341	cmd->scsi_done = (void *) done;
342
343	if (cmd->sc_data_direction == DMA_TO_DEVICE)
344		cp->DataOut = 1;	/* Output mode */
345	else
346		cp->DataIn = 0;	/* Input mode  */
347
348	cp->Interpret = (cmd->device->id == hd->hostid);
349	cp->cp_datalen = cpu_to_be32(scsi_bufflen(cmd));
350	cp->Auto_Req_Sen = 0;
351	cp->cp_reqDMA = 0;
352	cp->reqlen = 0;
353
354	cp->cp_id = cmd->device->id;
355	cp->cp_lun = cmd->device->lun;
356	cp->cp_dispri = 0;
357	cp->cp_identify = 1;
358	memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
359
360	cp->cp_statDMA = 0;
361
362	cp->cp_viraddr = cp;
363	cp->cmd = cmd;
364	cmd->host_scribble = (char *) &hd->ccb[y];
365
366	if (!scsi_bufflen(cmd)) {
367		cmd->SCp.buffers_residual = 1;
368		cmd->SCp.ptr = NULL;
369		cmd->SCp.this_residual = 0;
370		cmd->SCp.buffer = NULL;
371	} else {
372		cmd->SCp.buffer = scsi_sglist(cmd);
373		cmd->SCp.buffers_residual = scsi_sg_count(cmd);
374		cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
375		cmd->SCp.this_residual = cmd->SCp.buffer->length;
376	}
377	cmd->SCp.Status = (cmd->SCp.this_residual != 0);	/* TRUE as long as bytes 
378								 * are to transfer */
379
380	if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) {
381		cmd->result = DID_BUS_BUSY << 16;
382		scmd_printk(KERN_NOTICE, cmd,
383			"eata_pio_queue pid 0x%p, HBA busy, "
384			"returning DID_BUS_BUSY, done.\n", cmd);
385		done(cmd);
386		cp->status = FREE;
387		return 0;
388	}
389	/* FIXME: timeout */
390	while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
391		cpu_relax();
392	outsw(base + HA_RDATA, cp, hd->cplen);
393	outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
394	for (x = 0; x < hd->cppadlen; x++)
395		outw(0, base + HA_RDATA);
396
397	DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,
398		"Queued base %#.4lx cmd: 0x%p "
399		"slot %d irq %d\n", sh->base, cmd, y, sh->irq));
400
401	return 0;
402}
403
404static DEF_SCSI_QCMD(eata_pio_queue)
405
406static int eata_pio_abort(struct scsi_cmnd *cmd)
407{
408	unsigned int loop = 100;
409
410	DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,
411		"eata_pio_abort called pid: 0x%p\n", cmd));
412
413	while (inb(cmd->device->host->base + HA_RAUXSTAT) & HA_ABUSY)
414		if (--loop == 0) {
415			printk(KERN_WARNING "eata_pio: abort, timeout error.\n");
416			return FAILED;
417		}
418	if (CD(cmd)->status == FREE) {
419		DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_NOT_RUNNING\n"));
420		return FAILED;
421	}
422	if (CD(cmd)->status == USED) {
423		DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_BUSY\n"));
424		/* We want to sleep a bit more here */
425		return FAILED;		/* SNOOZE */
426	}
427	if (CD(cmd)->status == RESET) {
428		printk(KERN_WARNING "eata_pio: abort, command reset error.\n");
429		return FAILED;
430	}
431	if (CD(cmd)->status == LOCKED) {
432		DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio: abort, queue slot " "locked.\n"));
433		return FAILED;
434	}
435	panic("eata_pio: abort: invalid slot status\n");
436}
437
438static int eata_pio_host_reset(struct scsi_cmnd *cmd)
439{
440	unsigned int x, limit = 0;
441	unsigned char success = 0;
442	struct scsi_cmnd *sp;
443	struct Scsi_Host *host = cmd->device->host;
444
445	DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,
446		"eata_pio_reset called\n"));
447
448	spin_lock_irq(host->host_lock);
449
450	if (HD(cmd)->state == RESET) {
451		printk(KERN_WARNING "eata_pio_reset: exit, already in reset.\n");
452		spin_unlock_irq(host->host_lock);
453		return FAILED;
454	}
455
456	/* force all slots to be free */
457
458	for (x = 0; x < cmd->device->host->can_queue; x++) {
459
460		if (HD(cmd)->ccb[x].status == FREE)
461			continue;
462
463		sp = HD(cmd)->ccb[x].cmd;
464		HD(cmd)->ccb[x].status = RESET;
465		printk(KERN_WARNING "eata_pio_reset: slot %d in reset.\n", x);
466
467		if (sp == NULL)
468			panic("eata_pio_reset: slot %d, sp==NULL.\n", x);
469	}
470
471	/* hard reset the HBA  */
472	outb(EATA_CMD_RESET, cmd->device->host->base + HA_WCOMMAND);
473
474	DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: board reset done.\n"));
475	HD(cmd)->state = RESET;
476
477	spin_unlock_irq(host->host_lock);
478	msleep(3000);
479	spin_lock_irq(host->host_lock);
480
481	DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: interrupts disabled, " "loops %d.\n", limit));
482
483	for (x = 0; x < cmd->device->host->can_queue; x++) {
484
485		/* Skip slots already set free by interrupt */
486		if (HD(cmd)->ccb[x].status != RESET)
487			continue;
488
489		sp = HD(cmd)->ccb[x].cmd;
490		sp->result = DID_RESET << 16;
491
492		/* This mailbox is terminated */
493		printk(KERN_WARNING "eata_pio_reset: reset ccb %d.\n", x);
494		HD(cmd)->ccb[x].status = FREE;
495
496		sp->scsi_done(sp);
497	}
498
499	HD(cmd)->state = 0;
500
501	spin_unlock_irq(host->host_lock);
502
503	if (success) {		/* hmmm... */
504		DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, success.\n"));
505		return SUCCESS;
506	} else {
507		DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, wakeup.\n"));
508		return FAILED;
509	}
510}
511
512static char *get_pio_board_data(unsigned long base, unsigned int irq, unsigned int id, unsigned long cplen, unsigned short cppadlen)
513{
514	struct eata_ccb cp;
515	static char buff[256];
516	int z;
517
518	memset(&cp, 0, sizeof(struct eata_ccb));
519	memset(buff, 0, sizeof(buff));
520
521	cp.DataIn = 1;
522	cp.Interpret = 1;	/* Interpret command */
523
524	cp.cp_datalen = cpu_to_be32(254);
525	cp.cp_dataDMA = cpu_to_be32(0);
526
527	cp.cp_id = id;
528	cp.cp_lun = 0;
529
530	cp.cp_cdb[0] = INQUIRY;
531	cp.cp_cdb[1] = 0;
532	cp.cp_cdb[2] = 0;
533	cp.cp_cdb[3] = 0;
534	cp.cp_cdb[4] = 254;
535	cp.cp_cdb[5] = 0;
536
537	if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP))
538		return NULL;
539
540	while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
541		cpu_relax();
542
543	outsw(base + HA_RDATA, &cp, cplen);
544	outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
545	for (z = 0; z < cppadlen; z++)
546		outw(0, base + HA_RDATA);
547
548	while (inb(base + HA_RSTATUS) & HA_SBUSY)
549		cpu_relax();
550
551	if (inb(base + HA_RSTATUS) & HA_SERROR)
552		return NULL;
553	else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))
554		return NULL;
555	else {
556		insw(base + HA_RDATA, &buff, 127);
557		while (inb(base + HA_RSTATUS) & HA_SDRQ)
558			inw(base + HA_RDATA);
559		return buff;
560	}
561}
562
563static int get_pio_conf_PIO(unsigned long base, struct get_conf *buf)
564{
565	unsigned long loop = HZ / 2;
566	int z;
567	unsigned short *p;
568
569	if (!request_region(base, 9, "eata_pio"))
570		return 0;
571
572	memset(buf, 0, sizeof(struct get_conf));
573
574	while (inb(base + HA_RSTATUS) & HA_SBUSY)
575		if (--loop == 0)
576			goto fail;
577
578	DBG(DBG_PIO && DBG_PROBE, printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#lx\n", base));
579	eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG);
580
581	loop = 50;
582	for (p = (unsigned short *) buf; (long) p <= ((long) buf + (sizeof(struct get_conf) / 2)); p++) {
583		while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
584			if (--loop == 0)
585				goto fail;
586
587		loop = 50;
588		*p = inw(base + HA_RDATA);
589	}
590	if (inb(base + HA_RSTATUS) & HA_SERROR) {
591		DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during "
592					"transfer for HBA at %lx\n", base));
593		goto fail;
594	}
595
596	if (cpu_to_be32(EATA_SIGNATURE) != buf->signature)
597		goto fail;
598
599	DBG(DBG_PIO && DBG_PROBE, printk(KERN_NOTICE "EATA Controller found "
600				"at %#4lx EATA Level: %x\n",
601				base, (unsigned int) (buf->version)));
602
603	while (inb(base + HA_RSTATUS) & HA_SDRQ)
604		inw(base + HA_RDATA);
605
606	if (!ALLOW_DMA_BOARDS) {
607		for (z = 0; z < MAXISA; z++)
608			if (base == ISAbases[z]) {
609				buf->IRQ = ISAirqs[z];
610				break;
611			}
612	}
613
614	return 1;
615
616 fail:
617	release_region(base, 9);
618	return 0;
619}
620
621static void print_pio_config(struct get_conf *gc)
622{
623	printk("Please check values: (read config data)\n");
624	printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n", be32_to_cpu(gc->len), gc->version, gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support);
625	printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n", gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2], gc->scsi_id[1], be16_to_cpu(gc->queuesiz), be16_to_cpu(gc->SGsiz), gc->SECOND);
626	printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n", gc->IRQ, gc->IRQ_TR, gc->FORCADR, gc->MAX_CHAN, gc->ID_qest);
627}
628
629static unsigned int print_selftest(unsigned int base)
630{
631	unsigned char buffer[512];
632#ifdef VERBOSE_SETUP
633	int z;
634#endif
635
636	printk("eata_pio: executing controller self test & setup...\n");
637	while (inb(base + HA_RSTATUS) & HA_SBUSY);
638	outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND);
639	do {
640		while (inb(base + HA_RSTATUS) & HA_SBUSY)
641			/* nothing */ ;
642		if (inb(base + HA_RSTATUS) & HA_SDRQ) {
643			insw(base + HA_RDATA, &buffer, 256);
644#ifdef VERBOSE_SETUP
645			/* no beeps please... */
646			for (z = 0; z < 511 && buffer[z]; z++)
647				if (buffer[z] != 7)
648					printk("%c", buffer[z]);
649#endif
650		}
651	} while (inb(base + HA_RSTATUS) & (HA_SBUSY | HA_SDRQ));
652
653	return (!(inb(base + HA_RSTATUS) & HA_SERROR));
654}
655
656static int register_pio_HBA(long base, struct get_conf *gc, struct pci_dev *pdev)
657{
658	unsigned long size = 0;
659	char *buff;
660	unsigned long cplen;
661	unsigned short cppadlen;
662	struct Scsi_Host *sh;
663	hostdata *hd;
664
665	DBG(DBG_REGISTER, print_pio_config(gc));
666
667	if (gc->DMA_support) {
668		printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n", base);
669		if (!ALLOW_DMA_BOARDS)
670			return 0;
671	}
672
673	if ((buff = get_pio_board_data(base, gc->IRQ, gc->scsi_id[3], cplen = (cpu_to_be32(gc->cplen) + 1) / 2, cppadlen = (cpu_to_be16(gc->cppadlen) + 1) / 2)) == NULL) {
674		printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", base);
675		return 0;
676	}
677
678	if (!print_selftest(base) && !ALLOW_DMA_BOARDS) {
679		printk("HBA at %#lx failed while performing self test & setup.\n", base);
680		return 0;
681	}
682
683	size = sizeof(hostdata) + (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz));
684
685	sh = scsi_register(&driver_template, size);
686	if (sh == NULL)
687		return 0;
688
689	if (!reg_IRQ[gc->IRQ]) {	/* Interrupt already registered ? */
690		if (!request_irq(gc->IRQ, do_eata_pio_int_handler, 0, "EATA-PIO", sh)) {
691			reg_IRQ[gc->IRQ]++;
692			if (!gc->IRQ_TR)
693				reg_IRQL[gc->IRQ] = 1;	/* IRQ is edge triggered */
694		} else {
695			printk("Couldn't allocate IRQ %d, Sorry.\n", gc->IRQ);
696			return 0;
697		}
698	} else {		/* More than one HBA on this IRQ */
699		if (reg_IRQL[gc->IRQ]) {
700			printk("Can't support more than one HBA on this IRQ,\n" "  if the IRQ is edge triggered. Sorry.\n");
701			return 0;
702		} else
703			reg_IRQ[gc->IRQ]++;
704	}
705
706	hd = SD(sh);
707
708	memset(hd->ccb, 0, (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz)));
709	memset(hd->reads, 0, sizeof(hd->reads));
710
711	strlcpy(SD(sh)->vendor, &buff[8], sizeof(SD(sh)->vendor));
712	strlcpy(SD(sh)->name, &buff[16], sizeof(SD(sh)->name));
713	SD(sh)->revision[0] = buff[32];
714	SD(sh)->revision[1] = buff[33];
715	SD(sh)->revision[2] = buff[34];
716	SD(sh)->revision[3] = '.';
717	SD(sh)->revision[4] = buff[35];
718	SD(sh)->revision[5] = 0;
719
720	switch (be32_to_cpu(gc->len)) {
721	case 0x1c:
722		SD(sh)->EATA_revision = 'a';
723		break;
724	case 0x1e:
725		SD(sh)->EATA_revision = 'b';
726		break;
727	case 0x22:
728		SD(sh)->EATA_revision = 'c';
729		break;
730	case 0x24:
731		SD(sh)->EATA_revision = 'z';
732	default:
733		SD(sh)->EATA_revision = '?';
734	}
735
736	if (be32_to_cpu(gc->len) >= 0x22) {
737		if (gc->is_PCI)
738			hd->bustype = IS_PCI;
739		else if (gc->is_EISA)
740			hd->bustype = IS_EISA;
741		else
742			hd->bustype = IS_ISA;
743	} else {
744		if (buff[21] == '4')
745			hd->bustype = IS_PCI;
746		else if (buff[21] == '2')
747			hd->bustype = IS_EISA;
748		else
749			hd->bustype = IS_ISA;
750	}
751
752	SD(sh)->cplen = cplen;
753	SD(sh)->cppadlen = cppadlen;
754	SD(sh)->hostid = gc->scsi_id[3];
755	SD(sh)->devflags = 1 << gc->scsi_id[3];
756	SD(sh)->moresupport = gc->MORE_support;
757	sh->unique_id = base;
758	sh->base = base;
759	sh->io_port = base;
760	sh->n_io_port = 9;
761	sh->irq = gc->IRQ;
762	sh->dma_channel = PIO;
763	sh->this_id = gc->scsi_id[3];
764	sh->can_queue = 1;
765	sh->cmd_per_lun = 1;
766	sh->sg_tablesize = SG_ALL;
767
768	hd->channel = 0;
769
770	hd->pdev = pci_dev_get(pdev);	/* Keep a PCI reference */
771
772	sh->max_id = 8;
773	sh->max_lun = 8;
774
775	if (gc->SECOND)
776		hd->primary = 0;
777	else
778		hd->primary = 1;
779
780	hd->next = NULL;	/* build a linked list of all HBAs */
781	hd->prev = last_HBA;
782	if (hd->prev != NULL)
783		SD(hd->prev)->next = sh;
784	last_HBA = sh;
785	if (first_HBA == NULL)
786		first_HBA = sh;
787	registered_HBAs++;
788	return (1);
789}
790
791static void find_pio_ISA(struct get_conf *buf)
792{
793	int i;
794
795	for (i = 0; i < MAXISA; i++) {
796		if (!ISAbases[i])
797			continue;
798		if (!get_pio_conf_PIO(ISAbases[i], buf))
799			continue;
800		if (!register_pio_HBA(ISAbases[i], buf, NULL))
801			release_region(ISAbases[i], 9);
802		else
803			ISAbases[i] = 0;
804	}
805	return;
806}
807
808static void find_pio_EISA(struct get_conf *buf)
809{
810	u32 base;
811	int i;
812
813#ifdef CHECKPAL
814	u8 pal1, pal2, pal3;
815#endif
816
817	for (i = 0; i < MAXEISA; i++) {
818		if (EISAbases[i]) {	/* Still a possibility ?          */
819
820			base = 0x1c88 + (i * 0x1000);
821#ifdef CHECKPAL
822			pal1 = inb((u16) base - 8);
823			pal2 = inb((u16) base - 7);
824			pal3 = inb((u16) base - 6);
825
826			if (((pal1 == 0x12) && (pal2 == 0x14)) || ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) || ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
827				DBG(DBG_PROBE, printk(KERN_NOTICE "EISA EATA id tags found: " "%x %x %x \n", (int) pal1, (int) pal2, (int) pal3));
828#endif
829				if (get_pio_conf_PIO(base, buf)) {
830					DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));
831					if (buf->IRQ) {
832						if (!register_pio_HBA(base, buf, NULL))
833							release_region(base, 9);
834					} else {
835						printk(KERN_NOTICE "eata_dma: No valid IRQ. HBA " "removed from list\n");
836						release_region(base, 9);
837					}
838				}
839				/* Nothing found here so we take it from the list */
840				EISAbases[i] = 0;
841#ifdef CHECKPAL
842			}
843#endif
844		}
845	}
846	return;
847}
848
849static void find_pio_PCI(struct get_conf *buf)
850{
851#ifndef CONFIG_PCI
852	printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
853#else
854	struct pci_dev *dev = NULL;
855	unsigned long base, x;
856
857	while ((dev = pci_get_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) {
858		DBG(DBG_PROBE && DBG_PCI, printk("eata_pio: find_PCI, HBA at %s\n", pci_name(dev)));
859		if (pci_enable_device(dev))
860			continue;
861		pci_set_master(dev);
862		base = pci_resource_flags(dev, 0);
863		if (base & IORESOURCE_MEM) {
864			printk("eata_pio: invalid base address of device %s\n", pci_name(dev));
865			continue;
866		}
867		base = pci_resource_start(dev, 0);
868		/* EISA tag there ? */
869		if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
870			continue;	/* Jep, it's forced, so move on  */
871		base += 0x10;	/* Now, THIS is the real address */
872		if (base != 0x1f8) {
873			/* We didn't find it in the primary search */
874			if (get_pio_conf_PIO(base, buf)) {
875				if (buf->FORCADR) {	/* If the address is forced */
876					release_region(base, 9);
877					continue;	/* we'll find it later      */
878				}
879
880				/* OK. We made it till here, so we can go now  
881				 * and register it. We  only have to check and 
882				 * eventually remove it from the EISA and ISA list 
883				 */
884
885				if (!register_pio_HBA(base, buf, dev)) {
886					release_region(base, 9);
887					continue;
888				}
889
890				if (base < 0x1000) {
891					for (x = 0; x < MAXISA; ++x) {
892						if (ISAbases[x] == base) {
893							ISAbases[x] = 0;
894							break;
895						}
896					}
897				} else if ((base & 0x0fff) == 0x0c88) {
898					x = (base >> 12) & 0x0f;
899					EISAbases[x] = 0;
900				}
901			}
902#ifdef CHECK_BLINK
903			else if (check_blink_state(base)) {
904				printk("eata_pio: HBA is in BLINK state.\n" "Consult your HBAs manual to correct this.\n");
905			}
906#endif
907		}
908	}
909#endif				/* #ifndef CONFIG_PCI */
910}
911
912static int eata_pio_detect(struct scsi_host_template *tpnt)
913{
914	struct Scsi_Host *HBA_ptr;
915	struct get_conf gc;
916	int i;
917
918	find_pio_PCI(&gc);
919	find_pio_EISA(&gc);
920	find_pio_ISA(&gc);
921
922	for (i = 0; i < MAXIRQ; i++)
923		if (reg_IRQ[i])
924			request_irq(i, do_eata_pio_int_handler, 0, "EATA-PIO", NULL);
925
926	HBA_ptr = first_HBA;
927
928	if (registered_HBAs != 0) {
929		printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
930		       "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n" "            Alfred Arnold,   a.arnold@kfa-juelich.de\n" "This release only supports DASD devices (harddisks)\n", VER_MAJOR, VER_MINOR, VER_SUB);
931
932		printk("Registered HBAs:\n");
933		printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:" " QS: SG: CPL:\n");
934		for (i = 1; i <= registered_HBAs; i++) {
935			printk("scsi%-2d: %.10s v%s 2.0%c  %s %#.4lx   %2d   %d   %d   %c"
936			       "  %2d  %2d  %2d\n",
937			       HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
938			       SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P') ?
939			       "PCI " : (SD(HBA_ptr)->bustype == 'E') ? "EISA" : "ISA ",
940			       HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, HBA_ptr->this_id,
941			       SD(HBA_ptr)->primary ? 'Y' : 'N', HBA_ptr->can_queue,
942			       HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);
943			HBA_ptr = SD(HBA_ptr)->next;
944		}
945	}
946	return (registered_HBAs);
947}
948
949static struct scsi_host_template driver_template = {
950	.proc_name		= "eata_pio",
951	.name              	= "EATA (Extended Attachment) PIO driver",
952	.show_info         	= eata_pio_show_info,
953	.detect            	= eata_pio_detect,
954	.release           	= eata_pio_release,
955	.queuecommand      	= eata_pio_queue,
956	.eh_abort_handler  	= eata_pio_abort,
957	.eh_host_reset_handler	= eata_pio_host_reset,
958	.use_clustering    	= ENABLE_CLUSTERING,
959};
960
961MODULE_AUTHOR("Michael Neuffer, Alfred Arnold");
962MODULE_DESCRIPTION("EATA SCSI PIO driver");
963MODULE_LICENSE("GPL");
964
965#include "scsi_module.c"