Blame view

drivers/scsi/eata_pio.c 27.3 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  /************************************************************
   *                                                          *
   *               Linux EATA SCSI PIO driver                 *
   *                                                          *
   *  based on the CAM document CAM/89-004 rev. 2.0c,         *
   *  DPT's driver kit, some internal documents and source,   *
   *  and several other Linux scsi drivers and kernel docs.   *
   *                                                          *
   *  The driver currently:                                   *
   *      -supports all EATA-PIO boards                       *
   *      -only supports DASD devices                         *
   *                                                          *
   *  (c)1993-96 Michael Neuffer, Alfred Arnold               *
   *             neuffer@goofy.zdv.uni-mainz.de               *
   *             a.arnold@kfa-juelich.de                      * 
   *                                                          *
fa195afe4   Alan Cox   [SCSI] Clean up m...
17
18
   *  Updated 2002 by Alan Cox <alan@lxorguk.ukuu.org.uk> for *
   *   Linux 2.5.x and the newer locking and error handling   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
   *                                                          *
   *  This program is free software; you can redistribute it  *
   *  and/or modify it under the terms of the GNU General     *
   *  Public License as published by the Free Software        *
   *  Foundation; either version 2 of the License, or         *
   *  (at your option) any later version.                     *
   *                                                          *
   *  This program is distributed in the hope that it will be *
   *  useful, but WITHOUT ANY WARRANTY; without even the      *
   *  implied warranty of MERCHANTABILITY or FITNESS FOR A    *
   *  PARTICULAR PURPOSE.  See the GNU General Public License *
   *  for more details.                                       *
   *                                                          *
   *  You should have received a copy of the GNU General      *
   *  Public License along with this kernel; if not, write to *
   *  the Free Software Foundation, Inc., 675 Mass Ave,       *
   *  Cambridge, MA 02139, USA.                               *
   *							    *
   *  For the avoidance of doubt the "preferred form" of this *
   *  code is one which is in an open non patent encumbered   *
   *  format. Where cryptographic key signing forms part of   *
   *  the process of creating an executable the information   *
   *  including keys needed to generate an equivalently       *
   *  functional executable are deemed to be part of the 	    *
   *  source code are deemed to be part of the source code.   *
   *                                                          *
   ************************************************************
   *  last change: 2002/11/02               OS: Linux 2.5.45  *
   ************************************************************/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
49
  #include <linux/module.h>
  #include <linux/kernel.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
  #include <linux/string.h>
  #include <linux/ioport.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  #include <linux/in.h>
  #include <linux/pci.h>
  #include <linux/proc_fs.h>
  #include <linux/interrupt.h>
  #include <linux/blkdev.h>
  #include <linux/spinlock.h>
  #include <linux/delay.h>
  
  #include <asm/io.h>
  
  #include <scsi/scsi.h>
  #include <scsi/scsi_cmnd.h>
  #include <scsi/scsi_device.h>
  #include <scsi/scsi_host.h>
  
  #include "eata_generic.h"
  #include "eata_pio.h"
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
69
  static unsigned int ISAbases[MAXISA] =	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
71
  	 0x1F0, 0x170, 0x330, 0x230
  };
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
72
  static unsigned int ISAirqs[MAXISA] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
74
75
76
77
78
79
  	14, 12, 15, 11
  };
  
  static unsigned char EISAbases[] = { 
  	1, 1, 1, 1, 1, 1, 1, 1,
  	1, 1, 1, 1, 1, 1, 1, 1 
  };
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
80
  static unsigned int registered_HBAs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  static struct Scsi_Host *last_HBA;
  static struct Scsi_Host *first_HBA;
  static unsigned char reg_IRQ[16];
  static unsigned char reg_IRQL[16];
  static unsigned long int_counter;
  static unsigned long queue_counter;
  
  static struct scsi_host_template driver_template;
  
  /*
   * eata_proc_info
   * inout : decides on the direction of the dataflow and the meaning of the 
   *         variables
   * buffer: If inout==FALSE data is being written to it else read from it
   * *start: If inout==FALSE start of the valid data in the buffer
   * offset: If inout==FALSE offset from the beginning of the imaginary file 
   *         from which we start writing into the buffer
   * length: If inout==FALSE max number of bytes to be written into the buffer 
   *         else number of bytes in the buffer
   */
  static int eata_pio_proc_info(struct Scsi_Host *shost, char *buffer, char **start, off_t offset,
  			      int length, int rw)
  {
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
104
105
  	int len = 0;
  	off_t begin = 0, pos = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
106

1a1d64149   Alan Cox   [SCSI] eata_pio: ...
107
108
  	if (rw)
  		return -ENOSYS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109

1a1d64149   Alan Cox   [SCSI] eata_pio: ...
110
  	len += sprintf(buffer+len, "EATA (Extended Attachment) PIO driver version: "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
  		   "%d.%d%s
  ",VER_MAJOR, VER_MINOR, VER_SUB);
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
113
114
  	len += sprintf(buffer + len, "queued commands:     %10ld
  "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
  		   "processed interrupts:%10ld
  ", queue_counter, int_counter);
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
117
118
119
  	len += sprintf(buffer + len, "
  scsi%-2d: HBA %.10s
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120
  		   shost->host_no, SD(shost)->name);
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
121
122
  	len += sprintf(buffer + len, "Firmware revision: v%s
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
  		   SD(shost)->revision);
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
124
125
126
127
128
129
  	len += sprintf(buffer + len, "IO: PIO
  ");
  	len += sprintf(buffer + len, "Base IO : %#.4x
  ", (u32) shost->base);
  	len += sprintf(buffer + len, "Host Bus: %s
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130
131
132
  		   (SD(shost)->bustype == 'P')?"PCI ":
  		   (SD(shost)->bustype == 'E')?"EISA":"ISA ");
      
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
133
  	pos = begin + len;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
      
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
135
136
137
138
139
140
  	if (pos < offset) {
  		len = 0;
  		begin = pos;
  	}
  	if (pos > offset + length)
  		goto stop_output;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
      
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
142
143
144
145
146
147
148
149
150
  stop_output:
  	DBG(DBG_PROC, printk("2pos: %ld offset: %ld len: %d
  ", pos, offset, len));
  	*start = buffer + (offset - begin);   /* Start of wanted data */
  	len -= (offset - begin);            /* Start slop */
  	if (len > length)
  		len = length;               /* Ending slop */
  	DBG(DBG_PROC, printk("3pos: %ld offset: %ld len: %d
  ", pos, offset, len));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
151
      
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
152
  	return len;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
154
155
156
  }
  
  static int eata_pio_release(struct Scsi_Host *sh)
  {
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
157
  	hostdata *hd = SD(sh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
158
159
160
161
162
163
164
165
  	if (sh->irq && reg_IRQ[sh->irq] == 1)
  		free_irq(sh->irq, NULL);
  	else
  		reg_IRQ[sh->irq]--;
  	if (SD(sh)->channel == 0) {
  		if (sh->io_port && sh->n_io_port)
  			release_region(sh->io_port, sh->n_io_port);
  	}
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
166
167
168
  	/* At this point the PCI reference can go */
  	if (hd->pdev)
  		pci_dev_put(hd->pdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
170
  	return 1;
  }
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
171
  static void IncStat(struct scsi_pointer *SCp, unsigned int Increment)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172
173
174
175
176
177
178
  {
  	SCp->ptr += Increment;
  	if ((SCp->this_residual -= Increment) == 0) {
  		if ((--SCp->buffers_residual) == 0)
  			SCp->Status = 0;
  		else {
  			SCp->buffer++;
45711f1af   Jens Axboe   [SG] Update drive...
179
  			SCp->ptr = sg_virt(SCp->buffer);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
181
182
183
  			SCp->this_residual = SCp->buffer->length;
  		}
  	}
  }
7d12e780e   David Howells   IRQ: Maintain reg...
184
  static irqreturn_t eata_pio_int_handler(int irq, void *dev_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
185

7d12e780e   David Howells   IRQ: Maintain reg...
186
  static irqreturn_t do_eata_pio_int_handler(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
188
189
  {
  	unsigned long flags;
  	struct Scsi_Host *dev = dev_id;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
190
  	irqreturn_t ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
191
192
  
  	spin_lock_irqsave(dev->host_lock, flags);
a31baca58   Alan Cox   [PATCH] irq updat...
193
  	ret = eata_pio_int_handler(irq, dev_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
194
  	spin_unlock_irqrestore(dev->host_lock, flags);
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
195
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
196
  }
7d12e780e   David Howells   IRQ: Maintain reg...
197
  static irqreturn_t eata_pio_int_handler(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198
  {
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
199
  	unsigned int eata_stat = 0xfffff;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
200
201
202
  	struct scsi_cmnd *cmd;
  	hostdata *hd;
  	struct eata_ccb *cp;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
203
204
  	unsigned long base;
  	unsigned int x, z;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205
206
207
  	struct Scsi_Host *sh;
  	unsigned short zwickel = 0;
  	unsigned char stat, odd;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
208
  	irqreturn_t ret = IRQ_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
210
211
212
213
  
  	for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) 
  	{
  		if (sh->irq != irq)
  			continue;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
214
  		if (inb(sh->base + HA_RSTATUS) & HA_SBUSY)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
215
216
217
  			continue;
  
  		int_counter++;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
218
  		ret = IRQ_HANDLED;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219
220
221
222
223
  
  		hd = SD(sh);
  
  		cp = &hd->ccb[0];
  		cmd = cp->cmd;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
224
  		base = cmd->device->host->base;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
  
  		do {
  			stat = inb(base + HA_RSTATUS);
  			if (stat & HA_SDRQ) {
  				if (cp->DataIn) {
  					z = 256;
  					odd = 0;
  					while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
  						if (odd) {
  							*(cmd->SCp.ptr) = zwickel >> 8;
  							IncStat(&cmd->SCp, 1);
  							odd = 0;
  						}
  						x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
  						insw(base + HA_RDATA, cmd->SCp.ptr, x);
  						z -= x;
  						IncStat(&cmd->SCp, 2 * x);
  						if ((z > 0) && (cmd->SCp.this_residual == 1)) {
  							zwickel = inw(base + HA_RDATA);
  							*(cmd->SCp.ptr) = zwickel & 0xff;
  							IncStat(&cmd->SCp, 1);
  							z--;
  							odd = 1;
  						}
  					}
  					while (z > 0) {
  						zwickel = inw(base + HA_RDATA);
  						z--;
  					}
  				} else {	/* cp->DataOut */
  
  					odd = 0;
  					z = 256;
  					while ((cmd->SCp.Status) && ((z > 0) || (odd))) {
  						if (odd) {
  							zwickel += *(cmd->SCp.ptr) << 8;
  							IncStat(&cmd->SCp, 1);
  							outw(zwickel, base + HA_RDATA);
  							z--;
  							odd = 0;
  						}
  						x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);
  						outsw(base + HA_RDATA, cmd->SCp.ptr, x);
  						z -= x;
  						IncStat(&cmd->SCp, 2 * x);
  						if ((z > 0) && (cmd->SCp.this_residual == 1)) {
  							zwickel = *(cmd->SCp.ptr);
  							zwickel &= 0xff;
  							IncStat(&cmd->SCp, 1);
  							odd = 1;
  						}
  					}
  					while (z > 0 || odd) {
  						outw(zwickel, base + HA_RDATA);
  						z--;
  						odd = 0;
  					}
  				}
  			}
  		}
  		while ((stat & HA_SDRQ) || ((stat & HA_SMORE) && hd->moresupport));
  
  		/* terminate handler if HBA goes busy again, i.e. transfers
  		 * more data */
  
  		if (stat & HA_SBUSY)
  			break;
  
  		/* OK, this is quite stupid, but I haven't found any correct
  		 * way to get HBA&SCSI status so far */
  
  		if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {
  			cmd->result = (DID_OK << 16);
  			hd->devflags |= (1 << cp->cp_id);
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
299
  		} else if (hd->devflags & (1 << cp->cp_id))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
300
301
302
303
304
305
306
307
308
  			cmd->result = (DID_OK << 16) + 0x02;
  		else
  			cmd->result = (DID_NO_CONNECT << 16);
  
  		if (cp->status == LOCKED) {
  			cp->status = FREE;
  			eata_stat = inb(base + HA_RSTATUS);
  			printk(KERN_CRIT "eata_pio: int_handler, freeing locked " "queueslot
  ");
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
309
  			return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
311
312
313
314
315
316
317
318
319
320
  		}
  #if DBG_INTR2
  		if (stat != 0x50)
  			printk(KERN_DEBUG "stat: %#.2x, result: %#.8x
  ", stat, cmd->result);
  #endif
  
  		cp->status = FREE;	/* now we can release the slot  */
  
  		cmd->scsi_done(cmd);
  	}
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
321
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
322
  }
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
323
  static inline unsigned int eata_pio_send_command(unsigned long base, unsigned char command)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
324
  {
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
325
  	unsigned int loop = 50;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
326
327
328
329
330
331
332
333
334
335
336
337
338
339
  
  	while (inb(base + HA_RSTATUS) & HA_SBUSY)
  		if (--loop == 0)
  			return 1;
  
  	/* Enable interrupts for HBA.  It is not the best way to do it at this
  	 * place, but I hope that it doesn't interfere with the IDE driver 
  	 * initialization this way */
  
  	outb(HA_CTRL_8HEADS, base + HA_CTRLREG);
  
  	outb(command, base + HA_WCOMMAND);
  	return 0;
  }
f281233d3   Jeff Garzik   SCSI host lock pu...
340
  static int eata_pio_queue_lck(struct scsi_cmnd *cmd,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
341
342
  		void (*done)(struct scsi_cmnd *))
  {
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
343
344
  	unsigned int x, y;
  	unsigned long base;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345
346
347
348
349
350
351
352
353
  
  	hostdata *hd;
  	struct Scsi_Host *sh;
  	struct eata_ccb *cp;
  
  	queue_counter++;
  
  	hd = HD(cmd);
  	sh = cmd->device->host;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
354
  	base = sh->base;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
  
  	/* use only slot 0, as 2001 can handle only one cmd at a time */
  
  	y = x = 0;
  
  	if (hd->ccb[y].status != FREE) {
  
  		DBG(DBG_QUEUE, printk(KERN_EMERG "can_queue %d, x %d, y %d
  ", sh->can_queue, x, y));
  #if DEBUG_EATA
  		panic(KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld " "intrno: %ld
  ", queue_counter, int_counter);
  #else
  		panic(KERN_EMERG "eata_pio: run out of queue slots....
  ");
  #endif
  	}
  
  	cp = &hd->ccb[y];
  
  	memset(cp, 0, sizeof(struct eata_ccb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
376
377
  
  	cp->status = USED;	/* claim free slot */
017560fca   Jeff Garzik   [SCSI] use sfoo_p...
378
  	DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,
5cd049a59   Christoph Hellwig   [SCSI] remove cmd...
379
380
  		"eata_pio_queue 0x%p, y %d
  ", cmd, y));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381
382
383
384
385
386
387
388
389
  
  	cmd->scsi_done = (void *) done;
  
  	if (cmd->sc_data_direction == DMA_TO_DEVICE)
  		cp->DataOut = 1;	/* Output mode */
  	else
  		cp->DataIn = 0;	/* Input mode  */
  
  	cp->Interpret = (cmd->device->id == hd->hostid);
7410d849a   Boaz Harrosh   [SCSI] eata_pio: ...
390
  	cp->cp_datalen = cpu_to_be32(scsi_bufflen(cmd));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
391
  	cp->Auto_Req_Sen = 0;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
392
  	cp->cp_reqDMA = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
393
394
395
396
397
398
399
  	cp->reqlen = 0;
  
  	cp->cp_id = cmd->device->id;
  	cp->cp_lun = cmd->device->lun;
  	cp->cp_dispri = 0;
  	cp->cp_identify = 1;
  	memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
400
  	cp->cp_statDMA = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
401
402
403
404
  
  	cp->cp_viraddr = cp;
  	cp->cmd = cmd;
  	cmd->host_scribble = (char *) &hd->ccb[y];
7410d849a   Boaz Harrosh   [SCSI] eata_pio: ...
405
  	if (!scsi_bufflen(cmd)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
406
  		cmd->SCp.buffers_residual = 1;
7410d849a   Boaz Harrosh   [SCSI] eata_pio: ...
407
408
  		cmd->SCp.ptr = NULL;
  		cmd->SCp.this_residual = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
  		cmd->SCp.buffer = NULL;
  	} else {
7410d849a   Boaz Harrosh   [SCSI] eata_pio: ...
411
412
  		cmd->SCp.buffer = scsi_sglist(cmd);
  		cmd->SCp.buffers_residual = scsi_sg_count(cmd);
45711f1af   Jens Axboe   [SG] Update drive...
413
  		cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
414
415
416
417
418
419
420
  		cmd->SCp.this_residual = cmd->SCp.buffer->length;
  	}
  	cmd->SCp.Status = (cmd->SCp.this_residual != 0);	/* TRUE as long as bytes 
  								 * are to transfer */
  
  	if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) {
  		cmd->result = DID_BUS_BUSY << 16;
017560fca   Jeff Garzik   [SCSI] use sfoo_p...
421
  		scmd_printk(KERN_NOTICE, cmd,
5cd049a59   Christoph Hellwig   [SCSI] remove cmd...
422
423
424
  			"eata_pio_queue pid 0x%p, HBA busy, "
  			"returning DID_BUS_BUSY, done.
  ", cmd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
425
426
  		done(cmd);
  		cp->status = FREE;
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
427
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
428
429
430
431
432
433
434
435
  	}
  	/* FIXME: timeout */
  	while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
  		cpu_relax();
  	outsw(base + HA_RDATA, cp, hd->cplen);
  	outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
  	for (x = 0; x < hd->cppadlen; x++)
  		outw(0, base + HA_RDATA);
017560fca   Jeff Garzik   [SCSI] use sfoo_p...
436
  	DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,
5cd049a59   Christoph Hellwig   [SCSI] remove cmd...
437
438
439
  		"Queued base %#.4lx cmd: 0x%p "
  		"slot %d irq %d
  ", sh->base, cmd, y, sh->irq));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
440

1a1d64149   Alan Cox   [SCSI] eata_pio: ...
441
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
442
  }
f281233d3   Jeff Garzik   SCSI host lock pu...
443
  static DEF_SCSI_QCMD(eata_pio_queue)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
444
445
  static int eata_pio_abort(struct scsi_cmnd *cmd)
  {
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
446
  	unsigned int loop = 100;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
447

017560fca   Jeff Garzik   [SCSI] use sfoo_p...
448
  	DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,
5cd049a59   Christoph Hellwig   [SCSI] remove cmd...
449
450
  		"eata_pio_abort called pid: 0x%p
  ", cmd));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
  
  	while (inb(cmd->device->host->base + HA_RAUXSTAT) & HA_ABUSY)
  		if (--loop == 0) {
  			printk(KERN_WARNING "eata_pio: abort, timeout error.
  ");
  			return FAILED;
  		}
  	if (CD(cmd)->status == FREE) {
  		DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_NOT_RUNNING
  "));
  		return FAILED;
  	}
  	if (CD(cmd)->status == USED) {
  		DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_BUSY
  "));
  		/* We want to sleep a bit more here */
  		return FAILED;		/* SNOOZE */
  	}
  	if (CD(cmd)->status == RESET) {
  		printk(KERN_WARNING "eata_pio: abort, command reset error.
  ");
  		return FAILED;
  	}
  	if (CD(cmd)->status == LOCKED) {
  		DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio: abort, queue slot " "locked.
  "));
  		return FAILED;
  	}
  	panic("eata_pio: abort: invalid slot status
  ");
  }
  
  static int eata_pio_host_reset(struct scsi_cmnd *cmd)
  {
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
485
  	unsigned int x, limit = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
486
487
488
  	unsigned char success = 0;
  	struct scsi_cmnd *sp;
  	struct Scsi_Host *host = cmd->device->host;
017560fca   Jeff Garzik   [SCSI] use sfoo_p...
489
  	DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,
5cd049a59   Christoph Hellwig   [SCSI] remove cmd...
490
491
  		"eata_pio_reset called
  "));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
492

df0ae2497   Jeff Garzik   [SCSI] allow slee...
493
  	spin_lock_irq(host->host_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
494
495
496
  	if (HD(cmd)->state == RESET) {
  		printk(KERN_WARNING "eata_pio_reset: exit, already in reset.
  ");
df0ae2497   Jeff Garzik   [SCSI] allow slee...
497
  		spin_unlock_irq(host->host_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
498
499
500
501
502
503
504
505
506
507
508
509
  		return FAILED;
  	}
  
  	/* force all slots to be free */
  
  	for (x = 0; x < cmd->device->host->can_queue; x++) {
  
  		if (HD(cmd)->ccb[x].status == FREE)
  			continue;
  
  		sp = HD(cmd)->ccb[x].cmd;
  		HD(cmd)->ccb[x].status = RESET;
5cd049a59   Christoph Hellwig   [SCSI] remove cmd...
510
511
  		printk(KERN_WARNING "eata_pio_reset: slot %d in reset.
  ", x);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
512
513
514
515
516
517
518
  
  		if (sp == NULL)
  			panic("eata_pio_reset: slot %d, sp==NULL.
  ", x);
  	}
  
  	/* hard reset the HBA  */
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
519
  	outb(EATA_CMD_RESET, cmd->device->host->base + HA_WCOMMAND);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
  
  	DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: board reset done.
  "));
  	HD(cmd)->state = RESET;
  
  	spin_unlock_irq(host->host_lock);
  	msleep(3000);
  	spin_lock_irq(host->host_lock);
  
  	DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: interrupts disabled, " "loops %d.
  ", limit));
  
  	for (x = 0; x < cmd->device->host->can_queue; x++) {
  
  		/* Skip slots already set free by interrupt */
  		if (HD(cmd)->ccb[x].status != RESET)
  			continue;
  
  		sp = HD(cmd)->ccb[x].cmd;
  		sp->result = DID_RESET << 16;
  
  		/* This mailbox is terminated */
  		printk(KERN_WARNING "eata_pio_reset: reset ccb %d.
  ", x);
  		HD(cmd)->ccb[x].status = FREE;
  
  		sp->scsi_done(sp);
  	}
  
  	HD(cmd)->state = 0;
df0ae2497   Jeff Garzik   [SCSI] allow slee...
550
  	spin_unlock_irq(host->host_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
551
552
553
554
555
556
557
558
559
560
  	if (success) {		/* hmmm... */
  		DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, success.
  "));
  		return SUCCESS;
  	} else {
  		DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, wakeup.
  "));
  		return FAILED;
  	}
  }
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
561
  static char *get_pio_board_data(unsigned long base, unsigned int irq, unsigned int id, unsigned long cplen, unsigned short cppadlen)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
562
563
564
565
566
567
568
569
570
571
  {
  	struct eata_ccb cp;
  	static char buff[256];
  	int z;
  
  	memset(&cp, 0, sizeof(struct eata_ccb));
  	memset(buff, 0, sizeof(buff));
  
  	cp.DataIn = 1;
  	cp.Interpret = 1;	/* Interpret command */
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
572
573
  	cp.cp_datalen = cpu_to_be32(254);
  	cp.cp_dataDMA = cpu_to_be32(0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
574
575
576
577
578
579
580
581
582
583
  
  	cp.cp_id = id;
  	cp.cp_lun = 0;
  
  	cp.cp_cdb[0] = INQUIRY;
  	cp.cp_cdb[1] = 0;
  	cp.cp_cdb[2] = 0;
  	cp.cp_cdb[3] = 0;
  	cp.cp_cdb[4] = 254;
  	cp.cp_cdb[5] = 0;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
584
  	if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP))
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
585
586
587
588
  		return NULL;
  
  	while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
  		cpu_relax();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
589
590
591
592
  	outsw(base + HA_RDATA, &cp, cplen);
  	outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
  	for (z = 0; z < cppadlen; z++)
  		outw(0, base + HA_RDATA);
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
593
594
  	while (inb(base + HA_RSTATUS) & HA_SBUSY)
  		cpu_relax();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
595
  	if (inb(base + HA_RSTATUS) & HA_SERROR)
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
596
  		return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
597
  	else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
598
  		return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
599
600
601
602
  	else {
  		insw(base + HA_RDATA, &buff, 127);
  		while (inb(base + HA_RSTATUS) & HA_SDRQ)
  			inw(base + HA_RDATA);
1a1d64149   Alan Cox   [SCSI] eata_pio: ...
603
  		return buff;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
604
605
  	}
  }
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
606
  static int get_pio_conf_PIO(unsigned long base, struct get_conf *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
607
608
609
610
611
612
613
614
615
616
617
618
619
  {
  	unsigned long loop = HZ / 2;
  	int z;
  	unsigned short *p;
  
  	if (!request_region(base, 9, "eata_pio"))
  		return 0;
  
  	memset(buf, 0, sizeof(struct get_conf));
  
  	while (inb(base + HA_RSTATUS) & HA_SBUSY)
  		if (--loop == 0)
  			goto fail;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
620
621
  	DBG(DBG_PIO && DBG_PROBE, printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#lx
  ", base));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
622
  	eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG);
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
623
  	loop = 50;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
624
625
626
627
  	for (p = (unsigned short *) buf; (long) p <= ((long) buf + (sizeof(struct get_conf) / 2)); p++) {
  		while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
  			if (--loop == 0)
  				goto fail;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
628
  		loop = 50;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
629
630
631
632
  		*p = inw(base + HA_RDATA);
  	}
  	if (inb(base + HA_RSTATUS) & HA_SERROR) {
  		DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during "
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
633
634
  					"transfer for HBA at %lx
  ", base));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
635
636
  		goto fail;
  	}
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
637
  	if (cpu_to_be32(EATA_SIGNATURE) != buf->signature)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
638
639
640
  		goto fail;
  
  	DBG(DBG_PIO && DBG_PROBE, printk(KERN_NOTICE "EATA Controller found "
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
641
642
643
  				"at %#4lx EATA Level: %x
  ",
  				base, (unsigned int) (buf->version)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
  
  	while (inb(base + HA_RSTATUS) & HA_SDRQ)
  		inw(base + HA_RDATA);
  
  	if (!ALLOW_DMA_BOARDS) {
  		for (z = 0; z < MAXISA; z++)
  			if (base == ISAbases[z]) {
  				buf->IRQ = ISAirqs[z];
  				break;
  			}
  	}
  
  	return 1;
  
   fail:
  	release_region(base, 9);
  	return 0;
  }
  
  static void print_pio_config(struct get_conf *gc)
  {
  	printk("Please check values: (read config data)
  ");
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
667
668
669
670
  	printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d
  ", be32_to_cpu(gc->len), gc->version, gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support);
  	printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d
  ", 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);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
671
672
673
  	printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d
  ", gc->IRQ, gc->IRQ_TR, gc->FORCADR, gc->MAX_CHAN, gc->ID_qest);
  }
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
674
  static unsigned int print_selftest(unsigned int base)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
  {
  	unsigned char buffer[512];
  #ifdef VERBOSE_SETUP
  	int z;
  #endif
  
  	printk("eata_pio: executing controller self test & setup...
  ");
  	while (inb(base + HA_RSTATUS) & HA_SBUSY);
  	outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND);
  	do {
  		while (inb(base + HA_RSTATUS) & HA_SBUSY)
  			/* nothing */ ;
  		if (inb(base + HA_RSTATUS) & HA_SDRQ) {
  			insw(base + HA_RDATA, &buffer, 256);
  #ifdef VERBOSE_SETUP
  			/* no beeps please... */
  			for (z = 0; z < 511 && buffer[z]; z++)
  				if (buffer[z] != 7)
  					printk("%c", buffer[z]);
  #endif
  		}
  	} while (inb(base + HA_RSTATUS) & (HA_SBUSY | HA_SDRQ));
  
  	return (!(inb(base + HA_RSTATUS) & HA_SERROR));
  }
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
701
  static int register_pio_HBA(long base, struct get_conf *gc, struct pci_dev *pdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
  {
  	unsigned long size = 0;
  	char *buff;
  	unsigned long cplen;
  	unsigned short cppadlen;
  	struct Scsi_Host *sh;
  	hostdata *hd;
  
  	DBG(DBG_REGISTER, print_pio_config(gc));
  
  	if (gc->DMA_support) {
  		printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.
  ", base);
  		if (!ALLOW_DMA_BOARDS)
  			return 0;
  	}
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
718
719
720
  	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) {
  		printk("HBA at %#lx didn't react on INQUIRY. Sorry.
  ", base);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
721
722
723
724
  		return 0;
  	}
  
  	if (!print_selftest(base) && !ALLOW_DMA_BOARDS) {
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
725
726
  		printk("HBA at %#lx failed while performing self test & setup.
  ", base);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
727
728
  		return 0;
  	}
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
729
  	size = sizeof(hostdata) + (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
730
731
732
733
734
735
  
  	sh = scsi_register(&driver_template, size);
  	if (sh == NULL)
  		return 0;
  
  	if (!reg_IRQ[gc->IRQ]) {	/* Interrupt already registered ? */
1d6f359a2   Thomas Gleixner   [PATCH] irq-flags...
736
  		if (!request_irq(gc->IRQ, do_eata_pio_int_handler, IRQF_DISABLED, "EATA-PIO", sh)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
  			reg_IRQ[gc->IRQ]++;
  			if (!gc->IRQ_TR)
  				reg_IRQL[gc->IRQ] = 1;	/* IRQ is edge triggered */
  		} else {
  			printk("Couldn't allocate IRQ %d, Sorry.
  ", gc->IRQ);
  			return 0;
  		}
  	} else {		/* More than one HBA on this IRQ */
  		if (reg_IRQL[gc->IRQ]) {
  			printk("Can't support more than one HBA on this IRQ,
  " "  if the IRQ is edge triggered. Sorry.
  ");
  			return 0;
  		} else
  			reg_IRQ[gc->IRQ]++;
  	}
  
  	hd = SD(sh);
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
756
757
  	memset(hd->ccb, 0, (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz)));
  	memset(hd->reads, 0, sizeof(hd->reads));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
758
759
760
761
762
763
764
765
766
  
  	strlcpy(SD(sh)->vendor, &buff[8], sizeof(SD(sh)->vendor));
  	strlcpy(SD(sh)->name, &buff[16], sizeof(SD(sh)->name));
  	SD(sh)->revision[0] = buff[32];
  	SD(sh)->revision[1] = buff[33];
  	SD(sh)->revision[2] = buff[34];
  	SD(sh)->revision[3] = '.';
  	SD(sh)->revision[4] = buff[35];
  	SD(sh)->revision[5] = 0;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
767
  	switch (be32_to_cpu(gc->len)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
768
769
770
771
772
773
774
775
776
777
778
779
780
781
  	case 0x1c:
  		SD(sh)->EATA_revision = 'a';
  		break;
  	case 0x1e:
  		SD(sh)->EATA_revision = 'b';
  		break;
  	case 0x22:
  		SD(sh)->EATA_revision = 'c';
  		break;
  	case 0x24:
  		SD(sh)->EATA_revision = 'z';
  	default:
  		SD(sh)->EATA_revision = '?';
  	}
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
782
  	if (be32_to_cpu(gc->len) >= 0x22) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
  		if (gc->is_PCI)
  			hd->bustype = IS_PCI;
  		else if (gc->is_EISA)
  			hd->bustype = IS_EISA;
  		else
  			hd->bustype = IS_ISA;
  	} else {
  		if (buff[21] == '4')
  			hd->bustype = IS_PCI;
  		else if (buff[21] == '2')
  			hd->bustype = IS_EISA;
  		else
  			hd->bustype = IS_ISA;
  	}
  
  	SD(sh)->cplen = cplen;
  	SD(sh)->cppadlen = cppadlen;
  	SD(sh)->hostid = gc->scsi_id[3];
  	SD(sh)->devflags = 1 << gc->scsi_id[3];
  	SD(sh)->moresupport = gc->MORE_support;
  	sh->unique_id = base;
  	sh->base = base;
  	sh->io_port = base;
  	sh->n_io_port = 9;
  	sh->irq = gc->IRQ;
  	sh->dma_channel = PIO;
  	sh->this_id = gc->scsi_id[3];
  	sh->can_queue = 1;
  	sh->cmd_per_lun = 1;
  	sh->sg_tablesize = SG_ALL;
  
  	hd->channel = 0;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
815
  	hd->pdev = pci_dev_get(pdev);	/* Keep a PCI reference */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
816
817
818
819
820
821
822
  	sh->max_id = 8;
  	sh->max_lun = 8;
  
  	if (gc->SECOND)
  		hd->primary = 0;
  	else
  		hd->primary = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
  	hd->next = NULL;	/* build a linked list of all HBAs */
  	hd->prev = last_HBA;
  	if (hd->prev != NULL)
  		SD(hd->prev)->next = sh;
  	last_HBA = sh;
  	if (first_HBA == NULL)
  		first_HBA = sh;
  	registered_HBAs++;
  	return (1);
  }
  
  static void find_pio_ISA(struct get_conf *buf)
  {
  	int i;
  
  	for (i = 0; i < MAXISA; i++) {
  		if (!ISAbases[i])
  			continue;
  		if (!get_pio_conf_PIO(ISAbases[i], buf))
  			continue;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
843
  		if (!register_pio_HBA(ISAbases[i], buf, NULL))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
  			release_region(ISAbases[i], 9);
  		else
  			ISAbases[i] = 0;
  	}
  	return;
  }
  
  static void find_pio_EISA(struct get_conf *buf)
  {
  	u32 base;
  	int i;
  
  #ifdef CHECKPAL
  	u8 pal1, pal2, pal3;
  #endif
  
  	for (i = 0; i < MAXEISA; i++) {
  		if (EISAbases[i]) {	/* Still a possibility ?          */
  
  			base = 0x1c88 + (i * 0x1000);
  #ifdef CHECKPAL
  			pal1 = inb((u16) base - 8);
  			pal2 = inb((u16) base - 7);
  			pal3 = inb((u16) base - 6);
  
  			if (((pal1 == 0x12) && (pal2 == 0x14)) || ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) || ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
  				DBG(DBG_PROBE, printk(KERN_NOTICE "EISA EATA id tags found: " "%x %x %x 
  ", (int) pal1, (int) pal2, (int) pal3));
  #endif
  				if (get_pio_conf_PIO(base, buf)) {
  					DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));
  					if (buf->IRQ) {
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
876
  						if (!register_pio_HBA(base, buf, NULL))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
  							release_region(base, 9);
  					} else {
  						printk(KERN_NOTICE "eata_dma: No valid IRQ. HBA " "removed from list
  ");
  						release_region(base, 9);
  					}
  				}
  				/* Nothing found here so we take it from the list */
  				EISAbases[i] = 0;
  #ifdef CHECKPAL
  			}
  #endif
  		}
  	}
  	return;
  }
  
  static void find_pio_PCI(struct get_conf *buf)
  {
  #ifndef CONFIG_PCI
  	printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.
  ");
  #else
  	struct pci_dev *dev = NULL;
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
901
  	unsigned long base, x;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
902

1a68d41a3   Alan Cox   [SCSI] eata_pio c...
903
  	while ((dev = pci_get_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
  		DBG(DBG_PROBE && DBG_PCI, printk("eata_pio: find_PCI, HBA at %s
  ", pci_name(dev)));
  		if (pci_enable_device(dev))
  			continue;
  		pci_set_master(dev);
  		base = pci_resource_flags(dev, 0);
  		if (base & IORESOURCE_MEM) {
  			printk("eata_pio: invalid base address of device %s
  ", pci_name(dev));
  			continue;
  		}
  		base = pci_resource_start(dev, 0);
  		/* EISA tag there ? */
  		if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
  			continue;	/* Jep, it's forced, so move on  */
  		base += 0x10;	/* Now, THIS is the real address */
  		if (base != 0x1f8) {
  			/* We didn't find it in the primary search */
  			if (get_pio_conf_PIO(base, buf)) {
  				if (buf->FORCADR) {	/* If the address is forced */
  					release_region(base, 9);
  					continue;	/* we'll find it later      */
  				}
  
  				/* OK. We made it till here, so we can go now  
  				 * and register it. We  only have to check and 
  				 * eventually remove it from the EISA and ISA list 
  				 */
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
932
  				if (!register_pio_HBA(base, buf, dev)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
  					release_region(base, 9);
  					continue;
  				}
  
  				if (base < 0x1000) {
  					for (x = 0; x < MAXISA; ++x) {
  						if (ISAbases[x] == base) {
  							ISAbases[x] = 0;
  							break;
  						}
  					}
  				} else if ((base & 0x0fff) == 0x0c88) {
  					x = (base >> 12) & 0x0f;
  					EISAbases[x] = 0;
  				}
  			}
  #ifdef CHECK_BLINK
  			else if (check_blink_state(base)) {
  				printk("eata_pio: HBA is in BLINK state.
  " "Consult your HBAs manual to correct this.
  ");
  			}
  #endif
  		}
  	}
  #endif				/* #ifndef CONFIG_PCI */
  }
  
  static int eata_pio_detect(struct scsi_host_template *tpnt)
  {
  	struct Scsi_Host *HBA_ptr;
  	struct get_conf gc;
  	int i;
  
  	find_pio_PCI(&gc);
  	find_pio_EISA(&gc);
  	find_pio_ISA(&gc);
  
  	for (i = 0; i <= MAXIRQ; i++)
  		if (reg_IRQ[i])
1d6f359a2   Thomas Gleixner   [PATCH] irq-flags...
973
  			request_irq(i, do_eata_pio_int_handler, IRQF_DISABLED, "EATA-PIO", NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
  
  	HBA_ptr = first_HBA;
  
  	if (registered_HBAs != 0) {
  		printk("EATA (Extended Attachment) PIO driver version: %d.%d%s
  "
  		       "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de
  " "            Alfred Arnold,   a.arnold@kfa-juelich.de
  " "This release only supports DASD devices (harddisks)
  ", VER_MAJOR, VER_MINOR, VER_SUB);
  
  		printk("Registered HBAs:
  ");
  		printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:" " QS: SG: CPL:
  ");
  		for (i = 1; i <= registered_HBAs; i++) {
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
990
  			printk("scsi%-2d: %.10s v%s 2.0%c  %s %#.4lx   %2d   %d   %d   %c"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
991
992
993
994
995
  			       "  %2d  %2d  %2d
  ",
  			       HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
  			       SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P') ?
  			       "PCI " : (SD(HBA_ptr)->bustype == 'E') ? "EISA" : "ISA ",
1a68d41a3   Alan Cox   [SCSI] eata_pio c...
996
  			       HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, HBA_ptr->this_id,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
  			       SD(HBA_ptr)->primary ? 'Y' : 'N', HBA_ptr->can_queue,
  			       HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);
  			HBA_ptr = SD(HBA_ptr)->next;
  		}
  	}
  	return (registered_HBAs);
  }
  
  static struct scsi_host_template driver_template = {
  	.proc_name		= "eata_pio",
  	.name              	= "EATA (Extended Attachment) PIO driver",
  	.proc_info         	= eata_pio_proc_info,
  	.detect            	= eata_pio_detect,
  	.release           	= eata_pio_release,
  	.queuecommand      	= eata_pio_queue,
  	.eh_abort_handler  	= eata_pio_abort,
  	.eh_host_reset_handler	= eata_pio_host_reset,
  	.use_clustering    	= ENABLE_CLUSTERING,
  };
  
  MODULE_AUTHOR("Michael Neuffer, Alfred Arnold");
  MODULE_DESCRIPTION("EATA SCSI PIO driver");
  MODULE_LICENSE("GPL");
  
  #include "scsi_module.c"