Thomas Gleixner | c82ee6d | 2019-05-19 15:51:48 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /************************************************************************** |
| 3 | * Initio 9100 device driver for Linux. |
| 4 | * |
| 5 | * Copyright (c) 1994-1998 Initio Corporation |
| 6 | * Copyright (c) 1998 Bas Vermeulen <bvermeul@blackstar.xs4all.nl> |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 7 | * Copyright (c) 2004 Christoph Hellwig <hch@lst.de> |
Alan Cox | fa195af | 2008-10-27 15:16:36 +0000 | [diff] [blame] | 8 | * Copyright (c) 2007 Red Hat |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | ************************************************************************* |
| 11 | * |
| 12 | * DESCRIPTION: |
| 13 | * |
| 14 | * This is the Linux low-level SCSI driver for Initio INI-9X00U/UW SCSI host |
| 15 | * adapters |
| 16 | * |
| 17 | * 08/06/97 hc - v1.01h |
| 18 | * - Support inic-940 and inic-935 |
| 19 | * 09/26/97 hc - v1.01i |
| 20 | * - Make correction from J.W. Schultz suggestion |
| 21 | * 10/13/97 hc - Support reset function |
| 22 | * 10/21/97 hc - v1.01j |
| 23 | * - Support 32 LUN (SCSI 3) |
| 24 | * 01/14/98 hc - v1.01k |
| 25 | * - Fix memory allocation problem |
| 26 | * 03/04/98 hc - v1.01l |
| 27 | * - Fix tape rewind which will hang the system problem |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 28 | * - Set can_queue to initio_num_scb |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * 06/25/98 hc - v1.01m |
| 30 | * - Get it work for kernel version >= 2.1.75 |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 31 | * - Dynamic assign SCSI bus reset holding time in initio_init() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * 07/02/98 hc - v1.01n |
| 33 | * - Support 0002134A |
| 34 | * 08/07/98 hc - v1.01o |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 35 | * - Change the initio_abort_srb routine to use scsi_done. <01> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * 09/07/98 hl - v1.02 |
| 37 | * - Change the INI9100U define and proc_dir_entry to |
| 38 | * reflect the newer Kernel 2.1.118, but the v1.o1o |
| 39 | * should work with Kernel 2.1.118. |
| 40 | * 09/20/98 wh - v1.02a |
| 41 | * - Support Abort command. |
| 42 | * - Handle reset routine. |
| 43 | * 09/21/98 hl - v1.03 |
| 44 | * - remove comments. |
| 45 | * 12/09/98 bv - v1.03a |
| 46 | * - Removed unused code |
| 47 | * 12/13/98 bv - v1.03b |
| 48 | * - Remove cli() locking for kernels >= 2.1.95. This uses |
| 49 | * spinlocks to serialize access to the pSRB_head and |
| 50 | * pSRB_tail members of the HCS structure. |
| 51 | * 09/01/99 bv - v1.03d |
| 52 | * - Fixed a deadlock problem in SMP. |
| 53 | * 21/01/99 bv - v1.03e |
| 54 | * - Add support for the Domex 3192U PCI SCSI |
| 55 | * This is a slightly modified patch by |
| 56 | * Brian Macy <bmacy@sunshinecomputing.com> |
| 57 | * 22/02/99 bv - v1.03f |
| 58 | * - Didn't detect the INIC-950 in 2.0.x correctly. |
| 59 | * Now fixed. |
| 60 | * 05/07/99 bv - v1.03g |
| 61 | * - Changed the assumption that HZ = 100 |
| 62 | * 10/17/03 mc - v1.04 |
| 63 | * - added new DMA API support |
| 64 | * 06/01/04 jmd - v1.04a |
| 65 | * - Re-add reset_bus support |
| 66 | **************************************************************************/ |
| 67 | |
| 68 | #include <linux/module.h> |
| 69 | #include <linux/errno.h> |
| 70 | #include <linux/delay.h> |
| 71 | #include <linux/pci.h> |
| 72 | #include <linux/init.h> |
| 73 | #include <linux/blkdev.h> |
| 74 | #include <linux/spinlock.h> |
| 75 | #include <linux/stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #include <linux/kernel.h> |
| 77 | #include <linux/proc_fs.h> |
| 78 | #include <linux/string.h> |
| 79 | #include <linux/interrupt.h> |
| 80 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #include <linux/slab.h> |
| 82 | #include <linux/jiffies.h> |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 83 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #include <asm/io.h> |
| 85 | |
| 86 | #include <scsi/scsi.h> |
| 87 | #include <scsi/scsi_cmnd.h> |
| 88 | #include <scsi/scsi_device.h> |
| 89 | #include <scsi/scsi_host.h> |
| 90 | #include <scsi/scsi_tcq.h> |
| 91 | |
| 92 | #include "initio.h" |
| 93 | |
| 94 | #define SENSE_SIZE 14 |
| 95 | |
| 96 | #define i91u_MAXQUEUE 2 |
| 97 | #define i91u_REVID "Initio INI-9X00U/UW SCSI device driver; Revision: 1.04a" |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | #ifdef DEBUG_i91u |
| 100 | static unsigned int i91u_debug = DEBUG_DEFAULT; |
| 101 | #endif |
| 102 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 103 | static int initio_tag_enable = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | #ifdef DEBUG_i91u |
| 106 | static int setup_debug = 0; |
| 107 | #endif |
| 108 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 109 | static void i91uSCBPost(u8 * pHcb, u8 * pScb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | #define DEBUG_INTERRUPT 0 |
| 112 | #define DEBUG_QUEUE 0 |
| 113 | #define DEBUG_STATE 0 |
| 114 | #define INT_DISC 0 |
| 115 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 116 | /*--- forward references ---*/ |
| 117 | static struct scsi_ctrl_blk *initio_find_busy_scb(struct initio_host * host, u16 tarlun); |
| 118 | static struct scsi_ctrl_blk *initio_find_done_scb(struct initio_host * host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 120 | static int tulip_main(struct initio_host * host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 122 | static int initio_next_state(struct initio_host * host); |
| 123 | static int initio_state_1(struct initio_host * host); |
| 124 | static int initio_state_2(struct initio_host * host); |
| 125 | static int initio_state_3(struct initio_host * host); |
| 126 | static int initio_state_4(struct initio_host * host); |
| 127 | static int initio_state_5(struct initio_host * host); |
| 128 | static int initio_state_6(struct initio_host * host); |
| 129 | static int initio_state_7(struct initio_host * host); |
| 130 | static int initio_xfer_data_in(struct initio_host * host); |
| 131 | static int initio_xfer_data_out(struct initio_host * host); |
| 132 | static int initio_xpad_in(struct initio_host * host); |
| 133 | static int initio_xpad_out(struct initio_host * host); |
| 134 | static int initio_status_msg(struct initio_host * host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 136 | static int initio_msgin(struct initio_host * host); |
| 137 | static int initio_msgin_sync(struct initio_host * host); |
| 138 | static int initio_msgin_accept(struct initio_host * host); |
| 139 | static int initio_msgout_reject(struct initio_host * host); |
| 140 | static int initio_msgin_extend(struct initio_host * host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 142 | static int initio_msgout_ide(struct initio_host * host); |
| 143 | static int initio_msgout_abort_targ(struct initio_host * host); |
| 144 | static int initio_msgout_abort_tag(struct initio_host * host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 146 | static int initio_bus_device_reset(struct initio_host * host); |
| 147 | static void initio_select_atn(struct initio_host * host, struct scsi_ctrl_blk * scb); |
| 148 | static void initio_select_atn3(struct initio_host * host, struct scsi_ctrl_blk * scb); |
| 149 | static void initio_select_atn_stop(struct initio_host * host, struct scsi_ctrl_blk * scb); |
| 150 | static int int_initio_busfree(struct initio_host * host); |
| 151 | static int int_initio_scsi_rst(struct initio_host * host); |
| 152 | static int int_initio_bad_seq(struct initio_host * host); |
| 153 | static int int_initio_resel(struct initio_host * host); |
| 154 | static int initio_sync_done(struct initio_host * host); |
| 155 | static int wdtr_done(struct initio_host * host); |
| 156 | static int wait_tulip(struct initio_host * host); |
| 157 | static int initio_wait_done_disc(struct initio_host * host); |
| 158 | static int initio_wait_disc(struct initio_host * host); |
| 159 | static void tulip_scsi(struct initio_host * host); |
| 160 | static int initio_post_scsi_rst(struct initio_host * host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 162 | static void initio_se2_ew_en(unsigned long base); |
| 163 | static void initio_se2_ew_ds(unsigned long base); |
| 164 | static int initio_se2_rd_all(unsigned long base); |
| 165 | static void initio_se2_update_all(unsigned long base); /* setup default pattern */ |
| 166 | static void initio_read_eeprom(unsigned long base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 168 | /* ---- INTERNAL VARIABLES ---- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | static NVRAM i91unvram; |
| 171 | static NVRAM *i91unvramp; |
| 172 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 173 | static u8 i91udftNvRam[64] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 175 | /*----------- header -----------*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | 0x25, 0xc9, /* Signature */ |
| 177 | 0x40, /* Size */ |
| 178 | 0x01, /* Revision */ |
| 179 | /* -- Host Adapter Structure -- */ |
| 180 | 0x95, /* ModelByte0 */ |
| 181 | 0x00, /* ModelByte1 */ |
| 182 | 0x00, /* ModelInfo */ |
| 183 | 0x01, /* NumOfCh */ |
| 184 | NBC1_DEFAULT, /* BIOSConfig1 */ |
| 185 | 0, /* BIOSConfig2 */ |
| 186 | 0, /* HAConfig1 */ |
| 187 | 0, /* HAConfig2 */ |
| 188 | /* SCSI channel 0 and target Structure */ |
| 189 | 7, /* SCSIid */ |
| 190 | NCC1_DEFAULT, /* SCSIconfig1 */ |
| 191 | 0, /* SCSIconfig2 */ |
| 192 | 0x10, /* NumSCSItarget */ |
| 193 | |
| 194 | NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, |
| 195 | NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, |
| 196 | NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, |
| 197 | NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, |
| 198 | |
| 199 | /* SCSI channel 1 and target Structure */ |
| 200 | 7, /* SCSIid */ |
| 201 | NCC1_DEFAULT, /* SCSIconfig1 */ |
| 202 | 0, /* SCSIconfig2 */ |
| 203 | 0x10, /* NumSCSItarget */ |
| 204 | |
| 205 | NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, |
| 206 | NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, |
| 207 | NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, |
| 208 | NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, NTC_DEFAULT, |
| 209 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 210 | 0, 0}; /* - CheckSum - */ |
| 211 | |
| 212 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 213 | static u8 initio_rate_tbl[8] = /* fast 20 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 215 | /* nanosecond divide by 4 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | 12, /* 50ns, 20M */ |
| 217 | 18, /* 75ns, 13.3M */ |
| 218 | 25, /* 100ns, 10M */ |
| 219 | 31, /* 125ns, 8M */ |
| 220 | 37, /* 150ns, 6.6M */ |
| 221 | 43, /* 175ns, 5.7M */ |
| 222 | 50, /* 200ns, 5M */ |
| 223 | 62 /* 250ns, 4M */ |
| 224 | }; |
| 225 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 226 | static void initio_do_pause(unsigned amount) |
| 227 | { |
| 228 | /* Pause for amount jiffies */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | unsigned long the_time = jiffies + amount; |
| 230 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 231 | while (time_before_eq(jiffies, the_time)) |
| 232 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /*-- forward reference --*/ |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /****************************************************************** |
| 238 | Input: instruction for Serial E2PROM |
| 239 | |
| 240 | EX: se2_rd(0 call se2_instr() to send address and read command |
| 241 | |
| 242 | StartBit OP_Code Address Data |
| 243 | --------- -------- ------------------ ------- |
| 244 | 1 1 , 0 A5,A4,A3,A2,A1,A0 D15-D0 |
| 245 | |
| 246 | +----------------------------------------------------- |
| 247 | | |
| 248 | CS -----+ |
| 249 | +--+ +--+ +--+ +--+ +--+ |
| 250 | ^ | ^ | ^ | ^ | ^ | |
| 251 | | | | | | | | | | | |
| 252 | CLK -------+ +--+ +--+ +--+ +--+ +-- |
| 253 | (leading edge trigger) |
| 254 | |
| 255 | +--1-----1--+ |
| 256 | | SB OP | OP A5 A4 |
| 257 | DI ----+ +--0------------------ |
| 258 | (address and cmd sent to nvram) |
| 259 | |
| 260 | -------------------------------------------+ |
| 261 | | |
| 262 | DO +--- |
| 263 | (data sent from nvram) |
| 264 | |
| 265 | |
| 266 | ******************************************************************/ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 267 | |
| 268 | /** |
| 269 | * initio_se2_instr - bitbang an instruction |
| 270 | * @base: Base of InitIO controller |
| 271 | * @instr: Instruction for serial E2PROM |
| 272 | * |
| 273 | * Bitbang an instruction out to the serial E2Prom |
| 274 | */ |
| 275 | |
| 276 | static void initio_se2_instr(unsigned long base, u8 instr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
| 278 | int i; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 279 | u8 b; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 281 | outb(SE2CS | SE2DO, base + TUL_NVRAM); /* cs+start bit */ |
| 282 | udelay(30); |
| 283 | outb(SE2CS | SE2CLK | SE2DO, base + TUL_NVRAM); /* +CLK */ |
| 284 | udelay(30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | for (i = 0; i < 8; i++) { |
| 287 | if (instr & 0x80) |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 288 | b = SE2CS | SE2DO; /* -CLK+dataBit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 290 | b = SE2CS; /* -CLK */ |
| 291 | outb(b, base + TUL_NVRAM); |
| 292 | udelay(30); |
| 293 | outb(b | SE2CLK, base + TUL_NVRAM); /* +CLK */ |
| 294 | udelay(30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | instr <<= 1; |
| 296 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 297 | outb(SE2CS, base + TUL_NVRAM); /* -CLK */ |
| 298 | udelay(30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 302 | /** |
| 303 | * initio_se2_ew_en - Enable erase/write |
| 304 | * @base: Base address of InitIO controller |
| 305 | * |
| 306 | * Enable erase/write state of serial EEPROM |
| 307 | */ |
| 308 | void initio_se2_ew_en(unsigned long base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 310 | initio_se2_instr(base, 0x30); /* EWEN */ |
| 311 | outb(0, base + TUL_NVRAM); /* -CS */ |
| 312 | udelay(30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 316 | /** |
| 317 | * initio_se2_ew_ds - Disable erase/write |
| 318 | * @base: Base address of InitIO controller |
| 319 | * |
| 320 | * Disable erase/write state of serial EEPROM |
| 321 | */ |
| 322 | void initio_se2_ew_ds(unsigned long base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 324 | initio_se2_instr(base, 0); /* EWDS */ |
| 325 | outb(0, base + TUL_NVRAM); /* -CS */ |
| 326 | udelay(30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 330 | /** |
| 331 | * initio_se2_rd - read E2PROM word |
| 332 | * @base: Base of InitIO controller |
| 333 | * @addr: Address of word in E2PROM |
| 334 | * |
| 335 | * Read a word from the NV E2PROM device |
| 336 | */ |
| 337 | static u16 initio_se2_rd(unsigned long base, u8 addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 339 | u8 instr, rb; |
| 340 | u16 val = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | int i; |
| 342 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 343 | instr = (u8) (addr | 0x80); |
| 344 | initio_se2_instr(base, instr); /* READ INSTR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | for (i = 15; i >= 0; i--) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 347 | outb(SE2CS | SE2CLK, base + TUL_NVRAM); /* +CLK */ |
| 348 | udelay(30); |
| 349 | outb(SE2CS, base + TUL_NVRAM); /* -CLK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | /* sample data after the following edge of clock */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 352 | rb = inb(base + TUL_NVRAM); |
| 353 | rb &= SE2DI; |
| 354 | val += (rb << i); |
| 355 | udelay(30); /* 6/20/95 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 358 | outb(0, base + TUL_NVRAM); /* no chip select */ |
| 359 | udelay(30); |
| 360 | return val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 363 | /** |
| 364 | * initio_se2_wr - read E2PROM word |
| 365 | * @base: Base of InitIO controller |
| 366 | * @addr: Address of word in E2PROM |
| 367 | * @val: Value to write |
| 368 | * |
| 369 | * Write a word to the NV E2PROM device. Used when recovering from |
| 370 | * a problem with the NV. |
| 371 | */ |
| 372 | static void initio_se2_wr(unsigned long base, u8 addr, u16 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 374 | u8 rb; |
| 375 | u8 instr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | int i; |
| 377 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 378 | instr = (u8) (addr | 0x40); |
| 379 | initio_se2_instr(base, instr); /* WRITE INSTR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | for (i = 15; i >= 0; i--) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 381 | if (val & 0x8000) |
| 382 | outb(SE2CS | SE2DO, base + TUL_NVRAM); /* -CLK+dataBit 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 384 | outb(SE2CS, base + TUL_NVRAM); /* -CLK+dataBit 0 */ |
| 385 | udelay(30); |
| 386 | outb(SE2CS | SE2CLK, base + TUL_NVRAM); /* +CLK */ |
| 387 | udelay(30); |
| 388 | val <<= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 390 | outb(SE2CS, base + TUL_NVRAM); /* -CLK */ |
| 391 | udelay(30); |
| 392 | outb(0, base + TUL_NVRAM); /* -CS */ |
| 393 | udelay(30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 395 | outb(SE2CS, base + TUL_NVRAM); /* +CS */ |
| 396 | udelay(30); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | for (;;) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 399 | outb(SE2CS | SE2CLK, base + TUL_NVRAM); /* +CLK */ |
| 400 | udelay(30); |
| 401 | outb(SE2CS, base + TUL_NVRAM); /* -CLK */ |
| 402 | udelay(30); |
| 403 | if ((rb = inb(base + TUL_NVRAM)) & SE2DI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | break; /* write complete */ |
| 405 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 406 | outb(0, base + TUL_NVRAM); /* -CS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 409 | /** |
| 410 | * initio_se2_rd_all - read hostadapter NV configuration |
| 411 | * @base: Base address of InitIO controller |
| 412 | * |
| 413 | * Reads the E2PROM data into main memory. Ensures that the checksum |
| 414 | * and header marker are valid. Returns 1 on success -1 on error. |
| 415 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 417 | static int initio_se2_rd_all(unsigned long base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | { |
| 419 | int i; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 420 | u16 chksum = 0; |
| 421 | u16 *np; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | i91unvramp = &i91unvram; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 424 | np = (u16 *) i91unvramp; |
| 425 | for (i = 0; i < 32; i++) |
| 426 | *np++ = initio_se2_rd(base, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 428 | /* Is signature "ini" ok ? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | if (i91unvramp->NVM_Signature != INI_SIGNATURE) |
| 430 | return -1; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 431 | /* Is ckecksum ok ? */ |
| 432 | np = (u16 *) i91unvramp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | for (i = 0; i < 31; i++) |
| 434 | chksum += *np++; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 435 | if (i91unvramp->NVM_CheckSum != chksum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | return -1; |
| 437 | return 1; |
| 438 | } |
| 439 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 440 | /** |
| 441 | * initio_se2_update_all - Update E2PROM |
| 442 | * @base: Base of InitIO controller |
| 443 | * |
| 444 | * Update the E2PROM by wrting any changes into the E2PROM |
| 445 | * chip, rewriting the checksum. |
| 446 | */ |
| 447 | static void initio_se2_update_all(unsigned long base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { /* setup default pattern */ |
| 449 | int i; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 450 | u16 chksum = 0; |
| 451 | u16 *np, *np1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | i91unvramp = &i91unvram; |
| 454 | /* Calculate checksum first */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 455 | np = (u16 *) i91udftNvRam; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | for (i = 0; i < 31; i++) |
| 457 | chksum += *np++; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 458 | *np = chksum; |
| 459 | initio_se2_ew_en(base); /* Enable write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 461 | np = (u16 *) i91udftNvRam; |
| 462 | np1 = (u16 *) i91unvramp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | for (i = 0; i < 32; i++, np++, np1++) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 464 | if (*np != *np1) |
| 465 | initio_se2_wr(base, i, *np); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 467 | initio_se2_ew_ds(base); /* Disable write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 470 | /** |
| 471 | * initio_read_eeprom - Retrieve configuration |
| 472 | * @base: Base of InitIO Host Adapter |
| 473 | * |
| 474 | * Retrieve the host adapter configuration data from E2Prom. If the |
| 475 | * data is invalid then the defaults are used and are also restored |
| 476 | * into the E2PROM. This forms the access point for the SCSI driver |
| 477 | * into the E2PROM layer, the other functions for the E2PROM are all |
| 478 | * internal use. |
| 479 | * |
| 480 | * Must be called single threaded, uses a shared global area. |
| 481 | */ |
| 482 | |
| 483 | static void initio_read_eeprom(unsigned long base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 485 | u8 gctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
| 487 | i91unvramp = &i91unvram; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 488 | /* Enable EEProm programming */ |
| 489 | gctrl = inb(base + TUL_GCTRL); |
| 490 | outb(gctrl | TUL_GCTRL_EEPROM_BIT, base + TUL_GCTRL); |
| 491 | if (initio_se2_rd_all(base) != 1) { |
| 492 | initio_se2_update_all(base); /* setup default pattern */ |
| 493 | initio_se2_rd_all(base); /* load again */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 495 | /* Disable EEProm programming */ |
| 496 | gctrl = inb(base + TUL_GCTRL); |
| 497 | outb(gctrl & ~TUL_GCTRL_EEPROM_BIT, base + TUL_GCTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 500 | /** |
| 501 | * initio_stop_bm - stop bus master |
| 502 | * @host: InitIO we are stopping |
| 503 | * |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 504 | * Stop any pending DMA operation, aborting the DMA if necessary |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 505 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 507 | static void initio_stop_bm(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
| 509 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 510 | if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ |
| 511 | outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | /* wait Abort DMA xfer done */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 513 | while ((inb(host->addr + TUL_Int) & XABT) == 0) |
| 514 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 516 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 519 | /** |
| 520 | * initio_reset_scsi - Reset SCSI host controller |
| 521 | * @host: InitIO host to reset |
| 522 | * @seconds: Recovery time |
| 523 | * |
| 524 | * Perform a full reset of the SCSI subsystem. |
| 525 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 527 | static int initio_reset_scsi(struct initio_host * host, int seconds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 529 | outb(TSC_RST_BUS, host->addr + TUL_SCtrl0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 531 | while (!((host->jsint = inb(host->addr + TUL_SInt)) & TSS_SCSIRST_INT)) |
| 532 | cpu_relax(); |
| 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | /* reset tulip chip */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 535 | outb(0, host->addr + TUL_SSignal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
| 537 | /* Stall for a while, wait for target's firmware ready,make it 2 sec ! */ |
| 538 | /* SONY 5200 tape drive won't work if only stall for 1 sec */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 539 | /* FIXME: this is a very long busy wait right now */ |
| 540 | initio_do_pause(seconds * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 542 | inb(host->addr + TUL_SInt); |
| 543 | return SCSI_RESET_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 546 | /** |
| 547 | * initio_init - set up an InitIO host adapter |
| 548 | * @host: InitIO host adapter |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 549 | * @bios_addr: BIOS address |
| 550 | * |
| 551 | * Set up the host adapter and devices according to the configuration |
| 552 | * retrieved from the E2PROM. |
| 553 | * |
| 554 | * Locking: Calls E2PROM layer code which is not re-enterable so must |
| 555 | * run single threaded for now. |
| 556 | */ |
| 557 | |
| 558 | static void initio_init(struct initio_host * host, u8 *bios_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
| 560 | int i; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 561 | u8 *flags; |
| 562 | u8 *heads; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 564 | /* Get E2Prom configuration */ |
| 565 | initio_read_eeprom(host->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | if (i91unvramp->NVM_SCSIInfo[0].NVM_NumOfTarg == 8) |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 567 | host->max_tar = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 569 | host->max_tar = 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 571 | host->config = i91unvramp->NVM_SCSIInfo[0].NVM_ChConfig1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 573 | host->scsi_id = i91unvramp->NVM_SCSIInfo[0].NVM_ChSCSIID; |
| 574 | host->idmask = ~(1 << host->scsi_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 576 | #ifdef CHK_PARITY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | /* Enable parity error response */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 578 | outb(inb(host->addr + TUL_PCMD) | 0x40, host->addr + TUL_PCMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | #endif |
| 580 | |
| 581 | /* Mask all the interrupt */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 582 | outb(0x1F, host->addr + TUL_Mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 584 | initio_stop_bm(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | /* --- Initialize the tulip --- */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 586 | outb(TSC_RST_CHIP, host->addr + TUL_SCtrl0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
| 588 | /* program HBA's SCSI ID */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 589 | outb(host->scsi_id << 4, host->addr + TUL_SScsiId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
| 591 | /* Enable Initiator Mode ,phase latch,alternate sync period mode, |
| 592 | disable SCSI reset */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 593 | if (host->config & HCC_EN_PAR) |
| 594 | host->sconf1 = (TSC_INITDEFAULT | TSC_EN_SCSI_PAR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 596 | host->sconf1 = (TSC_INITDEFAULT); |
| 597 | outb(host->sconf1, host->addr + TUL_SConfig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 599 | /* Enable HW reselect */ |
| 600 | outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 602 | outb(0, host->addr + TUL_SPeriod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
| 604 | /* selection time out = 250 ms */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 605 | outb(153, host->addr + TUL_STimeOut); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 607 | /* Enable SCSI terminator */ |
| 608 | outb((host->config & (HCC_ACT_TERM1 | HCC_ACT_TERM2)), |
| 609 | host->addr + TUL_XCtrl); |
| 610 | outb(((host->config & HCC_AUTO_TERM) >> 4) | |
| 611 | (inb(host->addr + TUL_GCTRL1) & 0xFE), |
| 612 | host->addr + TUL_GCTRL1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | for (i = 0, |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 615 | flags = & (i91unvramp->NVM_SCSIInfo[0].NVM_Targ0Config), |
| 616 | heads = bios_addr + 0x180; |
| 617 | i < host->max_tar; |
| 618 | i++, flags++) { |
| 619 | host->targets[i].flags = *flags & ~(TCF_SYNC_DONE | TCF_WDTR_DONE); |
| 620 | if (host->targets[i].flags & TCF_EN_255) |
| 621 | host->targets[i].drv_flags = TCF_DRV_255_63; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 623 | host->targets[i].drv_flags = 0; |
| 624 | host->targets[i].js_period = 0; |
| 625 | host->targets[i].sconfig0 = host->sconf1; |
| 626 | host->targets[i].heads = *heads++; |
| 627 | if (host->targets[i].heads == 255) |
| 628 | host->targets[i].drv_flags = TCF_DRV_255_63; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 630 | host->targets[i].drv_flags = 0; |
| 631 | host->targets[i].sectors = *heads++; |
| 632 | host->targets[i].flags &= ~TCF_BUSY; |
| 633 | host->act_tags[i] = 0; |
| 634 | host->max_tags[i] = 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } /* for */ |
| 636 | printk("i91u: PCI Base=0x%04X, IRQ=%d, BIOS=0x%04X0, SCSI ID=%d\n", |
Alan Cox | e9e42fa | 2007-10-15 20:51:32 +0100 | [diff] [blame] | 637 | host->addr, host->pci_dev->irq, |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 638 | host->bios_addr, host->scsi_id); |
| 639 | /* Reset SCSI Bus */ |
| 640 | if (host->config & HCC_SCSI_RESET) { |
| 641 | printk(KERN_INFO "i91u: Reset SCSI Bus ... \n"); |
| 642 | initio_reset_scsi(host, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 644 | outb(0x17, host->addr + TUL_SCFG1); |
| 645 | outb(0xE9, host->addr + TUL_SIntEnable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 648 | /** |
| 649 | * initio_alloc_scb - Allocate an SCB |
| 650 | * @host: InitIO host we are allocating for |
| 651 | * |
| 652 | * Walk the SCB list for the controller and allocate a free SCB if |
| 653 | * one exists. |
| 654 | */ |
| 655 | static struct scsi_ctrl_blk *initio_alloc_scb(struct initio_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 657 | struct scsi_ctrl_blk *scb; |
| 658 | unsigned long flags; |
| 659 | |
| 660 | spin_lock_irqsave(&host->avail_lock, flags); |
| 661 | if ((scb = host->first_avail) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 663 | printk("find scb at %p\n", scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 665 | if ((host->first_avail = scb->next) == NULL) |
| 666 | host->last_avail = NULL; |
| 667 | scb->next = NULL; |
| 668 | scb->status = SCB_RENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 670 | spin_unlock_irqrestore(&host->avail_lock, flags); |
| 671 | return scb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 674 | /** |
| 675 | * initio_release_scb - Release an SCB |
| 676 | * @host: InitIO host that owns the SCB |
| 677 | * @cmnd: SCB command block being returned |
| 678 | * |
| 679 | * Return an allocated SCB to the host free list |
| 680 | */ |
| 681 | |
| 682 | static void initio_release_scb(struct initio_host * host, struct scsi_ctrl_blk * cmnd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 684 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
| 686 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 687 | printk("Release SCB %p; ", cmnd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 689 | spin_lock_irqsave(&(host->avail_lock), flags); |
| 690 | cmnd->srb = NULL; |
| 691 | cmnd->status = 0; |
| 692 | cmnd->next = NULL; |
| 693 | if (host->last_avail != NULL) { |
| 694 | host->last_avail->next = cmnd; |
| 695 | host->last_avail = cmnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 697 | host->first_avail = cmnd; |
| 698 | host->last_avail = cmnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 700 | spin_unlock_irqrestore(&(host->avail_lock), flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /***************************************************************************/ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 704 | static void initio_append_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
| 706 | |
| 707 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 708 | printk("Append pend SCB %p; ", scbp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 710 | scbp->status = SCB_PEND; |
| 711 | scbp->next = NULL; |
| 712 | if (host->last_pending != NULL) { |
| 713 | host->last_pending->next = scbp; |
| 714 | host->last_pending = scbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 716 | host->first_pending = scbp; |
| 717 | host->last_pending = scbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | /***************************************************************************/ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 722 | static void initio_push_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { |
| 724 | |
| 725 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 726 | printk("Push pend SCB %p; ", scbp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 728 | scbp->status = SCB_PEND; |
| 729 | if ((scbp->next = host->first_pending) != NULL) { |
| 730 | host->first_pending = scbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 732 | host->first_pending = scbp; |
| 733 | host->last_pending = scbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 737 | static struct scsi_ctrl_blk *initio_find_first_pend_scb(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 739 | struct scsi_ctrl_blk *first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 742 | first = host->first_pending; |
| 743 | while (first != NULL) { |
| 744 | if (first->opcode != ExecSCSI) |
| 745 | return first; |
| 746 | if (first->tagmsg == 0) { |
| 747 | if ((host->act_tags[first->target] == 0) && |
| 748 | !(host->targets[first->target].flags & TCF_BUSY)) |
| 749 | return first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 751 | if ((host->act_tags[first->target] >= |
| 752 | host->max_tags[first->target]) | |
| 753 | (host->targets[first->target].flags & TCF_BUSY)) { |
| 754 | first = first->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | continue; |
| 756 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 757 | return first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 759 | first = first->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 761 | return first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 763 | |
| 764 | static void initio_unlink_pend_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 766 | struct scsi_ctrl_blk *tmp, *prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
| 768 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 769 | printk("unlink pend SCB %p; ", scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | #endif |
| 771 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 772 | prev = tmp = host->first_pending; |
| 773 | while (tmp != NULL) { |
| 774 | if (scb == tmp) { /* Unlink this SCB */ |
| 775 | if (tmp == host->first_pending) { |
| 776 | if ((host->first_pending = tmp->next) == NULL) |
| 777 | host->last_pending = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 779 | prev->next = tmp->next; |
| 780 | if (tmp == host->last_pending) |
| 781 | host->last_pending = prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 783 | tmp->next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | break; |
| 785 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 786 | prev = tmp; |
| 787 | tmp = tmp->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 790 | |
| 791 | static void initio_append_busy_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | { |
| 793 | |
| 794 | #if DEBUG_QUEUE |
Stuart Swales | e2d435e | 2008-01-23 20:00:48 +0000 | [diff] [blame] | 795 | printk("append busy SCB %p; ", scbp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 797 | if (scbp->tagmsg) |
| 798 | host->act_tags[scbp->target]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 800 | host->targets[scbp->target].flags |= TCF_BUSY; |
| 801 | scbp->status = SCB_BUSY; |
| 802 | scbp->next = NULL; |
| 803 | if (host->last_busy != NULL) { |
| 804 | host->last_busy->next = scbp; |
| 805 | host->last_busy = scbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 807 | host->first_busy = scbp; |
| 808 | host->last_busy = scbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | |
| 812 | /***************************************************************************/ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 813 | static struct scsi_ctrl_blk *initio_pop_busy_scb(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 815 | struct scsi_ctrl_blk *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
| 817 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 818 | if ((tmp = host->first_busy) != NULL) { |
| 819 | if ((host->first_busy = tmp->next) == NULL) |
| 820 | host->last_busy = NULL; |
| 821 | tmp->next = NULL; |
| 822 | if (tmp->tagmsg) |
| 823 | host->act_tags[tmp->target]--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 825 | host->targets[tmp->target].flags &= ~TCF_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
| 827 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 828 | printk("Pop busy SCB %p; ", tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 830 | return tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /***************************************************************************/ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 834 | static void initio_unlink_busy_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 836 | struct scsi_ctrl_blk *tmp, *prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 839 | printk("unlink busy SCB %p; ", scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | #endif |
| 841 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 842 | prev = tmp = host->first_busy; |
| 843 | while (tmp != NULL) { |
| 844 | if (scb == tmp) { /* Unlink this SCB */ |
| 845 | if (tmp == host->first_busy) { |
| 846 | if ((host->first_busy = tmp->next) == NULL) |
| 847 | host->last_busy = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 849 | prev->next = tmp->next; |
| 850 | if (tmp == host->last_busy) |
| 851 | host->last_busy = prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 853 | tmp->next = NULL; |
| 854 | if (tmp->tagmsg) |
| 855 | host->act_tags[tmp->target]--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 857 | host->targets[tmp->target].flags &= ~TCF_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | break; |
| 859 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 860 | prev = tmp; |
| 861 | tmp = tmp->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | } |
| 863 | return; |
| 864 | } |
| 865 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 866 | struct scsi_ctrl_blk *initio_find_busy_scb(struct initio_host * host, u16 tarlun) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | { |
Lee Jones | 78e40ac | 2021-03-12 09:47:31 +0000 | [diff] [blame] | 868 | struct scsi_ctrl_blk *tmp; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 869 | u16 scbp_tarlun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
| 871 | |
Lee Jones | 78e40ac | 2021-03-12 09:47:31 +0000 | [diff] [blame] | 872 | tmp = host->first_busy; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 873 | while (tmp != NULL) { |
| 874 | scbp_tarlun = (tmp->lun << 8) | (tmp->target); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | if (scbp_tarlun == tarlun) { /* Unlink this SCB */ |
| 876 | break; |
| 877 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 878 | tmp = tmp->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | } |
| 880 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 881 | printk("find busy SCB %p; ", tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 883 | return tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 886 | static void initio_append_done_scb(struct initio_host * host, struct scsi_ctrl_blk * scbp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 889 | printk("append done SCB %p; ", scbp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | #endif |
| 891 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 892 | scbp->status = SCB_DONE; |
| 893 | scbp->next = NULL; |
| 894 | if (host->last_done != NULL) { |
| 895 | host->last_done->next = scbp; |
| 896 | host->last_done = scbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 898 | host->first_done = scbp; |
| 899 | host->last_done = scbp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
| 901 | } |
| 902 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 903 | struct scsi_ctrl_blk *initio_find_done_scb(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 905 | struct scsi_ctrl_blk *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 907 | if ((tmp = host->first_done) != NULL) { |
| 908 | if ((host->first_done = tmp->next) == NULL) |
| 909 | host->last_done = NULL; |
| 910 | tmp->next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | } |
| 912 | #if DEBUG_QUEUE |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 913 | printk("find done SCB %p; ",tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 915 | return tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | } |
| 917 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 918 | static int initio_abort_srb(struct initio_host * host, struct scsi_cmnd *srbp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 920 | unsigned long flags; |
| 921 | struct scsi_ctrl_blk *tmp, *prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 923 | spin_lock_irqsave(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 925 | if ((host->semaph == 0) && (host->active == NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | /* disable Jasmin SCSI Int */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 927 | outb(0x1F, host->addr + TUL_Mask); |
| 928 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
| 929 | /* FIXME: synchronize_irq needed ? */ |
| 930 | tulip_main(host); |
| 931 | spin_lock_irqsave(&host->semaph_lock, flags); |
| 932 | host->semaph = 1; |
| 933 | outb(0x0F, host->addr + TUL_Mask); |
| 934 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | return SCSI_ABORT_SNOOZE; |
| 936 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 937 | prev = tmp = host->first_pending; /* Check Pend queue */ |
| 938 | while (tmp != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | /* 07/27/98 */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 940 | if (tmp->srb == srbp) { |
| 941 | if (tmp == host->active) { |
| 942 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | return SCSI_ABORT_BUSY; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 944 | } else if (tmp == host->first_pending) { |
| 945 | if ((host->first_pending = tmp->next) == NULL) |
| 946 | host->last_pending = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 948 | prev->next = tmp->next; |
| 949 | if (tmp == host->last_pending) |
| 950 | host->last_pending = prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 952 | tmp->hastat = HOST_ABORTED; |
| 953 | tmp->flags |= SCF_DONE; |
| 954 | if (tmp->flags & SCF_POST) |
| 955 | (*tmp->post) ((u8 *) host, (u8 *) tmp); |
| 956 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | return SCSI_ABORT_SUCCESS; |
| 958 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 959 | prev = tmp; |
| 960 | tmp = tmp->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 963 | prev = tmp = host->first_busy; /* Check Busy queue */ |
| 964 | while (tmp != NULL) { |
| 965 | if (tmp->srb == srbp) { |
| 966 | if (tmp == host->active) { |
| 967 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | return SCSI_ABORT_BUSY; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 969 | } else if (tmp->tagmsg == 0) { |
| 970 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | return SCSI_ABORT_BUSY; |
| 972 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 973 | host->act_tags[tmp->target]--; |
| 974 | if (tmp == host->first_busy) { |
| 975 | if ((host->first_busy = tmp->next) == NULL) |
| 976 | host->last_busy = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 978 | prev->next = tmp->next; |
| 979 | if (tmp == host->last_busy) |
| 980 | host->last_busy = prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 982 | tmp->next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
| 984 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 985 | tmp->hastat = HOST_ABORTED; |
| 986 | tmp->flags |= SCF_DONE; |
| 987 | if (tmp->flags & SCF_POST) |
| 988 | (*tmp->post) ((u8 *) host, (u8 *) tmp); |
| 989 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | return SCSI_ABORT_SUCCESS; |
| 991 | } |
| 992 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 993 | prev = tmp; |
| 994 | tmp = tmp->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 996 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
| 997 | return SCSI_ABORT_NOT_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /***************************************************************************/ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1001 | static int initio_bad_seq(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1003 | struct scsi_ctrl_blk *scb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1005 | printk("initio_bad_seg c=%d\n", host->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1007 | if ((scb = host->active) != NULL) { |
| 1008 | initio_unlink_busy_scb(host, scb); |
| 1009 | scb->hastat = HOST_BAD_PHAS; |
| 1010 | scb->tastat = 0; |
| 1011 | initio_append_done_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1013 | initio_stop_bm(host); |
| 1014 | initio_reset_scsi(host, 8); /* 7/29/98 */ |
| 1015 | return initio_post_scsi_rst(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
Adrian Bunk | a2ba192 | 2005-06-25 14:58:50 -0700 | [diff] [blame] | 1018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | /************************************************************************/ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1020 | static void initio_exec_scb(struct initio_host * host, struct scsi_ctrl_blk * scb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1022 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1024 | scb->mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1026 | scb->sgidx = 0; |
| 1027 | scb->sgmax = scb->sglen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1029 | spin_lock_irqsave(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1031 | initio_append_pend_scb(host, scb); /* Append this SCB to Pending queue */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
| 1033 | /* VVVVV 07/21/98 */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1034 | if (host->semaph == 1) { |
| 1035 | /* Disable Jasmin SCSI Int */ |
| 1036 | outb(0x1F, host->addr + TUL_Mask); |
| 1037 | host->semaph = 0; |
| 1038 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1040 | tulip_main(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1042 | spin_lock_irqsave(&host->semaph_lock, flags); |
| 1043 | host->semaph = 1; |
| 1044 | outb(0x0F, host->addr + TUL_Mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1046 | spin_unlock_irqrestore(&host->semaph_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | return; |
| 1048 | } |
| 1049 | |
| 1050 | /***************************************************************************/ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1051 | static int initio_isr(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1053 | if (inb(host->addr + TUL_Int) & TSS_INT_PENDING) { |
| 1054 | if (host->semaph == 1) { |
| 1055 | outb(0x1F, host->addr + TUL_Mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | /* Disable Tulip SCSI Int */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1057 | host->semaph = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1059 | tulip_main(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1061 | host->semaph = 1; |
| 1062 | outb(0x0F, host->addr + TUL_Mask); |
| 1063 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | } |
| 1065 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1066 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1069 | static int tulip_main(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1071 | struct scsi_ctrl_blk *scb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
| 1073 | for (;;) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1074 | tulip_scsi(host); /* Call tulip_scsi */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1076 | /* Walk the list of completed SCBs */ |
| 1077 | while ((scb = initio_find_done_scb(host)) != NULL) { /* find done entry */ |
| 1078 | if (scb->tastat == INI_QUEUE_FULL) { |
| 1079 | host->max_tags[scb->target] = |
| 1080 | host->act_tags[scb->target] - 1; |
| 1081 | scb->tastat = 0; |
| 1082 | initio_append_pend_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | continue; |
| 1084 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1085 | if (!(scb->mode & SCM_RSENS)) { /* not in auto req. sense mode */ |
| 1086 | if (scb->tastat == 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | |
| 1088 | /* clr sync. nego flag */ |
| 1089 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1090 | if (scb->flags & SCF_SENSE) { |
| 1091 | u8 len; |
| 1092 | len = scb->senselen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | if (len == 0) |
| 1094 | len = 1; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1095 | scb->buflen = scb->senselen; |
| 1096 | scb->bufptr = scb->senseptr; |
| 1097 | scb->flags &= ~(SCF_SG | SCF_DIR); /* for xfer_data_in */ |
| 1098 | /* so, we won't report wrong direction in xfer_data_in, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | and won't report HOST_DO_DU in state_6 */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1100 | scb->mode = SCM_RSENS; |
| 1101 | scb->ident &= 0xBF; /* Disable Disconnect */ |
| 1102 | scb->tagmsg = 0; |
| 1103 | scb->tastat = 0; |
| 1104 | scb->cdblen = 6; |
| 1105 | scb->cdb[0] = SCSICMD_RequestSense; |
| 1106 | scb->cdb[1] = 0; |
| 1107 | scb->cdb[2] = 0; |
| 1108 | scb->cdb[3] = 0; |
| 1109 | scb->cdb[4] = len; |
| 1110 | scb->cdb[5] = 0; |
| 1111 | initio_push_pend_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | break; |
| 1113 | } |
| 1114 | } |
| 1115 | } else { /* in request sense mode */ |
| 1116 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1117 | if (scb->tastat == 2) { /* check contition status again after sending |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | requset sense cmd 0x3 */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1119 | scb->hastat = HOST_BAD_PHAS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1121 | scb->tastat = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1123 | scb->flags |= SCF_DONE; |
| 1124 | if (scb->flags & SCF_POST) { |
| 1125 | /* FIXME: only one post method and lose casts */ |
| 1126 | (*scb->post) ((u8 *) host, (u8 *) scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | } |
| 1128 | } /* while */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | /* find_active: */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1130 | if (inb(host->addr + TUL_SStatus0) & TSS_INT_PENDING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | continue; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1132 | if (host->active) /* return to OS and wait for xfer_done_ISR/Selected_ISR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | return 1; /* return to OS, enable interrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | /* Check pending SCB */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1135 | if (initio_find_first_pend_scb(host) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | return 1; /* return to OS, enable interrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | } /* End of for loop */ |
| 1138 | /* statement won't reach here */ |
| 1139 | } |
| 1140 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1141 | static void tulip_scsi(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1143 | struct scsi_ctrl_blk *scb; |
| 1144 | struct target_control *active_tc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
| 1146 | /* make sure to service interrupt asap */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1147 | if ((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING) { |
| 1148 | host->phase = host->jsstatus0 & TSS_PH_MASK; |
| 1149 | host->jsstatus1 = inb(host->addr + TUL_SStatus1); |
| 1150 | host->jsint = inb(host->addr + TUL_SInt); |
| 1151 | if (host->jsint & TSS_SCSIRST_INT) { /* SCSI bus reset detected */ |
| 1152 | int_initio_scsi_rst(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | return; |
| 1154 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1155 | if (host->jsint & TSS_RESEL_INT) { /* if selected/reselected interrupt */ |
| 1156 | if (int_initio_resel(host) == 0) |
| 1157 | initio_next_state(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | return; |
| 1159 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1160 | if (host->jsint & TSS_SEL_TIMEOUT) { |
| 1161 | int_initio_busfree(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | return; |
| 1163 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1164 | if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ |
| 1165 | int_initio_busfree(host); /* unexpected bus free or sel timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | return; |
| 1167 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1168 | if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) { /* func complete or Bus service */ |
| 1169 | if ((scb = host->active) != NULL) |
| 1170 | initio_next_state(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | return; |
| 1172 | } |
| 1173 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1174 | if (host->active != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | return; |
| 1176 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1177 | if ((scb = initio_find_first_pend_scb(host)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | return; |
| 1179 | |
| 1180 | /* program HBA's SCSI ID & target SCSI ID */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1181 | outb((host->scsi_id << 4) | (scb->target & 0x0F), |
| 1182 | host->addr + TUL_SScsiId); |
| 1183 | if (scb->opcode == ExecSCSI) { |
| 1184 | active_tc = &host->targets[scb->target]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1186 | if (scb->tagmsg) |
| 1187 | active_tc->drv_flags |= TCF_DRV_EN_TAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1189 | active_tc->drv_flags &= ~TCF_DRV_EN_TAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1191 | outb(active_tc->js_period, host->addr + TUL_SPeriod); |
| 1192 | if ((active_tc->flags & (TCF_WDTR_DONE | TCF_NO_WDTR)) == 0) { /* do wdtr negotiation */ |
| 1193 | initio_select_atn_stop(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1195 | if ((active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) { /* do sync negotiation */ |
| 1196 | initio_select_atn_stop(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1198 | if (scb->tagmsg) |
| 1199 | initio_select_atn3(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1201 | initio_select_atn(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | } |
| 1203 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1204 | if (scb->flags & SCF_POLL) { |
| 1205 | while (wait_tulip(host) != -1) { |
| 1206 | if (initio_next_state(host) == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | break; |
| 1208 | } |
| 1209 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1210 | } else if (scb->opcode == BusDevRst) { |
| 1211 | initio_select_atn_stop(host, scb); |
| 1212 | scb->next_state = 8; |
| 1213 | if (scb->flags & SCF_POLL) { |
| 1214 | while (wait_tulip(host) != -1) { |
| 1215 | if (initio_next_state(host) == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | break; |
| 1217 | } |
| 1218 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1219 | } else if (scb->opcode == AbortCmd) { |
| 1220 | if (initio_abort_srb(host, scb->srb) != 0) { |
| 1221 | initio_unlink_pend_scb(host, scb); |
| 1222 | initio_release_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1224 | scb->opcode = BusDevRst; |
| 1225 | initio_select_atn_stop(host, scb); |
| 1226 | scb->next_state = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1229 | initio_unlink_pend_scb(host, scb); |
| 1230 | scb->hastat = 0x16; /* bad command */ |
| 1231 | initio_append_done_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | } |
| 1233 | return; |
| 1234 | } |
| 1235 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1236 | /** |
| 1237 | * initio_next_state - Next SCSI state |
| 1238 | * @host: InitIO host we are processing |
| 1239 | * |
| 1240 | * Progress the active command block along the state machine |
| 1241 | * until we hit a state which we must wait for activity to occur. |
| 1242 | * |
| 1243 | * Returns zero or a negative code. |
| 1244 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1246 | static int initio_next_state(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | { |
| 1248 | int next; |
| 1249 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1250 | next = host->active->next_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | for (;;) { |
| 1252 | switch (next) { |
| 1253 | case 1: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1254 | next = initio_state_1(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | break; |
| 1256 | case 2: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1257 | next = initio_state_2(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | break; |
| 1259 | case 3: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1260 | next = initio_state_3(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | break; |
| 1262 | case 4: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1263 | next = initio_state_4(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | break; |
| 1265 | case 5: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1266 | next = initio_state_5(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | break; |
| 1268 | case 6: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1269 | next = initio_state_6(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | break; |
| 1271 | case 7: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1272 | next = initio_state_7(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | break; |
| 1274 | case 8: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1275 | return initio_bus_device_reset(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | default: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1277 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | } |
| 1279 | if (next <= 0) |
| 1280 | return next; |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1285 | /** |
| 1286 | * initio_state_1 - SCSI state machine |
| 1287 | * @host: InitIO host we are controlling |
| 1288 | * |
| 1289 | * Perform SCSI state processing for Select/Attention/Stop |
| 1290 | */ |
| 1291 | |
| 1292 | static int initio_state_1(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1294 | struct scsi_ctrl_blk *scb = host->active; |
| 1295 | struct target_control *active_tc = host->active_tc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | #if DEBUG_STATE |
| 1297 | printk("-s1-"); |
| 1298 | #endif |
| 1299 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1300 | /* Move the SCB from pending to busy */ |
| 1301 | initio_unlink_pend_scb(host, scb); |
| 1302 | initio_append_busy_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1304 | outb(active_tc->sconfig0, host->addr + TUL_SConfig ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | /* ATN on */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1306 | if (host->phase == MSG_OUT) { |
| 1307 | outb(TSC_EN_BUS_IN | TSC_HW_RESELECT, host->addr + TUL_SCtrl1); |
| 1308 | outb(scb->ident, host->addr + TUL_SFifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1310 | if (scb->tagmsg) { |
| 1311 | outb(scb->tagmsg, host->addr + TUL_SFifo); |
| 1312 | outb(scb->tagid, host->addr + TUL_SFifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1314 | if ((active_tc->flags & (TCF_WDTR_DONE | TCF_NO_WDTR)) == 0) { |
| 1315 | active_tc->flags |= TCF_WDTR_DONE; |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1316 | outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1317 | outb(2, host->addr + TUL_SFifo); /* Extended msg length */ |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1318 | outb(EXTENDED_SDTR, host->addr + TUL_SFifo); /* Sync request */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1319 | outb(1, host->addr + TUL_SFifo); /* Start from 16 bits */ |
| 1320 | } else if ((active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) { |
| 1321 | active_tc->flags |= TCF_SYNC_DONE; |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1322 | outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1323 | outb(3, host->addr + TUL_SFifo); /* extended msg length */ |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1324 | outb(EXTENDED_SDTR, host->addr + TUL_SFifo); /* sync request */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1325 | outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); |
| 1326 | outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1328 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1329 | if (wait_tulip(host) == -1) |
| 1330 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1332 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
| 1333 | outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); |
| 1334 | /* Into before CDB xfer */ |
| 1335 | return 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1339 | /** |
| 1340 | * initio_state_2 - SCSI state machine |
| 1341 | * @host: InitIO host we are controlling |
| 1342 | * |
| 1343 | * state after selection with attention |
| 1344 | * state after selection with attention3 |
| 1345 | */ |
| 1346 | |
| 1347 | static int initio_state_2(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1349 | struct scsi_ctrl_blk *scb = host->active; |
| 1350 | struct target_control *active_tc = host->active_tc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | #if DEBUG_STATE |
| 1352 | printk("-s2-"); |
| 1353 | #endif |
| 1354 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1355 | initio_unlink_pend_scb(host, scb); |
| 1356 | initio_append_busy_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1358 | outb(active_tc->sconfig0, host->addr + TUL_SConfig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1360 | if (host->jsstatus1 & TSS_CMD_PH_CMP) |
| 1361 | return 4; |
| 1362 | |
| 1363 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
| 1364 | outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), host->addr + TUL_SSignal); |
| 1365 | /* Into before CDB xfer */ |
| 1366 | return 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1369 | /** |
| 1370 | * initio_state_3 - SCSI state machine |
| 1371 | * @host: InitIO host we are controlling |
| 1372 | * |
| 1373 | * state before CDB xfer is done |
| 1374 | */ |
| 1375 | |
| 1376 | static int initio_state_3(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1378 | struct scsi_ctrl_blk *scb = host->active; |
| 1379 | struct target_control *active_tc = host->active_tc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | int i; |
| 1381 | |
| 1382 | #if DEBUG_STATE |
| 1383 | printk("-s3-"); |
| 1384 | #endif |
| 1385 | for (;;) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1386 | switch (host->phase) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | case CMD_OUT: /* Command out phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1388 | for (i = 0; i < (int) scb->cdblen; i++) |
| 1389 | outb(scb->cdb[i], host->addr + TUL_SFifo); |
| 1390 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1391 | if (wait_tulip(host) == -1) |
| 1392 | return -1; |
| 1393 | if (host->phase == CMD_OUT) |
| 1394 | return initio_bad_seq(host); |
| 1395 | return 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | |
| 1397 | case MSG_IN: /* Message in phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1398 | scb->next_state = 3; |
| 1399 | if (initio_msgin(host) == -1) |
| 1400 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | break; |
| 1402 | |
| 1403 | case STATUS_IN: /* Status phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1404 | if (initio_status_msg(host) == -1) |
| 1405 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | break; |
| 1407 | |
| 1408 | case MSG_OUT: /* Message out phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1409 | if (active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) { |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1410 | outb(NOP, host->addr + TUL_SFifo); /* msg nop */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1411 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1412 | if (wait_tulip(host) == -1) |
| 1413 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1415 | active_tc->flags |= TCF_SYNC_DONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1417 | outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1418 | outb(3, host->addr + TUL_SFifo); /* ext. msg len */ |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1419 | outb(EXTENDED_SDTR, host->addr + TUL_SFifo); /* sync request */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1420 | outb(initio_rate_tbl[active_tc->flags & TCF_SCSI_RATE], host->addr + TUL_SFifo); |
| 1421 | outb(MAX_OFFSET, host->addr + TUL_SFifo); /* REQ/ACK offset */ |
| 1422 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1423 | if (wait_tulip(host) == -1) |
| 1424 | return -1; |
| 1425 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
| 1426 | outb(inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7), host->addr + TUL_SSignal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | |
| 1428 | } |
| 1429 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | default: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1431 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1436 | /** |
| 1437 | * initio_state_4 - SCSI state machine |
| 1438 | * @host: InitIO host we are controlling |
| 1439 | * |
| 1440 | * SCSI state machine. State 4 |
| 1441 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1443 | static int initio_state_4(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1445 | struct scsi_ctrl_blk *scb = host->active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
| 1447 | #if DEBUG_STATE |
| 1448 | printk("-s4-"); |
| 1449 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1450 | if ((scb->flags & SCF_DIR) == SCF_NO_XF) { |
| 1451 | return 6; /* Go to state 6 (After data) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | } |
| 1453 | for (;;) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1454 | if (scb->buflen == 0) |
| 1455 | return 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1457 | switch (host->phase) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
| 1459 | case STATUS_IN: /* Status phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1460 | if ((scb->flags & SCF_DIR) != 0) /* if direction bit set then report data underrun */ |
| 1461 | scb->hastat = HOST_DO_DU; |
| 1462 | if ((initio_status_msg(host)) == -1) |
| 1463 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | break; |
| 1465 | |
| 1466 | case MSG_IN: /* Message in phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1467 | scb->next_state = 0x4; |
| 1468 | if (initio_msgin(host) == -1) |
| 1469 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | break; |
| 1471 | |
| 1472 | case MSG_OUT: /* Message out phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1473 | if (host->jsstatus0 & TSS_PAR_ERROR) { |
| 1474 | scb->buflen = 0; |
| 1475 | scb->hastat = HOST_DO_DU; |
| 1476 | if (initio_msgout_ide(host) == -1) |
| 1477 | return -1; |
| 1478 | return 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | } else { |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1480 | outb(NOP, host->addr + TUL_SFifo); /* msg nop */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1481 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1482 | if (wait_tulip(host) == -1) |
| 1483 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | } |
| 1485 | break; |
| 1486 | |
| 1487 | case DATA_IN: /* Data in phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1488 | return initio_xfer_data_in(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | |
| 1490 | case DATA_OUT: /* Data out phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1491 | return initio_xfer_data_out(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | |
| 1493 | default: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1494 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | } |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1500 | /** |
| 1501 | * initio_state_5 - SCSI state machine |
| 1502 | * @host: InitIO host we are controlling |
| 1503 | * |
| 1504 | * State after dma xfer done or phase change before xfer done |
| 1505 | */ |
| 1506 | |
| 1507 | static int initio_state_5(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1509 | struct scsi_ctrl_blk *scb = host->active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | long cnt, xcnt; /* cannot use unsigned !! code: if (xcnt < 0) */ |
| 1511 | |
| 1512 | #if DEBUG_STATE |
| 1513 | printk("-s5-"); |
| 1514 | #endif |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1515 | /*------ get remaining count -------*/ |
| 1516 | cnt = inl(host->addr + TUL_SCnt0) & 0x0FFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1518 | if (inb(host->addr + TUL_XCmd) & 0x20) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | /* ----------------------- DATA_IN ----------------------------- */ |
| 1520 | /* check scsi parity error */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1521 | if (host->jsstatus0 & TSS_PAR_ERROR) |
| 1522 | scb->hastat = HOST_DO_DU; |
| 1523 | if (inb(host->addr + TUL_XStatus) & XPEND) { /* DMA xfer pending, Send STOP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | /* tell Hardware scsi xfer has been terminated */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1525 | outb(inb(host->addr + TUL_XCtrl) | 0x80, host->addr + TUL_XCtrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | /* wait until DMA xfer not pending */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1527 | while (inb(host->addr + TUL_XStatus) & XPEND) |
| 1528 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | } |
| 1530 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1531 | /*-------- DATA OUT -----------*/ |
| 1532 | if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) { |
| 1533 | if (host->active_tc->js_period & TSC_WIDE_SCSI) |
| 1534 | cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F) << 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1536 | cnt += (inb(host->addr + TUL_SFifoCnt) & 0x1F); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1538 | if (inb(host->addr + TUL_XStatus) & XPEND) { /* if DMA xfer is pending, abort DMA xfer */ |
| 1539 | outb(TAX_X_ABT, host->addr + TUL_XCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | /* wait Abort DMA xfer done */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1541 | while ((inb(host->addr + TUL_Int) & XABT) == 0) |
| 1542 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1544 | if ((cnt == 1) && (host->phase == DATA_OUT)) { |
| 1545 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1546 | if (wait_tulip(host) == -1) |
| 1547 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | cnt = 0; |
| 1549 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1550 | if ((inb(host->addr + TUL_SStatus1) & TSS_XFER_CMP) == 0) |
| 1551 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | } |
| 1553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | if (cnt == 0) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1555 | scb->buflen = 0; |
| 1556 | return 6; /* After Data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | } |
| 1558 | /* Update active data pointer */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1559 | xcnt = (long) scb->buflen - cnt; /* xcnt== bytes already xferred */ |
| 1560 | scb->buflen = (u32) cnt; /* cnt == bytes left to be xferred */ |
| 1561 | if (scb->flags & SCF_SG) { |
| 1562 | struct sg_entry *sgp; |
| 1563 | unsigned long i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1565 | sgp = &scb->sglist[scb->sgidx]; |
| 1566 | for (i = scb->sgidx; i < scb->sgmax; sgp++, i++) { |
| 1567 | xcnt -= (long) sgp->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | if (xcnt < 0) { /* this sgp xfer half done */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1569 | xcnt += (long) sgp->len; /* xcnt == bytes xferred in this sgp */ |
| 1570 | sgp->data += (u32) xcnt; /* new ptr to be xfer */ |
| 1571 | sgp->len -= (u32) xcnt; /* new len to be xfer */ |
| 1572 | scb->bufptr += ((u32) (i - scb->sgidx) << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | /* new SG table ptr */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1574 | scb->sglen = (u8) (scb->sgmax - i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | /* new SG table len */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1576 | scb->sgidx = (u16) i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | /* for next disc and come in this loop */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1578 | return 4; /* Go to state 4 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | } |
| 1580 | /* else (xcnt >= 0 , i.e. this sgp already xferred */ |
| 1581 | } /* for */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1582 | return 6; /* Go to state 6 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1584 | scb->bufptr += (u32) xcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1586 | return 4; /* Go to state 4 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1589 | /** |
| 1590 | * initio_state_6 - SCSI state machine |
| 1591 | * @host: InitIO host we are controlling |
| 1592 | * |
| 1593 | * State after Data phase |
| 1594 | */ |
| 1595 | |
| 1596 | static int initio_state_6(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1598 | struct scsi_ctrl_blk *scb = host->active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | |
| 1600 | #if DEBUG_STATE |
| 1601 | printk("-s6-"); |
| 1602 | #endif |
| 1603 | for (;;) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1604 | switch (host->phase) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | case STATUS_IN: /* Status phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1606 | if ((initio_status_msg(host)) == -1) |
| 1607 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | break; |
| 1609 | |
| 1610 | case MSG_IN: /* Message in phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1611 | scb->next_state = 6; |
| 1612 | if ((initio_msgin(host)) == -1) |
| 1613 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | break; |
| 1615 | |
| 1616 | case MSG_OUT: /* Message out phase */ |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1617 | outb(NOP, host->addr + TUL_SFifo); /* msg nop */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1618 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1619 | if (wait_tulip(host) == -1) |
| 1620 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | break; |
| 1622 | |
| 1623 | case DATA_IN: /* Data in phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1624 | return initio_xpad_in(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | |
| 1626 | case DATA_OUT: /* Data out phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1627 | return initio_xpad_out(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | |
| 1629 | default: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1630 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | } |
| 1632 | } |
| 1633 | } |
| 1634 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1635 | /** |
| 1636 | * initio_state_7 - SCSI state machine |
| 1637 | * @host: InitIO host we are controlling |
| 1638 | * |
| 1639 | */ |
| 1640 | |
Chen Zhou | 0c3dbde | 2019-12-17 21:43:09 +0800 | [diff] [blame] | 1641 | static int initio_state_7(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | { |
| 1643 | int cnt, i; |
| 1644 | |
| 1645 | #if DEBUG_STATE |
| 1646 | printk("-s7-"); |
| 1647 | #endif |
| 1648 | /* flush SCSI FIFO */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1649 | cnt = inb(host->addr + TUL_SFifoCnt) & 0x1F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | if (cnt) { |
| 1651 | for (i = 0; i < cnt; i++) |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1652 | inb(host->addr + TUL_SFifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1654 | switch (host->phase) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | case DATA_IN: /* Data in phase */ |
| 1656 | case DATA_OUT: /* Data out phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1657 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | default: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1659 | return 6; /* Go to state 6 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | } |
| 1661 | } |
| 1662 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1663 | /** |
| 1664 | * initio_xfer_data_in - Commence data input |
| 1665 | * @host: InitIO host in use |
| 1666 | * |
| 1667 | * Commence a block of data transfer. The transfer itself will |
| 1668 | * be managed by the controller and we will get a completion (or |
| 1669 | * failure) interrupt. |
| 1670 | */ |
| 1671 | static int initio_xfer_data_in(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1673 | struct scsi_ctrl_blk *scb = host->active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1675 | if ((scb->flags & SCF_DIR) == SCF_DOUT) |
| 1676 | return 6; /* wrong direction */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1678 | outl(scb->buflen, host->addr + TUL_SCnt0); |
| 1679 | outb(TSC_XF_DMA_IN, host->addr + TUL_SCmd); /* 7/25/95 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1681 | if (scb->flags & SCF_SG) { /* S/G xfer */ |
| 1682 | outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); |
| 1683 | outl(scb->bufptr, host->addr + TUL_XAddH); |
| 1684 | outb(TAX_SG_IN, host->addr + TUL_XCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1686 | outl(scb->buflen, host->addr + TUL_XCntH); |
| 1687 | outl(scb->bufptr, host->addr + TUL_XAddH); |
| 1688 | outb(TAX_X_IN, host->addr + TUL_XCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1690 | scb->next_state = 0x5; |
| 1691 | return 0; /* return to OS, wait xfer done , let jas_isr come in */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | } |
| 1693 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1694 | /** |
| 1695 | * initio_xfer_data_out - Commence data output |
| 1696 | * @host: InitIO host in use |
| 1697 | * |
| 1698 | * Commence a block of data transfer. The transfer itself will |
| 1699 | * be managed by the controller and we will get a completion (or |
| 1700 | * failure) interrupt. |
| 1701 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1703 | static int initio_xfer_data_out(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1705 | struct scsi_ctrl_blk *scb = host->active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1707 | if ((scb->flags & SCF_DIR) == SCF_DIN) |
| 1708 | return 6; /* wrong direction */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1710 | outl(scb->buflen, host->addr + TUL_SCnt0); |
| 1711 | outb(TSC_XF_DMA_OUT, host->addr + TUL_SCmd); |
| 1712 | |
| 1713 | if (scb->flags & SCF_SG) { /* S/G xfer */ |
| 1714 | outl(((u32) scb->sglen) << 3, host->addr + TUL_XCntH); |
| 1715 | outl(scb->bufptr, host->addr + TUL_XAddH); |
| 1716 | outb(TAX_SG_OUT, host->addr + TUL_XCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1718 | outl(scb->buflen, host->addr + TUL_XCntH); |
| 1719 | outl(scb->bufptr, host->addr + TUL_XAddH); |
| 1720 | outb(TAX_X_OUT, host->addr + TUL_XCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1723 | scb->next_state = 0x5; |
| 1724 | return 0; /* return to OS, wait xfer done , let jas_isr come in */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1727 | int initio_xpad_in(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1729 | struct scsi_ctrl_blk *scb = host->active; |
| 1730 | struct target_control *active_tc = host->active_tc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1732 | if ((scb->flags & SCF_DIR) != SCF_NO_DCHK) |
| 1733 | scb->hastat = HOST_DO_DU; /* over run */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | for (;;) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1735 | if (active_tc->js_period & TSC_WIDE_SCSI) |
| 1736 | outl(2, host->addr + TUL_SCnt0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1738 | outl(1, host->addr + TUL_SCnt0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1740 | outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); |
| 1741 | if (wait_tulip(host) == -1) |
| 1742 | return -1; |
| 1743 | if (host->phase != DATA_IN) { |
| 1744 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
| 1745 | return 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1747 | inb(host->addr + TUL_SFifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | } |
| 1749 | } |
| 1750 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1751 | int initio_xpad_out(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1753 | struct scsi_ctrl_blk *scb = host->active; |
| 1754 | struct target_control *active_tc = host->active_tc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1756 | if ((scb->flags & SCF_DIR) != SCF_NO_DCHK) |
| 1757 | scb->hastat = HOST_DO_DU; /* over run */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | for (;;) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1759 | if (active_tc->js_period & TSC_WIDE_SCSI) |
| 1760 | outl(2, host->addr + TUL_SCnt0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | else |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1762 | outl(1, host->addr + TUL_SCnt0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1764 | outb(0, host->addr + TUL_SFifo); |
| 1765 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1766 | if ((wait_tulip(host)) == -1) |
| 1767 | return -1; |
| 1768 | if (host->phase != DATA_OUT) { /* Disable wide CPU to allow read 16 bits */ |
| 1769 | outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); |
| 1770 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
| 1771 | return 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | } |
| 1775 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1776 | int initio_status_msg(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | { /* status & MSG_IN */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1778 | struct scsi_ctrl_blk *scb = host->active; |
| 1779 | u8 msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1781 | outb(TSC_CMD_COMP, host->addr + TUL_SCmd); |
| 1782 | if (wait_tulip(host) == -1) |
| 1783 | return -1; |
| 1784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | /* get status */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1786 | scb->tastat = inb(host->addr + TUL_SFifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1788 | if (host->phase == MSG_OUT) { |
| 1789 | if (host->jsstatus0 & TSS_PAR_ERROR) |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1790 | outb(MSG_PARITY_ERROR, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1791 | else |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1792 | outb(NOP, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1793 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1794 | return wait_tulip(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1796 | if (host->phase == MSG_IN) { |
| 1797 | msg = inb(host->addr + TUL_SFifo); |
| 1798 | if (host->jsstatus0 & TSS_PAR_ERROR) { /* Parity error */ |
| 1799 | if ((initio_msgin_accept(host)) == -1) |
| 1800 | return -1; |
| 1801 | if (host->phase != MSG_OUT) |
| 1802 | return initio_bad_seq(host); |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1803 | outb(MSG_PARITY_ERROR, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1804 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 1805 | return wait_tulip(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | } |
| 1807 | if (msg == 0) { /* Command complete */ |
| 1808 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1809 | if ((scb->tastat & 0x18) == 0x10) /* No link support */ |
| 1810 | return initio_bad_seq(host); |
| 1811 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
| 1812 | outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); |
| 1813 | return initio_wait_done_disc(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | |
| 1815 | } |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1816 | if (msg == LINKED_CMD_COMPLETE || |
| 1817 | msg == LINKED_FLG_CMD_COMPLETE) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1818 | if ((scb->tastat & 0x18) == 0x10) |
| 1819 | return initio_msgin_accept(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | } |
| 1821 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1822 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | /* scsi bus free */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1827 | int int_initio_busfree(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1829 | struct scsi_ctrl_blk *scb = host->active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1831 | if (scb != NULL) { |
| 1832 | if (scb->status & SCB_SELECT) { /* selection timeout */ |
| 1833 | initio_unlink_pend_scb(host, scb); |
| 1834 | scb->hastat = HOST_SEL_TOUT; |
| 1835 | initio_append_done_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | } else { /* Unexpected bus free */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1837 | initio_unlink_busy_scb(host, scb); |
| 1838 | scb->hastat = HOST_BUS_FREE; |
| 1839 | initio_append_done_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1841 | host->active = NULL; |
| 1842 | host->active_tc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1844 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ |
| 1845 | outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); |
| 1846 | outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ |
| 1847 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1851 | /** |
| 1852 | * int_initio_scsi_rst - SCSI reset occurred |
| 1853 | * @host: Host seeing the reset |
| 1854 | * |
| 1855 | * A SCSI bus reset has occurred. Clean up any pending transfer |
| 1856 | * the hardware is doing by DMA and then abort all active and |
| 1857 | * disconnected commands. The mid layer should sort the rest out |
| 1858 | * for us |
| 1859 | */ |
| 1860 | |
| 1861 | static int int_initio_scsi_rst(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1863 | struct scsi_ctrl_blk *scb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | int i; |
| 1865 | |
| 1866 | /* if DMA xfer is pending, abort DMA xfer */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1867 | if (inb(host->addr + TUL_XStatus) & 0x01) { |
| 1868 | outb(TAX_X_ABT | TAX_X_CLR_FIFO, host->addr + TUL_XCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | /* wait Abort DMA xfer done */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1870 | while ((inb(host->addr + TUL_Int) & 0x04) == 0) |
| 1871 | cpu_relax(); |
| 1872 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | } |
| 1874 | /* Abort all active & disconnected scb */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1875 | while ((scb = initio_pop_busy_scb(host)) != NULL) { |
| 1876 | scb->hastat = HOST_BAD_PHAS; |
| 1877 | initio_append_done_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1879 | host->active = NULL; |
| 1880 | host->active_tc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | |
| 1882 | /* clr sync nego. done flag */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1883 | for (i = 0; i < host->max_tar; i++) |
| 1884 | host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); |
| 1885 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1888 | /** |
Lee Jones | 100ec49 | 2021-03-17 09:12:04 +0000 | [diff] [blame] | 1889 | * int_initio_resel - Reselection occurred |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1890 | * @host: InitIO host adapter |
| 1891 | * |
| 1892 | * A SCSI reselection event has been signalled and the interrupt |
| 1893 | * is now being processed. Work out which command block needs attention |
| 1894 | * and continue processing that command. |
| 1895 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1897 | int int_initio_resel(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1899 | struct scsi_ctrl_blk *scb; |
| 1900 | struct target_control *active_tc; |
| 1901 | u8 tag, msg = 0; |
| 1902 | u8 tar, lun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1904 | if ((scb = host->active) != NULL) { |
| 1905 | /* FIXME: Why check and not just clear ? */ |
| 1906 | if (scb->status & SCB_SELECT) /* if waiting for selection complete */ |
| 1907 | scb->status &= ~SCB_SELECT; |
| 1908 | host->active = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | } |
| 1910 | /* --------- get target id---------------------- */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1911 | tar = inb(host->addr + TUL_SBusId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | /* ------ get LUN from Identify message----------- */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1913 | lun = inb(host->addr + TUL_SIdent) & 0x0F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | /* 07/22/98 from 0x1F -> 0x0F */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1915 | active_tc = &host->targets[tar]; |
| 1916 | host->active_tc = active_tc; |
| 1917 | outb(active_tc->sconfig0, host->addr + TUL_SConfig); |
| 1918 | outb(active_tc->js_period, host->addr + TUL_SPeriod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
| 1920 | /* ------------- tag queueing ? ------------------- */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1921 | if (active_tc->drv_flags & TCF_DRV_EN_TAG) { |
| 1922 | if ((initio_msgin_accept(host)) == -1) |
| 1923 | return -1; |
| 1924 | if (host->phase != MSG_IN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | goto no_tag; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1926 | outl(1, host->addr + TUL_SCnt0); |
| 1927 | outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); |
| 1928 | if (wait_tulip(host) == -1) |
| 1929 | return -1; |
| 1930 | msg = inb(host->addr + TUL_SFifo); /* Read Tag Message */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 1932 | if (msg < SIMPLE_QUEUE_TAG || msg > ORDERED_QUEUE_TAG) |
| 1933 | /* Is simple Tag */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | goto no_tag; |
| 1935 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1936 | if (initio_msgin_accept(host) == -1) |
| 1937 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1939 | if (host->phase != MSG_IN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | goto no_tag; |
| 1941 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1942 | outl(1, host->addr + TUL_SCnt0); |
| 1943 | outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); |
| 1944 | if (wait_tulip(host) == -1) |
| 1945 | return -1; |
| 1946 | tag = inb(host->addr + TUL_SFifo); /* Read Tag ID */ |
| 1947 | scb = host->scb + tag; |
| 1948 | if (scb->target != tar || scb->lun != lun) { |
| 1949 | return initio_msgout_abort_tag(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1951 | if (scb->status != SCB_BUSY) { /* 03/24/95 */ |
| 1952 | return initio_msgout_abort_tag(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1954 | host->active = scb; |
| 1955 | if ((initio_msgin_accept(host)) == -1) |
| 1956 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | } else { /* No tag */ |
| 1958 | no_tag: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1959 | if ((scb = initio_find_busy_scb(host, tar | (lun << 8))) == NULL) { |
| 1960 | return initio_msgout_abort_targ(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1962 | host->active = scb; |
| 1963 | if (!(active_tc->drv_flags & TCF_DRV_EN_TAG)) { |
| 1964 | if ((initio_msgin_accept(host)) == -1) |
| 1965 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | } |
| 1967 | } |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1971 | /** |
| 1972 | * int_initio_bad_seq - out of phase |
| 1973 | * @host: InitIO host flagging event |
| 1974 | * |
| 1975 | * We have ended up out of phase somehow. Reset the host controller |
| 1976 | * and throw all our toys out of the pram. Let the midlayer clean up |
| 1977 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1979 | static int int_initio_bad_seq(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | { /* target wrong phase */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1981 | struct scsi_ctrl_blk *scb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | int i; |
| 1983 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1984 | initio_reset_scsi(host, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1986 | while ((scb = initio_pop_busy_scb(host)) != NULL) { |
| 1987 | scb->hastat = HOST_BAD_PHAS; |
| 1988 | initio_append_done_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1990 | for (i = 0; i < host->max_tar; i++) |
| 1991 | host->targets[i].flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); |
| 1992 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 1996 | /** |
| 1997 | * initio_msgout_abort_targ - abort a tag |
| 1998 | * @host: InitIO host |
| 1999 | * |
| 2000 | * Abort when the target/lun does not match or when our SCB is not |
| 2001 | * busy. Used by untagged commands. |
| 2002 | */ |
| 2003 | |
| 2004 | static int initio_msgout_abort_targ(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | { |
| 2006 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2007 | outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal); |
| 2008 | if (initio_msgin_accept(host) == -1) |
| 2009 | return -1; |
| 2010 | if (host->phase != MSG_OUT) |
| 2011 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2013 | outb(ABORT_TASK_SET, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2014 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2016 | return initio_wait_disc(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2019 | /** |
| 2020 | * initio_msgout_abort_tag - abort a tag |
| 2021 | * @host: InitIO host |
| 2022 | * |
| 2023 | * Abort when the target/lun does not match or when our SCB is not |
| 2024 | * busy. Used for tagged commands. |
| 2025 | */ |
| 2026 | |
| 2027 | static int initio_msgout_abort_tag(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | { |
| 2029 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2030 | outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal); |
| 2031 | if (initio_msgin_accept(host) == -1) |
| 2032 | return -1; |
| 2033 | if (host->phase != MSG_OUT) |
| 2034 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2036 | outb(ABORT_TASK, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2037 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2039 | return initio_wait_disc(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | |
| 2041 | } |
| 2042 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2043 | /** |
| 2044 | * initio_msgin - Message in |
| 2045 | * @host: InitIO Host |
| 2046 | * |
| 2047 | * Process incoming message |
| 2048 | */ |
| 2049 | static int initio_msgin(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2051 | struct target_control *active_tc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | |
| 2053 | for (;;) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2054 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2056 | outl(1, host->addr + TUL_SCnt0); |
| 2057 | outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); |
| 2058 | if (wait_tulip(host) == -1) |
| 2059 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2061 | switch (inb(host->addr + TUL_SFifo)) { |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2062 | case DISCONNECT: /* Disconnect msg */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2063 | outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); |
| 2064 | return initio_wait_disc(host); |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2065 | case SAVE_POINTERS: |
| 2066 | case RESTORE_POINTERS: |
| 2067 | case NOP: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2068 | initio_msgin_accept(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | break; |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2070 | case MESSAGE_REJECT: /* Clear ATN first */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2071 | outb((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)), |
| 2072 | host->addr + TUL_SSignal); |
| 2073 | active_tc = host->active_tc; |
| 2074 | if ((active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) /* do sync nego */ |
| 2075 | outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), |
| 2076 | host->addr + TUL_SSignal); |
| 2077 | initio_msgin_accept(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | break; |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2079 | case EXTENDED_MESSAGE: /* extended msg */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2080 | initio_msgin_extend(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | break; |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2082 | case IGNORE_WIDE_RESIDUE: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2083 | initio_msgin_accept(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | break; |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2085 | case COMMAND_COMPLETE: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2086 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
| 2087 | outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); |
| 2088 | return initio_wait_done_disc(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | default: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2090 | initio_msgout_reject(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | break; |
| 2092 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2093 | if (host->phase != MSG_IN) |
| 2094 | return host->phase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | } |
| 2096 | /* statement won't reach here */ |
| 2097 | } |
| 2098 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2099 | static int initio_msgout_reject(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2101 | outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2103 | if (initio_msgin_accept(host) == -1) |
| 2104 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2106 | if (host->phase == MSG_OUT) { |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2107 | outb(MESSAGE_REJECT, host->addr + TUL_SFifo); /* Msg reject */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2108 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 2109 | return wait_tulip(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2111 | return host->phase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2114 | static int initio_msgout_ide(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | { |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2116 | outb(INITIATOR_ERROR, host->addr + TUL_SFifo); /* Initiator Detected Error */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2117 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 2118 | return wait_tulip(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2121 | static int initio_msgin_extend(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2123 | u8 len, idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2125 | if (initio_msgin_accept(host) != MSG_IN) |
| 2126 | return host->phase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | |
| 2128 | /* Get extended msg length */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2129 | outl(1, host->addr + TUL_SCnt0); |
| 2130 | outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); |
| 2131 | if (wait_tulip(host) == -1) |
| 2132 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2134 | len = inb(host->addr + TUL_SFifo); |
| 2135 | host->msg[0] = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | for (idx = 1; len != 0; len--) { |
| 2137 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2138 | if ((initio_msgin_accept(host)) != MSG_IN) |
| 2139 | return host->phase; |
| 2140 | outl(1, host->addr + TUL_SCnt0); |
| 2141 | outb(TSC_XF_FIFO_IN, host->addr + TUL_SCmd); |
| 2142 | if (wait_tulip(host) == -1) |
| 2143 | return -1; |
| 2144 | host->msg[idx++] = inb(host->addr + TUL_SFifo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2146 | if (host->msg[1] == 1) { /* if it's synchronous data transfer request */ |
| 2147 | u8 r; |
| 2148 | if (host->msg[0] != 3) /* if length is not right */ |
| 2149 | return initio_msgout_reject(host); |
| 2150 | if (host->active_tc->flags & TCF_NO_SYNC_NEGO) { /* Set OFFSET=0 to do async, nego back */ |
| 2151 | host->msg[3] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2153 | if (initio_msgin_sync(host) == 0 && |
| 2154 | (host->active_tc->flags & TCF_SYNC_DONE)) { |
| 2155 | initio_sync_done(host); |
| 2156 | return initio_msgin_accept(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2160 | r = inb(host->addr + TUL_SSignal); |
| 2161 | outb((r & (TSC_SET_ACK | 7)) | TSC_SET_ATN, |
| 2162 | host->addr + TUL_SSignal); |
| 2163 | if (initio_msgin_accept(host) != MSG_OUT) |
| 2164 | return host->phase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | /* sync msg out */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2166 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2168 | initio_sync_done(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2170 | outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2171 | outb(3, host->addr + TUL_SFifo); |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2172 | outb(EXTENDED_SDTR, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2173 | outb(host->msg[2], host->addr + TUL_SFifo); |
| 2174 | outb(host->msg[3], host->addr + TUL_SFifo); |
| 2175 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 2176 | return wait_tulip(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2178 | if (host->msg[0] != 2 || host->msg[1] != 3) |
| 2179 | return initio_msgout_reject(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | /* if it's WIDE DATA XFER REQ */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2181 | if (host->active_tc->flags & TCF_NO_WDTR) { |
| 2182 | host->msg[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2184 | if (host->msg[2] > 2) /* > 32 bits */ |
| 2185 | return initio_msgout_reject(host); |
| 2186 | if (host->msg[2] == 2) { /* == 32 */ |
| 2187 | host->msg[2] = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2189 | if ((host->active_tc->flags & TCF_NO_WDTR) == 0) { |
| 2190 | wdtr_done(host); |
| 2191 | if ((host->active_tc->flags & (TCF_SYNC_DONE | TCF_NO_SYNC_NEGO)) == 0) |
| 2192 | outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal); |
| 2193 | return initio_msgin_accept(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2197 | outb(((inb(host->addr + TUL_SSignal) & (TSC_SET_ACK | 7)) | TSC_SET_ATN), host->addr + TUL_SSignal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2199 | if (initio_msgin_accept(host) != MSG_OUT) |
| 2200 | return host->phase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | /* WDTR msg out */ |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2202 | outb(EXTENDED_MESSAGE, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2203 | outb(2, host->addr + TUL_SFifo); |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2204 | outb(EXTENDED_WDTR, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2205 | outb(host->msg[2], host->addr + TUL_SFifo); |
| 2206 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 2207 | return wait_tulip(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2210 | static int initio_msgin_sync(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | { |
| 2212 | char default_period; |
| 2213 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2214 | default_period = initio_rate_tbl[host->active_tc->flags & TCF_SCSI_RATE]; |
| 2215 | if (host->msg[3] > MAX_OFFSET) { |
| 2216 | host->msg[3] = MAX_OFFSET; |
| 2217 | if (host->msg[2] < default_period) { |
| 2218 | host->msg[2] = default_period; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | return 1; |
| 2220 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2221 | if (host->msg[2] >= 59) /* Change to async */ |
| 2222 | host->msg[3] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | return 1; |
| 2224 | } |
| 2225 | /* offset requests asynchronous transfers ? */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2226 | if (host->msg[3] == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | return 0; |
| 2228 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2229 | if (host->msg[2] < default_period) { |
| 2230 | host->msg[2] = default_period; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | return 1; |
| 2232 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2233 | if (host->msg[2] >= 59) { |
| 2234 | host->msg[3] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | return 1; |
| 2236 | } |
| 2237 | return 0; |
| 2238 | } |
| 2239 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2240 | static int wdtr_done(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2242 | host->active_tc->flags &= ~TCF_SYNC_DONE; |
| 2243 | host->active_tc->flags |= TCF_WDTR_DONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2245 | host->active_tc->js_period = 0; |
| 2246 | if (host->msg[2]) /* if 16 bit */ |
| 2247 | host->active_tc->js_period |= TSC_WIDE_SCSI; |
| 2248 | host->active_tc->sconfig0 &= ~TSC_ALT_PERIOD; |
| 2249 | outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); |
| 2250 | outb(host->active_tc->js_period, host->addr + TUL_SPeriod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | |
| 2252 | return 1; |
| 2253 | } |
| 2254 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2255 | static int initio_sync_done(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | { |
| 2257 | int i; |
| 2258 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2259 | host->active_tc->flags |= TCF_SYNC_DONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2261 | if (host->msg[3]) { |
| 2262 | host->active_tc->js_period |= host->msg[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | for (i = 0; i < 8; i++) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2264 | if (initio_rate_tbl[i] >= host->msg[2]) /* pick the big one */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | break; |
| 2266 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2267 | host->active_tc->js_period |= (i << 4); |
| 2268 | host->active_tc->sconfig0 |= TSC_ALT_PERIOD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2270 | outb(host->active_tc->sconfig0, host->addr + TUL_SConfig); |
| 2271 | outb(host->active_tc->js_period, host->addr + TUL_SPeriod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2273 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2277 | static int initio_post_scsi_rst(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2279 | struct scsi_ctrl_blk *scb; |
| 2280 | struct target_control *active_tc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | int i; |
| 2282 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2283 | host->active = NULL; |
| 2284 | host->active_tc = NULL; |
| 2285 | host->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2287 | while ((scb = initio_pop_busy_scb(host)) != NULL) { |
| 2288 | scb->hastat = HOST_BAD_PHAS; |
| 2289 | initio_append_done_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | } |
| 2291 | /* clear sync done flag */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2292 | active_tc = &host->targets[0]; |
| 2293 | for (i = 0; i < host->max_tar; active_tc++, i++) { |
| 2294 | active_tc->flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | /* Initialize the sync. xfer register values to an asyn xfer */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2296 | active_tc->js_period = 0; |
| 2297 | active_tc->sconfig0 = host->sconf1; |
| 2298 | host->act_tags[0] = 0; /* 07/22/98 */ |
| 2299 | host->targets[i].flags &= ~TCF_BUSY; /* 07/22/98 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | } /* for */ |
| 2301 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2302 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2305 | static void initio_select_atn_stop(struct initio_host * host, struct scsi_ctrl_blk * scb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2307 | scb->status |= SCB_SELECT; |
| 2308 | scb->next_state = 0x1; |
| 2309 | host->active = scb; |
| 2310 | host->active_tc = &host->targets[scb->target]; |
| 2311 | outb(TSC_SELATNSTOP, host->addr + TUL_SCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2315 | static void initio_select_atn(struct initio_host * host, struct scsi_ctrl_blk * scb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | { |
| 2317 | int i; |
| 2318 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2319 | scb->status |= SCB_SELECT; |
| 2320 | scb->next_state = 0x2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2322 | outb(scb->ident, host->addr + TUL_SFifo); |
| 2323 | for (i = 0; i < (int) scb->cdblen; i++) |
| 2324 | outb(scb->cdb[i], host->addr + TUL_SFifo); |
| 2325 | host->active_tc = &host->targets[scb->target]; |
| 2326 | host->active = scb; |
| 2327 | outb(TSC_SEL_ATN, host->addr + TUL_SCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2330 | static void initio_select_atn3(struct initio_host * host, struct scsi_ctrl_blk * scb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | { |
| 2332 | int i; |
| 2333 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2334 | scb->status |= SCB_SELECT; |
| 2335 | scb->next_state = 0x2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2337 | outb(scb->ident, host->addr + TUL_SFifo); |
| 2338 | outb(scb->tagmsg, host->addr + TUL_SFifo); |
| 2339 | outb(scb->tagid, host->addr + TUL_SFifo); |
| 2340 | for (i = 0; i < scb->cdblen; i++) |
| 2341 | outb(scb->cdb[i], host->addr + TUL_SFifo); |
| 2342 | host->active_tc = &host->targets[scb->target]; |
| 2343 | host->active = scb; |
| 2344 | outb(TSC_SEL_ATN3, host->addr + TUL_SCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2347 | /** |
| 2348 | * initio_bus_device_reset - SCSI Bus Device Reset |
| 2349 | * @host: InitIO host to reset |
| 2350 | * |
| 2351 | * Perform a device reset and abort all pending SCBs for the |
| 2352 | * victim device |
| 2353 | */ |
| 2354 | int initio_bus_device_reset(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2356 | struct scsi_ctrl_blk *scb = host->active; |
| 2357 | struct target_control *active_tc = host->active_tc; |
| 2358 | struct scsi_ctrl_blk *tmp, *prev; |
| 2359 | u8 tar; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2361 | if (host->phase != MSG_OUT) |
| 2362 | return int_initio_bad_seq(host); /* Unexpected phase */ |
| 2363 | |
| 2364 | initio_unlink_pend_scb(host, scb); |
| 2365 | initio_release_scb(host, scb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | |
| 2367 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2368 | tar = scb->target; /* target */ |
| 2369 | active_tc->flags &= ~(TCF_SYNC_DONE | TCF_WDTR_DONE | TCF_BUSY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | /* clr sync. nego & WDTR flags 07/22/98 */ |
| 2371 | |
| 2372 | /* abort all SCB with same target */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2373 | prev = tmp = host->first_busy; /* Check Busy queue */ |
| 2374 | while (tmp != NULL) { |
| 2375 | if (tmp->target == tar) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | /* unlink it */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2377 | if (tmp == host->first_busy) { |
| 2378 | if ((host->first_busy = tmp->next) == NULL) |
| 2379 | host->last_busy = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2381 | prev->next = tmp->next; |
| 2382 | if (tmp == host->last_busy) |
| 2383 | host->last_busy = prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2385 | tmp->hastat = HOST_ABORTED; |
| 2386 | initio_append_done_scb(host, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | } |
| 2388 | /* Previous haven't change */ |
| 2389 | else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2390 | prev = tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2392 | tmp = tmp->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | } |
Hannes Reinecke | 9df17f46 | 2021-01-13 10:04:46 +0100 | [diff] [blame] | 2394 | outb(TARGET_RESET, host->addr + TUL_SFifo); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2395 | outb(TSC_XF_FIFO_OUT, host->addr + TUL_SCmd); |
| 2396 | return initio_wait_disc(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | |
| 2398 | } |
| 2399 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2400 | static int initio_msgin_accept(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2402 | outb(TSC_MSG_ACCEPT, host->addr + TUL_SCmd); |
| 2403 | return wait_tulip(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | } |
| 2405 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2406 | static int wait_tulip(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | { |
| 2408 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2409 | while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) |
| 2410 | & TSS_INT_PENDING)) |
| 2411 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2413 | host->jsint = inb(host->addr + TUL_SInt); |
| 2414 | host->phase = host->jsstatus0 & TSS_PH_MASK; |
| 2415 | host->jsstatus1 = inb(host->addr + TUL_SStatus1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2417 | if (host->jsint & TSS_RESEL_INT) /* if SCSI bus reset detected */ |
| 2418 | return int_initio_resel(host); |
| 2419 | if (host->jsint & TSS_SEL_TIMEOUT) /* if selected/reselected timeout interrupt */ |
| 2420 | return int_initio_busfree(host); |
| 2421 | if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ |
| 2422 | return int_initio_scsi_rst(host); |
| 2423 | |
| 2424 | if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ |
| 2425 | if (host->flags & HCF_EXPECT_DONE_DISC) { |
| 2426 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ |
| 2427 | initio_unlink_busy_scb(host, host->active); |
| 2428 | host->active->hastat = 0; |
| 2429 | initio_append_done_scb(host, host->active); |
| 2430 | host->active = NULL; |
| 2431 | host->active_tc = NULL; |
| 2432 | host->flags &= ~HCF_EXPECT_DONE_DISC; |
| 2433 | outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); |
| 2434 | outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ |
| 2435 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2437 | if (host->flags & HCF_EXPECT_DISC) { |
| 2438 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ |
| 2439 | host->active = NULL; |
| 2440 | host->active_tc = NULL; |
| 2441 | host->flags &= ~HCF_EXPECT_DISC; |
| 2442 | outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); |
| 2443 | outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ |
| 2444 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2446 | return int_initio_busfree(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2448 | /* The old code really does the below. Can probably be removed */ |
| 2449 | if (host->jsint & (TSS_FUNC_COMP | TSS_BUS_SERV)) |
| 2450 | return host->phase; |
| 2451 | return host->phase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2453 | |
| 2454 | static int initio_wait_disc(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2456 | while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) & TSS_INT_PENDING)) |
| 2457 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2459 | host->jsint = inb(host->addr + TUL_SInt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2461 | if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ |
| 2462 | return int_initio_scsi_rst(host); |
| 2463 | if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ |
| 2464 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ |
| 2465 | outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); |
| 2466 | outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ |
| 2467 | host->active = NULL; |
| 2468 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2470 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2473 | static int initio_wait_done_disc(struct initio_host * host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2475 | while (!((host->jsstatus0 = inb(host->addr + TUL_SStatus0)) |
| 2476 | & TSS_INT_PENDING)) |
| 2477 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2479 | host->jsint = inb(host->addr + TUL_SInt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2481 | if (host->jsint & TSS_SCSIRST_INT) /* if SCSI bus reset detected */ |
| 2482 | return int_initio_scsi_rst(host); |
| 2483 | if (host->jsint & TSS_DISC_INT) { /* BUS disconnection */ |
| 2484 | outb(TSC_FLUSH_FIFO, host->addr + TUL_SCtrl0); /* Flush SCSI FIFO */ |
| 2485 | outb(TSC_INITDEFAULT, host->addr + TUL_SConfig); |
| 2486 | outb(TSC_HW_RESELECT, host->addr + TUL_SCtrl1); /* Enable HW reselect */ |
| 2487 | initio_unlink_busy_scb(host, host->active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2489 | initio_append_done_scb(host, host->active); |
| 2490 | host->active = NULL; |
| 2491 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2493 | return initio_bad_seq(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | } |
| 2495 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2496 | /** |
| 2497 | * i91u_intr - IRQ handler |
| 2498 | * @irqno: IRQ number |
| 2499 | * @dev_id: IRQ identifier |
| 2500 | * |
| 2501 | * Take the relevant locks and then invoke the actual isr processing |
| 2502 | * code under the lock. |
| 2503 | */ |
| 2504 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2505 | static irqreturn_t i91u_intr(int irqno, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | { |
| 2507 | struct Scsi_Host *dev = dev_id; |
| 2508 | unsigned long flags; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2509 | int r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | |
| 2511 | spin_lock_irqsave(dev->host_lock, flags); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2512 | r = initio_isr((struct initio_host *)dev->hostdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | spin_unlock_irqrestore(dev->host_lock, flags); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2514 | if (r) |
| 2515 | return IRQ_HANDLED; |
| 2516 | else |
| 2517 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2521 | /** |
| 2522 | * initio_build_scb - Build the mappings and SCB |
| 2523 | * @host: InitIO host taking the command |
| 2524 | * @cblk: Firmware command block |
| 2525 | * @cmnd: SCSI midlayer command block |
| 2526 | * |
| 2527 | * Translate the abstract SCSI command into a firmware command block |
| 2528 | * suitable for feeding to the InitIO host controller. This also requires |
| 2529 | * we build the scatter gather lists and ensure they are mapped properly. |
| 2530 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2532 | static void initio_build_scb(struct initio_host * host, struct scsi_ctrl_blk * cblk, struct scsi_cmnd * cmnd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | { /* Create corresponding SCB */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2534 | struct scatterlist *sglist; |
| 2535 | struct sg_entry *sg; /* Pointer to SG list */ |
FUJITA Tomonori | a258c85 | 2007-05-21 14:58:30 +0900 | [diff] [blame] | 2536 | int i, nseg; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2537 | long total_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | dma_addr_t dma_addr; |
| 2539 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2540 | /* Fill in the command headers */ |
| 2541 | cblk->post = i91uSCBPost; /* i91u's callback routine */ |
| 2542 | cblk->srb = cmnd; |
| 2543 | cblk->opcode = ExecSCSI; |
| 2544 | cblk->flags = SCF_POST; /* After SCSI done, call post routine */ |
| 2545 | cblk->target = cmnd->device->id; |
| 2546 | cblk->lun = cmnd->device->lun; |
| 2547 | cblk->ident = cmnd->device->lun | DISC_ALLOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2549 | cblk->flags |= SCF_SENSE; /* Turn on auto request sense */ |
| 2550 | |
| 2551 | /* Map the sense buffer into bus memory */ |
| 2552 | dma_addr = dma_map_single(&host->pci_dev->dev, cmnd->sense_buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | SENSE_SIZE, DMA_FROM_DEVICE); |
Grant Grundler | 423eef6 | 2008-04-05 10:14:22 -0600 | [diff] [blame] | 2554 | cblk->senseptr = (u32)dma_addr; |
| 2555 | cblk->senselen = SENSE_SIZE; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2556 | cmnd->SCp.ptr = (char *)(unsigned long)dma_addr; |
| 2557 | cblk->cdblen = cmnd->cmd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2559 | /* Clear the returned status */ |
| 2560 | cblk->hastat = 0; |
| 2561 | cblk->tastat = 0; |
| 2562 | /* Command the command */ |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 2563 | memcpy(cblk->cdb, cmnd->cmnd, cmnd->cmd_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2565 | /* Set up tags */ |
| 2566 | if (cmnd->device->tagged_supported) { /* Tag Support */ |
| 2567 | cblk->tagmsg = SIMPLE_QUEUE_TAG; /* Do simple tag only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2569 | cblk->tagmsg = 0; /* No tag support */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | /* todo handle map_sg error */ |
FUJITA Tomonori | a258c85 | 2007-05-21 14:58:30 +0900 | [diff] [blame] | 2573 | nseg = scsi_dma_map(cmnd); |
| 2574 | BUG_ON(nseg < 0); |
| 2575 | if (nseg) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2576 | dma_addr = dma_map_single(&host->pci_dev->dev, &cblk->sglist[0], |
| 2577 | sizeof(struct sg_entry) * TOTAL_SG_ENTRY, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | DMA_BIDIRECTIONAL); |
Grant Grundler | 423eef6 | 2008-04-05 10:14:22 -0600 | [diff] [blame] | 2579 | cblk->bufptr = (u32)dma_addr; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2580 | cmnd->SCp.dma_handle = dma_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | |
Stuart Swales | e2d435e | 2008-01-23 20:00:48 +0000 | [diff] [blame] | 2582 | cblk->sglen = nseg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2584 | cblk->flags |= SCF_SG; /* Turn on SG list flag */ |
FUJITA Tomonori | a258c85 | 2007-05-21 14:58:30 +0900 | [diff] [blame] | 2585 | total_len = 0; |
| 2586 | sg = &cblk->sglist[0]; |
| 2587 | scsi_for_each_sg(cmnd, sglist, cblk->sglen, i) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2588 | sg->data = cpu_to_le32((u32)sg_dma_address(sglist)); |
Grant Grundler | 423eef6 | 2008-04-05 10:14:22 -0600 | [diff] [blame] | 2589 | sg->len = cpu_to_le32((u32)sg_dma_len(sglist)); |
| 2590 | total_len += sg_dma_len(sglist); |
Boaz Harrosh | a169e63 | 2007-12-17 18:08:59 +0200 | [diff] [blame] | 2591 | ++sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
FUJITA Tomonori | a258c85 | 2007-05-21 14:58:30 +0900 | [diff] [blame] | 2594 | cblk->buflen = (scsi_bufflen(cmnd) > total_len) ? |
| 2595 | total_len : scsi_bufflen(cmnd); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2596 | } else { /* No data transfer required */ |
| 2597 | cblk->buflen = 0; |
| 2598 | cblk->sglen = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | } |
| 2600 | } |
| 2601 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2602 | /** |
Lee Jones | 100ec49 | 2021-03-17 09:12:04 +0000 | [diff] [blame] | 2603 | * i91u_queuecommand_lck - Queue a new command if possible |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2604 | * @cmd: SCSI command block from the mid layer |
| 2605 | * @done: Completion handler |
| 2606 | * |
| 2607 | * Attempts to queue a new command with the host adapter. Will return |
| 2608 | * zero if successful or indicate a host busy condition if not (which |
| 2609 | * will cause the mid layer to call us again later with the command) |
| 2610 | */ |
| 2611 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 2612 | static int i91u_queuecommand_lck(struct scsi_cmnd *cmd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | void (*done)(struct scsi_cmnd *)) |
| 2614 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2615 | struct initio_host *host = (struct initio_host *) cmd->device->host->hostdata; |
| 2616 | struct scsi_ctrl_blk *cmnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | |
| 2618 | cmd->scsi_done = done; |
| 2619 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2620 | cmnd = initio_alloc_scb(host); |
| 2621 | if (!cmnd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | return SCSI_MLQUEUE_HOST_BUSY; |
| 2623 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2624 | initio_build_scb(host, cmnd, cmd); |
| 2625 | initio_exec_scb(host, cmnd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | return 0; |
| 2627 | } |
| 2628 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 2629 | static DEF_SCSI_QCMD(i91u_queuecommand) |
| 2630 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2631 | /** |
| 2632 | * i91u_bus_reset - reset the SCSI bus |
| 2633 | * @cmnd: Command block we want to trigger the reset for |
| 2634 | * |
| 2635 | * Initiate a SCSI bus reset sequence |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2637 | |
| 2638 | static int i91u_bus_reset(struct scsi_cmnd * cmnd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2640 | struct initio_host *host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2642 | host = (struct initio_host *) cmnd->device->host->hostdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2644 | spin_lock_irq(cmnd->device->host->host_lock); |
| 2645 | initio_reset_scsi(host, 0); |
| 2646 | spin_unlock_irq(cmnd->device->host->host_lock); |
Jeff Garzik | 68b3aa7 | 2005-05-28 07:56:31 -0400 | [diff] [blame] | 2647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | return SUCCESS; |
| 2649 | } |
| 2650 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2651 | /** |
Lee Jones | 100ec49 | 2021-03-17 09:12:04 +0000 | [diff] [blame] | 2652 | * i91u_biosparam - return the "logical geometry |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2653 | * @sdev: SCSI device |
Lee Jones | 100ec49 | 2021-03-17 09:12:04 +0000 | [diff] [blame] | 2654 | * @dev: Matching block device |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2655 | * @capacity: Sector size of drive |
| 2656 | * @info_array: Return space for BIOS geometry |
| 2657 | * |
| 2658 | * Map the device geometry in a manner compatible with the host |
| 2659 | * controller BIOS behaviour. |
| 2660 | * |
| 2661 | * FIXME: limited to 2^32 sector devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | static int i91u_biosparam(struct scsi_device *sdev, struct block_device *dev, |
| 2665 | sector_t capacity, int *info_array) |
| 2666 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2667 | struct initio_host *host; /* Point to Host adapter control block */ |
| 2668 | struct target_control *tc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2670 | host = (struct initio_host *) sdev->host->hostdata; |
| 2671 | tc = &host->targets[sdev->id]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2673 | if (tc->heads) { |
| 2674 | info_array[0] = tc->heads; |
| 2675 | info_array[1] = tc->sectors; |
| 2676 | info_array[2] = (unsigned long)capacity / tc->heads / tc->sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | } else { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2678 | if (tc->drv_flags & TCF_DRV_255_63) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | info_array[0] = 255; |
| 2680 | info_array[1] = 63; |
| 2681 | info_array[2] = (unsigned long)capacity / 255 / 63; |
| 2682 | } else { |
| 2683 | info_array[0] = 64; |
| 2684 | info_array[1] = 32; |
| 2685 | info_array[2] = (unsigned long)capacity >> 11; |
| 2686 | } |
| 2687 | } |
| 2688 | |
| 2689 | #if defined(DEBUG_BIOSPARAM) |
| 2690 | if (i91u_debug & debug_biosparam) { |
| 2691 | printk("bios geometry: head=%d, sec=%d, cyl=%d\n", |
| 2692 | info_array[0], info_array[1], info_array[2]); |
| 2693 | printk("WARNING: check, if the bios geometry is correct.\n"); |
| 2694 | } |
| 2695 | #endif |
| 2696 | |
| 2697 | return 0; |
| 2698 | } |
| 2699 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2700 | /** |
| 2701 | * i91u_unmap_scb - Unmap a command |
| 2702 | * @pci_dev: PCI device the command is for |
| 2703 | * @cmnd: The command itself |
| 2704 | * |
| 2705 | * Unmap any PCI mapping/IOMMU resources allocated when the command |
| 2706 | * was mapped originally as part of initio_build_scb |
| 2707 | */ |
| 2708 | |
| 2709 | static void i91u_unmap_scb(struct pci_dev *pci_dev, struct scsi_cmnd *cmnd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | { |
| 2711 | /* auto sense buffer */ |
| 2712 | if (cmnd->SCp.ptr) { |
| 2713 | dma_unmap_single(&pci_dev->dev, |
| 2714 | (dma_addr_t)((unsigned long)cmnd->SCp.ptr), |
| 2715 | SENSE_SIZE, DMA_FROM_DEVICE); |
| 2716 | cmnd->SCp.ptr = NULL; |
| 2717 | } |
| 2718 | |
| 2719 | /* request buffer */ |
FUJITA Tomonori | a258c85 | 2007-05-21 14:58:30 +0900 | [diff] [blame] | 2720 | if (scsi_sg_count(cmnd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | dma_unmap_single(&pci_dev->dev, cmnd->SCp.dma_handle, |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2722 | sizeof(struct sg_entry) * TOTAL_SG_ENTRY, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | DMA_BIDIRECTIONAL); |
| 2724 | |
FUJITA Tomonori | a258c85 | 2007-05-21 14:58:30 +0900 | [diff] [blame] | 2725 | scsi_dma_unmap(cmnd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | } |
| 2727 | } |
| 2728 | |
Lee Jones | 100ec49 | 2021-03-17 09:12:04 +0000 | [diff] [blame] | 2729 | /* |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2730 | * i91uSCBPost - SCSI callback |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2731 | * |
| 2732 | * This is callback routine be called when tulip finish one |
| 2733 | * SCSI command. |
| 2734 | */ |
| 2735 | |
| 2736 | static void i91uSCBPost(u8 * host_mem, u8 * cblk_mem) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2738 | struct scsi_cmnd *cmnd; /* Pointer to SCSI request block */ |
| 2739 | struct initio_host *host; |
| 2740 | struct scsi_ctrl_blk *cblk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2742 | host = (struct initio_host *) host_mem; |
| 2743 | cblk = (struct scsi_ctrl_blk *) cblk_mem; |
| 2744 | if ((cmnd = cblk->srb) == NULL) { |
| 2745 | printk(KERN_ERR "i91uSCBPost: SRB pointer is empty\n"); |
| 2746 | WARN_ON(1); |
| 2747 | initio_release_scb(host, cblk); /* Release SCB for current channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | return; |
| 2749 | } |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2750 | |
| 2751 | /* |
| 2752 | * Remap the firmware error status into a mid layer one |
| 2753 | */ |
| 2754 | switch (cblk->hastat) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | case 0x0: |
| 2756 | case 0xa: /* Linked command complete without error and linked normally */ |
| 2757 | case 0xb: /* Linked command complete without error interrupt generated */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2758 | cblk->hastat = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | break; |
| 2760 | |
| 2761 | case 0x11: /* Selection time out-The initiator selection or target |
| 2762 | reselection was not complete within the SCSI Time out period */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2763 | cblk->hastat = DID_TIME_OUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | break; |
| 2765 | |
| 2766 | case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus |
| 2767 | phase sequence was requested by the target. The host adapter |
| 2768 | will generate a SCSI Reset Condition, notifying the host with |
| 2769 | a SCRD interrupt */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2770 | cblk->hastat = DID_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | break; |
| 2772 | |
| 2773 | case 0x1a: /* SCB Aborted. 07/21/98 */ |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2774 | cblk->hastat = DID_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | break; |
| 2776 | |
| 2777 | case 0x12: /* Data overrun/underrun-The target attempted to transfer more data |
| 2778 | than was allocated by the Data Length field or the sum of the |
| 2779 | Scatter / Gather Data Length fields. */ |
| 2780 | case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */ |
| 2781 | case 0x16: /* Invalid SCB Operation Code. */ |
| 2782 | |
| 2783 | default: |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2784 | printk("ini9100u: %x %x\n", cblk->hastat, cblk->tastat); |
| 2785 | cblk->hastat = DID_ERROR; /* Couldn't find any better */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | break; |
| 2787 | } |
| 2788 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2789 | cmnd->result = cblk->tastat | (cblk->hastat << 16); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2790 | i91u_unmap_scb(host->pci_dev, cmnd); |
| 2791 | cmnd->scsi_done(cmnd); /* Notify system DONE */ |
| 2792 | initio_release_scb(host, cblk); /* Release SCB for current channel */ |
| 2793 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2795 | static struct scsi_host_template initio_template = { |
| 2796 | .proc_name = "INI9100U", |
| 2797 | .name = "Initio INI-9X00U/UW SCSI device driver", |
| 2798 | .queuecommand = i91u_queuecommand, |
| 2799 | .eh_bus_reset_handler = i91u_bus_reset, |
| 2800 | .bios_param = i91u_biosparam, |
| 2801 | .can_queue = MAX_TARGETS * i91u_MAXQUEUE, |
| 2802 | .this_id = 1, |
| 2803 | .sg_tablesize = SG_ALL, |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2804 | }; |
| 2805 | |
| 2806 | static int initio_probe_one(struct pci_dev *pdev, |
| 2807 | const struct pci_device_id *id) |
| 2808 | { |
| 2809 | struct Scsi_Host *shost; |
| 2810 | struct initio_host *host; |
| 2811 | u32 reg; |
| 2812 | u16 bios_seg; |
| 2813 | struct scsi_ctrl_blk *scb, *tmp, *prev = NULL /* silence gcc */; |
| 2814 | int num_scb, i, error; |
| 2815 | |
| 2816 | error = pci_enable_device(pdev); |
| 2817 | if (error) |
| 2818 | return error; |
| 2819 | |
| 2820 | pci_read_config_dword(pdev, 0x44, (u32 *) & reg); |
| 2821 | bios_seg = (u16) (reg & 0xFF); |
| 2822 | if (((reg & 0xFF00) >> 8) == 0xFF) |
| 2823 | reg = 0; |
| 2824 | bios_seg = (bios_seg << 8) + ((u16) ((reg & 0xFF00) >> 8)); |
| 2825 | |
Christoph Hellwig | 663b411 | 2018-10-18 15:10:19 +0200 | [diff] [blame] | 2826 | if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2827 | printk(KERN_WARNING "i91u: Could not set 32 bit DMA mask\n"); |
| 2828 | error = -ENODEV; |
| 2829 | goto out_disable_device; |
| 2830 | } |
| 2831 | shost = scsi_host_alloc(&initio_template, sizeof(struct initio_host)); |
| 2832 | if (!shost) { |
| 2833 | printk(KERN_WARNING "initio: Could not allocate host structure.\n"); |
| 2834 | error = -ENOMEM; |
| 2835 | goto out_disable_device; |
| 2836 | } |
| 2837 | host = (struct initio_host *)shost->hostdata; |
| 2838 | memset(host, 0, sizeof(struct initio_host)); |
Alan Cox | 99f1f53 | 2007-12-13 16:14:05 -0800 | [diff] [blame] | 2839 | host->addr = pci_resource_start(pdev, 0); |
Stuart Swales | e2d435e | 2008-01-23 20:00:48 +0000 | [diff] [blame] | 2840 | host->bios_addr = bios_seg; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2841 | |
| 2842 | if (!request_region(host->addr, 256, "i91u")) { |
| 2843 | printk(KERN_WARNING "initio: I/O port range 0x%x is busy.\n", host->addr); |
| 2844 | error = -ENODEV; |
| 2845 | goto out_host_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2848 | if (initio_tag_enable) /* 1.01i */ |
| 2849 | num_scb = MAX_TARGETS * i91u_MAXQUEUE; |
| 2850 | else |
| 2851 | num_scb = MAX_TARGETS + 3; /* 1-tape, 1-CD_ROM, 1- extra */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2853 | for (; num_scb >= MAX_TARGETS + 3; num_scb--) { |
| 2854 | i = num_scb * sizeof(struct scsi_ctrl_blk); |
| 2855 | if ((scb = kzalloc(i, GFP_DMA)) != NULL) |
| 2856 | break; |
| 2857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2859 | if (!scb) { |
| 2860 | printk(KERN_WARNING "initio: Cannot allocate SCB array.\n"); |
| 2861 | error = -ENOMEM; |
| 2862 | goto out_release_region; |
| 2863 | } |
| 2864 | |
Alan Cox | e9e42fa | 2007-10-15 20:51:32 +0100 | [diff] [blame] | 2865 | host->pci_dev = pdev; |
| 2866 | |
Stuart Swales | e2d435e | 2008-01-23 20:00:48 +0000 | [diff] [blame] | 2867 | host->semaph = 1; |
| 2868 | spin_lock_init(&host->semaph_lock); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2869 | host->num_scbs = num_scb; |
| 2870 | host->scb = scb; |
| 2871 | host->next_pending = scb; |
| 2872 | host->next_avail = scb; |
| 2873 | for (i = 0, tmp = scb; i < num_scb; i++, tmp++) { |
| 2874 | tmp->tagid = i; |
| 2875 | if (i != 0) |
| 2876 | prev->next = tmp; |
| 2877 | prev = tmp; |
| 2878 | } |
| 2879 | prev->next = NULL; |
| 2880 | host->scb_end = tmp; |
| 2881 | host->first_avail = scb; |
| 2882 | host->last_avail = prev; |
Alan Cox | e9e42fa | 2007-10-15 20:51:32 +0100 | [diff] [blame] | 2883 | spin_lock_init(&host->avail_lock); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2884 | |
Stuart Swales | e2d435e | 2008-01-23 20:00:48 +0000 | [diff] [blame] | 2885 | initio_init(host, phys_to_virt(((u32)bios_seg << 4))); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2886 | |
| 2887 | host->jsstatus0 = 0; |
| 2888 | |
| 2889 | shost->io_port = host->addr; |
| 2890 | shost->n_io_port = 0xff; |
| 2891 | shost->can_queue = num_scb; /* 03/05/98 */ |
| 2892 | shost->unique_id = host->addr; |
| 2893 | shost->max_id = host->max_tar; |
| 2894 | shost->max_lun = 32; /* 10/21/97 */ |
| 2895 | shost->irq = pdev->irq; |
| 2896 | shost->this_id = host->scsi_id; /* Assign HCS index */ |
| 2897 | shost->base = host->addr; |
| 2898 | shost->sg_tablesize = TOTAL_SG_ENTRY; |
| 2899 | |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 2900 | error = request_irq(pdev->irq, i91u_intr, IRQF_SHARED, "i91u", shost); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2901 | if (error < 0) { |
| 2902 | printk(KERN_WARNING "initio: Unable to request IRQ %d\n", pdev->irq); |
| 2903 | goto out_free_scbs; |
| 2904 | } |
| 2905 | |
| 2906 | pci_set_drvdata(pdev, shost); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2907 | |
| 2908 | error = scsi_add_host(shost, &pdev->dev); |
| 2909 | if (error) |
| 2910 | goto out_free_irq; |
| 2911 | scsi_scan_host(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | return 0; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2913 | out_free_irq: |
| 2914 | free_irq(pdev->irq, shost); |
| 2915 | out_free_scbs: |
| 2916 | kfree(host->scb); |
| 2917 | out_release_region: |
| 2918 | release_region(host->addr, 256); |
| 2919 | out_host_put: |
| 2920 | scsi_host_put(shost); |
| 2921 | out_disable_device: |
| 2922 | pci_disable_device(pdev); |
| 2923 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2926 | /** |
| 2927 | * initio_remove_one - control shutdown |
| 2928 | * @pdev: PCI device being released |
| 2929 | * |
| 2930 | * Release the resources assigned to this adapter after it has |
| 2931 | * finished being used. |
| 2932 | */ |
| 2933 | |
| 2934 | static void initio_remove_one(struct pci_dev *pdev) |
| 2935 | { |
| 2936 | struct Scsi_Host *host = pci_get_drvdata(pdev); |
| 2937 | struct initio_host *s = (struct initio_host *)host->hostdata; |
| 2938 | scsi_remove_host(host); |
| 2939 | free_irq(pdev->irq, host); |
| 2940 | release_region(s->addr, 256); |
| 2941 | scsi_host_put(host); |
| 2942 | pci_disable_device(pdev); |
| 2943 | } |
| 2944 | |
| 2945 | MODULE_LICENSE("GPL"); |
| 2946 | |
| 2947 | static struct pci_device_id initio_pci_tbl[] = { |
| 2948 | {PCI_VENDOR_ID_INIT, 0x9500, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 2949 | {PCI_VENDOR_ID_INIT, 0x9400, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 2950 | {PCI_VENDOR_ID_INIT, 0x9401, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 2951 | {PCI_VENDOR_ID_INIT, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 2952 | {PCI_VENDOR_ID_DOMEX, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 2953 | {0,} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | }; |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2955 | MODULE_DEVICE_TABLE(pci, initio_pci_tbl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2957 | static struct pci_driver initio_pci_driver = { |
| 2958 | .name = "initio", |
| 2959 | .id_table = initio_pci_tbl, |
| 2960 | .probe = initio_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 2961 | .remove = initio_remove_one, |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2962 | }; |
Liu Shixin | ca57b06 | 2020-09-17 15:10:45 +0800 | [diff] [blame] | 2963 | module_pci_driver(initio_pci_driver); |
Alan Cox | 72d39fe | 2007-05-21 15:06:43 +0100 | [diff] [blame] | 2964 | |
| 2965 | MODULE_DESCRIPTION("Initio INI-9X00U/UW SCSI device driver"); |
| 2966 | MODULE_AUTHOR("Initio Corporation"); |
| 2967 | MODULE_LICENSE("GPL"); |