aha1542: remove DEB macro and simplify debug code
[deliverable/linux.git] / drivers / scsi / aha1542.c
CommitLineData
1d084d20
OZ
1/*
2 * Driver for Adaptec AHA-1542 SCSI host adapters
1da177e4
LT
3 *
4 * Copyright (C) 1992 Tommy Thorn
5 * Copyright (C) 1993, 1994, 1995 Eric Youngdale
1d084d20 6 * Copyright (C) 2015 Ondrej Zary
1da177e4
LT
7 */
8
1da177e4
LT
9#include <linux/module.h>
10#include <linux/interrupt.h>
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/string.h>
1da177e4 14#include <linux/delay.h>
1da177e4
LT
15#include <linux/init.h>
16#include <linux/spinlock.h>
643a7c43
OZ
17#include <linux/isa.h>
18#include <linux/pnp.h>
5a0e3ad6 19#include <linux/slab.h>
954a9fd7 20#include <linux/io.h>
1da177e4 21#include <asm/dma.h>
954a9fd7
OZ
22#include <scsi/scsi_cmnd.h>
23#include <scsi/scsi_device.h>
1da177e4
LT
24#include <scsi/scsi_host.h>
25#include "aha1542.h"
1da177e4 26
f71429ab 27#define MAXBOARDS 4
1da177e4 28
f71429ab
OZ
29static bool isapnp = 1;
30module_param(isapnp, bool, 0);
31MODULE_PARM_DESC(isapnp, "enable PnP support (default=1)");
1da177e4 32
f71429ab
OZ
33static int io[MAXBOARDS] = { 0x330, 0x334, 0, 0 };
34module_param_array(io, int, NULL, 0);
35MODULE_PARM_DESC(io, "base IO address of controller (0x130,0x134,0x230,0x234,0x330,0x334, default=0x330,0x334)");
1da177e4 36
f71429ab
OZ
37/* time AHA spends on the AT-bus during data transfer */
38static int bus_on[MAXBOARDS] = { -1, -1, -1, -1 }; /* power-on default: 11us */
39module_param_array(bus_on, int, NULL, 0);
40MODULE_PARM_DESC(bus_on, "bus on time [us] (2-15, default=-1 [HW default: 11])");
1da177e4 41
f71429ab
OZ
42/* time AHA spends off the bus (not to monopolize it) during data transfer */
43static int bus_off[MAXBOARDS] = { -1, -1, -1, -1 }; /* power-on default: 4us */
44module_param_array(bus_off, int, NULL, 0);
45MODULE_PARM_DESC(bus_off, "bus off time [us] (1-64, default=-1 [HW default: 4])");
1da177e4 46
f71429ab
OZ
47/* default is jumper selected (J1 on 1542A), factory default = 5 MB/s */
48static int dma_speed[MAXBOARDS] = { -1, -1, -1, -1 };
49module_param_array(dma_speed, int, NULL, 0);
50MODULE_PARM_DESC(dma_speed, "DMA speed [MB/s] (5,6,7,8,10, default=-1 [by jumper])");
1da177e4 51
1da177e4
LT
52#define BIOS_TRANSLATION_6432 1 /* Default case these days */
53#define BIOS_TRANSLATION_25563 2 /* Big disk case */
54
55struct aha1542_hostdata {
56 /* This will effectively start both of them at the first mailbox */
57 int bios_translation; /* Mapping bios uses - for compatibility */
58 int aha1542_last_mbi_used;
59 int aha1542_last_mbo_used;
55b28f9f 60 struct scsi_cmnd *int_cmds[AHA1542_MAILBOXES];
1da177e4
LT
61 struct mailbox mb[2 * AHA1542_MAILBOXES];
62 struct ccb ccb[AHA1542_MAILBOXES];
63};
64
1da177e4
LT
65static DEFINE_SPINLOCK(aha1542_lock);
66
f1bbef63
OZ
67static inline void aha1542_intr_reset(u16 base)
68{
69 outb(IRST, CONTROL(base));
70}
1da177e4 71
2093bfa1
OZ
72static inline bool wait_mask(u16 port, u8 mask, u8 allof, u8 noneof, int timeout)
73{
74 bool delayed = true;
75
76 if (timeout == 0) {
77 timeout = 3000000;
78 delayed = false;
79 }
80
81 while (1) {
82 u8 bits = inb(port) & mask;
83 if ((bits & allof) == allof && ((bits & noneof) == 0))
84 break;
85 if (delayed)
86 mdelay(1);
87 if (--timeout == 0)
88 return false;
89 }
90
91 return true;
92}
1da177e4 93
1da177e4
LT
94/* This is a bit complicated, but we need to make sure that an interrupt
95 routine does not send something out while we are in the middle of this.
96 Fortunately, it is only at boot time that multi-byte messages
97 are ever sent. */
cad2fc72 98static int aha1542_outb(unsigned int base, u8 val)
1da177e4 99{
0c2b6481
OZ
100 unsigned long flags;
101
102 while (1) {
2906b3ce 103 if (!wait_mask(STATUS(base), CDF, 0, CDF, 0))
0c2b6481 104 return 1;
1da177e4 105 spin_lock_irqsave(&aha1542_lock, flags);
0c2b6481
OZ
106 if (inb(STATUS(base)) & CDF) {
107 spin_unlock_irqrestore(&aha1542_lock, flags);
108 continue;
1da177e4 109 }
cad2fc72 110 outb(val, DATA(base));
1da177e4 111 spin_unlock_irqrestore(&aha1542_lock, flags);
0c2b6481 112 return 0;
1da177e4 113 }
0c2b6481
OZ
114}
115
cad2fc72 116static int aha1542_out(unsigned int base, u8 *buf, int len)
0c2b6481
OZ
117{
118 unsigned long flags;
119
120 spin_lock_irqsave(&aha1542_lock, flags);
121 while (len--) {
122 if (!wait_mask(STATUS(base), CDF, 0, CDF, 0)) {
123 spin_unlock_irqrestore(&aha1542_lock, flags);
0c2b6481
OZ
124 return 1;
125 }
cad2fc72 126 outb(*buf++, DATA(base));
0c2b6481
OZ
127 }
128 spin_unlock_irqrestore(&aha1542_lock, flags);
23e6940a
OZ
129 if (!wait_mask(INTRFLAGS(base), INTRMASK, HACC, 0, 0))
130 return 1;
0c2b6481 131
1da177e4 132 return 0;
1da177e4
LT
133}
134
135/* Only used at boot time, so we do not need to worry about latency as much
136 here */
137
cad2fc72 138static int aha1542_in(unsigned int base, u8 *buf, int len, int timeout)
1da177e4
LT
139{
140 unsigned long flags;
141
142 spin_lock_irqsave(&aha1542_lock, flags);
143 while (len--) {
a13b3722
OZ
144 if (!wait_mask(STATUS(base), DF, DF, 0, timeout)) {
145 spin_unlock_irqrestore(&aha1542_lock, flags);
a13b3722
OZ
146 return 1;
147 }
cad2fc72 148 *buf++ = inb(DATA(base));
1da177e4
LT
149 }
150 spin_unlock_irqrestore(&aha1542_lock, flags);
151 return 0;
1da177e4
LT
152}
153
154static int makecode(unsigned hosterr, unsigned scsierr)
155{
156 switch (hosterr) {
157 case 0x0:
158 case 0xa: /* Linked command complete without error and linked normally */
159 case 0xb: /* Linked command complete without error, interrupt generated */
160 hosterr = 0;
161 break;
162
163 case 0x11: /* Selection time out-The initiator selection or target
164 reselection was not complete within the SCSI Time out period */
165 hosterr = DID_TIME_OUT;
166 break;
167
168 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
169 than was allocated by the Data Length field or the sum of the
170 Scatter / Gather Data Length fields. */
171
172 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
173
174 case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
175 invalid. This usually indicates a software failure. */
176
177 case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
178 This usually indicates a software failure. */
179
180 case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
181 of linked CCB's does not specify the same logical unit number as
182 the first. */
183 case 0x18: /* Invalid Target Direction received from Host-The direction of a
184 Target Mode CCB was invalid. */
185
186 case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
187 received to service data transfer between the same target LUN
188 and initiator SCSI ID in the same direction. */
189
190 case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
191 length segment or invalid segment list boundaries was received.
192 A CCB parameter was invalid. */
fde1fb8a
OZ
193#ifdef DEBUG
194 printk("Aha1542: %x %x\n", hosterr, scsierr);
195#endif
1da177e4
LT
196 hosterr = DID_ERROR; /* Couldn't find any better */
197 break;
198
199 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
200 phase sequence was requested by the target. The host adapter
201 will generate a SCSI Reset Condition, notifying the host with
202 a SCRD interrupt */
203 hosterr = DID_RESET;
204 break;
205 default:
206 printk(KERN_ERR "aha1542: makecode: unknown hoststatus %x\n", hosterr);
207 break;
208 }
209 return scsierr | (hosterr << 16);
210}
211
68ea9de3 212static int aha1542_test_port(struct Scsi_Host *sh)
1da177e4 213{
cb5b570c 214 u8 inquiry_result[4];
cad2fc72 215 int i;
1da177e4
LT
216
217 /* Quick and dirty test for presence of the card. */
68ea9de3 218 if (inb(STATUS(sh->io_port)) == 0xff)
1da177e4
LT
219 return 0;
220
221 /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
222
1da177e4 223 /* In case some other card was probing here, reset interrupts */
68ea9de3 224 aha1542_intr_reset(sh->io_port); /* reset interrupts, so they don't block */
1da177e4 225
68ea9de3 226 outb(SRST | IRST /*|SCRST */ , CONTROL(sh->io_port));
1da177e4
LT
227
228 mdelay(20); /* Wait a little bit for things to settle down. */
229
1da177e4 230 /* Expect INIT and IDLE, any of the others are bad */
68ea9de3 231 if (!wait_mask(STATUS(sh->io_port), STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF, 0))
a13b3722 232 return 0;
1da177e4 233
1da177e4 234 /* Shouldn't have generated any interrupts during reset */
68ea9de3 235 if (inb(INTRFLAGS(sh->io_port)) & INTRMASK)
a13b3722 236 return 0;
1da177e4 237
1da177e4
LT
238 /* Perform a host adapter inquiry instead so we do not need to set
239 up the mailboxes ahead of time */
240
68ea9de3 241 aha1542_outb(sh->io_port, CMD_INQUIRY);
1da177e4 242
cad2fc72 243 for (i = 0; i < 4; i++) {
68ea9de3 244 if (!wait_mask(STATUS(sh->io_port), DF, DF, 0, 0))
a13b3722 245 return 0;
68ea9de3 246 inquiry_result[i] = inb(DATA(sh->io_port));
1da177e4
LT
247 }
248
1da177e4 249 /* Reading port should reset DF */
68ea9de3 250 if (inb(STATUS(sh->io_port)) & DF)
a13b3722 251 return 0;
1da177e4 252
1da177e4 253 /* When HACC, command is completed, and we're though testing */
68ea9de3 254 if (!wait_mask(INTRFLAGS(sh->io_port), HACC, HACC, 0, 0))
a13b3722 255 return 0;
1da177e4 256
1da177e4 257 /* Clear interrupts */
68ea9de3 258 outb(IRST, CONTROL(sh->io_port));
1da177e4 259
bdebe224 260 return 1;
1da177e4
LT
261}
262
1da177e4 263/* A "high" level interrupt handler */
c2532f68 264static void aha1542_intr_handle(struct Scsi_Host *sh)
1da177e4 265{
c2532f68 266 struct aha1542_hostdata *aha1542 = shost_priv(sh);
55b28f9f 267 void (*my_done)(struct scsi_cmnd *) = NULL;
1da177e4
LT
268 int errstatus, mbi, mbo, mbistatus;
269 int number_serviced;
270 unsigned long flags;
55b28f9f 271 struct scsi_cmnd *tmp_cmd;
1da177e4 272 int flag;
e98878f7
OZ
273 struct mailbox *mb = aha1542->mb;
274 struct ccb *ccb = aha1542->ccb;
1da177e4
LT
275
276#ifdef DEBUG
277 {
c2532f68 278 flag = inb(INTRFLAGS(sh->io_port));
2906b3ce 279 shost_printk(KERN_DEBUG, sh, "aha1542_intr_handle: ");
1da177e4
LT
280 if (!(flag & ANYINTR))
281 printk("no interrupt?");
282 if (flag & MBIF)
283 printk("MBIF ");
284 if (flag & MBOA)
285 printk("MBOF ");
286 if (flag & HACC)
287 printk("HACC ");
288 if (flag & SCRD)
289 printk("SCRD ");
c2532f68 290 printk("status %02x\n", inb(STATUS(sh->io_port)));
1da177e4
LT
291 };
292#endif
293 number_serviced = 0;
1da177e4
LT
294
295 while (1 == 1) {
c2532f68 296 flag = inb(INTRFLAGS(sh->io_port));
1da177e4
LT
297
298 /* Check for unusual interrupts. If any of these happen, we should
299 probably do something special, but for now just printing a message
300 is sufficient. A SCSI reset detected is something that we really
301 need to deal with in some way. */
302 if (flag & ~MBIF) {
303 if (flag & MBOA)
304 printk("MBOF ");
305 if (flag & HACC)
306 printk("HACC ");
dfd7c991 307 if (flag & SCRD)
1da177e4 308 printk("SCRD ");
1da177e4 309 }
c2532f68 310 aha1542_intr_reset(sh->io_port);
1da177e4
LT
311
312 spin_lock_irqsave(&aha1542_lock, flags);
e98878f7 313 mbi = aha1542->aha1542_last_mbi_used + 1;
1da177e4
LT
314 if (mbi >= 2 * AHA1542_MAILBOXES)
315 mbi = AHA1542_MAILBOXES;
316
317 do {
318 if (mb[mbi].status != 0)
319 break;
320 mbi++;
321 if (mbi >= 2 * AHA1542_MAILBOXES)
322 mbi = AHA1542_MAILBOXES;
e98878f7 323 } while (mbi != aha1542->aha1542_last_mbi_used);
1da177e4
LT
324
325 if (mb[mbi].status == 0) {
326 spin_unlock_irqrestore(&aha1542_lock, flags);
327 /* Hmm, no mail. Must have read it the last time around */
dfd7c991 328 if (!number_serviced)
2906b3ce 329 shost_printk(KERN_WARNING, sh, "interrupt received, but no mail.\n");
1da177e4
LT
330 return;
331 };
332
10be6250 333 mbo = (scsi2int(mb[mbi].ccbptr) - (isa_virt_to_bus(&ccb[0]))) / sizeof(struct ccb);
1da177e4
LT
334 mbistatus = mb[mbi].status;
335 mb[mbi].status = 0;
e98878f7 336 aha1542->aha1542_last_mbi_used = mbi;
1da177e4
LT
337 spin_unlock_irqrestore(&aha1542_lock, flags);
338
339#ifdef DEBUG
fde1fb8a
OZ
340 if (ccb[mbo].tarstat | ccb[mbo].hastat)
341 shost_printk(KERN_DEBUG, sh, "aha1542_command: returning %x (status %d)\n",
342 ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
1da177e4
LT
343#endif
344
345 if (mbistatus == 3)
346 continue; /* Aborted command not found */
347
348#ifdef DEBUG
2906b3ce 349 shost_printk(KERN_DEBUG, sh, "...done %d %d\n", mbo, mbi);
1da177e4
LT
350#endif
351
55b28f9f 352 tmp_cmd = aha1542->int_cmds[mbo];
1da177e4 353
55b28f9f 354 if (!tmp_cmd || !tmp_cmd->scsi_done) {
2906b3ce
OZ
355 shost_printk(KERN_WARNING, sh, "Unexpected interrupt\n");
356 shost_printk(KERN_WARNING, sh, "tarstat=%x, hastat=%x idlun=%x ccb#=%d\n", ccb[mbo].tarstat,
1da177e4
LT
357 ccb[mbo].hastat, ccb[mbo].idlun, mbo);
358 return;
359 }
55b28f9f
OZ
360 my_done = tmp_cmd->scsi_done;
361 kfree(tmp_cmd->host_scribble);
362 tmp_cmd->host_scribble = NULL;
1da177e4
LT
363 /* Fetch the sense data, and tuck it away, in the required slot. The
364 Adaptec automatically fetches it, and there is no guarantee that
365 we will still have it in the cdb when we come back */
366 if (ccb[mbo].tarstat == 2)
55b28f9f 367 memcpy(tmp_cmd->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen],
b80ca4f7 368 SCSI_SENSE_BUFFERSIZE);
1da177e4
LT
369
370
371 /* is there mail :-) */
372
373 /* more error checking left out here */
374 if (mbistatus != 1)
375 /* This is surely wrong, but I don't know what's right */
376 errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
377 else
378 errstatus = 0;
379
380#ifdef DEBUG
381 if (errstatus)
2906b3ce 382 shost_printk(KERN_DEBUG, sh, "(aha1542 error:%x %x %x) ", errstatus,
1da177e4 383 ccb[mbo].hastat, ccb[mbo].tarstat);
1da177e4 384 if (ccb[mbo].tarstat == 2) {
1da177e4 385 int i;
fde1fb8a
OZ
386
387 printk("aha1542_intr_handle: sense:");
1da177e4
LT
388 for (i = 0; i < 12; i++)
389 printk("%02x ", ccb[mbo].cdb[ccb[mbo].cdblen + i]);
390 printk("\n");
1da177e4 391 }
fde1fb8a
OZ
392 if (errstatus)
393 printk("aha1542_intr_handle: returning %6x\n", errstatus);
394#endif
55b28f9f
OZ
395 tmp_cmd->result = errstatus;
396 aha1542->int_cmds[mbo] = NULL; /* This effectively frees up the mailbox slot, as
e98878f7 397 far as queuecommand is concerned */
55b28f9f 398 my_done(tmp_cmd);
1da177e4
LT
399 number_serviced++;
400 };
401}
402
09a44833
OZ
403/* A quick wrapper for do_aha1542_intr_handle to grab the spin lock */
404static irqreturn_t do_aha1542_intr_handle(int dummy, void *dev_id)
405{
406 unsigned long flags;
c2532f68 407 struct Scsi_Host *sh = dev_id;
09a44833 408
c2532f68
OZ
409 spin_lock_irqsave(sh->host_lock, flags);
410 aha1542_intr_handle(sh);
411 spin_unlock_irqrestore(sh->host_lock, flags);
09a44833
OZ
412 return IRQ_HANDLED;
413}
414
55b28f9f 415static int aha1542_queuecommand_lck(struct scsi_cmnd *cmd, void (*done) (struct scsi_cmnd *))
1da177e4 416{
2906b3ce
OZ
417 struct Scsi_Host *sh = cmd->device->host;
418 struct aha1542_hostdata *aha1542 = shost_priv(sh);
cb5b570c 419 u8 direction;
55b28f9f
OZ
420 u8 target = cmd->device->id;
421 u8 lun = cmd->device->lun;
1da177e4 422 unsigned long flags;
55b28f9f 423 int bufflen = scsi_bufflen(cmd);
1da177e4 424 int mbo;
e98878f7
OZ
425 struct mailbox *mb = aha1542->mb;
426 struct ccb *ccb = aha1542->ccb;
fde1fb8a
OZ
427#ifdef DEBUG
428 int i;
1da177e4 429
fde1fb8a
OZ
430 if (target > 1) {
431 cmd->result = DID_TIME_OUT << 16;
432 done(cmd);
433 return 0;
434 }
435#endif
55b28f9f 436 if (*cmd->cmnd == REQUEST_SENSE) {
1da177e4 437 /* Don't do the command - we have the sense data already */
55b28f9f
OZ
438 cmd->result = 0;
439 done(cmd);
1da177e4
LT
440 return 0;
441 }
442#ifdef DEBUG
55b28f9f
OZ
443 if (*cmd->cmnd == READ_10 || *cmd->cmnd == WRITE_10)
444 i = xscsi2int(cmd->cmnd + 2);
445 else if (*cmd->cmnd == READ_6 || *cmd->cmnd == WRITE_6)
446 i = scsi2int(cmd->cmnd + 2);
1da177e4
LT
447 else
448 i = -1;
449 if (done)
2906b3ce 450 shost_printk(KERN_DEBUG, sh, "aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target, *cmd->cmnd, i, bufflen);
1da177e4 451 else
2906b3ce
OZ
452 shost_printk(KERN_DEBUG, sh, "aha1542_command: dev %d cmd %02x pos %d len %d ", target, *cmd->cmnd, i, bufflen);
453 shost_printk(KERN_DEBUG, sh, "aha1542_queuecommand: dumping scsi cmd:");
55b28f9f
OZ
454 for (i = 0; i < cmd->cmd_len; i++)
455 printk("%02x ", cmd->cmnd[i]);
1da177e4 456 printk("\n");
55b28f9f 457 if (*cmd->cmnd == WRITE_10 || *cmd->cmnd == WRITE_6)
1da177e4
LT
458 return 0; /* we are still testing, so *don't* write */
459#endif
460 /* Use the outgoing mailboxes in a round-robin fashion, because this
461 is how the host adapter will scan for them */
462
463 spin_lock_irqsave(&aha1542_lock, flags);
e98878f7 464 mbo = aha1542->aha1542_last_mbo_used + 1;
1da177e4
LT
465 if (mbo >= AHA1542_MAILBOXES)
466 mbo = 0;
467
468 do {
55b28f9f 469 if (mb[mbo].status == 0 && aha1542->int_cmds[mbo] == NULL)
1da177e4
LT
470 break;
471 mbo++;
472 if (mbo >= AHA1542_MAILBOXES)
473 mbo = 0;
e98878f7 474 } while (mbo != aha1542->aha1542_last_mbo_used);
1da177e4 475
55b28f9f 476 if (mb[mbo].status || aha1542->int_cmds[mbo])
1da177e4
LT
477 panic("Unable to find empty mailbox for aha1542.\n");
478
55b28f9f 479 aha1542->int_cmds[mbo] = cmd; /* This will effectively prevent someone else from
e98878f7 480 screwing with this cdb. */
1da177e4 481
e98878f7 482 aha1542->aha1542_last_mbo_used = mbo;
1da177e4
LT
483 spin_unlock_irqrestore(&aha1542_lock, flags);
484
485#ifdef DEBUG
2906b3ce 486 shost_printk(KERN_DEBUG, sh, "Sending command (%d %x)...", mbo, done);
1da177e4
LT
487#endif
488
10be6250 489 any2scsi(mb[mbo].ccbptr, isa_virt_to_bus(&ccb[mbo])); /* This gets trashed for some reason */
1da177e4
LT
490
491 memset(&ccb[mbo], 0, sizeof(struct ccb));
492
55b28f9f 493 ccb[mbo].cdblen = cmd->cmd_len;
1da177e4
LT
494
495 direction = 0;
55b28f9f 496 if (*cmd->cmnd == READ_10 || *cmd->cmnd == READ_6)
1da177e4 497 direction = 8;
55b28f9f 498 else if (*cmd->cmnd == WRITE_10 || *cmd->cmnd == WRITE_6)
1da177e4
LT
499 direction = 16;
500
55b28f9f 501 memcpy(ccb[mbo].cdb, cmd->cmnd, ccb[mbo].cdblen);
1da177e4 502
fc3fdfcc 503 if (bufflen) {
51cf2249 504 struct scatterlist *sg;
1da177e4
LT
505 struct chain *cptr;
506#ifdef DEBUG
507 unsigned char *ptr;
508#endif
55b28f9f 509 int i, sg_count = scsi_sg_count(cmd);
1da177e4 510 ccb[mbo].op = 2; /* SCSI Initiator Command w/scatter-gather */
55b28f9f 511 cmd->host_scribble = kmalloc(sizeof(*cptr)*sg_count,
fc3fdfcc 512 GFP_KERNEL | GFP_DMA);
55b28f9f 513 cptr = (struct chain *) cmd->host_scribble;
1da177e4
LT
514 if (cptr == NULL) {
515 /* free the claimed mailbox slot */
55b28f9f 516 aha1542->int_cmds[mbo] = NULL;
1da177e4
LT
517 return SCSI_MLQUEUE_HOST_BUSY;
518 }
55b28f9f 519 scsi_for_each_sg(cmd, sg, sg_count, i) {
10be6250
OZ
520 any2scsi(cptr[i].dataptr, isa_page_to_bus(sg_page(sg))
521 + sg->offset);
51cf2249 522 any2scsi(cptr[i].datalen, sg->length);
1da177e4 523 };
fc3fdfcc 524 any2scsi(ccb[mbo].datalen, sg_count * sizeof(struct chain));
10be6250 525 any2scsi(ccb[mbo].dataptr, isa_virt_to_bus(cptr));
1da177e4
LT
526#ifdef DEBUG
527 printk("cptr %x: ", cptr);
528 ptr = (unsigned char *) cptr;
529 for (i = 0; i < 18; i++)
530 printk("%02x ", ptr[i]);
531#endif
532 } else {
533 ccb[mbo].op = 0; /* SCSI Initiator Command */
55b28f9f 534 cmd->host_scribble = NULL;
fc3fdfcc
BH
535 any2scsi(ccb[mbo].datalen, 0);
536 any2scsi(ccb[mbo].dataptr, 0);
1da177e4
LT
537 };
538 ccb[mbo].idlun = (target & 7) << 5 | direction | (lun & 7); /*SCSI Target Id */
539 ccb[mbo].rsalen = 16;
540 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
541 ccb[mbo].commlinkid = 0;
542
543#ifdef DEBUG
544 {
545 int i;
2906b3ce 546 shost_printk(KERN_DEBUG, sh, "aha1542_command: sending.. ");
1da177e4 547 for (i = 0; i < sizeof(ccb[mbo]) - 10; i++)
cb5b570c 548 printk("%02x ", ((u8 *) &ccb[mbo])[i]);
1da177e4
LT
549 };
550#endif
551
552 if (done) {
fde1fb8a
OZ
553#ifdef DEBUG
554 printk("aha1542_queuecommand: now waiting for interrupt ");
555#endif
55b28f9f 556 cmd->scsi_done = done;
1da177e4 557 mb[mbo].status = 1;
55b28f9f 558 aha1542_outb(cmd->device->host->io_port, CMD_START_SCSI);
1da177e4
LT
559 } else
560 printk("aha1542_queuecommand: done can't be NULL\n");
561
562 return 0;
563}
564
f281233d
JG
565static DEF_SCSI_QCMD(aha1542_queuecommand)
566
1da177e4 567/* Initialize mailboxes */
68ea9de3 568static void setup_mailboxes(struct Scsi_Host *sh)
1da177e4 569{
c2532f68 570 struct aha1542_hostdata *aha1542 = shost_priv(sh);
1da177e4 571 int i;
e98878f7
OZ
572 struct mailbox *mb = aha1542->mb;
573 struct ccb *ccb = aha1542->ccb;
1da177e4 574
cad2fc72 575 u8 mb_cmd[5] = { CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
1da177e4 576
1da177e4
LT
577 for (i = 0; i < AHA1542_MAILBOXES; i++) {
578 mb[i].status = mb[AHA1542_MAILBOXES + i].status = 0;
10be6250 579 any2scsi(mb[i].ccbptr, isa_virt_to_bus(&ccb[i]));
1da177e4 580 };
68ea9de3 581 aha1542_intr_reset(sh->io_port); /* reset interrupts, so they don't block */
cad2fc72 582 any2scsi((mb_cmd + 2), isa_virt_to_bus(mb));
68ea9de3 583 if (aha1542_out(sh->io_port, mb_cmd, 5))
2906b3ce 584 shost_printk(KERN_ERR, sh, "failed setting up mailboxes\n");
68ea9de3 585 aha1542_intr_reset(sh->io_port);
1da177e4
LT
586}
587
68ea9de3 588static int aha1542_getconfig(struct Scsi_Host *sh)
1da177e4 589{
cb5b570c 590 u8 inquiry_result[3];
1da177e4 591 int i;
68ea9de3 592 i = inb(STATUS(sh->io_port));
1da177e4 593 if (i & DF) {
68ea9de3 594 i = inb(DATA(sh->io_port));
1da177e4 595 };
68ea9de3
OZ
596 aha1542_outb(sh->io_port, CMD_RETCONF);
597 aha1542_in(sh->io_port, inquiry_result, 3, 0);
598 if (!wait_mask(INTRFLAGS(sh->io_port), INTRMASK, HACC, 0, 0))
2906b3ce 599 shost_printk(KERN_ERR, sh, "error querying board settings\n");
68ea9de3 600 aha1542_intr_reset(sh->io_port);
1da177e4
LT
601 switch (inquiry_result[0]) {
602 case 0x80:
68ea9de3 603 sh->dma_channel = 7;
1da177e4
LT
604 break;
605 case 0x40:
68ea9de3 606 sh->dma_channel = 6;
1da177e4
LT
607 break;
608 case 0x20:
68ea9de3 609 sh->dma_channel = 5;
1da177e4
LT
610 break;
611 case 0x01:
68ea9de3 612 sh->dma_channel = 0;
1da177e4
LT
613 break;
614 case 0:
615 /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
616 Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
68ea9de3 617 sh->dma_channel = 0xFF;
1da177e4
LT
618 break;
619 default:
2906b3ce 620 shost_printk(KERN_ERR, sh, "Unable to determine DMA channel.\n");
1da177e4
LT
621 return -1;
622 };
623 switch (inquiry_result[1]) {
624 case 0x40:
68ea9de3 625 sh->irq = 15;
1da177e4
LT
626 break;
627 case 0x20:
68ea9de3 628 sh->irq = 14;
1da177e4
LT
629 break;
630 case 0x8:
68ea9de3 631 sh->irq = 12;
1da177e4
LT
632 break;
633 case 0x4:
68ea9de3 634 sh->irq = 11;
1da177e4
LT
635 break;
636 case 0x2:
68ea9de3 637 sh->irq = 10;
1da177e4
LT
638 break;
639 case 0x1:
68ea9de3 640 sh->irq = 9;
1da177e4
LT
641 break;
642 default:
2906b3ce 643 shost_printk(KERN_ERR, sh, "Unable to determine IRQ level.\n");
1da177e4
LT
644 return -1;
645 };
68ea9de3 646 sh->this_id = inquiry_result[2] & 7;
1da177e4
LT
647 return 0;
648}
649
650/* This function should only be called for 1542C boards - we can detect
651 the special firmware settings and unlock the board */
652
68ea9de3 653static int aha1542_mbenable(struct Scsi_Host *sh)
1da177e4 654{
cb5b570c
OZ
655 static u8 mbenable_cmd[3];
656 static u8 mbenable_result[2];
1da177e4
LT
657 int retval;
658
659 retval = BIOS_TRANSLATION_6432;
660
68ea9de3
OZ
661 aha1542_outb(sh->io_port, CMD_EXTBIOS);
662 if (aha1542_in(sh->io_port, mbenable_result, 2, 100))
1da177e4 663 return retval;
68ea9de3 664 if (!wait_mask(INTRFLAGS(sh->io_port), INTRMASK, HACC, 0, 100))
2093bfa1 665 goto fail;
68ea9de3 666 aha1542_intr_reset(sh->io_port);
1da177e4
LT
667
668 if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
669 mbenable_cmd[0] = CMD_MBENABLE;
670 mbenable_cmd[1] = 0;
671 mbenable_cmd[2] = mbenable_result[1];
672
673 if ((mbenable_result[0] & 0x08) && (mbenable_result[1] & 0x03))
674 retval = BIOS_TRANSLATION_25563;
675
68ea9de3 676 if (aha1542_out(sh->io_port, mbenable_cmd, 3))
2093bfa1 677 goto fail;
1da177e4
LT
678 };
679 while (0) {
680fail:
2906b3ce 681 shost_printk(KERN_ERR, sh, "Mailbox init failed\n");
1da177e4 682 }
68ea9de3 683 aha1542_intr_reset(sh->io_port);
1da177e4
LT
684 return retval;
685}
686
687/* Query the board to find out if it is a 1542 or a 1740, or whatever. */
68ea9de3 688static int aha1542_query(struct Scsi_Host *sh)
1da177e4 689{
68ea9de3 690 struct aha1542_hostdata *aha1542 = shost_priv(sh);
cb5b570c 691 u8 inquiry_result[4];
1da177e4 692 int i;
68ea9de3 693 i = inb(STATUS(sh->io_port));
1da177e4 694 if (i & DF) {
68ea9de3 695 i = inb(DATA(sh->io_port));
1da177e4 696 };
68ea9de3
OZ
697 aha1542_outb(sh->io_port, CMD_INQUIRY);
698 aha1542_in(sh->io_port, inquiry_result, 4, 0);
699 if (!wait_mask(INTRFLAGS(sh->io_port), INTRMASK, HACC, 0, 0))
2906b3ce 700 shost_printk(KERN_ERR, sh, "error querying card type\n");
68ea9de3 701 aha1542_intr_reset(sh->io_port);
1da177e4 702
68ea9de3 703 aha1542->bios_translation = BIOS_TRANSLATION_6432; /* Default case */
1da177e4
LT
704
705 /* For an AHA1740 series board, we ignore the board since there is a
706 hardware bug which can lead to wrong blocks being returned if the board
707 is operating in the 1542 emulation mode. Since there is an extended mode
708 driver, we simply ignore the board and let the 1740 driver pick it up.
709 */
710
711 if (inquiry_result[0] == 0x43) {
2906b3ce 712 shost_printk(KERN_INFO, sh, "Emulation mode not supported for AHA-1740 hardware, use aha1740 driver instead.\n");
1da177e4
LT
713 return 1;
714 };
715
716 /* Always call this - boards that do not support extended bios translation
717 will ignore the command, and we will set the proper default */
718
68ea9de3 719 aha1542->bios_translation = aha1542_mbenable(sh);
1da177e4
LT
720
721 return 0;
722}
723
f71429ab 724static u8 dma_speed_hw(int dma_speed)
1da177e4 725{
f71429ab
OZ
726 switch (dma_speed) {
727 case 5:
728 return 0x00;
729 case 6:
730 return 0x04;
731 case 7:
732 return 0x01;
733 case 8:
734 return 0x02;
735 case 10:
736 return 0x03;
1da177e4 737 }
1da177e4 738
f71429ab 739 return 0xff; /* invalid */
1da177e4
LT
740}
741
f71429ab 742/* Set the Bus on/off-times as not to ruin floppy performance */
37d607bd 743static void aha1542_set_bus_times(struct Scsi_Host *sh, int bus_on, int bus_off, int dma_speed)
1da177e4 744{
37d607bd
OZ
745 if (bus_on > 0) {
746 u8 oncmd[] = { CMD_BUSON_TIME, clamp(bus_on, 2, 15) };
1da177e4 747
37d607bd
OZ
748 aha1542_intr_reset(sh->io_port);
749 if (aha1542_out(sh->io_port, oncmd, 2))
f71429ab
OZ
750 goto fail;
751 }
1da177e4 752
37d607bd
OZ
753 if (bus_off > 0) {
754 u8 offcmd[] = { CMD_BUSOFF_TIME, clamp(bus_off, 1, 64) };
1da177e4 755
37d607bd
OZ
756 aha1542_intr_reset(sh->io_port);
757 if (aha1542_out(sh->io_port, offcmd, 2))
f71429ab
OZ
758 goto fail;
759 }
1da177e4 760
37d607bd
OZ
761 if (dma_speed_hw(dma_speed) != 0xff) {
762 u8 dmacmd[] = { CMD_DMASPEED, dma_speed_hw(dma_speed) };
b847fd0d 763
37d607bd
OZ
764 aha1542_intr_reset(sh->io_port);
765 if (aha1542_out(sh->io_port, dmacmd, 2))
b847fd0d
OZ
766 goto fail;
767 }
37d607bd 768 aha1542_intr_reset(sh->io_port);
b847fd0d
OZ
769 return;
770fail:
2906b3ce 771 shost_printk(KERN_ERR, sh, "setting bus on/off-time failed\n");
37d607bd 772 aha1542_intr_reset(sh->io_port);
b847fd0d
OZ
773}
774
1da177e4 775/* return non-zero on detection */
643a7c43 776static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct device *pdev, int indx)
1da177e4 777{
f71429ab 778 unsigned int base_io = io[indx];
c2532f68 779 struct Scsi_Host *sh;
e98878f7 780 struct aha1542_hostdata *aha1542;
2906b3ce 781 char dma_info[] = "no DMA";
1da177e4 782
3a70c006
OZ
783 if (base_io == 0)
784 return NULL;
1da177e4 785
3a70c006
OZ
786 if (!request_region(base_io, AHA1542_REGION_SIZE, "aha1542"))
787 return NULL;
1da177e4 788
c2532f68
OZ
789 sh = scsi_host_alloc(tpnt, sizeof(struct aha1542_hostdata));
790 if (!sh)
3a70c006 791 goto release;
c2532f68 792 aha1542 = shost_priv(sh);
b847fd0d 793
68ea9de3
OZ
794 sh->unique_id = base_io;
795 sh->io_port = base_io;
796 sh->n_io_port = AHA1542_REGION_SIZE;
797 aha1542->aha1542_last_mbi_used = 2 * AHA1542_MAILBOXES - 1;
798 aha1542->aha1542_last_mbo_used = AHA1542_MAILBOXES - 1;
799
800 if (!aha1542_test_port(sh))
3a70c006 801 goto unregister;
1da177e4 802
37d607bd 803 aha1542_set_bus_times(sh, bus_on[indx], bus_off[indx], dma_speed[indx]);
68ea9de3 804 if (aha1542_query(sh))
3a70c006 805 goto unregister;
68ea9de3 806 if (aha1542_getconfig(sh) == -1)
3a70c006 807 goto unregister;
1da177e4 808
c2532f68 809 if (sh->dma_channel != 0xFF)
2906b3ce
OZ
810 snprintf(dma_info, sizeof(dma_info), "DMA %d", sh->dma_channel);
811 shost_printk(KERN_INFO, sh, "Adaptec AHA-1542 (SCSI-ID %d) at IO 0x%x, IRQ %d, %s\n",
812 sh->this_id, base_io, sh->irq, dma_info);
3a70c006 813 if (aha1542->bios_translation == BIOS_TRANSLATION_25563)
2906b3ce 814 shost_printk(KERN_INFO, sh, "Using extended bios translation\n");
1da177e4 815
68ea9de3 816 setup_mailboxes(sh);
1da177e4 817
c2532f68
OZ
818 if (request_irq(sh->irq, do_aha1542_intr_handle, 0,
819 "aha1542", sh)) {
2906b3ce 820 shost_printk(KERN_ERR, sh, "Unable to allocate IRQ.\n");
3a70c006
OZ
821 goto unregister;
822 }
c2532f68
OZ
823 if (sh->dma_channel != 0xFF) {
824 if (request_dma(sh->dma_channel, "aha1542")) {
2906b3ce 825 shost_printk(KERN_ERR, sh, "Unable to allocate DMA channel.\n");
3a70c006
OZ
826 goto free_irq;
827 }
c2532f68
OZ
828 if (sh->dma_channel == 0 || sh->dma_channel >= 5) {
829 set_dma_mode(sh->dma_channel, DMA_MODE_CASCADE);
830 enable_dma(sh->dma_channel);
3a70c006
OZ
831 }
832 }
1da177e4 833
c2532f68 834 if (scsi_add_host(sh, pdev))
3a70c006 835 goto free_dma;
1da177e4 836
c2532f68 837 scsi_scan_host(sh);
1da177e4 838
c2532f68 839 return sh;
3a70c006 840free_dma:
c2532f68
OZ
841 if (sh->dma_channel != 0xff)
842 free_dma(sh->dma_channel);
3a70c006 843free_irq:
c2532f68 844 free_irq(sh->irq, sh);
3a70c006 845unregister:
c2532f68 846 scsi_host_put(sh);
3a70c006
OZ
847release:
848 release_region(base_io, AHA1542_REGION_SIZE);
1da177e4 849
643a7c43 850 return NULL;
1da177e4
LT
851}
852
c2532f68 853static int aha1542_release(struct Scsi_Host *sh)
1da177e4 854{
c2532f68
OZ
855 scsi_remove_host(sh);
856 if (sh->dma_channel != 0xff)
857 free_dma(sh->dma_channel);
858 if (sh->irq)
859 free_irq(sh->irq, sh);
860 if (sh->io_port && sh->n_io_port)
861 release_region(sh->io_port, sh->n_io_port);
862 scsi_host_put(sh);
1da177e4
LT
863 return 0;
864}
865
1da177e4 866
1da177e4
LT
867/*
868 * This is a device reset. This is handled by sending a special command
869 * to the device.
870 */
55b28f9f 871static int aha1542_dev_reset(struct scsi_cmnd *cmd)
1da177e4 872{
55b28f9f 873 struct aha1542_hostdata *aha1542 = shost_priv(cmd->device->host);
1da177e4 874 unsigned long flags;
e98878f7 875 struct mailbox *mb = aha1542->mb;
55b28f9f
OZ
876 u8 target = cmd->device->id;
877 u8 lun = cmd->device->lun;
1da177e4 878 int mbo;
e98878f7 879 struct ccb *ccb = aha1542->ccb;
1da177e4 880
1da177e4 881 spin_lock_irqsave(&aha1542_lock, flags);
e98878f7 882 mbo = aha1542->aha1542_last_mbo_used + 1;
1da177e4
LT
883 if (mbo >= AHA1542_MAILBOXES)
884 mbo = 0;
885
886 do {
55b28f9f 887 if (mb[mbo].status == 0 && aha1542->int_cmds[mbo] == NULL)
1da177e4
LT
888 break;
889 mbo++;
890 if (mbo >= AHA1542_MAILBOXES)
891 mbo = 0;
e98878f7 892 } while (mbo != aha1542->aha1542_last_mbo_used);
1da177e4 893
55b28f9f 894 if (mb[mbo].status || aha1542->int_cmds[mbo])
1da177e4
LT
895 panic("Unable to find empty mailbox for aha1542.\n");
896
55b28f9f 897 aha1542->int_cmds[mbo] = cmd; /* This will effectively
e98878f7
OZ
898 prevent someone else from
899 screwing with this cdb. */
1da177e4 900
e98878f7 901 aha1542->aha1542_last_mbo_used = mbo;
1da177e4
LT
902 spin_unlock_irqrestore(&aha1542_lock, flags);
903
10be6250 904 any2scsi(mb[mbo].ccbptr, isa_virt_to_bus(&ccb[mbo])); /* This gets trashed for some reason */
1da177e4
LT
905
906 memset(&ccb[mbo], 0, sizeof(struct ccb));
907
908 ccb[mbo].op = 0x81; /* BUS DEVICE RESET */
909
910 ccb[mbo].idlun = (target & 7) << 5 | (lun & 7); /*SCSI Target Id */
911
912 ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
913 ccb[mbo].commlinkid = 0;
914
915 /*
916 * Now tell the 1542 to flush all pending commands for this
917 * target
918 */
55b28f9f 919 aha1542_outb(cmd->device->host->io_port, CMD_START_SCSI);
1da177e4 920
55b28f9f 921 scmd_printk(KERN_WARNING, cmd,
017560fc 922 "Trying device reset for target\n");
1da177e4
LT
923
924 return SUCCESS;
1da177e4
LT
925}
926
55b28f9f 927static int aha1542_reset(struct scsi_cmnd *cmd, u8 reset_cmd)
1da177e4 928{
55b28f9f 929 struct aha1542_hostdata *aha1542 = shost_priv(cmd->device->host);
1da177e4
LT
930 int i;
931
932 /*
933 * This does a scsi reset for all devices on the bus.
934 * In principle, we could also reset the 1542 - should
935 * we do this? Try this first, and we can add that later
936 * if it turns out to be useful.
937 */
55b28f9f 938 outb(reset_cmd, CONTROL(cmd->device->host->io_port));
1da177e4
LT
939
940 /*
941 * Wait for the thing to settle down a bit. Unfortunately
942 * this is going to basically lock up the machine while we
943 * wait for this to complete. To be 100% correct, we need to
944 * check for timeout, and if we are doing something like this
945 * we are pretty desperate anyways.
946 */
1da177e4 947 ssleep(4);
55b28f9f 948 spin_lock_irq(cmd->device->host->host_lock);
1da177e4 949
55b28f9f 950 if (!wait_mask(STATUS(cmd->device->host->io_port),
a13b3722 951 STATMASK, INIT | IDLE, STST | DIAGF | INVDCMD | DF | CDF, 0)) {
55b28f9f 952 spin_unlock_irq(cmd->device->host->host_lock);
a13b3722
OZ
953 return FAILED;
954 }
8537cba8
OZ
955 /*
956 * We need to do this too before the 1542 can interact with
957 * us again after host reset.
958 */
959 if (reset_cmd & HRST)
68ea9de3 960 setup_mailboxes(cmd->device->host);
1da177e4
LT
961 /*
962 * Now try to pick up the pieces. For all pending commands,
963 * free any internal data structures, and basically clear things
964 * out. We do not try and restart any commands or anything -
965 * the strategy handler takes care of that crap.
966 */
2906b3ce 967 shost_printk(KERN_WARNING, cmd->device->host, "Sent BUS RESET to scsi host %d\n", cmd->device->host->host_no);
1da177e4
LT
968
969 for (i = 0; i < AHA1542_MAILBOXES; i++) {
55b28f9f
OZ
970 if (aha1542->int_cmds[i] != NULL) {
971 struct scsi_cmnd *tmp_cmd;
972 tmp_cmd = aha1542->int_cmds[i];
1da177e4 973
55b28f9f 974 if (tmp_cmd->device->soft_reset) {
1da177e4
LT
975 /*
976 * If this device implements the soft reset option,
977 * then it is still holding onto the command, and
978 * may yet complete it. In this case, we don't
979 * flush the data.
980 */
981 continue;
982 }
55b28f9f
OZ
983 kfree(tmp_cmd->host_scribble);
984 tmp_cmd->host_scribble = NULL;
985 aha1542->int_cmds[i] = NULL;
e98878f7 986 aha1542->mb[i].status = 0;
1da177e4
LT
987 }
988 }
989
55b28f9f 990 spin_unlock_irq(cmd->device->host->host_lock);
1da177e4 991 return SUCCESS;
1da177e4
LT
992}
993
55b28f9f 994static int aha1542_bus_reset(struct scsi_cmnd *cmd)
1da177e4 995{
55b28f9f 996 return aha1542_reset(cmd, SCRST);
8537cba8 997}
1da177e4 998
55b28f9f 999static int aha1542_host_reset(struct scsi_cmnd *cmd)
8537cba8 1000{
55b28f9f 1001 return aha1542_reset(cmd, HRST | SCRST);
1da177e4
LT
1002}
1003
1da177e4 1004static int aha1542_biosparam(struct scsi_device *sdev,
17787a09 1005 struct block_device *bdev, sector_t capacity, int geom[])
1da177e4 1006{
e98878f7 1007 struct aha1542_hostdata *aha1542 = shost_priv(sdev->host);
1da177e4 1008
17787a09
OZ
1009 if (capacity >= 0x200000 &&
1010 aha1542->bios_translation == BIOS_TRANSLATION_25563) {
1da177e4 1011 /* Please verify that this is the same as what DOS returns */
17787a09
OZ
1012 geom[0] = 255; /* heads */
1013 geom[1] = 63; /* sectors */
1da177e4 1014 } else {
17787a09
OZ
1015 geom[0] = 64; /* heads */
1016 geom[1] = 32; /* sectors */
1da177e4 1017 }
17787a09 1018 geom[2] = sector_div(capacity, geom[0] * geom[1]); /* cylinders */
1da177e4
LT
1019
1020 return 0;
1021}
1022MODULE_LICENSE("GPL");
1023
d0be4a7d 1024static struct scsi_host_template driver_template = {
643a7c43 1025 .module = THIS_MODULE,
1da177e4
LT
1026 .proc_name = "aha1542",
1027 .name = "Adaptec 1542",
1da177e4 1028 .queuecommand = aha1542_queuecommand,
1da177e4
LT
1029 .eh_device_reset_handler= aha1542_dev_reset,
1030 .eh_bus_reset_handler = aha1542_bus_reset,
1031 .eh_host_reset_handler = aha1542_host_reset,
1032 .bios_param = aha1542_biosparam,
1033 .can_queue = AHA1542_MAILBOXES,
1034 .this_id = 7,
10be6250
OZ
1035 .sg_tablesize = 16,
1036 .cmd_per_lun = 1,
1da177e4
LT
1037 .unchecked_isa_dma = 1,
1038 .use_clustering = ENABLE_CLUSTERING,
1039};
643a7c43
OZ
1040
1041static int aha1542_isa_match(struct device *pdev, unsigned int ndev)
1042{
1043 struct Scsi_Host *sh = aha1542_hw_init(&driver_template, pdev, ndev);
1044
1045 if (!sh)
1046 return 0;
1047
1048 dev_set_drvdata(pdev, sh);
1049 return 1;
1050}
1051
1052static int aha1542_isa_remove(struct device *pdev,
1053 unsigned int ndev)
1054{
1055 aha1542_release(dev_get_drvdata(pdev));
1056 dev_set_drvdata(pdev, NULL);
1057 return 0;
1058}
1059
1060static struct isa_driver aha1542_isa_driver = {
1061 .match = aha1542_isa_match,
1062 .remove = aha1542_isa_remove,
1063 .driver = {
1064 .name = "aha1542"
1065 },
1066};
1067static int isa_registered;
1068
1069#ifdef CONFIG_PNP
1070static struct pnp_device_id aha1542_pnp_ids[] = {
1071 { .id = "ADP1542" },
1072 { .id = "" }
1073};
1074MODULE_DEVICE_TABLE(pnp, aha1542_pnp_ids);
1075
1076static int aha1542_pnp_probe(struct pnp_dev *pdev, const struct pnp_device_id *id)
1077{
1078 int indx;
1079 struct Scsi_Host *sh;
1080
f71429ab
OZ
1081 for (indx = 0; indx < ARRAY_SIZE(io); indx++) {
1082 if (io[indx])
643a7c43
OZ
1083 continue;
1084
1085 if (pnp_activate_dev(pdev) < 0)
1086 continue;
1087
f71429ab 1088 io[indx] = pnp_port_start(pdev, 0);
643a7c43
OZ
1089
1090 /* The card can be queried for its DMA, we have
1091 the DMA set up that is enough */
1092
2906b3ce 1093 dev_info(&pdev->dev, "ISAPnP found an AHA1535 at I/O 0x%03X", io[indx]);
643a7c43
OZ
1094 }
1095
1096 sh = aha1542_hw_init(&driver_template, &pdev->dev, indx);
1097 if (!sh)
1098 return -ENODEV;
1099
1100 pnp_set_drvdata(pdev, sh);
1101 return 0;
1102}
1103
1104static void aha1542_pnp_remove(struct pnp_dev *pdev)
1105{
1106 aha1542_release(pnp_get_drvdata(pdev));
1107 pnp_set_drvdata(pdev, NULL);
1108}
1109
1110static struct pnp_driver aha1542_pnp_driver = {
1111 .name = "aha1542",
1112 .id_table = aha1542_pnp_ids,
1113 .probe = aha1542_pnp_probe,
1114 .remove = aha1542_pnp_remove,
1115};
1116static int pnp_registered;
1117#endif /* CONFIG_PNP */
1118
1119static int __init aha1542_init(void)
1120{
1121 int ret = 0;
643a7c43
OZ
1122
1123#ifdef CONFIG_PNP
1124 if (isapnp) {
1125 ret = pnp_register_driver(&aha1542_pnp_driver);
1126 if (!ret)
1127 pnp_registered = 1;
1128 }
1129#endif
1130 ret = isa_register_driver(&aha1542_isa_driver, MAXBOARDS);
1131 if (!ret)
1132 isa_registered = 1;
1133
1134#ifdef CONFIG_PNP
1135 if (pnp_registered)
1136 ret = 0;
1137#endif
1138 if (isa_registered)
1139 ret = 0;
1140
1141 return ret;
1142}
1143
1144static void __exit aha1542_exit(void)
1145{
1146#ifdef CONFIG_PNP
1147 if (pnp_registered)
1148 pnp_unregister_driver(&aha1542_pnp_driver);
1149#endif
1150 if (isa_registered)
1151 isa_unregister_driver(&aha1542_isa_driver);
1152}
1153
1154module_init(aha1542_init);
1155module_exit(aha1542_exit);
This page took 0.888661 seconds and 5 git commands to generate.