Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * NCR 5380 generic driver routines. These should make it *trivial* |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 3 | * to implement 5380 SCSI drivers under Linux with a non-trantor |
| 4 | * architecture. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 6 | * Note that these routines also work with NR53c400 family chips. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Copyright 1993, Drew Eckhardt |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 9 | * Visionary Computing |
| 10 | * (Unix and Linux consulting and custom programming) |
| 11 | * drew@colorado.edu |
| 12 | * +1 (303) 666-5836 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 14 | * For more information, please consult |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * |
| 16 | * NCR 5380 Family |
| 17 | * SCSI Protocol Controller |
| 18 | * Databook |
| 19 | * |
| 20 | * NCR Microelectronics |
| 21 | * 1635 Aeroplaza Drive |
| 22 | * Colorado Springs, CO 80916 |
| 23 | * 1+ (719) 578-3400 |
| 24 | * 1+ (800) 334-5454 |
| 25 | */ |
| 26 | |
| 27 | /* |
Finn Thain | c16df32 | 2016-01-03 16:06:08 +1100 | [diff] [blame] | 28 | * With contributions from Ray Van Tassle, Ingmar Baumgart, |
| 29 | * Ronald van Cuijlenborg, Alan Cox and others. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | */ |
| 31 | |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 32 | /* Ported to Atari by Roman Hodek and others. */ |
| 33 | |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 34 | /* Adapted for the Sun 3 by Sam Creasey. */ |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | * Design |
| 38 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 39 | * This is a generic 5380 driver. To use it on a different platform, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | * one simply writes appropriate system specific macros (ie, data |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 41 | * transfer - some PC's will use the I/O bus, 68K's must use |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | * memory mapped) and drops this file in their 'C' wrapper. |
| 43 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 44 | * As far as command queueing, two queues are maintained for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | * each 5380 in the system - commands that haven't been issued yet, |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 46 | * and commands that are currently executing. This means that an |
| 47 | * unlimited number of commands may be queued, letting |
| 48 | * more commands propagate from the higher driver levels giving higher |
| 49 | * throughput. Note that both I_T_L and I_T_L_Q nexuses are supported, |
| 50 | * allowing multiple commands to propagate all the way to a SCSI-II device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | * while a command is already executing. |
| 52 | * |
| 53 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 54 | * Issues specific to the NCR5380 : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 56 | * When used in a PIO or pseudo-dma mode, the NCR5380 is a braindead |
| 57 | * piece of hardware that requires you to sit in a loop polling for |
| 58 | * the REQ signal as long as you are connected. Some devices are |
| 59 | * brain dead (ie, many TEXEL CD ROM drives) and won't disconnect |
Finn Thain | 686f399 | 2016-01-03 16:05:26 +1100 | [diff] [blame] | 60 | * while doing long seek operations. [...] These |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | * broken devices are the exception rather than the rule and I'd rather |
| 62 | * spend my time optimizing for the normal case. |
| 63 | * |
| 64 | * Architecture : |
| 65 | * |
| 66 | * At the heart of the design is a coroutine, NCR5380_main, |
| 67 | * which is started from a workqueue for each NCR5380 host in the |
| 68 | * system. It attempts to establish I_T_L or I_T_L_Q nexuses by |
| 69 | * removing the commands from the issue queue and calling |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 70 | * NCR5380_select() if a nexus is not established. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | * |
| 72 | * Once a nexus is established, the NCR5380_information_transfer() |
| 73 | * phase goes through the various phases as instructed by the target. |
| 74 | * if the target goes into MSG IN and sends a DISCONNECT message, |
| 75 | * the command structure is placed into the per instance disconnected |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 76 | * queue, and NCR5380_main tries to find more work. If the target is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * idle for too long, the system will try to sleep. |
| 78 | * |
| 79 | * If a command has disconnected, eventually an interrupt will trigger, |
| 80 | * calling NCR5380_intr() which will in turn call NCR5380_reselect |
| 81 | * to reestablish a nexus. This will run main if necessary. |
| 82 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 83 | * On command termination, the done function will be called as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | * appropriate. |
| 85 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 86 | * SCSI pointers are maintained in the SCp field of SCSI command |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | * structures, being initialized after the command is connected |
| 88 | * in NCR5380_select, and set as appropriate in NCR5380_information_transfer. |
| 89 | * Note that in violation of the standard, an implicit SAVE POINTERS operation |
| 90 | * is done, since some BROKEN disks fail to issue an explicit SAVE POINTERS. |
| 91 | */ |
| 92 | |
| 93 | /* |
| 94 | * Using this file : |
| 95 | * This file a skeleton Linux SCSI driver for the NCR 5380 series |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 96 | * of chips. To use it, you write an architecture specific functions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | * and macros and include this file in your driver. |
| 98 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 99 | * These macros control options : |
| 100 | * AUTOPROBE_IRQ - if defined, the NCR5380_probe_irq() function will be |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 101 | * defined. |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 102 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 104 | * for commands that return with a CHECK CONDITION status. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | * |
| 106 | * DIFFERENTIAL - if defined, NCR53c81 chips will use external differential |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 107 | * transceivers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * |
| 109 | * DONT_USE_INTR - if defined, never use interrupts, even if we probe or |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 110 | * override-configure an IRQ. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * PSEUDO_DMA - if defined, PSEUDO DMA is used during the data transfer phases. |
| 113 | * |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 114 | * REAL_DMA - if defined, REAL DMA is used during the data transfer phases. |
| 115 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | * These macros MUST be defined : |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 117 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | * NCR5380_read(register) - read from the specified register |
| 119 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 120 | * NCR5380_write(register, value) - write to the specific register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 122 | * NCR5380_implementation_fields - additional fields needed for this |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 123 | * specific implementation of the NCR5380 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * |
| 125 | * Either real DMA *or* pseudo DMA may be implemented |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | * NCR5380_dma_write_setup(instance, src, count) - initialize |
| 128 | * NCR5380_dma_read_setup(instance, dst, count) - initialize |
| 129 | * NCR5380_dma_residual(instance); - residual count |
| 130 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | * The generic driver is initialized by calling NCR5380_init(instance), |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 132 | * after setting the appropriate host specific fields and ID. If the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance, |
| 134 | * possible) function may be used. |
| 135 | */ |
| 136 | |
Finn Thain | e5d55d1 | 2016-03-23 21:10:16 +1100 | [diff] [blame] | 137 | #ifndef NCR5380_io_delay |
| 138 | #define NCR5380_io_delay(x) |
| 139 | #endif |
| 140 | |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 141 | #ifndef NCR5380_acquire_dma_irq |
| 142 | #define NCR5380_acquire_dma_irq(x) (1) |
| 143 | #endif |
| 144 | |
| 145 | #ifndef NCR5380_release_dma_irq |
| 146 | #define NCR5380_release_dma_irq(x) |
| 147 | #endif |
| 148 | |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 149 | static int do_abort(struct Scsi_Host *); |
| 150 | static void do_reset(struct Scsi_Host *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Finn Thain | c16df32 | 2016-01-03 16:06:08 +1100 | [diff] [blame] | 152 | /** |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 153 | * initialize_SCp - init the scsi pointer field |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 154 | * @cmd: command block to set up |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 156 | * Set up the internal fields in the SCSI command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | */ |
| 158 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 159 | static inline void initialize_SCp(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 161 | /* |
| 162 | * Initialize the Scsi Pointer field so that all of the commands in the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | * various queues are valid. |
| 164 | */ |
| 165 | |
Boaz Harrosh | 9e0fe44 | 2007-11-05 11:23:35 +0200 | [diff] [blame] | 166 | if (scsi_bufflen(cmd)) { |
| 167 | cmd->SCp.buffer = scsi_sglist(cmd); |
| 168 | cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1; |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 169 | cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | cmd->SCp.this_residual = cmd->SCp.buffer->length; |
| 171 | } else { |
| 172 | cmd->SCp.buffer = NULL; |
| 173 | cmd->SCp.buffers_residual = 0; |
Boaz Harrosh | 9e0fe44 | 2007-11-05 11:23:35 +0200 | [diff] [blame] | 174 | cmd->SCp.ptr = NULL; |
| 175 | cmd->SCp.this_residual = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 177 | |
| 178 | cmd->SCp.Status = 0; |
| 179 | cmd->SCp.Message = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 183 | * NCR5380_poll_politely2 - wait for two chip register values |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 184 | * @instance: controller to poll |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 185 | * @reg1: 5380 register to poll |
| 186 | * @bit1: Bitmask to check |
| 187 | * @val1: Expected value |
| 188 | * @reg2: Second 5380 register to poll |
| 189 | * @bit2: Second bitmask to check |
| 190 | * @val2: Second expected value |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 191 | * @wait: Time-out in jiffies |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | * |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 193 | * Polls the chip in a reasonably efficient manner waiting for an |
| 194 | * event to occur. After a short quick poll we begin to yield the CPU |
| 195 | * (if possible). In irq contexts the time-out is arbitrarily limited. |
| 196 | * Callers may hold locks as long as they are held in irq mode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | * |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 198 | * Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 201 | static int NCR5380_poll_politely2(struct Scsi_Host *instance, |
| 202 | int reg1, int bit1, int val1, |
| 203 | int reg2, int bit2, int val2, int wait) |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 204 | { |
| 205 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 206 | unsigned long deadline = jiffies + wait; |
| 207 | unsigned long n; |
| 208 | |
| 209 | /* Busy-wait for up to 10 ms */ |
| 210 | n = min(10000U, jiffies_to_usecs(wait)); |
| 211 | n *= hostdata->accesses_per_ms; |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 212 | n /= 2000; |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 213 | do { |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 214 | if ((NCR5380_read(reg1) & bit1) == val1) |
| 215 | return 0; |
| 216 | if ((NCR5380_read(reg2) & bit2) == val2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return 0; |
| 218 | cpu_relax(); |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 219 | } while (n--); |
| 220 | |
| 221 | if (irqs_disabled() || in_interrupt()) |
| 222 | return -ETIMEDOUT; |
| 223 | |
| 224 | /* Repeatedly sleep for 1 ms until deadline */ |
| 225 | while (time_is_after_jiffies(deadline)) { |
| 226 | schedule_timeout_uninterruptible(1); |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 227 | if ((NCR5380_read(reg1) & bit1) == val1) |
| 228 | return 0; |
| 229 | if ((NCR5380_read(reg2) & bit2) == val2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | return -ETIMEDOUT; |
| 234 | } |
| 235 | |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 236 | static inline int NCR5380_poll_politely(struct Scsi_Host *instance, |
| 237 | int reg, int bit, int val, int wait) |
| 238 | { |
| 239 | return NCR5380_poll_politely2(instance, reg, bit, val, |
| 240 | reg, bit, val, wait); |
| 241 | } |
| 242 | |
viro@ZenIV.linux.org.uk | 185a7a1 | 2005-09-07 23:18:24 +0100 | [diff] [blame] | 243 | #if NDEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | static struct { |
| 245 | unsigned char mask; |
| 246 | const char *name; |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 247 | } signals[] = { |
| 248 | {SR_DBP, "PARITY"}, |
| 249 | {SR_RST, "RST"}, |
| 250 | {SR_BSY, "BSY"}, |
| 251 | {SR_REQ, "REQ"}, |
| 252 | {SR_MSG, "MSG"}, |
| 253 | {SR_CD, "CD"}, |
| 254 | {SR_IO, "IO"}, |
| 255 | {SR_SEL, "SEL"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | {0, NULL} |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 257 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | basrs[] = { |
Finn Thain | 12866b9 | 2016-03-23 21:10:25 +1100 | [diff] [blame^] | 259 | {BASR_END_DMA_TRANSFER, "END OF DMA"}, |
| 260 | {BASR_DRQ, "DRQ"}, |
| 261 | {BASR_PARITY_ERROR, "PARITY ERROR"}, |
| 262 | {BASR_IRQ, "IRQ"}, |
| 263 | {BASR_PHASE_MATCH, "PHASE MATCH"}, |
| 264 | {BASR_BUSY_ERROR, "BUSY ERROR"}, |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 265 | {BASR_ATN, "ATN"}, |
| 266 | {BASR_ACK, "ACK"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | {0, NULL} |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 268 | }, |
| 269 | icrs[] = { |
| 270 | {ICR_ASSERT_RST, "ASSERT RST"}, |
Finn Thain | 12866b9 | 2016-03-23 21:10:25 +1100 | [diff] [blame^] | 271 | {ICR_ARBITRATION_PROGRESS, "ARB. IN PROGRESS"}, |
| 272 | {ICR_ARBITRATION_LOST, "LOST ARB."}, |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 273 | {ICR_ASSERT_ACK, "ASSERT ACK"}, |
| 274 | {ICR_ASSERT_BSY, "ASSERT BSY"}, |
| 275 | {ICR_ASSERT_SEL, "ASSERT SEL"}, |
| 276 | {ICR_ASSERT_ATN, "ASSERT ATN"}, |
| 277 | {ICR_ASSERT_DATA, "ASSERT DATA"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | {0, NULL} |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 279 | }, |
| 280 | mrs[] = { |
Finn Thain | 12866b9 | 2016-03-23 21:10:25 +1100 | [diff] [blame^] | 281 | {MR_BLOCK_DMA_MODE, "BLOCK DMA MODE"}, |
| 282 | {MR_TARGET, "TARGET"}, |
| 283 | {MR_ENABLE_PAR_CHECK, "PARITY CHECK"}, |
| 284 | {MR_ENABLE_PAR_INTR, "PARITY INTR"}, |
| 285 | {MR_ENABLE_EOP_INTR, "EOP INTR"}, |
| 286 | {MR_MONITOR_BSY, "MONITOR BSY"}, |
| 287 | {MR_DMA_MODE, "DMA MODE"}, |
| 288 | {MR_ARBITRATE, "ARBITRATE"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | {0, NULL} |
| 290 | }; |
| 291 | |
| 292 | /** |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 293 | * NCR5380_print - print scsi bus signals |
| 294 | * @instance: adapter state to dump |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 296 | * Print the SCSI bus signals for debugging purposes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | */ |
| 298 | |
| 299 | static void NCR5380_print(struct Scsi_Host *instance) |
| 300 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | unsigned char status, data, basr, mr, icr, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | data = NCR5380_read(CURRENT_SCSI_DATA_REG); |
| 304 | status = NCR5380_read(STATUS_REG); |
| 305 | mr = NCR5380_read(MODE_REG); |
| 306 | icr = NCR5380_read(INITIATOR_COMMAND_REG); |
| 307 | basr = NCR5380_read(BUS_AND_STATUS_REG); |
| 308 | |
Finn Thain | 12866b9 | 2016-03-23 21:10:25 +1100 | [diff] [blame^] | 309 | printk(KERN_DEBUG "SR = 0x%02x : ", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | for (i = 0; signals[i].mask; ++i) |
| 311 | if (status & signals[i].mask) |
Finn Thain | 12866b9 | 2016-03-23 21:10:25 +1100 | [diff] [blame^] | 312 | printk(KERN_CONT "%s, ", signals[i].name); |
| 313 | printk(KERN_CONT "\nBASR = 0x%02x : ", basr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | for (i = 0; basrs[i].mask; ++i) |
| 315 | if (basr & basrs[i].mask) |
Finn Thain | 12866b9 | 2016-03-23 21:10:25 +1100 | [diff] [blame^] | 316 | printk(KERN_CONT "%s, ", basrs[i].name); |
| 317 | printk(KERN_CONT "\nICR = 0x%02x : ", icr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | for (i = 0; icrs[i].mask; ++i) |
| 319 | if (icr & icrs[i].mask) |
Finn Thain | 12866b9 | 2016-03-23 21:10:25 +1100 | [diff] [blame^] | 320 | printk(KERN_CONT "%s, ", icrs[i].name); |
| 321 | printk(KERN_CONT "\nMR = 0x%02x : ", mr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | for (i = 0; mrs[i].mask; ++i) |
| 323 | if (mr & mrs[i].mask) |
Finn Thain | 12866b9 | 2016-03-23 21:10:25 +1100 | [diff] [blame^] | 324 | printk(KERN_CONT "%s, ", mrs[i].name); |
| 325 | printk(KERN_CONT "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 328 | static struct { |
| 329 | unsigned char value; |
| 330 | const char *name; |
| 331 | } phases[] = { |
| 332 | {PHASE_DATAOUT, "DATAOUT"}, |
| 333 | {PHASE_DATAIN, "DATAIN"}, |
| 334 | {PHASE_CMDOUT, "CMDOUT"}, |
| 335 | {PHASE_STATIN, "STATIN"}, |
| 336 | {PHASE_MSGOUT, "MSGOUT"}, |
| 337 | {PHASE_MSGIN, "MSGIN"}, |
| 338 | {PHASE_UNKNOWN, "UNKNOWN"} |
| 339 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Finn Thain | c16df32 | 2016-01-03 16:06:08 +1100 | [diff] [blame] | 341 | /** |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 342 | * NCR5380_print_phase - show SCSI phase |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 343 | * @instance: adapter to dump |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 345 | * Print the current SCSI phase for debugging purposes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | */ |
| 347 | |
| 348 | static void NCR5380_print_phase(struct Scsi_Host *instance) |
| 349 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | unsigned char status; |
| 351 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | status = NCR5380_read(STATUS_REG); |
| 354 | if (!(status & SR_REQ)) |
Finn Thain | 6a6ff4a | 2016-01-03 16:06:04 +1100 | [diff] [blame] | 355 | shost_printk(KERN_DEBUG, instance, "REQ not asserted, phase unknown.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | else { |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 357 | for (i = 0; (phases[i].value != PHASE_UNKNOWN) && |
| 358 | (phases[i].value != (status & PHASE_MASK)); ++i) |
| 359 | ; |
Finn Thain | 6a6ff4a | 2016-01-03 16:06:04 +1100 | [diff] [blame] | 360 | shost_printk(KERN_DEBUG, instance, "phase %s\n", phases[i].name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | #endif |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Finn Thain | d5f7e65 | 2016-01-03 16:05:03 +1100 | [diff] [blame] | 366 | static int probe_irq __initdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
| 368 | /** |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 369 | * probe_intr - helper for IRQ autoprobe |
| 370 | * @irq: interrupt number |
| 371 | * @dev_id: unused |
| 372 | * @regs: unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 374 | * Set a flag to indicate the IRQ in question was received. This is |
| 375 | * used by the IRQ probe code. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | */ |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 377 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 378 | static irqreturn_t __init probe_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
| 380 | probe_irq = irq; |
| 381 | return IRQ_HANDLED; |
| 382 | } |
| 383 | |
| 384 | /** |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 385 | * NCR5380_probe_irq - find the IRQ of an NCR5380 |
| 386 | * @instance: NCR5380 controller |
| 387 | * @possible: bitmask of ISA IRQ lines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 389 | * Autoprobe for the IRQ line used by the NCR5380 by triggering an IRQ |
| 390 | * and then looking to see what interrupt actually turned up. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | */ |
| 392 | |
Andrew Morton | 702809c | 2007-05-23 14:41:56 -0700 | [diff] [blame] | 393 | static int __init __maybe_unused NCR5380_probe_irq(struct Scsi_Host *instance, |
| 394 | int possible) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Finn Thain | e8a6014 | 2016-01-03 16:05:54 +1100 | [diff] [blame] | 396 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | unsigned long timeout; |
| 398 | int trying_irqs, i, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 400 | for (trying_irqs = 0, i = 1, mask = 2; i < 16; ++i, mask <<= 1) |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 401 | if ((mask & possible) && (request_irq(i, &probe_intr, 0, "NCR-probe", NULL) == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | trying_irqs |= mask; |
| 403 | |
Nicholas Mc Guire | 4e5a800 | 2015-02-04 13:30:20 -0500 | [diff] [blame] | 404 | timeout = jiffies + msecs_to_jiffies(250); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 405 | probe_irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | /* |
| 408 | * A interrupt is triggered whenever BSY = false, SEL = true |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 409 | * and a bit set in the SELECT_ENABLE_REG is asserted on the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | * SCSI bus. |
| 411 | * |
| 412 | * Note that the bus is only driven when the phase control signals |
| 413 | * (I/O, C/D, and MSG) match those in the TCR, so we must reset that |
| 414 | * to zero. |
| 415 | */ |
| 416 | |
| 417 | NCR5380_write(TARGET_COMMAND_REG, 0); |
| 418 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
| 419 | NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask); |
| 420 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA | ICR_ASSERT_SEL); |
| 421 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 422 | while (probe_irq == NO_IRQ && time_before(jiffies, timeout)) |
Nishanth Aravamudan | a9a3047 | 2005-11-07 01:01:20 -0800 | [diff] [blame] | 423 | schedule_timeout_uninterruptible(1); |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | NCR5380_write(SELECT_ENABLE_REG, 0); |
| 426 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 427 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 428 | for (i = 1, mask = 2; i < 16; ++i, mask <<= 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | if (trying_irqs & mask) |
| 430 | free_irq(i, NULL); |
| 431 | |
| 432 | return probe_irq; |
| 433 | } |
| 434 | |
| 435 | /** |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 436 | * NCR58380_info - report driver and host information |
| 437 | * @instance: relevant scsi host instance |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 439 | * For use as the host template info() handler. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | */ |
| 441 | |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 442 | static const char *NCR5380_info(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 444 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 445 | |
| 446 | return hostdata->info; |
| 447 | } |
| 448 | |
| 449 | static void prepare_info(struct Scsi_Host *instance) |
| 450 | { |
| 451 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 452 | |
| 453 | snprintf(hostdata->info, sizeof(hostdata->info), |
| 454 | "%s, io_port 0x%lx, n_io_port %d, " |
| 455 | "base 0x%lx, irq %d, " |
| 456 | "can_queue %d, cmd_per_lun %d, " |
| 457 | "sg_tablesize %d, this_id %d, " |
Finn Thain | be3f412 | 2016-01-03 16:05:50 +1100 | [diff] [blame] | 458 | "flags { %s%s%s}, " |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 459 | "options { %s} ", |
| 460 | instance->hostt->name, instance->io_port, instance->n_io_port, |
| 461 | instance->base, instance->irq, |
| 462 | instance->can_queue, instance->cmd_per_lun, |
| 463 | instance->sg_tablesize, instance->this_id, |
Finn Thain | 1bb4600 | 2016-03-23 21:10:14 +1100 | [diff] [blame] | 464 | hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "", |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 465 | hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "", |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 466 | hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : "", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | #ifdef AUTOPROBE_IRQ |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 468 | "AUTOPROBE_IRQ " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | #ifdef DIFFERENTIAL |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 471 | "DIFFERENTIAL " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | #ifdef PARITY |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 474 | "PARITY " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | #endif |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 476 | ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /** |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 480 | * NCR5380_init - initialise an NCR5380 |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 481 | * @instance: adapter to configure |
| 482 | * @flags: control flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 484 | * Initializes *instance and corresponding 5380 chip, |
| 485 | * with flags OR'd into the initial flags value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 487 | * Notes : I assume that the host, hostno, and id bits have been |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 488 | * set correctly. I don't care about the irq and other fields. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 490 | * Returns 0 for success |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | */ |
| 492 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 493 | static int NCR5380_init(struct Scsi_Host *instance, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | { |
Finn Thain | e8a6014 | 2016-01-03 16:05:54 +1100 | [diff] [blame] | 495 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | b6488f9 | 2016-01-03 16:05:08 +1100 | [diff] [blame] | 496 | int i; |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 497 | unsigned long deadline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Finn Thain | ae5e33a | 2016-03-23 21:10:23 +1100 | [diff] [blame] | 499 | instance->max_lun = 7; |
| 500 | |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 501 | hostdata->host = instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | hostdata->id_mask = 1 << instance->this_id; |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 503 | hostdata->id_higher_mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | for (i = hostdata->id_mask; i <= 0x80; i <<= 1) |
| 505 | if (i > hostdata->id_mask) |
| 506 | hostdata->id_higher_mask |= i; |
| 507 | for (i = 0; i < 8; ++i) |
| 508 | hostdata->busy[i] = 0; |
Finn Thain | e4dec68 | 2016-03-23 21:10:12 +1100 | [diff] [blame] | 509 | hostdata->dma_len = 0; |
| 510 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 511 | spin_lock_init(&hostdata->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | hostdata->connected = NULL; |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 513 | hostdata->sensing = NULL; |
| 514 | INIT_LIST_HEAD(&hostdata->autosense); |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 515 | INIT_LIST_HEAD(&hostdata->unissued); |
| 516 | INIT_LIST_HEAD(&hostdata->disconnected); |
| 517 | |
Finn Thain | 55181be | 2016-01-03 16:05:42 +1100 | [diff] [blame] | 518 | hostdata->flags = flags; |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 519 | |
Finn Thain | 8d8601a | 2016-01-03 16:05:37 +1100 | [diff] [blame] | 520 | INIT_WORK(&hostdata->main_task, NCR5380_main); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 521 | hostdata->work_q = alloc_workqueue("ncr5380_%d", |
| 522 | WQ_UNBOUND | WQ_MEM_RECLAIM, |
| 523 | 1, instance->host_no); |
| 524 | if (!hostdata->work_q) |
| 525 | return -ENOMEM; |
| 526 | |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 527 | prepare_info(instance); |
| 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 530 | NCR5380_write(MODE_REG, MR_BASE); |
| 531 | NCR5380_write(TARGET_COMMAND_REG, 0); |
| 532 | NCR5380_write(SELECT_ENABLE_REG, 0); |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 533 | |
| 534 | /* Calibrate register polling loop */ |
| 535 | i = 0; |
| 536 | deadline = jiffies + 1; |
| 537 | do { |
| 538 | cpu_relax(); |
| 539 | } while (time_is_after_jiffies(deadline)); |
| 540 | deadline += msecs_to_jiffies(256); |
| 541 | do { |
| 542 | NCR5380_read(STATUS_REG); |
| 543 | ++i; |
| 544 | cpu_relax(); |
| 545 | } while (time_is_after_jiffies(deadline)); |
| 546 | hostdata->accesses_per_ms = i / 256; |
| 547 | |
Finn Thain | b6488f9 | 2016-01-03 16:05:08 +1100 | [diff] [blame] | 548 | return 0; |
| 549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Finn Thain | b6488f9 | 2016-01-03 16:05:08 +1100 | [diff] [blame] | 551 | /** |
| 552 | * NCR5380_maybe_reset_bus - Detect and correct bus wedge problems. |
| 553 | * @instance: adapter to check |
| 554 | * |
| 555 | * If the system crashed, it may have crashed with a connected target and |
| 556 | * the SCSI bus busy. Check for BUS FREE phase. If not, try to abort the |
| 557 | * currently established nexus, which we know nothing about. Failing that |
| 558 | * do a bus reset. |
| 559 | * |
| 560 | * Note that a bus reset will cause the chip to assert IRQ. |
| 561 | * |
| 562 | * Returns 0 if successful, otherwise -ENXIO. |
| 563 | */ |
| 564 | |
| 565 | static int NCR5380_maybe_reset_bus(struct Scsi_Host *instance) |
| 566 | { |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 567 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | b6488f9 | 2016-01-03 16:05:08 +1100 | [diff] [blame] | 568 | int pass; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | for (pass = 1; (NCR5380_read(STATUS_REG) & SR_BSY) && pass <= 6; ++pass) { |
| 571 | switch (pass) { |
| 572 | case 1: |
| 573 | case 3: |
| 574 | case 5: |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 575 | shost_printk(KERN_ERR, instance, "SCSI bus busy, waiting up to five seconds\n"); |
| 576 | NCR5380_poll_politely(instance, |
| 577 | STATUS_REG, SR_BSY, 0, 5 * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | break; |
| 579 | case 2: |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 580 | shost_printk(KERN_ERR, instance, "bus busy, attempting abort\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | do_abort(instance); |
| 582 | break; |
| 583 | case 4: |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 584 | shost_printk(KERN_ERR, instance, "bus busy, attempting reset\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | do_reset(instance); |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 586 | /* Wait after a reset; the SCSI standard calls for |
| 587 | * 250ms, we wait 500ms to be on the safe side. |
| 588 | * But some Toshiba CD-ROMs need ten times that. |
| 589 | */ |
| 590 | if (hostdata->flags & FLAG_TOSHIBA_DELAY) |
| 591 | msleep(2500); |
| 592 | else |
| 593 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | break; |
| 595 | case 6: |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 596 | shost_printk(KERN_ERR, instance, "bus locked solid\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | return -ENXIO; |
| 598 | } |
| 599 | } |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | /** |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 604 | * NCR5380_exit - remove an NCR5380 |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 605 | * @instance: adapter to remove |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 606 | * |
| 607 | * Assumes that no more work can be queued (e.g. by NCR5380_intr). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | */ |
| 609 | |
Randy Dunlap | a43cf0f | 2008-01-22 21:39:33 -0800 | [diff] [blame] | 610 | static void NCR5380_exit(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
Finn Thain | e8a6014 | 2016-01-03 16:05:54 +1100 | [diff] [blame] | 612 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Finn Thain | 8d8601a | 2016-01-03 16:05:37 +1100 | [diff] [blame] | 614 | cancel_work_sync(&hostdata->main_task); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 615 | destroy_workqueue(hostdata->work_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /** |
Finn Thain | 677e019 | 2016-01-03 16:05:59 +1100 | [diff] [blame] | 619 | * complete_cmd - finish processing a command and return it to the SCSI ML |
| 620 | * @instance: the host instance |
| 621 | * @cmd: command to complete |
| 622 | */ |
| 623 | |
| 624 | static void complete_cmd(struct Scsi_Host *instance, |
| 625 | struct scsi_cmnd *cmd) |
| 626 | { |
| 627 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 628 | |
| 629 | dsprintk(NDEBUG_QUEUES, instance, "complete_cmd: cmd %p\n", cmd); |
| 630 | |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 631 | if (hostdata->sensing == cmd) { |
| 632 | /* Autosense processing ends here */ |
| 633 | if ((cmd->result & 0xff) != SAM_STAT_GOOD) { |
| 634 | scsi_eh_restore_cmnd(cmd, &hostdata->ses); |
| 635 | set_host_byte(cmd, DID_ERROR); |
| 636 | } else |
| 637 | scsi_eh_restore_cmnd(cmd, &hostdata->ses); |
| 638 | hostdata->sensing = NULL; |
| 639 | } |
| 640 | |
Finn Thain | 677e019 | 2016-01-03 16:05:59 +1100 | [diff] [blame] | 641 | hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); |
| 642 | |
| 643 | cmd->scsi_done(cmd); |
| 644 | } |
| 645 | |
| 646 | /** |
Finn Thain | 1bb4058 | 2016-01-03 16:05:29 +1100 | [diff] [blame] | 647 | * NCR5380_queue_command - queue a command |
| 648 | * @instance: the relevant SCSI adapter |
| 649 | * @cmd: SCSI command |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | * |
Finn Thain | 1bb4058 | 2016-01-03 16:05:29 +1100 | [diff] [blame] | 651 | * cmd is added to the per-instance issue queue, with minor |
| 652 | * twiddling done to the host specific fields of cmd. If the |
| 653 | * main coroutine is not running, it is restarted. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | */ |
| 655 | |
Finn Thain | 1bb4058 | 2016-01-03 16:05:29 +1100 | [diff] [blame] | 656 | static int NCR5380_queue_command(struct Scsi_Host *instance, |
| 657 | struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { |
Finn Thain | 1bb4058 | 2016-01-03 16:05:29 +1100 | [diff] [blame] | 659 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 660 | struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd); |
Finn Thain | 1bb4058 | 2016-01-03 16:05:29 +1100 | [diff] [blame] | 661 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
| 663 | #if (NDEBUG & NDEBUG_NO_WRITE) |
| 664 | switch (cmd->cmnd[0]) { |
| 665 | case WRITE_6: |
| 666 | case WRITE_10: |
Finn Thain | dbb6b35 | 2016-01-03 16:05:53 +1100 | [diff] [blame] | 667 | shost_printk(KERN_DEBUG, instance, "WRITE attempted with NDEBUG_NO_WRITE set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | cmd->result = (DID_ERROR << 16); |
Finn Thain | 1bb4058 | 2016-01-03 16:05:29 +1100 | [diff] [blame] | 669 | cmd->scsi_done(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | return 0; |
| 671 | } |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 672 | #endif /* (NDEBUG & NDEBUG_NO_WRITE) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | cmd->result = 0; |
| 675 | |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 676 | if (!NCR5380_acquire_dma_irq(instance)) |
| 677 | return SCSI_MLQUEUE_HOST_BUSY; |
| 678 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 679 | spin_lock_irqsave(&hostdata->lock, flags); |
Finn Thain | 1bb4058 | 2016-01-03 16:05:29 +1100 | [diff] [blame] | 680 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 681 | /* |
| 682 | * Insert the cmd into the issue queue. Note that REQUEST SENSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | * commands are added to the head of the queue since any command will |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 684 | * clear the contingent allegiance condition that exists and the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | * sense data is only guaranteed to be valid while the condition exists. |
| 686 | */ |
| 687 | |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 688 | if (cmd->cmnd[0] == REQUEST_SENSE) |
| 689 | list_add(&ncmd->list, &hostdata->unissued); |
| 690 | else |
| 691 | list_add_tail(&ncmd->list, &hostdata->unissued); |
| 692 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 693 | spin_unlock_irqrestore(&hostdata->lock, flags); |
Finn Thain | 1bb4058 | 2016-01-03 16:05:29 +1100 | [diff] [blame] | 694 | |
Finn Thain | dbb6b35 | 2016-01-03 16:05:53 +1100 | [diff] [blame] | 695 | dsprintk(NDEBUG_QUEUES, instance, "command %p added to %s of queue\n", |
| 696 | cmd, (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | /* Kick off command processing */ |
Finn Thain | 8d8601a | 2016-01-03 16:05:37 +1100 | [diff] [blame] | 699 | queue_work(hostdata->work_q, &hostdata->main_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | return 0; |
| 701 | } |
| 702 | |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 703 | static inline void maybe_release_dma_irq(struct Scsi_Host *instance) |
| 704 | { |
| 705 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 706 | |
| 707 | /* Caller does the locking needed to set & test these data atomically */ |
| 708 | if (list_empty(&hostdata->disconnected) && |
| 709 | list_empty(&hostdata->unissued) && |
| 710 | list_empty(&hostdata->autosense) && |
| 711 | !hostdata->connected && |
| 712 | !hostdata->selecting) |
| 713 | NCR5380_release_dma_irq(instance); |
| 714 | } |
| 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | /** |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 717 | * dequeue_next_cmd - dequeue a command for processing |
| 718 | * @instance: the scsi host instance |
| 719 | * |
| 720 | * Priority is given to commands on the autosense queue. These commands |
| 721 | * need autosense because of a CHECK CONDITION result. |
| 722 | * |
| 723 | * Returns a command pointer if a command is found for a target that is |
| 724 | * not already busy. Otherwise returns NULL. |
| 725 | */ |
| 726 | |
| 727 | static struct scsi_cmnd *dequeue_next_cmd(struct Scsi_Host *instance) |
| 728 | { |
| 729 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 730 | struct NCR5380_cmd *ncmd; |
| 731 | struct scsi_cmnd *cmd; |
| 732 | |
Finn Thain | 8d5dbec | 2016-02-23 10:07:09 +1100 | [diff] [blame] | 733 | if (hostdata->sensing || list_empty(&hostdata->autosense)) { |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 734 | list_for_each_entry(ncmd, &hostdata->unissued, list) { |
| 735 | cmd = NCR5380_to_scmd(ncmd); |
| 736 | dsprintk(NDEBUG_QUEUES, instance, "dequeue: cmd=%p target=%d busy=0x%02x lun=%llu\n", |
| 737 | cmd, scmd_id(cmd), hostdata->busy[scmd_id(cmd)], cmd->device->lun); |
| 738 | |
| 739 | if (!(hostdata->busy[scmd_id(cmd)] & (1 << cmd->device->lun))) { |
| 740 | list_del(&ncmd->list); |
| 741 | dsprintk(NDEBUG_QUEUES, instance, |
| 742 | "dequeue: removed %p from issue queue\n", cmd); |
| 743 | return cmd; |
| 744 | } |
| 745 | } |
| 746 | } else { |
| 747 | /* Autosense processing begins here */ |
| 748 | ncmd = list_first_entry(&hostdata->autosense, |
| 749 | struct NCR5380_cmd, list); |
| 750 | list_del(&ncmd->list); |
| 751 | cmd = NCR5380_to_scmd(ncmd); |
| 752 | dsprintk(NDEBUG_QUEUES, instance, |
| 753 | "dequeue: removed %p from autosense queue\n", cmd); |
| 754 | scsi_eh_prep_cmnd(cmd, &hostdata->ses, NULL, 0, ~0); |
| 755 | hostdata->sensing = cmd; |
| 756 | return cmd; |
| 757 | } |
| 758 | return NULL; |
| 759 | } |
| 760 | |
| 761 | static void requeue_cmd(struct Scsi_Host *instance, struct scsi_cmnd *cmd) |
| 762 | { |
| 763 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 764 | struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd); |
| 765 | |
Finn Thain | 8d5dbec | 2016-02-23 10:07:09 +1100 | [diff] [blame] | 766 | if (hostdata->sensing == cmd) { |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 767 | scsi_eh_restore_cmnd(cmd, &hostdata->ses); |
| 768 | list_add(&ncmd->list, &hostdata->autosense); |
| 769 | hostdata->sensing = NULL; |
| 770 | } else |
| 771 | list_add(&ncmd->list, &hostdata->unissued); |
| 772 | } |
| 773 | |
| 774 | /** |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 775 | * NCR5380_main - NCR state machines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 777 | * NCR5380_main is a coroutine that runs as long as more work can |
| 778 | * be done on the NCR5380 host adapters in a system. Both |
| 779 | * NCR5380_queue_command() and NCR5380_intr() will try to start it |
| 780 | * in case it is not running. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | */ |
| 782 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 783 | static void NCR5380_main(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 785 | struct NCR5380_hostdata *hostdata = |
Finn Thain | 8d8601a | 2016-01-03 16:05:37 +1100 | [diff] [blame] | 786 | container_of(work, struct NCR5380_hostdata, main_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | struct Scsi_Host *instance = hostdata->host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | int done; |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | done = 1; |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 792 | |
Finn Thain | 0a4e361 | 2016-01-03 16:06:07 +1100 | [diff] [blame] | 793 | spin_lock_irq(&hostdata->lock); |
Finn Thain | ccf6efd | 2016-02-23 10:07:08 +1100 | [diff] [blame] | 794 | while (!hostdata->connected && !hostdata->selecting) { |
| 795 | struct scsi_cmnd *cmd = dequeue_next_cmd(instance); |
| 796 | |
| 797 | if (!cmd) |
| 798 | break; |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 799 | |
| 800 | dsprintk(NDEBUG_MAIN, instance, "main: dequeued %p\n", cmd); |
| 801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | /* |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 803 | * Attempt to establish an I_T_L nexus here. |
| 804 | * On success, instance->hostdata->connected is set. |
| 805 | * On failure, we must add the command back to the |
| 806 | * issue queue so we can keep trying. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | */ |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 808 | /* |
| 809 | * REQUEST SENSE commands are issued without tagged |
| 810 | * queueing, even on SCSI-II devices because the |
| 811 | * contingent allegiance condition exists for the |
| 812 | * entire unit. |
| 813 | */ |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 814 | |
Finn Thain | ccf6efd | 2016-02-23 10:07:08 +1100 | [diff] [blame] | 815 | if (!NCR5380_select(instance, cmd)) { |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 816 | dsprintk(NDEBUG_MAIN, instance, "main: select complete\n"); |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 817 | maybe_release_dma_irq(instance); |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 818 | } else { |
| 819 | dsprintk(NDEBUG_MAIN | NDEBUG_QUEUES, instance, |
| 820 | "main: select failed, returning %p to queue\n", cmd); |
| 821 | requeue_cmd(instance, cmd); |
| 822 | } |
| 823 | } |
Finn Thain | e4dec68 | 2016-03-23 21:10:12 +1100 | [diff] [blame] | 824 | if (hostdata->connected && !hostdata->dma_len) { |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 825 | dsprintk(NDEBUG_MAIN, instance, "main: performing information transfer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | NCR5380_information_transfer(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | done = 0; |
Finn Thain | 1d3db59 | 2016-01-03 16:05:24 +1100 | [diff] [blame] | 828 | } |
Finn Thain | 0a4e361 | 2016-01-03 16:06:07 +1100 | [diff] [blame] | 829 | spin_unlock_irq(&hostdata->lock); |
| 830 | if (!done) |
| 831 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } while (!done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 835 | /* |
| 836 | * NCR5380_dma_complete - finish DMA transfer |
| 837 | * @instance: the scsi host instance |
| 838 | * |
| 839 | * Called by the interrupt handler when DMA finishes or a phase |
| 840 | * mismatch occurs (which would end the DMA transfer). |
| 841 | */ |
| 842 | |
| 843 | static void NCR5380_dma_complete(struct Scsi_Host *instance) |
| 844 | { |
| 845 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 846 | int transferred; |
| 847 | unsigned char **data; |
| 848 | int *count; |
| 849 | int saved_data = 0, overrun = 0; |
| 850 | unsigned char p; |
| 851 | |
| 852 | if (hostdata->read_overruns) { |
| 853 | p = hostdata->connected->SCp.phase; |
| 854 | if (p & SR_IO) { |
| 855 | udelay(10); |
| 856 | if ((NCR5380_read(BUS_AND_STATUS_REG) & |
| 857 | (BASR_PHASE_MATCH | BASR_ACK)) == |
| 858 | (BASR_PHASE_MATCH | BASR_ACK)) { |
| 859 | saved_data = NCR5380_read(INPUT_DATA_REG); |
| 860 | overrun = 1; |
| 861 | dsprintk(NDEBUG_DMA, instance, "read overrun handled\n"); |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 866 | #ifdef CONFIG_SUN3 |
| 867 | if ((sun3scsi_dma_finish(rq_data_dir(hostdata->connected->request)))) { |
| 868 | pr_err("scsi%d: overrun in UDC counter -- not prepared to deal with this!\n", |
| 869 | instance->host_no); |
| 870 | BUG(); |
| 871 | } |
| 872 | |
| 873 | if ((NCR5380_read(BUS_AND_STATUS_REG) & (BASR_PHASE_MATCH | BASR_ACK)) == |
| 874 | (BASR_PHASE_MATCH | BASR_ACK)) { |
| 875 | pr_err("scsi%d: BASR %02x\n", instance->host_no, |
| 876 | NCR5380_read(BUS_AND_STATUS_REG)); |
| 877 | pr_err("scsi%d: bus stuck in data phase -- probably a single byte overrun!\n", |
| 878 | instance->host_no); |
| 879 | BUG(); |
| 880 | } |
| 881 | #endif |
| 882 | |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 883 | NCR5380_write(MODE_REG, MR_BASE); |
| 884 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 885 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 886 | |
| 887 | transferred = hostdata->dma_len - NCR5380_dma_residual(instance); |
| 888 | hostdata->dma_len = 0; |
| 889 | |
| 890 | data = (unsigned char **)&hostdata->connected->SCp.ptr; |
| 891 | count = &hostdata->connected->SCp.this_residual; |
| 892 | *data += transferred; |
| 893 | *count -= transferred; |
| 894 | |
| 895 | if (hostdata->read_overruns) { |
| 896 | int cnt, toPIO; |
| 897 | |
| 898 | if ((NCR5380_read(STATUS_REG) & PHASE_MASK) == p && (p & SR_IO)) { |
| 899 | cnt = toPIO = hostdata->read_overruns; |
| 900 | if (overrun) { |
| 901 | dsprintk(NDEBUG_DMA, instance, |
| 902 | "Got an input overrun, using saved byte\n"); |
| 903 | *(*data)++ = saved_data; |
| 904 | (*count)--; |
| 905 | cnt--; |
| 906 | toPIO--; |
| 907 | } |
| 908 | if (toPIO > 0) { |
| 909 | dsprintk(NDEBUG_DMA, instance, |
| 910 | "Doing %d byte PIO to 0x%p\n", cnt, *data); |
| 911 | NCR5380_transfer_pio(instance, &p, &cnt, data); |
| 912 | *count -= toPIO - cnt; |
| 913 | } |
| 914 | } |
| 915 | } |
| 916 | } |
| 917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | #ifndef DONT_USE_INTR |
| 919 | |
| 920 | /** |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 921 | * NCR5380_intr - generic NCR5380 irq handler |
| 922 | * @irq: interrupt number |
| 923 | * @dev_id: device info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | * |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 925 | * Handle interrupts, reestablishing I_T_L or I_T_L_Q nexuses |
| 926 | * from the disconnected queue, and restarting NCR5380_main() |
| 927 | * as required. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | * |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 929 | * The chip can assert IRQ in any of six different conditions. The IRQ flag |
| 930 | * is then cleared by reading the Reset Parity/Interrupt Register (RPIR). |
| 931 | * Three of these six conditions are latched in the Bus and Status Register: |
| 932 | * - End of DMA (cleared by ending DMA Mode) |
| 933 | * - Parity error (cleared by reading RPIR) |
| 934 | * - Loss of BSY (cleared by reading RPIR) |
| 935 | * Two conditions have flag bits that are not latched: |
| 936 | * - Bus phase mismatch (non-maskable in DMA Mode, cleared by ending DMA Mode) |
| 937 | * - Bus reset (non-maskable) |
| 938 | * The remaining condition has no flag bit at all: |
| 939 | * - Selection/reselection |
| 940 | * |
| 941 | * Hence, establishing the cause(s) of any interrupt is partly guesswork. |
| 942 | * In "The DP8490 and DP5380 Comparison Guide", National Semiconductor |
| 943 | * claimed that "the design of the [DP8490] interrupt logic ensures |
| 944 | * interrupts will not be lost (they can be on the DP5380)." |
| 945 | * The L5380/53C80 datasheet from LOGIC Devices has more details. |
| 946 | * |
| 947 | * Checking for bus reset by reading RST is futile because of interrupt |
| 948 | * latency, but a bus reset will reset chip logic. Checking for parity error |
| 949 | * is unnecessary because that interrupt is never enabled. A Loss of BSY |
| 950 | * condition will clear DMA Mode. We can tell when this occurs because the |
| 951 | * the Busy Monitor interrupt is enabled together with DMA Mode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | */ |
| 953 | |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 954 | static irqreturn_t NCR5380_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | { |
Jeff Garzik | baa9aac | 2007-12-13 16:14:14 -0800 | [diff] [blame] | 956 | struct Scsi_Host *instance = dev_id; |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 957 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 958 | int handled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | unsigned char basr; |
| 960 | unsigned long flags; |
| 961 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 962 | spin_lock_irqsave(&hostdata->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 964 | basr = NCR5380_read(BUS_AND_STATUS_REG); |
| 965 | if (basr & BASR_IRQ) { |
| 966 | unsigned char mr = NCR5380_read(MODE_REG); |
| 967 | unsigned char sr = NCR5380_read(STATUS_REG); |
| 968 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 969 | dsprintk(NDEBUG_INTR, instance, "IRQ %d, BASR 0x%02x, SR 0x%02x, MR 0x%02x\n", |
| 970 | irq, basr, sr, mr); |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 971 | |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 972 | if ((mr & MR_DMA_MODE) || (mr & MR_MONITOR_BSY)) { |
| 973 | /* Probably End of DMA, Phase Mismatch or Loss of BSY. |
| 974 | * We ack IRQ after clearing Mode Register. Workarounds |
| 975 | * for End of DMA errata need to happen in DMA Mode. |
| 976 | */ |
| 977 | |
| 978 | dsprintk(NDEBUG_INTR, instance, "interrupt in DMA mode\n"); |
| 979 | |
| 980 | if (hostdata->connected) { |
| 981 | NCR5380_dma_complete(instance); |
| 982 | queue_work(hostdata->work_q, &hostdata->main_task); |
| 983 | } else { |
| 984 | NCR5380_write(MODE_REG, MR_BASE); |
| 985 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 986 | } |
| 987 | } else if ((NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_mask) && |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 988 | (sr & (SR_SEL | SR_IO | SR_BSY | SR_RST)) == (SR_SEL | SR_IO)) { |
| 989 | /* Probably reselected */ |
| 990 | NCR5380_write(SELECT_ENABLE_REG, 0); |
| 991 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 992 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 993 | dsprintk(NDEBUG_INTR, instance, "interrupt with SEL and IO\n"); |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 994 | |
| 995 | if (!hostdata->connected) { |
| 996 | NCR5380_reselect(instance); |
| 997 | queue_work(hostdata->work_q, &hostdata->main_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | } |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 999 | if (!hostdata->connected) |
| 1000 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
| 1001 | } else { |
| 1002 | /* Probably Bus Reset */ |
| 1003 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 1004 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1005 | dsprintk(NDEBUG_INTR, instance, "unknown interrupt\n"); |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1006 | #ifdef SUN3_SCSI_VME |
| 1007 | dregs->csr |= CSR_DMA_ENABLE; |
| 1008 | #endif |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1009 | } |
| 1010 | handled = 1; |
| 1011 | } else { |
| 1012 | shost_printk(KERN_NOTICE, instance, "interrupt without IRQ bit\n"); |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1013 | #ifdef SUN3_SCSI_VME |
| 1014 | dregs->csr |= CSR_DMA_ENABLE; |
| 1015 | #endif |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1016 | } |
| 1017 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1018 | spin_unlock_irqrestore(&hostdata->lock, flags); |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1019 | |
| 1020 | return IRQ_RETVAL(handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1023 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1025 | /* |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 1026 | * Function : int NCR5380_select(struct Scsi_Host *instance, |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1027 | * struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | * |
| 1029 | * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command, |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1030 | * including ARBITRATION, SELECTION, and initial message out for |
| 1031 | * IDENTIFY and queue messages. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1033 | * Inputs : instance - instantiation of the 5380 driver on which this |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1034 | * target lives, cmd - SCSI command to execute. |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1035 | * |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1036 | * Returns cmd if selection failed but should be retried, |
| 1037 | * NULL if selection failed and should not be retried, or |
| 1038 | * NULL if selection succeeded (hostdata->connected == cmd). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1040 | * Side effects : |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1041 | * If bus busy, arbitration failed, etc, NCR5380_select() will exit |
| 1042 | * with registers as they should have been on entry - ie |
| 1043 | * SELECT_ENABLE will be set appropriately, the NCR5380 |
| 1044 | * will cease to drive any SCSI bus signals. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1046 | * If successful : I_T_L or I_T_L_Q nexus will be established, |
| 1047 | * instance->connected will be set to cmd. |
| 1048 | * SELECT interrupt will be disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1050 | * If failed (no target) : cmd->scsi_done() will be called, and the |
| 1051 | * cmd->result host byte set to DID_BAD_TARGET. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | */ |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1053 | |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1054 | static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance, |
| 1055 | struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | { |
Finn Thain | e8a6014 | 2016-01-03 16:05:54 +1100 | [diff] [blame] | 1057 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | unsigned char tmp[3], phase; |
| 1059 | unsigned char *data; |
| 1060 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | NCR5380_dprint(NDEBUG_ARBITRATION, instance); |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1064 | dsprintk(NDEBUG_ARBITRATION, instance, "starting arbitration, id = %d\n", |
| 1065 | instance->this_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1067 | /* |
| 1068 | * Arbitration and selection phases are slow and involve dropping the |
| 1069 | * lock, so we have to watch out for EH. An exception handler may |
| 1070 | * change 'selecting' to NULL. This function will then return NULL |
| 1071 | * so that the caller will forget about 'cmd'. (During information |
| 1072 | * transfer phases, EH may change 'connected' to NULL.) |
| 1073 | */ |
| 1074 | hostdata->selecting = cmd; |
| 1075 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1076 | /* |
| 1077 | * Set the phase bits to 0, otherwise the NCR5380 won't drive the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | * data bus during SELECTION. |
| 1079 | */ |
| 1080 | |
| 1081 | NCR5380_write(TARGET_COMMAND_REG, 0); |
| 1082 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1083 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | * Start arbitration. |
| 1085 | */ |
| 1086 | |
| 1087 | NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask); |
| 1088 | NCR5380_write(MODE_REG, MR_ARBITRATE); |
| 1089 | |
Finn Thain | 55500d9 | 2016-01-03 16:05:35 +1100 | [diff] [blame] | 1090 | /* The chip now waits for BUS FREE phase. Then after the 800 ns |
| 1091 | * Bus Free Delay, arbitration will begin. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | */ |
| 1093 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1094 | spin_unlock_irq(&hostdata->lock); |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 1095 | err = NCR5380_poll_politely2(instance, MODE_REG, MR_ARBITRATE, 0, |
| 1096 | INITIATOR_COMMAND_REG, ICR_ARBITRATION_PROGRESS, |
| 1097 | ICR_ARBITRATION_PROGRESS, HZ); |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1098 | spin_lock_irq(&hostdata->lock); |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 1099 | if (!(NCR5380_read(MODE_REG) & MR_ARBITRATE)) { |
| 1100 | /* Reselection interrupt */ |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1101 | goto out; |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 1102 | } |
Finn Thain | ccf6efd | 2016-02-23 10:07:08 +1100 | [diff] [blame] | 1103 | if (!hostdata->selecting) { |
| 1104 | /* Command was aborted */ |
| 1105 | NCR5380_write(MODE_REG, MR_BASE); |
| 1106 | goto out; |
| 1107 | } |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame] | 1108 | if (err < 0) { |
| 1109 | NCR5380_write(MODE_REG, MR_BASE); |
| 1110 | shost_printk(KERN_ERR, instance, |
| 1111 | "select: arbitration timeout\n"); |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1112 | goto out; |
Finn Thain | 55500d9 | 2016-01-03 16:05:35 +1100 | [diff] [blame] | 1113 | } |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1114 | spin_unlock_irq(&hostdata->lock); |
Finn Thain | 55500d9 | 2016-01-03 16:05:35 +1100 | [diff] [blame] | 1115 | |
| 1116 | /* The SCSI-2 arbitration delay is 2.4 us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | udelay(3); |
| 1118 | |
| 1119 | /* Check for lost arbitration */ |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1120 | if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) || |
| 1121 | (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) || |
| 1122 | (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | NCR5380_write(MODE_REG, MR_BASE); |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1124 | dsprintk(NDEBUG_ARBITRATION, instance, "lost arbitration, deasserting MR_ARBITRATE\n"); |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1125 | spin_lock_irq(&hostdata->lock); |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1126 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | } |
Finn Thain | cf13b08 | 2016-01-03 16:05:18 +1100 | [diff] [blame] | 1128 | |
| 1129 | /* After/during arbitration, BSY should be asserted. |
| 1130 | * IBM DPES-31080 Version S31Q works now |
| 1131 | * Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman) |
| 1132 | */ |
| 1133 | NCR5380_write(INITIATOR_COMMAND_REG, |
| 1134 | ICR_BASE | ICR_ASSERT_SEL | ICR_ASSERT_BSY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1136 | /* |
| 1137 | * Again, bus clear + bus settle time is 1.2us, however, this is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | * a minimum so we'll udelay ceil(1.2) |
| 1139 | */ |
| 1140 | |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 1141 | if (hostdata->flags & FLAG_TOSHIBA_DELAY) |
| 1142 | udelay(15); |
| 1143 | else |
| 1144 | udelay(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1146 | spin_lock_irq(&hostdata->lock); |
| 1147 | |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 1148 | /* NCR5380_reselect() clears MODE_REG after a reselection interrupt */ |
| 1149 | if (!(NCR5380_read(MODE_REG) & MR_ARBITRATE)) |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1150 | goto out; |
| 1151 | |
| 1152 | if (!hostdata->selecting) { |
| 1153 | NCR5380_write(MODE_REG, MR_BASE); |
| 1154 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1155 | goto out; |
| 1156 | } |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 1157 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1158 | dsprintk(NDEBUG_ARBITRATION, instance, "won arbitration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1160 | /* |
| 1161 | * Now that we have won arbitration, start Selection process, asserting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | * the host and target ID's on the SCSI bus. |
| 1163 | */ |
| 1164 | |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1165 | NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask | (1 << scmd_id(cmd))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1167 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | * Raise ATN while SEL is true before BSY goes false from arbitration, |
| 1169 | * since this is the only way to guarantee that we'll get a MESSAGE OUT |
| 1170 | * phase immediately after selection. |
| 1171 | */ |
| 1172 | |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1173 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY | |
| 1174 | ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | NCR5380_write(MODE_REG, MR_BASE); |
| 1176 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1177 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | * Reselect interrupts must be turned off prior to the dropping of BSY, |
| 1179 | * otherwise we will trigger an interrupt. |
| 1180 | */ |
| 1181 | NCR5380_write(SELECT_ENABLE_REG, 0); |
| 1182 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1183 | spin_unlock_irq(&hostdata->lock); |
| 1184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | /* |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1186 | * The initiator shall then wait at least two deskew delays and release |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | * the BSY signal. |
| 1188 | */ |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1189 | udelay(1); /* wingel -- wait two bus deskew delay >2*45ns */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
| 1191 | /* Reset BSY */ |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1192 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA | |
| 1193 | ICR_ASSERT_ATN | ICR_ASSERT_SEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1195 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | * Something weird happens when we cease to drive BSY - looks |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1197 | * like the board/chip is letting us do another read before the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | * appropriate propagation delay has expired, and we're confusing |
| 1199 | * a BSY signal from ourselves as the target's response to SELECTION. |
| 1200 | * |
| 1201 | * A small delay (the 'C++' frontend breaks the pipeline with an |
| 1202 | * unnecessary jump, making it work on my 386-33/Trantor T128, the |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1203 | * tighter 'C' code breaks and requires this) solves the problem - |
| 1204 | * the 1 us delay is arbitrary, and only used because this delay will |
| 1205 | * be the same on other platforms and since it works here, it should |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | * work there. |
| 1207 | * |
| 1208 | * wingel suggests that this could be due to failing to wait |
| 1209 | * one deskew delay. |
| 1210 | */ |
| 1211 | |
| 1212 | udelay(1); |
| 1213 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1214 | dsprintk(NDEBUG_SELECTION, instance, "selecting target %d\n", scmd_id(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1216 | /* |
| 1217 | * The SCSI specification calls for a 250 ms timeout for the actual |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | * selection. |
| 1219 | */ |
| 1220 | |
Finn Thain | ae753a3 | 2016-01-03 16:05:23 +1100 | [diff] [blame] | 1221 | err = NCR5380_poll_politely(instance, STATUS_REG, SR_BSY, SR_BSY, |
| 1222 | msecs_to_jiffies(250)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) { |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1225 | spin_lock_irq(&hostdata->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1227 | NCR5380_reselect(instance); |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1228 | if (!hostdata->connected) |
| 1229 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
Finn Thain | 6a6ff4a | 2016-01-03 16:06:04 +1100 | [diff] [blame] | 1230 | shost_printk(KERN_ERR, instance, "reselection after won arbitration?\n"); |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1231 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | } |
Finn Thain | ae753a3 | 2016-01-03 16:05:23 +1100 | [diff] [blame] | 1233 | |
| 1234 | if (err < 0) { |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1235 | spin_lock_irq(&hostdata->lock); |
Finn Thain | ae753a3 | 2016-01-03 16:05:23 +1100 | [diff] [blame] | 1236 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Finn Thain | ae753a3 | 2016-01-03 16:05:23 +1100 | [diff] [blame] | 1237 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1238 | /* Can't touch cmd if it has been reclaimed by the scsi ML */ |
| 1239 | if (hostdata->selecting) { |
| 1240 | cmd->result = DID_BAD_TARGET << 16; |
| 1241 | complete_cmd(instance, cmd); |
| 1242 | dsprintk(NDEBUG_SELECTION, instance, "target did not respond within 250ms\n"); |
| 1243 | cmd = NULL; |
| 1244 | } |
| 1245 | goto out; |
Finn Thain | ae753a3 | 2016-01-03 16:05:23 +1100 | [diff] [blame] | 1246 | } |
| 1247 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1248 | /* |
| 1249 | * No less than two deskew delays after the initiator detects the |
| 1250 | * BSY signal is true, it shall release the SEL signal and may |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | * change the DATA BUS. -wingel |
| 1252 | */ |
| 1253 | |
| 1254 | udelay(1); |
| 1255 | |
| 1256 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
| 1257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | /* |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1259 | * Since we followed the SCSI spec, and raised ATN while SEL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | * was true but before BSY was false during selection, the information |
| 1261 | * transfer phase should be a MESSAGE OUT phase so that we can send the |
| 1262 | * IDENTIFY message. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | */ |
| 1264 | |
| 1265 | /* Wait for start of REQ/ACK handshake */ |
| 1266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | err = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ); |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1268 | spin_lock_irq(&hostdata->lock); |
Finn Thain | 1cc160e | 2016-01-03 16:05:32 +1100 | [diff] [blame] | 1269 | if (err < 0) { |
Finn Thain | 55500d9 | 2016-01-03 16:05:35 +1100 | [diff] [blame] | 1270 | shost_printk(KERN_ERR, instance, "select: REQ timeout\n"); |
| 1271 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1273 | goto out; |
| 1274 | } |
| 1275 | if (!hostdata->selecting) { |
| 1276 | do_abort(instance); |
| 1277 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1280 | dsprintk(NDEBUG_SELECTION, instance, "target %d selected, going into MESSAGE OUT phase.\n", |
| 1281 | scmd_id(cmd)); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 1282 | tmp[0] = IDENTIFY(((instance->irq == NO_IRQ) ? 0 : 1), cmd->device->lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | |
| 1284 | len = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | data = tmp; |
| 1286 | phase = PHASE_MSGOUT; |
| 1287 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1288 | dsprintk(NDEBUG_SELECTION, instance, "nexus established.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | /* XXX need to handle errors here */ |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | hostdata->connected = cmd; |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1292 | hostdata->busy[cmd->device->id] |= 1 << cmd->device->lun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1294 | #ifdef SUN3_SCSI_VME |
| 1295 | dregs->csr |= CSR_INTR; |
| 1296 | #endif |
| 1297 | |
Boaz Harrosh | 28424d3 | 2007-09-10 22:37:45 +0300 | [diff] [blame] | 1298 | initialize_SCp(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 1300 | cmd = NULL; |
| 1301 | |
| 1302 | out: |
| 1303 | if (!hostdata->selecting) |
| 1304 | return NULL; |
| 1305 | hostdata->selecting = NULL; |
| 1306 | return cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1309 | /* |
| 1310 | * Function : int NCR5380_transfer_pio (struct Scsi_Host *instance, |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1311 | * unsigned char *phase, int *count, unsigned char **data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | * |
| 1313 | * Purpose : transfers data in given phase using polled I/O |
| 1314 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1315 | * Inputs : instance - instance of driver, *phase - pointer to |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1316 | * what phase is expected, *count - pointer to number of |
| 1317 | * bytes to transfer, **data - pointer to data pointer. |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1318 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | * Returns : -1 when different phase is entered without transferring |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1320 | * maximum number of bytes, 0 if all bytes are transferred or exit |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1321 | * is in same phase. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1323 | * Also, *phase, *count, *data are modified in place. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | * |
| 1325 | * XXX Note : handling for bus free may be useful. |
| 1326 | */ |
| 1327 | |
| 1328 | /* |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1329 | * Note : this code is not as quick as it could be, however it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | * IS 100% reliable, and for the actual data transfer where speed |
| 1331 | * counts, we will always do a pseudo DMA or DMA transfer. |
| 1332 | */ |
| 1333 | |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1334 | static int NCR5380_transfer_pio(struct Scsi_Host *instance, |
| 1335 | unsigned char *phase, int *count, |
| 1336 | unsigned char **data) |
| 1337 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | unsigned char p = *phase, tmp; |
| 1339 | int c = *count; |
| 1340 | unsigned char *d = *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1342 | /* |
| 1343 | * The NCR5380 chip will only drive the SCSI bus when the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | * phase specified in the appropriate bits of the TARGET COMMAND |
| 1345 | * REGISTER match the STATUS REGISTER |
| 1346 | */ |
| 1347 | |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1348 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | do { |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1351 | /* |
| 1352 | * Wait for assertion of REQ, after which the phase bits will be |
| 1353 | * valid |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | */ |
| 1355 | |
Finn Thain | 686f399 | 2016-01-03 16:05:26 +1100 | [diff] [blame] | 1356 | if (NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1359 | dsprintk(NDEBUG_HANDSHAKE, instance, "REQ asserted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | |
| 1361 | /* Check for phase mismatch */ |
Finn Thain | 686f399 | 2016-01-03 16:05:26 +1100 | [diff] [blame] | 1362 | if ((NCR5380_read(STATUS_REG) & PHASE_MASK) != p) { |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1363 | dsprintk(NDEBUG_PIO, instance, "phase mismatch\n"); |
| 1364 | NCR5380_dprint_phase(NDEBUG_PIO, instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | break; |
| 1366 | } |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | /* Do actual transfer from SCSI bus to / from memory */ |
| 1369 | if (!(p & SR_IO)) |
| 1370 | NCR5380_write(OUTPUT_DATA_REG, *d); |
| 1371 | else |
| 1372 | *d = NCR5380_read(CURRENT_SCSI_DATA_REG); |
| 1373 | |
| 1374 | ++d; |
| 1375 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1376 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | * The SCSI standard suggests that in MSGOUT phase, the initiator |
| 1378 | * should drop ATN on the last byte of the message phase |
| 1379 | * after REQ has been asserted for the handshake but before |
| 1380 | * the initiator raises ACK. |
| 1381 | */ |
| 1382 | |
| 1383 | if (!(p & SR_IO)) { |
| 1384 | if (!((p & SR_MSG) && c > 1)) { |
| 1385 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA); |
| 1386 | NCR5380_dprint(NDEBUG_PIO, instance); |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1387 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | |
| 1388 | ICR_ASSERT_DATA | ICR_ASSERT_ACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | } else { |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1390 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | |
| 1391 | ICR_ASSERT_DATA | ICR_ASSERT_ATN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | NCR5380_dprint(NDEBUG_PIO, instance); |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1393 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | |
| 1394 | ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_ACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | } |
| 1396 | } else { |
| 1397 | NCR5380_dprint(NDEBUG_PIO, instance); |
| 1398 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK); |
| 1399 | } |
| 1400 | |
Finn Thain | a2edc4a | 2016-01-03 16:05:27 +1100 | [diff] [blame] | 1401 | if (NCR5380_poll_politely(instance, |
| 1402 | STATUS_REG, SR_REQ, 0, 5 * HZ) < 0) |
| 1403 | break; |
| 1404 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1405 | dsprintk(NDEBUG_HANDSHAKE, instance, "REQ negated, handshake complete\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | |
| 1407 | /* |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1408 | * We have several special cases to consider during REQ/ACK handshaking : |
| 1409 | * 1. We were in MSGOUT phase, and we are on the last byte of the |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1410 | * message. ATN must be dropped as ACK is dropped. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1412 | * 2. We are in a MSGIN phase, and we are on the last byte of the |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1413 | * message. We must exit with ACK asserted, so that the calling |
| 1414 | * code may raise ATN before dropping ACK to reject the message. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | * |
| 1416 | * 3. ACK and ATN are clear and the target may proceed as normal. |
| 1417 | */ |
| 1418 | if (!(p == PHASE_MSGIN && c == 1)) { |
| 1419 | if (p == PHASE_MSGOUT && c > 1) |
| 1420 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
| 1421 | else |
| 1422 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1423 | } |
| 1424 | } while (--c); |
| 1425 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1426 | dsprintk(NDEBUG_PIO, instance, "residual %d\n", c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | |
| 1428 | *count = c; |
| 1429 | *data = d; |
| 1430 | tmp = NCR5380_read(STATUS_REG); |
Finn Thain | a2edc4a | 2016-01-03 16:05:27 +1100 | [diff] [blame] | 1431 | /* The phase read from the bus is valid if either REQ is (already) |
| 1432 | * asserted or if ACK hasn't been released yet. The latter applies if |
| 1433 | * we're in MSG IN, DATA IN or STATUS and all bytes have been received. |
| 1434 | */ |
| 1435 | if ((tmp & SR_REQ) || ((tmp & SR_IO) && c == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | *phase = tmp & PHASE_MASK; |
| 1437 | else |
| 1438 | *phase = PHASE_UNKNOWN; |
| 1439 | |
| 1440 | if (!c || (*phase == p)) |
| 1441 | return 0; |
| 1442 | else |
| 1443 | return -1; |
| 1444 | } |
| 1445 | |
| 1446 | /** |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 1447 | * do_reset - issue a reset command |
| 1448 | * @instance: adapter to reset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | * |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 1450 | * Issue a reset sequence to the NCR5380 and try and get the bus |
| 1451 | * back into sane shape. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | * |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 1453 | * This clears the reset interrupt flag because there may be no handler for |
| 1454 | * it. When the driver is initialized, the NCR5380_intr() handler has not yet |
| 1455 | * been installed. And when in EH we may have released the ST DMA interrupt. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | */ |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1457 | |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 1458 | static void do_reset(struct Scsi_Host *instance) |
| 1459 | { |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 1460 | unsigned long flags; |
| 1461 | |
| 1462 | local_irq_save(flags); |
| 1463 | NCR5380_write(TARGET_COMMAND_REG, |
| 1464 | PHASE_SR_TO_TCR(NCR5380_read(STATUS_REG) & PHASE_MASK)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST); |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 1466 | udelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 1468 | (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 1469 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1472 | /** |
| 1473 | * do_abort - abort the currently established nexus by going to |
| 1474 | * MESSAGE OUT phase and sending an ABORT message. |
| 1475 | * @instance: relevant scsi host instance |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | * |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1477 | * Returns 0 on success, -1 on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | */ |
| 1479 | |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 1480 | static int do_abort(struct Scsi_Host *instance) |
| 1481 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | unsigned char *msgptr, phase, tmp; |
| 1483 | int len; |
| 1484 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
| 1486 | /* Request message out phase */ |
| 1487 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
| 1488 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1489 | /* |
| 1490 | * Wait for the target to indicate a valid phase by asserting |
| 1491 | * REQ. Once this happens, we'll have either a MSGOUT phase |
| 1492 | * and can immediately send the ABORT message, or we'll have some |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | * other phase and will have to source/sink data. |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1494 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | * We really don't care what value was on the bus or what value |
| 1496 | * the target sees, so we just handshake. |
| 1497 | */ |
| 1498 | |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1499 | rc = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, 10 * HZ); |
Finn Thain | 1cc160e | 2016-01-03 16:05:32 +1100 | [diff] [blame] | 1500 | if (rc < 0) |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1501 | goto timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | |
Finn Thain | f35d347 | 2016-01-03 16:05:33 +1100 | [diff] [blame] | 1503 | tmp = NCR5380_read(STATUS_REG) & PHASE_MASK; |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp)); |
| 1506 | |
Finn Thain | f35d347 | 2016-01-03 16:05:33 +1100 | [diff] [blame] | 1507 | if (tmp != PHASE_MSGOUT) { |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1508 | NCR5380_write(INITIATOR_COMMAND_REG, |
| 1509 | ICR_BASE | ICR_ASSERT_ATN | ICR_ASSERT_ACK); |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 1510 | rc = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, 0, 3 * HZ); |
Finn Thain | 1cc160e | 2016-01-03 16:05:32 +1100 | [diff] [blame] | 1511 | if (rc < 0) |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1512 | goto timeout; |
| 1513 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | } |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | tmp = ABORT; |
| 1517 | msgptr = &tmp; |
| 1518 | len = 1; |
| 1519 | phase = PHASE_MSGOUT; |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 1520 | NCR5380_transfer_pio(instance, &phase, &len, &msgptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | |
| 1522 | /* |
| 1523 | * If we got here, and the command completed successfully, |
| 1524 | * we're about to go into bus free state. |
| 1525 | */ |
| 1526 | |
| 1527 | return len ? -1 : 0; |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1528 | |
| 1529 | timeout: |
| 1530 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1531 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1534 | /* |
| 1535 | * Function : int NCR5380_transfer_dma (struct Scsi_Host *instance, |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1536 | * unsigned char *phase, int *count, unsigned char **data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | * |
| 1538 | * Purpose : transfers data in given phase using either real |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1539 | * or pseudo DMA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1541 | * Inputs : instance - instance of driver, *phase - pointer to |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1542 | * what phase is expected, *count - pointer to number of |
| 1543 | * bytes to transfer, **data - pointer to data pointer. |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1544 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | * Returns : -1 when different phase is entered without transferring |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1546 | * maximum number of bytes, 0 if all bytes or transferred or exit |
| 1547 | * is in same phase. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | * |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1549 | * Also, *phase, *count, *data are modified in place. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | */ |
| 1551 | |
| 1552 | |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1553 | static int NCR5380_transfer_dma(struct Scsi_Host *instance, |
| 1554 | unsigned char *phase, int *count, |
| 1555 | unsigned char **data) |
| 1556 | { |
| 1557 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | register int c = *count; |
| 1559 | register unsigned char p = *phase; |
| 1560 | register unsigned char *d = *data; |
| 1561 | unsigned char tmp; |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 1562 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | if ((tmp = (NCR5380_read(STATUS_REG) & PHASE_MASK)) != p) { |
| 1565 | *phase = tmp; |
| 1566 | return -1; |
| 1567 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 1569 | hostdata->connected->SCp.phase = p; |
| 1570 | |
| 1571 | if (p & SR_IO) { |
| 1572 | if (hostdata->read_overruns) |
| 1573 | c -= hostdata->read_overruns; |
| 1574 | else if (hostdata->flags & FLAG_DMA_FIXUP) |
| 1575 | --c; |
| 1576 | } |
| 1577 | |
| 1578 | dsprintk(NDEBUG_DMA, instance, "initializing DMA %s: length %d, address %p\n", |
| 1579 | (p & SR_IO) ? "receive" : "send", c, d); |
| 1580 | |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1581 | #ifdef CONFIG_SUN3 |
| 1582 | /* send start chain */ |
| 1583 | sun3scsi_dma_start(c, *data); |
| 1584 | #endif |
| 1585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p)); |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 1587 | NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_MONITOR_BSY | |
| 1588 | MR_ENABLE_EOP_INTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 1590 | if (!(hostdata->flags & FLAG_LATE_DMA_SETUP)) { |
| 1591 | /* On the Medusa, it is a must to initialize the DMA before |
| 1592 | * starting the NCR. This is also the cleaner way for the TT. |
| 1593 | */ |
| 1594 | if (p & SR_IO) |
| 1595 | result = NCR5380_dma_recv_setup(instance, d, c); |
| 1596 | else |
| 1597 | result = NCR5380_dma_send_setup(instance, d, c); |
| 1598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1600 | /* |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1601 | * On the PAS16 at least I/O recovery delays are not needed here. |
| 1602 | * Everyone else seems to want them. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | */ |
| 1604 | |
| 1605 | if (p & SR_IO) { |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1606 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Finn Thain | e5d55d1 | 2016-03-23 21:10:16 +1100 | [diff] [blame] | 1607 | NCR5380_io_delay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0); |
| 1609 | } else { |
Finn Thain | e5d55d1 | 2016-03-23 21:10:16 +1100 | [diff] [blame] | 1610 | NCR5380_io_delay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA); |
Finn Thain | e5d55d1 | 2016-03-23 21:10:16 +1100 | [diff] [blame] | 1612 | NCR5380_io_delay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | NCR5380_write(START_DMA_SEND_REG, 0); |
Finn Thain | e5d55d1 | 2016-03-23 21:10:16 +1100 | [diff] [blame] | 1614 | NCR5380_io_delay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1617 | #ifdef CONFIG_SUN3 |
| 1618 | #ifdef SUN3_SCSI_VME |
| 1619 | dregs->csr |= CSR_DMA_ENABLE; |
| 1620 | #endif |
| 1621 | sun3_dma_active = 1; |
| 1622 | #endif |
| 1623 | |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 1624 | if (hostdata->flags & FLAG_LATE_DMA_SETUP) { |
| 1625 | /* On the Falcon, the DMA setup must be done after the last |
| 1626 | * NCR access, else the DMA setup gets trashed! |
| 1627 | */ |
| 1628 | if (p & SR_IO) |
| 1629 | result = NCR5380_dma_recv_setup(instance, d, c); |
| 1630 | else |
| 1631 | result = NCR5380_dma_send_setup(instance, d, c); |
| 1632 | } |
| 1633 | |
| 1634 | /* On failure, NCR5380_dma_xxxx_setup() returns a negative int. */ |
| 1635 | if (result < 0) |
| 1636 | return result; |
| 1637 | |
| 1638 | /* For real DMA, result is the byte count. DMA interrupt is expected. */ |
| 1639 | if (result > 0) { |
| 1640 | hostdata->dma_len = result; |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | /* The result is zero iff pseudo DMA send/receive was completed. */ |
| 1645 | hostdata->dma_len = c; |
| 1646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | /* |
Finn Thain | e4dec68 | 2016-03-23 21:10:12 +1100 | [diff] [blame] | 1648 | * A note regarding the DMA errata workarounds for early NMOS silicon. |
Finn Thain | c16df32 | 2016-01-03 16:06:08 +1100 | [diff] [blame] | 1649 | * |
| 1650 | * For DMA sends, we want to wait until the last byte has been |
| 1651 | * transferred out over the bus before we turn off DMA mode. Alas, there |
| 1652 | * seems to be no terribly good way of doing this on a 5380 under all |
| 1653 | * conditions. For non-scatter-gather operations, we can wait until REQ |
| 1654 | * and ACK both go false, or until a phase mismatch occurs. Gather-sends |
| 1655 | * are nastier, since the device will be expecting more data than we |
| 1656 | * are prepared to send it, and REQ will remain asserted. On a 53C8[01] we |
| 1657 | * could test Last Byte Sent to assure transfer (I imagine this is precisely |
| 1658 | * why this signal was added to the newer chips) but on the older 538[01] |
| 1659 | * this signal does not exist. The workaround for this lack is a watchdog; |
| 1660 | * we bail out of the wait-loop after a modest amount of wait-time if |
| 1661 | * the usual exit conditions are not met. Not a terribly clean or |
| 1662 | * correct solution :-% |
| 1663 | * |
| 1664 | * DMA receive is equally tricky due to a nasty characteristic of the NCR5380. |
| 1665 | * If the chip is in DMA receive mode, it will respond to a target's |
| 1666 | * REQ by latching the SCSI data into the INPUT DATA register and asserting |
| 1667 | * ACK, even if it has _already_ been notified by the DMA controller that |
| 1668 | * the current DMA transfer has completed! If the NCR5380 is then taken |
| 1669 | * out of DMA mode, this already-acknowledged byte is lost. This is |
| 1670 | * not a problem for "one DMA transfer per READ command", because |
| 1671 | * the situation will never arise... either all of the data is DMA'ed |
| 1672 | * properly, or the target switches to MESSAGE IN phase to signal a |
| 1673 | * disconnection (either operation bringing the DMA to a clean halt). |
| 1674 | * However, in order to handle scatter-receive, we must work around the |
Finn Thain | e4dec68 | 2016-03-23 21:10:12 +1100 | [diff] [blame] | 1675 | * problem. The chosen fix is to DMA fewer bytes, then check for the |
Finn Thain | c16df32 | 2016-01-03 16:06:08 +1100 | [diff] [blame] | 1676 | * condition before taking the NCR5380 out of DMA mode. One or two extra |
| 1677 | * bytes are transferred via PIO as necessary to fill out the original |
| 1678 | * request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | */ |
| 1680 | |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 1681 | if (hostdata->flags & FLAG_DMA_FIXUP) { |
| 1682 | if (p & SR_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | /* |
Finn Thain | e4dec68 | 2016-03-23 21:10:12 +1100 | [diff] [blame] | 1684 | * The workaround was to transfer fewer bytes than we |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1685 | * intended to with the pseudo-DMA read function, wait for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | * the chip to latch the last byte, read it, and then disable |
| 1687 | * pseudo-DMA mode. |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1688 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | * After REQ is asserted, the NCR5380 asserts DRQ and ACK. |
| 1690 | * REQ is deasserted when ACK is asserted, and not reasserted |
| 1691 | * until ACK goes false. Since the NCR5380 won't lower ACK |
| 1692 | * until DACK is asserted, which won't happen unless we twiddle |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1693 | * the DMA port or we take the NCR5380 out of DMA mode, we |
| 1694 | * can guarantee that we won't handshake another extra |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | * byte. |
| 1696 | */ |
| 1697 | |
Finn Thain | 55181be | 2016-01-03 16:05:42 +1100 | [diff] [blame] | 1698 | if (NCR5380_poll_politely(instance, BUS_AND_STATUS_REG, |
| 1699 | BASR_DRQ, BASR_DRQ, HZ) < 0) { |
Finn Thain | 438af51 | 2016-03-23 21:10:18 +1100 | [diff] [blame] | 1700 | result = -1; |
Finn Thain | 55181be | 2016-01-03 16:05:42 +1100 | [diff] [blame] | 1701 | shost_printk(KERN_ERR, instance, "PDMA read: DRQ timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | } |
Finn Thain | 55181be | 2016-01-03 16:05:42 +1100 | [diff] [blame] | 1703 | if (NCR5380_poll_politely(instance, STATUS_REG, |
| 1704 | SR_REQ, 0, HZ) < 0) { |
Finn Thain | 438af51 | 2016-03-23 21:10:18 +1100 | [diff] [blame] | 1705 | result = -1; |
Finn Thain | 55181be | 2016-01-03 16:05:42 +1100 | [diff] [blame] | 1706 | shost_printk(KERN_ERR, instance, "PDMA read: !REQ timeout\n"); |
| 1707 | } |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 1708 | d[*count - 1] = NCR5380_read(INPUT_DATA_REG); |
| 1709 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | /* |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1711 | * Wait for the last byte to be sent. If REQ is being asserted for |
| 1712 | * the byte we're interested, we'll ACK it and it will go false. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | */ |
Finn Thain | 55181be | 2016-01-03 16:05:42 +1100 | [diff] [blame] | 1714 | if (NCR5380_poll_politely2(instance, |
| 1715 | BUS_AND_STATUS_REG, BASR_DRQ, BASR_DRQ, |
| 1716 | BUS_AND_STATUS_REG, BASR_PHASE_MATCH, 0, HZ) < 0) { |
Finn Thain | 438af51 | 2016-03-23 21:10:18 +1100 | [diff] [blame] | 1717 | result = -1; |
Finn Thain | 55181be | 2016-01-03 16:05:42 +1100 | [diff] [blame] | 1718 | shost_printk(KERN_ERR, instance, "PDMA write: DRQ and phase timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | } |
| 1720 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | } |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 1722 | |
| 1723 | NCR5380_dma_complete(instance); |
Finn Thain | 438af51 | 2016-03-23 21:10:18 +1100 | [diff] [blame] | 1724 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
| 1727 | /* |
| 1728 | * Function : NCR5380_information_transfer (struct Scsi_Host *instance) |
| 1729 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1730 | * Purpose : run through the various SCSI phases and do as the target |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1731 | * directs us to. Operates on the currently connected command, |
| 1732 | * instance->connected. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | * |
| 1734 | * Inputs : instance, instance for which we are doing commands |
| 1735 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1736 | * Side effects : SCSI things happen, the disconnected queue will be |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1737 | * modified if a command disconnects, *instance->connected will |
| 1738 | * change. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1740 | * XXX Note : we need to watch for bus free or a reset condition here |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 1741 | * to recover from an unexpected bus free condition. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | */ |
| 1743 | |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1744 | static void NCR5380_information_transfer(struct Scsi_Host *instance) |
| 1745 | { |
Finn Thain | e8a6014 | 2016-01-03 16:05:54 +1100 | [diff] [blame] | 1746 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | unsigned char msgout = NOP; |
| 1748 | int sink = 0; |
| 1749 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | int transfersize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | unsigned char *data; |
| 1752 | unsigned char phase, tmp, extended_msg[10], old_phase = 0xff; |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1753 | struct scsi_cmnd *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1755 | #ifdef SUN3_SCSI_VME |
| 1756 | dregs->csr |= CSR_INTR; |
| 1757 | #endif |
| 1758 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1759 | while ((cmd = hostdata->connected)) { |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 1760 | struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd); |
| 1761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | tmp = NCR5380_read(STATUS_REG); |
| 1763 | /* We only have a valid SCSI phase when REQ is asserted */ |
| 1764 | if (tmp & SR_REQ) { |
| 1765 | phase = (tmp & PHASE_MASK); |
| 1766 | if (phase != old_phase) { |
| 1767 | old_phase = phase; |
| 1768 | NCR5380_dprint_phase(NDEBUG_INFORMATION, instance); |
| 1769 | } |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1770 | #ifdef CONFIG_SUN3 |
| 1771 | if (phase == PHASE_CMDOUT) { |
| 1772 | void *d; |
| 1773 | unsigned long count; |
| 1774 | |
| 1775 | if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) { |
| 1776 | count = cmd->SCp.buffer->length; |
| 1777 | d = sg_virt(cmd->SCp.buffer); |
| 1778 | } else { |
| 1779 | count = cmd->SCp.this_residual; |
| 1780 | d = cmd->SCp.ptr; |
| 1781 | } |
| 1782 | |
| 1783 | if (sun3_dma_setup_done != cmd && |
| 1784 | sun3scsi_dma_xfer_len(count, cmd) > 0) { |
| 1785 | sun3scsi_dma_setup(instance, d, count, |
| 1786 | rq_data_dir(cmd->request)); |
| 1787 | sun3_dma_setup_done = cmd; |
| 1788 | } |
| 1789 | #ifdef SUN3_SCSI_VME |
| 1790 | dregs->csr |= CSR_INTR; |
| 1791 | #endif |
| 1792 | } |
| 1793 | #endif /* CONFIG_SUN3 */ |
| 1794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | if (sink && (phase != PHASE_MSGOUT)) { |
| 1796 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp)); |
| 1797 | |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1798 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN | |
| 1799 | ICR_ASSERT_ACK); |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1800 | while (NCR5380_read(STATUS_REG) & SR_REQ) |
| 1801 | ; |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1802 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | |
| 1803 | ICR_ASSERT_ATN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | sink = 0; |
| 1805 | continue; |
| 1806 | } |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | switch (phase) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | case PHASE_DATAOUT: |
| 1810 | #if (NDEBUG & NDEBUG_NO_DATAOUT) |
Finn Thain | 6a6ff4a | 2016-01-03 16:06:04 +1100 | [diff] [blame] | 1811 | shost_printk(KERN_DEBUG, instance, "NDEBUG_NO_DATAOUT set, attempted DATAOUT aborted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | sink = 1; |
| 1813 | do_abort(instance); |
| 1814 | cmd->result = DID_ERROR << 16; |
Finn Thain | 677e019 | 2016-01-03 16:05:59 +1100 | [diff] [blame] | 1815 | complete_cmd(instance, cmd); |
Finn Thain | dc18396 | 2016-02-23 10:07:07 +1100 | [diff] [blame] | 1816 | hostdata->connected = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | return; |
| 1818 | #endif |
Finn Thain | bf1a0c6 | 2016-01-03 16:05:47 +1100 | [diff] [blame] | 1819 | case PHASE_DATAIN: |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1820 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | * If there is no room left in the current buffer in the |
| 1822 | * scatter-gather list, move onto the next one. |
| 1823 | */ |
| 1824 | |
| 1825 | if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) { |
| 1826 | ++cmd->SCp.buffer; |
| 1827 | --cmd->SCp.buffers_residual; |
| 1828 | cmd->SCp.this_residual = cmd->SCp.buffer->length; |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 1829 | cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1830 | dsprintk(NDEBUG_INFORMATION, instance, "%d bytes and %d buffers left\n", |
| 1831 | cmd->SCp.this_residual, |
| 1832 | cmd->SCp.buffers_residual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | } |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | /* |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1836 | * The preferred transfer method is going to be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | * PSEUDO-DMA for systems that are strictly PIO, |
| 1838 | * since we can let the hardware do the handshaking. |
| 1839 | * |
| 1840 | * For this to work, we need to know the transfersize |
| 1841 | * ahead of time, since the pseudo-DMA code will sit |
| 1842 | * in an unconditional loop. |
| 1843 | */ |
| 1844 | |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 1845 | transfersize = 0; |
Finn Thain | 7e9ec8d | 2016-03-23 21:10:11 +1100 | [diff] [blame] | 1846 | if (!cmd->device->borken) |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 1847 | transfersize = NCR5380_dma_xfer_len(instance, cmd, phase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | |
Finn Thain | 438af51 | 2016-03-23 21:10:18 +1100 | [diff] [blame] | 1849 | if (transfersize > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | len = transfersize; |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1851 | if (NCR5380_transfer_dma(instance, &phase, |
| 1852 | &len, (unsigned char **)&cmd->SCp.ptr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | /* |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1854 | * If the watchdog timer fires, all future |
| 1855 | * accesses to this device will use the |
| 1856 | * polled-IO. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | */ |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 1858 | scmd_printk(KERN_INFO, cmd, |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1859 | "switching to slow handshake\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | cmd->device->borken = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | sink = 1; |
| 1862 | do_abort(instance); |
| 1863 | cmd->result = DID_ERROR << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | /* XXX - need to source or sink data here, as appropriate */ |
Finn Thain | 8053b0e | 2016-03-23 21:10:19 +1100 | [diff] [blame] | 1865 | } |
Finn Thain | f825e40 | 2016-03-23 21:10:15 +1100 | [diff] [blame] | 1866 | } else { |
Finn Thain | 1678847 | 2016-02-23 10:07:05 +1100 | [diff] [blame] | 1867 | /* Break up transfer into 3 ms chunks, |
| 1868 | * presuming 6 accesses per handshake. |
| 1869 | */ |
| 1870 | transfersize = min((unsigned long)cmd->SCp.this_residual, |
| 1871 | hostdata->accesses_per_ms / 2); |
| 1872 | len = transfersize; |
| 1873 | NCR5380_transfer_pio(instance, &phase, &len, |
Finn Thain | 3d07d22 | 2016-01-03 16:06:13 +1100 | [diff] [blame] | 1874 | (unsigned char **)&cmd->SCp.ptr); |
Finn Thain | 1678847 | 2016-02-23 10:07:05 +1100 | [diff] [blame] | 1875 | cmd->SCp.this_residual -= transfersize - len; |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1876 | } |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1877 | #ifdef CONFIG_SUN3 |
| 1878 | if (sun3_dma_setup_done == cmd) |
| 1879 | sun3_dma_setup_done = NULL; |
| 1880 | #endif |
Finn Thain | 1678847 | 2016-02-23 10:07:05 +1100 | [diff] [blame] | 1881 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | case PHASE_MSGIN: |
| 1883 | len = 1; |
| 1884 | data = &tmp; |
| 1885 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
| 1886 | cmd->SCp.Message = tmp; |
| 1887 | |
| 1888 | switch (tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | case ABORT: |
| 1890 | case COMMAND_COMPLETE: |
| 1891 | /* Accept message by clearing ACK */ |
| 1892 | sink = 1; |
| 1893 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Finn Thain | 0d3d9a4 | 2016-01-03 16:05:55 +1100 | [diff] [blame] | 1894 | dsprintk(NDEBUG_QUEUES, instance, |
| 1895 | "COMMAND COMPLETE %p target %d lun %llu\n", |
| 1896 | cmd, scmd_id(cmd), cmd->device->lun); |
| 1897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | hostdata->connected = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 1900 | cmd->result &= ~0xffff; |
| 1901 | cmd->result |= cmd->SCp.Status; |
| 1902 | cmd->result |= cmd->SCp.Message << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 1904 | if (cmd->cmnd[0] == REQUEST_SENSE) |
Finn Thain | 677e019 | 2016-01-03 16:05:59 +1100 | [diff] [blame] | 1905 | complete_cmd(instance, cmd); |
Finn Thain | f27db8e | 2016-01-03 16:06:00 +1100 | [diff] [blame] | 1906 | else { |
| 1907 | if (cmd->SCp.Status == SAM_STAT_CHECK_CONDITION || |
| 1908 | cmd->SCp.Status == SAM_STAT_COMMAND_TERMINATED) { |
| 1909 | dsprintk(NDEBUG_QUEUES, instance, "autosense: adding cmd %p to tail of autosense queue\n", |
| 1910 | cmd); |
| 1911 | list_add_tail(&ncmd->list, |
| 1912 | &hostdata->autosense); |
| 1913 | } else |
| 1914 | complete_cmd(instance, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1917 | /* |
| 1918 | * Restore phase bits to 0 so an interrupted selection, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | * arbitration can resume. |
| 1920 | */ |
| 1921 | NCR5380_write(TARGET_COMMAND_REG, 0); |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 1922 | |
| 1923 | /* Enable reselect interrupts */ |
| 1924 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 1925 | |
| 1926 | maybe_release_dma_irq(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | return; |
| 1928 | case MESSAGE_REJECT: |
| 1929 | /* Accept message by clearing ACK */ |
| 1930 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1931 | switch (hostdata->last_message) { |
| 1932 | case HEAD_OF_QUEUE_TAG: |
| 1933 | case ORDERED_QUEUE_TAG: |
| 1934 | case SIMPLE_QUEUE_TAG: |
| 1935 | cmd->device->simple_tags = 0; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 1936 | hostdata->busy[cmd->device->id] |= (1 << (cmd->device->lun & 0xFF)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | break; |
| 1938 | default: |
| 1939 | break; |
| 1940 | } |
Finn Thain | 340b961 | 2016-01-03 16:05:31 +1100 | [diff] [blame] | 1941 | break; |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1942 | case DISCONNECT: |
| 1943 | /* Accept message by clearing ACK */ |
| 1944 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1945 | hostdata->connected = NULL; |
| 1946 | list_add(&ncmd->list, &hostdata->disconnected); |
| 1947 | dsprintk(NDEBUG_INFORMATION | NDEBUG_QUEUES, |
| 1948 | instance, "connected command %p for target %d lun %llu moved to disconnected queue\n", |
| 1949 | cmd, scmd_id(cmd), cmd->device->lun); |
Finn Thain | 0d3d9a4 | 2016-01-03 16:05:55 +1100 | [diff] [blame] | 1950 | |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1951 | /* |
| 1952 | * Restore phase bits to 0 so an interrupted selection, |
| 1953 | * arbitration can resume. |
| 1954 | */ |
| 1955 | NCR5380_write(TARGET_COMMAND_REG, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1957 | /* Enable reselect interrupts */ |
| 1958 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 1959 | #ifdef SUN3_SCSI_VME |
| 1960 | dregs->csr |= CSR_DMA_ENABLE; |
| 1961 | #endif |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 1962 | return; |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1963 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | * The SCSI data pointer is *IMPLICITLY* saved on a disconnect |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1965 | * operation, in violation of the SCSI spec so we can safely |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | * ignore SAVE/RESTORE pointers calls. |
| 1967 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1968 | * Unfortunately, some disks violate the SCSI spec and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | * don't issue the required SAVE_POINTERS message before |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 1970 | * disconnecting, and we have to break spec to remain |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | * compatible. |
| 1972 | */ |
| 1973 | case SAVE_POINTERS: |
| 1974 | case RESTORE_POINTERS: |
| 1975 | /* Accept message by clearing ACK */ |
| 1976 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1977 | break; |
| 1978 | case EXTENDED_MESSAGE: |
Finn Thain | c16df32 | 2016-01-03 16:06:08 +1100 | [diff] [blame] | 1979 | /* |
| 1980 | * Start the message buffer with the EXTENDED_MESSAGE |
| 1981 | * byte, since spi_print_msg() wants the whole thing. |
| 1982 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | extended_msg[0] = EXTENDED_MESSAGE; |
| 1984 | /* Accept first byte by clearing ACK */ |
| 1985 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 1986 | |
| 1987 | spin_unlock_irq(&hostdata->lock); |
| 1988 | |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1989 | dsprintk(NDEBUG_EXTENDED, instance, "receiving extended message\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | |
| 1991 | len = 2; |
| 1992 | data = extended_msg + 1; |
| 1993 | phase = PHASE_MSGIN; |
| 1994 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 1995 | dsprintk(NDEBUG_EXTENDED, instance, "length %d, code 0x%02x\n", |
| 1996 | (int)extended_msg[1], |
| 1997 | (int)extended_msg[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
Finn Thain | e0783ed | 2016-01-03 16:05:45 +1100 | [diff] [blame] | 1999 | if (!len && extended_msg[1] > 0 && |
| 2000 | extended_msg[1] <= sizeof(extended_msg) - 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | /* Accept third byte by clearing ACK */ |
| 2002 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2003 | len = extended_msg[1] - 1; |
| 2004 | data = extended_msg + 3; |
| 2005 | phase = PHASE_MSGIN; |
| 2006 | |
| 2007 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 2008 | dsprintk(NDEBUG_EXTENDED, instance, "message received, residual %d\n", |
| 2009 | len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
| 2011 | switch (extended_msg[2]) { |
| 2012 | case EXTENDED_SDTR: |
| 2013 | case EXTENDED_WDTR: |
| 2014 | case EXTENDED_MODIFY_DATA_POINTER: |
| 2015 | case EXTENDED_EXTENDED_IDENTIFY: |
| 2016 | tmp = 0; |
| 2017 | } |
| 2018 | } else if (len) { |
Finn Thain | 6a6ff4a | 2016-01-03 16:06:04 +1100 | [diff] [blame] | 2019 | shost_printk(KERN_ERR, instance, "error receiving extended message\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | tmp = 0; |
| 2021 | } else { |
Finn Thain | 6a6ff4a | 2016-01-03 16:06:04 +1100 | [diff] [blame] | 2022 | shost_printk(KERN_NOTICE, instance, "extended message code %02x length %d is too long\n", |
| 2023 | extended_msg[2], extended_msg[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | tmp = 0; |
| 2025 | } |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2026 | |
| 2027 | spin_lock_irq(&hostdata->lock); |
| 2028 | if (!hostdata->connected) |
| 2029 | return; |
| 2030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | /* Fall through to reject message */ |
| 2032 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 2033 | /* |
| 2034 | * If we get something weird that we aren't expecting, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | * reject it. |
| 2036 | */ |
| 2037 | default: |
| 2038 | if (!tmp) { |
Finn Thain | 6a6ff4a | 2016-01-03 16:06:04 +1100 | [diff] [blame] | 2039 | shost_printk(KERN_ERR, instance, "rejecting message "); |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 2040 | spi_print_msg(extended_msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | printk("\n"); |
| 2042 | } else if (tmp != EXTENDED_MESSAGE) |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 2043 | scmd_printk(KERN_INFO, cmd, |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 2044 | "rejecting unknown message %02x\n", |
| 2045 | tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | else |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 2047 | scmd_printk(KERN_INFO, cmd, |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 2048 | "rejecting unknown extended message code %02x, length %d\n", |
| 2049 | extended_msg[1], extended_msg[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | |
| 2051 | msgout = MESSAGE_REJECT; |
| 2052 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
| 2053 | break; |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 2054 | } /* switch (tmp) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | break; |
| 2056 | case PHASE_MSGOUT: |
| 2057 | len = 1; |
| 2058 | data = &msgout; |
| 2059 | hostdata->last_message = msgout; |
| 2060 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
| 2061 | if (msgout == ABORT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | hostdata->connected = NULL; |
| 2063 | cmd->result = DID_ERROR << 16; |
Finn Thain | 677e019 | 2016-01-03 16:05:59 +1100 | [diff] [blame] | 2064 | complete_cmd(instance, cmd); |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 2065 | maybe_release_dma_irq(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
| 2067 | return; |
| 2068 | } |
| 2069 | msgout = NOP; |
| 2070 | break; |
| 2071 | case PHASE_CMDOUT: |
| 2072 | len = cmd->cmd_len; |
| 2073 | data = cmd->cmnd; |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 2074 | /* |
| 2075 | * XXX for performance reasons, on machines with a |
| 2076 | * PSEUDO-DMA architecture we should probably |
| 2077 | * use the dma transfer function. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | */ |
| 2079 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | break; |
| 2081 | case PHASE_STATIN: |
| 2082 | len = 1; |
| 2083 | data = &tmp; |
| 2084 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
| 2085 | cmd->SCp.Status = tmp; |
| 2086 | break; |
| 2087 | default: |
Finn Thain | 6a6ff4a | 2016-01-03 16:06:04 +1100 | [diff] [blame] | 2088 | shost_printk(KERN_ERR, instance, "unknown phase\n"); |
Finn Thain | 4dde8f7 | 2014-03-18 11:42:17 +1100 | [diff] [blame] | 2089 | NCR5380_dprint(NDEBUG_ANY, instance); |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 2090 | } /* switch(phase) */ |
Finn Thain | 686f399 | 2016-01-03 16:05:26 +1100 | [diff] [blame] | 2091 | } else { |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2092 | spin_unlock_irq(&hostdata->lock); |
Finn Thain | 686f399 | 2016-01-03 16:05:26 +1100 | [diff] [blame] | 2093 | NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ); |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2094 | spin_lock_irq(&hostdata->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | } |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2096 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | /* |
| 2100 | * Function : void NCR5380_reselect (struct Scsi_Host *instance) |
| 2101 | * |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 2102 | * Purpose : does reselection, initializing the instance->connected |
Finn Thain | 594d4ba | 2016-01-03 16:06:10 +1100 | [diff] [blame] | 2103 | * field to point to the scsi_cmnd for which the I_T_L or I_T_L_Q |
| 2104 | * nexus has been reestablished, |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 2105 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | * Inputs : instance - this instance of the NCR5380. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | */ |
| 2108 | |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 2109 | static void NCR5380_reselect(struct Scsi_Host *instance) |
| 2110 | { |
Finn Thain | e8a6014 | 2016-01-03 16:05:54 +1100 | [diff] [blame] | 2111 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | unsigned char target_mask; |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 2113 | unsigned char lun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | unsigned char msg[3]; |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 2115 | struct NCR5380_cmd *ncmd; |
| 2116 | struct scsi_cmnd *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | |
| 2118 | /* |
| 2119 | * Disable arbitration, etc. since the host adapter obviously |
| 2120 | * lost, and tell an interrupted NCR5380_select() to restart. |
| 2121 | */ |
| 2122 | |
| 2123 | NCR5380_write(MODE_REG, MR_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
| 2125 | target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask); |
Finn Thain | b746545 | 2016-01-03 16:06:05 +1100 | [diff] [blame] | 2126 | |
| 2127 | dsprintk(NDEBUG_RESELECTION, instance, "reselect\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | |
Finn Thain | aff0cf9 | 2016-01-03 16:06:09 +1100 | [diff] [blame] | 2129 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | * At this point, we have detected that our SCSI ID is on the bus, |
| 2131 | * SEL is true and BSY was false for at least one bus settle delay |
| 2132 | * (400 ns). |
| 2133 | * |
| 2134 | * We must assert BSY ourselves, until the target drops the SEL |
| 2135 | * signal. |
| 2136 | */ |
| 2137 | |
| 2138 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY); |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2139 | if (NCR5380_poll_politely(instance, |
| 2140 | STATUS_REG, SR_SEL, 0, 2 * HZ) < 0) { |
| 2141 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2142 | return; |
| 2143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2145 | |
| 2146 | /* |
| 2147 | * Wait for target to go into MSGIN. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | */ |
| 2149 | |
Finn Thain | 1cc160e | 2016-01-03 16:05:32 +1100 | [diff] [blame] | 2150 | if (NCR5380_poll_politely(instance, |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2151 | STATUS_REG, SR_REQ, SR_REQ, 2 * HZ) < 0) { |
| 2152 | do_abort(instance); |
| 2153 | return; |
| 2154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 2156 | #ifdef CONFIG_SUN3 |
| 2157 | /* acknowledge toggle to MSGIN */ |
| 2158 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(PHASE_MSGIN)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 2160 | /* peek at the byte without really hitting the bus */ |
| 2161 | msg[0] = NCR5380_read(CURRENT_SCSI_DATA_REG); |
| 2162 | #else |
| 2163 | { |
| 2164 | int len = 1; |
| 2165 | unsigned char *data = msg; |
| 2166 | unsigned char phase = PHASE_MSGIN; |
| 2167 | |
| 2168 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
| 2169 | |
| 2170 | if (len) { |
| 2171 | do_abort(instance); |
| 2172 | return; |
| 2173 | } |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2174 | } |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 2175 | #endif /* CONFIG_SUN3 */ |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | if (!(msg[0] & 0x80)) { |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2178 | shost_printk(KERN_ERR, instance, "expecting IDENTIFY message, got "); |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 2179 | spi_print_msg(msg); |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2180 | printk("\n"); |
| 2181 | do_abort(instance); |
| 2182 | return; |
| 2183 | } |
| 2184 | lun = msg[0] & 0x07; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2186 | /* |
| 2187 | * We need to add code for SCSI-II to track which devices have |
| 2188 | * I_T_L_Q nexuses established, and which have simple I_T_L |
| 2189 | * nexuses so we can chose to do additional data transfer. |
| 2190 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2192 | /* |
| 2193 | * Find the command corresponding to the I_T_L or I_T_L_Q nexus we |
| 2194 | * just reestablished, and remove it from the disconnected queue. |
| 2195 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 2197 | tmp = NULL; |
| 2198 | list_for_each_entry(ncmd, &hostdata->disconnected, list) { |
| 2199 | struct scsi_cmnd *cmd = NCR5380_to_scmd(ncmd); |
| 2200 | |
| 2201 | if (target_mask == (1 << scmd_id(cmd)) && |
| 2202 | lun == (u8)cmd->device->lun) { |
| 2203 | list_del(&ncmd->list); |
| 2204 | tmp = cmd; |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2205 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | } |
| 2207 | } |
Finn Thain | 0d3d9a4 | 2016-01-03 16:05:55 +1100 | [diff] [blame] | 2208 | |
| 2209 | if (tmp) { |
| 2210 | dsprintk(NDEBUG_RESELECTION | NDEBUG_QUEUES, instance, |
| 2211 | "reselect: removed %p from disconnected queue\n", tmp); |
| 2212 | } else { |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2213 | shost_printk(KERN_ERR, instance, "target bitmask 0x%02x lun %d not in disconnected queue.\n", |
| 2214 | target_mask, lun); |
| 2215 | /* |
Finn Thain | 0d2cf86 | 2016-01-03 16:06:11 +1100 | [diff] [blame] | 2216 | * Since we have an established nexus that we can't do anything |
| 2217 | * with, we must abort it. |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2218 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | do_abort(instance); |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2220 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | } |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2222 | |
Finn Thain | e9db319 | 2016-03-23 21:10:21 +1100 | [diff] [blame] | 2223 | #ifdef CONFIG_SUN3 |
| 2224 | { |
| 2225 | void *d; |
| 2226 | unsigned long count; |
| 2227 | |
| 2228 | if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) { |
| 2229 | count = tmp->SCp.buffer->length; |
| 2230 | d = sg_virt(tmp->SCp.buffer); |
| 2231 | } else { |
| 2232 | count = tmp->SCp.this_residual; |
| 2233 | d = tmp->SCp.ptr; |
| 2234 | } |
| 2235 | |
| 2236 | if (sun3_dma_setup_done != tmp && |
| 2237 | sun3scsi_dma_xfer_len(count, tmp) > 0) { |
| 2238 | sun3scsi_dma_setup(instance, d, count, |
| 2239 | rq_data_dir(tmp->request)); |
| 2240 | sun3_dma_setup_done = tmp; |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK); |
| 2245 | #endif /* CONFIG_SUN3 */ |
| 2246 | |
Finn Thain | 72064a7 | 2016-01-03 16:05:44 +1100 | [diff] [blame] | 2247 | /* Accept message by clearing ACK */ |
| 2248 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2249 | |
| 2250 | hostdata->connected = tmp; |
Finn Thain | c4ec6f9 | 2016-03-23 21:10:22 +1100 | [diff] [blame] | 2251 | dsprintk(NDEBUG_RESELECTION, instance, "nexus established, target %d, lun %llu\n", |
| 2252 | scmd_id(tmp), tmp->device->lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2255 | /** |
| 2256 | * list_find_cmd - test for presence of a command in a linked list |
| 2257 | * @haystack: list of commands |
| 2258 | * @needle: command to search for |
| 2259 | */ |
| 2260 | |
| 2261 | static bool list_find_cmd(struct list_head *haystack, |
| 2262 | struct scsi_cmnd *needle) |
| 2263 | { |
| 2264 | struct NCR5380_cmd *ncmd; |
| 2265 | |
| 2266 | list_for_each_entry(ncmd, haystack, list) |
| 2267 | if (NCR5380_to_scmd(ncmd) == needle) |
| 2268 | return true; |
| 2269 | return false; |
| 2270 | } |
| 2271 | |
| 2272 | /** |
| 2273 | * list_remove_cmd - remove a command from linked list |
| 2274 | * @haystack: list of commands |
| 2275 | * @needle: command to remove |
| 2276 | */ |
| 2277 | |
| 2278 | static bool list_del_cmd(struct list_head *haystack, |
| 2279 | struct scsi_cmnd *needle) |
| 2280 | { |
| 2281 | if (list_find_cmd(haystack, needle)) { |
| 2282 | struct NCR5380_cmd *ncmd = scsi_cmd_priv(needle); |
| 2283 | |
| 2284 | list_del(&ncmd->list); |
| 2285 | return true; |
| 2286 | } |
| 2287 | return false; |
| 2288 | } |
| 2289 | |
| 2290 | /** |
| 2291 | * NCR5380_abort - scsi host eh_abort_handler() method |
| 2292 | * @cmd: the command to be aborted |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | * |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2294 | * Try to abort a given command by removing it from queues and/or sending |
| 2295 | * the target an abort message. This may not succeed in causing a target |
| 2296 | * to abort the command. Nonetheless, the low-level driver must forget about |
| 2297 | * the command because the mid-layer reclaims it and it may be re-issued. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | * |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2299 | * The normal path taken by a command is as follows. For EH we trace this |
| 2300 | * same path to locate and abort the command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | * |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2302 | * unissued -> selecting -> [unissued -> selecting ->]... connected -> |
| 2303 | * [disconnected -> connected ->]... |
| 2304 | * [autosense -> connected ->] done |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | * |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2306 | * If cmd was not found at all then presumably it has already been completed, |
| 2307 | * in which case return SUCCESS to try to avoid further EH measures. |
Finn Thain | dc18396 | 2016-02-23 10:07:07 +1100 | [diff] [blame] | 2308 | * |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2309 | * If the command has not completed yet, we must not fail to find it. |
Finn Thain | dc18396 | 2016-02-23 10:07:07 +1100 | [diff] [blame] | 2310 | * We have no option but to forget the aborted command (even if it still |
| 2311 | * lacks sense data). The mid-layer may re-issue a command that is in error |
| 2312 | * recovery (see scsi_send_eh_cmnd), but the logic and data structures in |
| 2313 | * this driver are such that a command can appear on one queue only. |
Finn Thain | 71a0059 | 2016-02-23 10:07:06 +1100 | [diff] [blame] | 2314 | * |
| 2315 | * The lock protects driver data structures, but EH handlers also use it |
| 2316 | * to serialize their own execution and prevent their own re-entry. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | */ |
| 2318 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2319 | static int NCR5380_abort(struct scsi_cmnd *cmd) |
| 2320 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | struct Scsi_Host *instance = cmd->device->host; |
Finn Thain | e8a6014 | 2016-01-03 16:05:54 +1100 | [diff] [blame] | 2322 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2323 | unsigned long flags; |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2324 | int result = SUCCESS; |
Hannes Reinecke | 1fa6b5f | 2014-10-24 14:26:58 +0200 | [diff] [blame] | 2325 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2326 | spin_lock_irqsave(&hostdata->lock, flags); |
| 2327 | |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 2328 | #if (NDEBUG & NDEBUG_ANY) |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2329 | scmd_printk(KERN_INFO, cmd, __func__); |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 2330 | #endif |
Finn Thain | e5c3fdd | 2016-01-03 16:05:52 +1100 | [diff] [blame] | 2331 | NCR5380_dprint(NDEBUG_ANY, instance); |
| 2332 | NCR5380_dprint_phase(NDEBUG_ANY, instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2334 | if (list_del_cmd(&hostdata->unissued, cmd)) { |
| 2335 | dsprintk(NDEBUG_ABORT, instance, |
| 2336 | "abort: removed %p from issue queue\n", cmd); |
| 2337 | cmd->result = DID_ABORT << 16; |
| 2338 | cmd->scsi_done(cmd); /* No tag or busy flag to worry about */ |
Finn Thain | dc18396 | 2016-02-23 10:07:07 +1100 | [diff] [blame] | 2339 | goto out; |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2340 | } |
| 2341 | |
Finn Thain | 707d62b | 2016-01-03 16:06:02 +1100 | [diff] [blame] | 2342 | if (hostdata->selecting == cmd) { |
| 2343 | dsprintk(NDEBUG_ABORT, instance, |
| 2344 | "abort: cmd %p == selecting\n", cmd); |
| 2345 | hostdata->selecting = NULL; |
| 2346 | cmd->result = DID_ABORT << 16; |
| 2347 | complete_cmd(instance, cmd); |
| 2348 | goto out; |
| 2349 | } |
| 2350 | |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2351 | if (list_del_cmd(&hostdata->disconnected, cmd)) { |
| 2352 | dsprintk(NDEBUG_ABORT, instance, |
| 2353 | "abort: removed %p from disconnected list\n", cmd); |
Finn Thain | 71a0059 | 2016-02-23 10:07:06 +1100 | [diff] [blame] | 2354 | /* Can't call NCR5380_select() and send ABORT because that |
| 2355 | * means releasing the lock. Need a bus reset. |
| 2356 | */ |
Finn Thain | dc18396 | 2016-02-23 10:07:07 +1100 | [diff] [blame] | 2357 | set_host_byte(cmd, DID_ERROR); |
| 2358 | complete_cmd(instance, cmd); |
Finn Thain | 71a0059 | 2016-02-23 10:07:06 +1100 | [diff] [blame] | 2359 | result = FAILED; |
| 2360 | goto out; |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | if (hostdata->connected == cmd) { |
| 2364 | dsprintk(NDEBUG_ABORT, instance, "abort: cmd %p is connected\n", cmd); |
| 2365 | hostdata->connected = NULL; |
Finn Thain | dc18396 | 2016-02-23 10:07:07 +1100 | [diff] [blame] | 2366 | hostdata->dma_len = 0; |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2367 | if (do_abort(instance)) { |
| 2368 | set_host_byte(cmd, DID_ERROR); |
| 2369 | complete_cmd(instance, cmd); |
| 2370 | result = FAILED; |
| 2371 | goto out; |
| 2372 | } |
| 2373 | set_host_byte(cmd, DID_ABORT); |
Finn Thain | dc18396 | 2016-02-23 10:07:07 +1100 | [diff] [blame] | 2374 | complete_cmd(instance, cmd); |
| 2375 | goto out; |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2376 | } |
| 2377 | |
Finn Thain | dc18396 | 2016-02-23 10:07:07 +1100 | [diff] [blame] | 2378 | if (list_del_cmd(&hostdata->autosense, cmd)) { |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2379 | dsprintk(NDEBUG_ABORT, instance, |
Finn Thain | dc18396 | 2016-02-23 10:07:07 +1100 | [diff] [blame] | 2380 | "abort: removed %p from sense queue\n", cmd); |
| 2381 | set_host_byte(cmd, DID_ERROR); |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2382 | complete_cmd(instance, cmd); |
| 2383 | } |
| 2384 | |
| 2385 | out: |
| 2386 | if (result == FAILED) |
| 2387 | dsprintk(NDEBUG_ABORT, instance, "abort: failed to abort %p\n", cmd); |
| 2388 | else |
| 2389 | dsprintk(NDEBUG_ABORT, instance, "abort: successfully aborted %p\n", cmd); |
| 2390 | |
| 2391 | queue_work(hostdata->work_q, &hostdata->main_task); |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 2392 | maybe_release_dma_irq(instance); |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2393 | spin_unlock_irqrestore(&hostdata->lock, flags); |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 2394 | |
Finn Thain | 8b00c3d | 2016-01-03 16:06:01 +1100 | [diff] [blame] | 2395 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2399 | /** |
| 2400 | * NCR5380_bus_reset - reset the SCSI bus |
| 2401 | * @cmd: SCSI command undergoing EH |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | * |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2403 | * Returns SUCCESS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | */ |
| 2405 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2406 | static int NCR5380_bus_reset(struct scsi_cmnd *cmd) |
Jeff Garzik | 68b3aa7 | 2005-05-28 07:56:31 -0400 | [diff] [blame] | 2407 | { |
| 2408 | struct Scsi_Host *instance = cmd->device->host; |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2409 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2410 | int i; |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2411 | unsigned long flags; |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2412 | struct NCR5380_cmd *ncmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2414 | spin_lock_irqsave(&hostdata->lock, flags); |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2415 | |
| 2416 | #if (NDEBUG & NDEBUG_ANY) |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2417 | scmd_printk(KERN_INFO, cmd, __func__); |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2418 | #endif |
Finn Thain | e5c3fdd | 2016-01-03 16:05:52 +1100 | [diff] [blame] | 2419 | NCR5380_dprint(NDEBUG_ANY, instance); |
| 2420 | NCR5380_dprint_phase(NDEBUG_ANY, instance); |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2421 | |
Jeff Garzik | 68b3aa7 | 2005-05-28 07:56:31 -0400 | [diff] [blame] | 2422 | do_reset(instance); |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2423 | |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2424 | /* reset NCR registers */ |
| 2425 | NCR5380_write(MODE_REG, MR_BASE); |
| 2426 | NCR5380_write(TARGET_COMMAND_REG, 0); |
| 2427 | NCR5380_write(SELECT_ENABLE_REG, 0); |
| 2428 | |
| 2429 | /* After the reset, there are no more connected or disconnected commands |
| 2430 | * and no busy units; so clear the low-level status here to avoid |
| 2431 | * conflicts when the mid-level code tries to wake up the affected |
| 2432 | * commands! |
| 2433 | */ |
| 2434 | |
Finn Thain | 1884c28 | 2016-02-23 10:07:04 +1100 | [diff] [blame] | 2435 | if (list_del_cmd(&hostdata->unissued, cmd)) { |
| 2436 | cmd->result = DID_RESET << 16; |
| 2437 | cmd->scsi_done(cmd); |
| 2438 | } |
| 2439 | |
| 2440 | if (hostdata->selecting) { |
| 2441 | hostdata->selecting->result = DID_RESET << 16; |
| 2442 | complete_cmd(instance, hostdata->selecting); |
| 2443 | hostdata->selecting = NULL; |
| 2444 | } |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2445 | |
| 2446 | list_for_each_entry(ncmd, &hostdata->disconnected, list) { |
| 2447 | struct scsi_cmnd *cmd = NCR5380_to_scmd(ncmd); |
| 2448 | |
| 2449 | set_host_byte(cmd, DID_RESET); |
| 2450 | cmd->scsi_done(cmd); |
| 2451 | } |
Finn Thain | 1884c28 | 2016-02-23 10:07:04 +1100 | [diff] [blame] | 2452 | INIT_LIST_HEAD(&hostdata->disconnected); |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2453 | |
| 2454 | list_for_each_entry(ncmd, &hostdata->autosense, list) { |
| 2455 | struct scsi_cmnd *cmd = NCR5380_to_scmd(ncmd); |
| 2456 | |
| 2457 | set_host_byte(cmd, DID_RESET); |
| 2458 | cmd->scsi_done(cmd); |
| 2459 | } |
Finn Thain | 1884c28 | 2016-02-23 10:07:04 +1100 | [diff] [blame] | 2460 | INIT_LIST_HEAD(&hostdata->autosense); |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2461 | |
| 2462 | if (hostdata->connected) { |
| 2463 | set_host_byte(hostdata->connected, DID_RESET); |
| 2464 | complete_cmd(instance, hostdata->connected); |
| 2465 | hostdata->connected = NULL; |
| 2466 | } |
| 2467 | |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2468 | for (i = 0; i < 8; ++i) |
| 2469 | hostdata->busy[i] = 0; |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2470 | hostdata->dma_len = 0; |
Finn Thain | 62717f5 | 2016-01-03 16:06:03 +1100 | [diff] [blame] | 2471 | |
| 2472 | queue_work(hostdata->work_q, &hostdata->main_task); |
Finn Thain | 52d3e56 | 2016-03-23 21:10:20 +1100 | [diff] [blame] | 2473 | maybe_release_dma_irq(instance); |
Finn Thain | 11d2f63 | 2016-01-03 16:05:51 +1100 | [diff] [blame] | 2474 | spin_unlock_irqrestore(&hostdata->lock, flags); |
Jeff Garzik | 68b3aa7 | 2005-05-28 07:56:31 -0400 | [diff] [blame] | 2475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | return SUCCESS; |
| 2477 | } |