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