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