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