Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [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* |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 3 | * to implement 5380 SCSI drivers under Linux with a non-trantor |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * architecture. |
| 5 | * |
| 6 | * Note that these routines also work with NR53c400 family chips. |
| 7 | * |
| 8 | * Copyright 1993, Drew Eckhardt |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 9 | * Visionary Computing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * (Unix and Linux consulting and custom programming) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 11 | * drew@colorado.edu |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * +1 (303) 666-5836 |
| 13 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [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 | /* |
| 28 | * ++roman: To port the 5380 driver to the Atari, I had to do some changes in |
| 29 | * this file, too: |
| 30 | * |
| 31 | * - Some of the debug statements were incorrect (undefined variables and the |
| 32 | * like). I fixed that. |
| 33 | * |
| 34 | * - In information_transfer(), I think a #ifdef was wrong. Looking at the |
| 35 | * possible DMA transfer size should also happen for REAL_DMA. I added this |
| 36 | * in the #if statement. |
| 37 | * |
| 38 | * - When using real DMA, information_transfer() should return in a DATAOUT |
| 39 | * phase after starting the DMA. It has nothing more to do. |
| 40 | * |
| 41 | * - The interrupt service routine should run main after end of DMA, too (not |
| 42 | * only after RESELECTION interrupts). Additionally, it should _not_ test |
| 43 | * for more interrupts after running main, since a DMA process may have |
| 44 | * been started and interrupts are turned on now. The new int could happen |
| 45 | * inside the execution of NCR5380_intr(), leading to recursive |
| 46 | * calls. |
| 47 | * |
| 48 | * - I've added a function merge_contiguous_buffers() that tries to |
| 49 | * merge scatter-gather buffers that are located at contiguous |
| 50 | * physical addresses and can be processed with the same DMA setup. |
| 51 | * Since most scatter-gather operations work on a page (4K) of |
| 52 | * 4 buffers (1K), in more than 90% of all cases three interrupts and |
| 53 | * DMA setup actions are saved. |
| 54 | * |
| 55 | * - I've deleted all the stuff for AUTOPROBE_IRQ, REAL_DMA_POLL, PSEUDO_DMA |
| 56 | * and USLEEP, because these were messing up readability and will never be |
| 57 | * needed for Atari SCSI. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 58 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | * - I've revised the NCR5380_main() calling scheme (relax the 'main_running' |
| 60 | * stuff), and 'main' is executed in a bottom half if awoken by an |
| 61 | * interrupt. |
| 62 | * |
| 63 | * - The code was quite cluttered up by "#if (NDEBUG & NDEBUG_*) printk..." |
| 64 | * constructs. In my eyes, this made the source rather unreadable, so I |
| 65 | * finally replaced that by the *_PRINTK() macros. |
| 66 | * |
| 67 | */ |
| 68 | |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 69 | /* Adapted for the sun3 by Sam Creasey. */ |
| 70 | |
| db9dff3 | 2005-04-03 14:53:59 -0500 | [diff] [blame] | 71 | #include <scsi/scsi_dbg.h> |
Matthew Wilcox | 1abfd37 | 2005-12-15 16:22:01 -0500 | [diff] [blame] | 72 | #include <scsi/scsi_transport_spi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | #if (NDEBUG & NDEBUG_LISTS) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 75 | #define LIST(x, y) \ |
| 76 | do { \ |
| 77 | printk("LINE:%d Adding %p to %p\n", \ |
| 78 | __LINE__, (void*)(x), (void*)(y)); \ |
| 79 | if ((x) == (y)) \ |
| 80 | udelay(5); \ |
| 81 | } while (0) |
| 82 | #define REMOVE(w, x, y, z) \ |
| 83 | do { \ |
| 84 | printk("LINE:%d Removing: %p->%p %p->%p \n", \ |
| 85 | __LINE__, (void*)(w), (void*)(x), \ |
| 86 | (void*)(y), (void*)(z)); \ |
| 87 | if ((x) == (y)) \ |
| 88 | udelay(5); \ |
| 89 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | #else |
| 91 | #define LIST(x,y) |
| 92 | #define REMOVE(w,x,y,z) |
| 93 | #endif |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | /* |
| 96 | * Design |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 98 | * 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] | 99 | * one simply writes appropriate system specific macros (ie, data |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 100 | * 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] | 101 | * memory mapped) and drops this file in their 'C' wrapper. |
| 102 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 103 | * As far as command queueing, two queues are maintained for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | * each 5380 in the system - commands that haven't been issued yet, |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 105 | * and commands that are currently executing. This means that an |
| 106 | * unlimited number of commands may be queued, letting |
| 107 | * more commands propagate from the higher driver levels giving higher |
| 108 | * throughput. Note that both I_T_L and I_T_L_Q nexuses are supported, |
| 109 | * 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] | 110 | * while a command is already executing. |
| 111 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 113 | * Issues specific to the NCR5380 : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 115 | * When used in a PIO or pseudo-dma mode, the NCR5380 is a braindead |
| 116 | * piece of hardware that requires you to sit in a loop polling for |
| 117 | * the REQ signal as long as you are connected. Some devices are |
| 118 | * brain dead (ie, many TEXEL CD ROM drives) and won't disconnect |
Finn Thain | 686f399 | 2016-01-03 16:05:26 +1100 | [diff] [blame] | 119 | * while doing long seek operations. [...] These |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | * broken devices are the exception rather than the rule and I'd rather |
| 121 | * spend my time optimizing for the normal case. |
| 122 | * |
| 123 | * Architecture : |
| 124 | * |
| 125 | * At the heart of the design is a coroutine, NCR5380_main, |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 126 | * which is started from a workqueue for each NCR5380 host in the |
| 127 | * system. It attempts to establish I_T_L or I_T_L_Q nexuses by |
| 128 | * removing the commands from the issue queue and calling |
| 129 | * NCR5380_select() if a nexus is not established. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | * |
| 131 | * Once a nexus is established, the NCR5380_information_transfer() |
| 132 | * phase goes through the various phases as instructed by the target. |
| 133 | * if the target goes into MSG IN and sends a DISCONNECT message, |
| 134 | * the command structure is placed into the per instance disconnected |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 135 | * queue, and NCR5380_main tries to find more work. If the target is |
| 136 | * idle for too long, the system will try to sleep. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | * |
| 138 | * If a command has disconnected, eventually an interrupt will trigger, |
| 139 | * calling NCR5380_intr() which will in turn call NCR5380_reselect |
| 140 | * to reestablish a nexus. This will run main if necessary. |
| 141 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 142 | * On command termination, the done function will be called as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | * appropriate. |
| 144 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 145 | * SCSI pointers are maintained in the SCp field of SCSI command |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | * structures, being initialized after the command is connected |
| 147 | * in NCR5380_select, and set as appropriate in NCR5380_information_transfer. |
| 148 | * Note that in violation of the standard, an implicit SAVE POINTERS operation |
| 149 | * is done, since some BROKEN disks fail to issue an explicit SAVE POINTERS. |
| 150 | */ |
| 151 | |
| 152 | /* |
| 153 | * Using this file : |
| 154 | * This file a skeleton Linux SCSI driver for the NCR 5380 series |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 155 | * of chips. To use it, you write an architecture specific functions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | * and macros and include this file in your driver. |
| 157 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 158 | * These macros control options : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 160 | * for commands that return with a CHECK CONDITION status. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 162 | * DIFFERENTIAL - if defined, NCR53c81 chips will use external differential |
| 163 | * transceivers. |
| 164 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | * REAL_DMA - if defined, REAL DMA is used during the data transfer phases. |
| 166 | * |
| 167 | * SUPPORT_TAGS - if defined, SCSI-2 tagged queuing is used where possible |
| 168 | * |
| 169 | * These macros MUST be defined : |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 170 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | * NCR5380_read(register) - read from the specified register |
| 172 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 173 | * NCR5380_write(register, value) - write to the specific register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 175 | * NCR5380_implementation_fields - additional fields needed for this |
| 176 | * specific implementation of the NCR5380 |
| 177 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | * Either real DMA *or* pseudo DMA may be implemented |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 179 | * REAL functions : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | * NCR5380_REAL_DMA should be defined if real DMA is to be used. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 181 | * Note that the DMA setup functions should return the number of bytes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | * that they were able to program the controller for. |
| 183 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 184 | * Also note that generic i386/PC versions of these macros are |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | * available as NCR5380_i386_dma_write_setup, |
| 186 | * NCR5380_i386_dma_read_setup, and NCR5380_i386_dma_residual. |
| 187 | * |
| 188 | * NCR5380_dma_write_setup(instance, src, count) - initialize |
| 189 | * NCR5380_dma_read_setup(instance, dst, count) - initialize |
| 190 | * NCR5380_dma_residual(instance); - residual count |
| 191 | * |
| 192 | * PSEUDO functions : |
| 193 | * NCR5380_pwrite(instance, src, count) |
| 194 | * NCR5380_pread(instance, dst, count); |
| 195 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * The generic driver is initialized by calling NCR5380_init(instance), |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 197 | * after setting the appropriate host specific fields and ID. If the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance, |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 199 | * possible) function may be used. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | */ |
| 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | /* Macros ease life... :-) */ |
| 203 | #define SETUP_HOSTDATA(in) \ |
| 204 | struct NCR5380_hostdata *hostdata = \ |
| 205 | (struct NCR5380_hostdata *)(in)->hostdata |
| 206 | #define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata) |
| 207 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 208 | #define NEXT(cmd) ((struct scsi_cmnd *)(cmd)->host_scribble) |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 209 | #define SET_NEXT(cmd,next) ((cmd)->host_scribble = (void *)(next)) |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 210 | #define NEXTADDR(cmd) ((struct scsi_cmnd **)&(cmd)->host_scribble) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | #define HOSTNO instance->host_no |
| 213 | #define H_NO(cmd) (cmd)->device->host->host_no |
| 214 | |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 215 | static int do_abort(struct Scsi_Host *); |
| 216 | static void do_reset(struct Scsi_Host *); |
| 217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | #ifdef SUPPORT_TAGS |
| 219 | |
| 220 | /* |
| 221 | * Functions for handling tagged queuing |
| 222 | * ===================================== |
| 223 | * |
| 224 | * ++roman (01/96): Now I've implemented SCSI-2 tagged queuing. Some notes: |
| 225 | * |
| 226 | * Using consecutive numbers for the tags is no good idea in my eyes. There |
| 227 | * could be wrong re-usings if the counter (8 bit!) wraps and some early |
| 228 | * command has been preempted for a long time. My solution: a bitfield for |
| 229 | * remembering used tags. |
| 230 | * |
| 231 | * There's also the problem that each target has a certain queue size, but we |
| 232 | * cannot know it in advance :-( We just see a QUEUE_FULL status being |
| 233 | * returned. So, in this case, the driver internal queue size assumption is |
| 234 | * reduced to the number of active tags if QUEUE_FULL is returned by the |
| 235 | * target. The command is returned to the mid-level, but with status changed |
| 236 | * to BUSY, since --as I've seen-- the mid-level can't handle QUEUE_FULL |
| 237 | * correctly. |
| 238 | * |
| 239 | * We're also not allowed running tagged commands as long as an untagged |
| 240 | * command is active. And REQUEST SENSE commands after a contingent allegiance |
| 241 | * condition _must_ be untagged. To keep track whether an untagged command has |
| 242 | * been issued, the host->busy array is still employed, as it is without |
| 243 | * support for tagged queuing. |
| 244 | * |
| 245 | * One could suspect that there are possible race conditions between |
| 246 | * is_lun_busy(), cmd_get_tag() and cmd_free_tag(). But I think this isn't the |
| 247 | * case: is_lun_busy() and cmd_get_tag() are both called from NCR5380_main(), |
| 248 | * which already guaranteed to be running at most once. It is also the only |
| 249 | * place where tags/LUNs are allocated. So no other allocation can slip |
| 250 | * between that pair, there could only happen a reselection, which can free a |
| 251 | * tag, but that doesn't hurt. Only the sequence in cmd_free_tag() becomes |
| 252 | * important: the tag bit must be cleared before 'nr_allocated' is decreased. |
| 253 | */ |
| 254 | |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 255 | static void __init init_tags(struct NCR5380_hostdata *hostdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 257 | int target, lun; |
Finn Thain | 61d739a | 2014-11-12 16:12:20 +1100 | [diff] [blame] | 258 | struct tag_alloc *ta; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 259 | |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 260 | if (!(hostdata->flags & FLAG_TAGGED_QUEUING)) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 261 | return; |
| 262 | |
| 263 | for (target = 0; target < 8; ++target) { |
| 264 | for (lun = 0; lun < 8; ++lun) { |
Finn Thain | 61d739a | 2014-11-12 16:12:20 +1100 | [diff] [blame] | 265 | ta = &hostdata->TagAlloc[target][lun]; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 266 | bitmap_zero(ta->allocated, MAX_TAGS); |
| 267 | ta->nr_allocated = 0; |
| 268 | /* At the beginning, assume the maximum queue size we could |
| 269 | * support (MAX_TAGS). This value will be decreased if the target |
| 270 | * returns QUEUE_FULL status. |
| 271 | */ |
| 272 | ta->queue_size = MAX_TAGS; |
| 273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | |
| 278 | /* Check if we can issue a command to this LUN: First see if the LUN is marked |
| 279 | * busy by an untagged command. If the command should use tagged queuing, also |
| 280 | * check that there is a free tag and the target's queue won't overflow. This |
| 281 | * function should be called with interrupts disabled to avoid race |
| 282 | * conditions. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 283 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 285 | static int is_lun_busy(struct scsi_cmnd *cmd, int should_be_tagged) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 287 | u8 lun = cmd->device->lun; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 288 | SETUP_HOSTDATA(cmd->device->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 290 | if (hostdata->busy[cmd->device->id] & (1 << lun)) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 291 | return 1; |
| 292 | if (!should_be_tagged || |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 293 | !(hostdata->flags & FLAG_TAGGED_QUEUING) || |
| 294 | !cmd->device->tagged_supported) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 295 | return 0; |
Finn Thain | 61d739a | 2014-11-12 16:12:20 +1100 | [diff] [blame] | 296 | if (hostdata->TagAlloc[scmd_id(cmd)][lun].nr_allocated >= |
| 297 | hostdata->TagAlloc[scmd_id(cmd)][lun].queue_size) { |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 298 | dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d: no free tags\n", |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 299 | H_NO(cmd), cmd->device->id, lun); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 300 | return 1; |
| 301 | } |
| 302 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | |
| 306 | /* Allocate a tag for a command (there are no checks anymore, check_lun_busy() |
| 307 | * must be called before!), or reserve the LUN in 'busy' if the command is |
| 308 | * untagged. |
| 309 | */ |
| 310 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 311 | static void cmd_get_tag(struct scsi_cmnd *cmd, int should_be_tagged) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 313 | u8 lun = cmd->device->lun; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 314 | SETUP_HOSTDATA(cmd->device->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 316 | /* If we or the target don't support tagged queuing, allocate the LUN for |
| 317 | * an untagged command. |
| 318 | */ |
| 319 | if (!should_be_tagged || |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 320 | !(hostdata->flags & FLAG_TAGGED_QUEUING) || |
| 321 | !cmd->device->tagged_supported) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 322 | cmd->tag = TAG_NONE; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 323 | hostdata->busy[cmd->device->id] |= (1 << lun); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 324 | dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d now allocated by untagged " |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 325 | "command\n", H_NO(cmd), cmd->device->id, lun); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 326 | } else { |
Finn Thain | 61d739a | 2014-11-12 16:12:20 +1100 | [diff] [blame] | 327 | struct tag_alloc *ta = &hostdata->TagAlloc[scmd_id(cmd)][lun]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 329 | cmd->tag = find_first_zero_bit(ta->allocated, MAX_TAGS); |
| 330 | set_bit(cmd->tag, ta->allocated); |
| 331 | ta->nr_allocated++; |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 332 | dprintk(NDEBUG_TAGS, "scsi%d: using tag %d for target %d lun %d " |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 333 | "(now %d tags in use)\n", |
| 334 | H_NO(cmd), cmd->tag, cmd->device->id, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 335 | lun, ta->nr_allocated); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 336 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | |
| 340 | /* Mark the tag of command 'cmd' as free, or in case of an untagged command, |
| 341 | * unlock the LUN. |
| 342 | */ |
| 343 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 344 | static void cmd_free_tag(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 346 | u8 lun = cmd->device->lun; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 347 | SETUP_HOSTDATA(cmd->device->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 349 | if (cmd->tag == TAG_NONE) { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 350 | hostdata->busy[cmd->device->id] &= ~(1 << lun); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 351 | dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d untagged cmd finished\n", |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 352 | H_NO(cmd), cmd->device->id, lun); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 353 | } else if (cmd->tag >= MAX_TAGS) { |
| 354 | printk(KERN_NOTICE "scsi%d: trying to free bad tag %d!\n", |
| 355 | H_NO(cmd), cmd->tag); |
| 356 | } else { |
Finn Thain | 61d739a | 2014-11-12 16:12:20 +1100 | [diff] [blame] | 357 | struct tag_alloc *ta = &hostdata->TagAlloc[scmd_id(cmd)][lun]; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 358 | clear_bit(cmd->tag, ta->allocated); |
| 359 | ta->nr_allocated--; |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 360 | dprintk(NDEBUG_TAGS, "scsi%d: freed tag %d for target %d lun %d\n", |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 361 | H_NO(cmd), cmd->tag, cmd->device->id, lun); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 362 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 366 | static void free_all_tags(struct NCR5380_hostdata *hostdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 368 | int target, lun; |
Finn Thain | 61d739a | 2014-11-12 16:12:20 +1100 | [diff] [blame] | 369 | struct tag_alloc *ta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 371 | if (!(hostdata->flags & FLAG_TAGGED_QUEUING)) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 372 | return; |
| 373 | |
| 374 | for (target = 0; target < 8; ++target) { |
| 375 | for (lun = 0; lun < 8; ++lun) { |
Finn Thain | 61d739a | 2014-11-12 16:12:20 +1100 | [diff] [blame] | 376 | ta = &hostdata->TagAlloc[target][lun]; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 377 | bitmap_zero(ta->allocated, MAX_TAGS); |
| 378 | ta->nr_allocated = 0; |
| 379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | #endif /* SUPPORT_TAGS */ |
| 384 | |
| 385 | |
| 386 | /* |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 387 | * Function: void merge_contiguous_buffers( struct scsi_cmnd *cmd ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | * |
| 389 | * Purpose: Try to merge several scatter-gather requests into one DMA |
| 390 | * transfer. This is possible if the scatter buffers lie on |
| 391 | * physical contiguous addresses. |
| 392 | * |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 393 | * Parameters: struct scsi_cmnd *cmd |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | * The command to work on. The first scatter buffer's data are |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 395 | * assumed to be already transferred into ptr/this_residual. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | */ |
| 397 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 398 | static void merge_contiguous_buffers(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | { |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 400 | #if !defined(CONFIG_SUN3) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 401 | unsigned long endaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | #if (NDEBUG & NDEBUG_MERGING) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 403 | unsigned long oldlen = cmd->SCp.this_residual; |
| 404 | int cnt = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | #endif |
| 406 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 407 | for (endaddr = virt_to_phys(cmd->SCp.ptr + cmd->SCp.this_residual - 1) + 1; |
| 408 | cmd->SCp.buffers_residual && |
Geert Uytterhoeven | 5a1cb47 | 2007-10-24 08:55:40 +0200 | [diff] [blame] | 409 | virt_to_phys(sg_virt(&cmd->SCp.buffer[1])) == endaddr;) { |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 410 | dprintk(NDEBUG_MERGING, "VTOP(%p) == %08lx -> merging\n", |
Geert Uytterhoeven | 5a1cb47 | 2007-10-24 08:55:40 +0200 | [diff] [blame] | 411 | page_address(sg_page(&cmd->SCp.buffer[1])), endaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | #if (NDEBUG & NDEBUG_MERGING) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 413 | ++cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 415 | ++cmd->SCp.buffer; |
| 416 | --cmd->SCp.buffers_residual; |
| 417 | cmd->SCp.this_residual += cmd->SCp.buffer->length; |
| 418 | endaddr += cmd->SCp.buffer->length; |
| 419 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | #if (NDEBUG & NDEBUG_MERGING) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 421 | if (oldlen != cmd->SCp.this_residual) |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 422 | dprintk(NDEBUG_MERGING, "merged %d buffers from %p, new length %08x\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 423 | cnt, cmd->SCp.ptr, cmd->SCp.this_residual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | #endif |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 425 | #endif /* !defined(CONFIG_SUN3) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 428 | /** |
| 429 | * initialize_SCp - init the scsi pointer field |
| 430 | * @cmd: command block to set up |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 432 | * Set up the internal fields in the SCSI command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | */ |
| 434 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 435 | static inline void initialize_SCp(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 437 | /* |
| 438 | * Initialize the Scsi Pointer field so that all of the commands in the |
| 439 | * various queues are valid. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 441 | |
Boaz Harrosh | 9e0fe44 | 2007-11-05 11:23:35 +0200 | [diff] [blame] | 442 | if (scsi_bufflen(cmd)) { |
| 443 | cmd->SCp.buffer = scsi_sglist(cmd); |
| 444 | cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1; |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 445 | cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 446 | cmd->SCp.this_residual = cmd->SCp.buffer->length; |
| 447 | /* ++roman: Try to merge some scatter-buffers if they are at |
| 448 | * contiguous physical addresses. |
| 449 | */ |
| 450 | merge_contiguous_buffers(cmd); |
| 451 | } else { |
| 452 | cmd->SCp.buffer = NULL; |
| 453 | cmd->SCp.buffers_residual = 0; |
Boaz Harrosh | 9e0fe44 | 2007-11-05 11:23:35 +0200 | [diff] [blame] | 454 | cmd->SCp.ptr = NULL; |
| 455 | cmd->SCp.this_residual = 0; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 456 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 459 | /** |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame^] | 460 | * NCR5380_poll_politely2 - wait for two chip register values |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 461 | * @instance: controller to poll |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame^] | 462 | * @reg1: 5380 register to poll |
| 463 | * @bit1: Bitmask to check |
| 464 | * @val1: Expected value |
| 465 | * @reg2: Second 5380 register to poll |
| 466 | * @bit2: Second bitmask to check |
| 467 | * @val2: Second expected value |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 468 | * @wait: Time-out in jiffies |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 469 | * |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 470 | * Polls the chip in a reasonably efficient manner waiting for an |
| 471 | * event to occur. After a short quick poll we begin to yield the CPU |
| 472 | * (if possible). In irq contexts the time-out is arbitrarily limited. |
| 473 | * Callers may hold locks as long as they are held in irq mode. |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 474 | * |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame^] | 475 | * Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT. |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 476 | */ |
| 477 | |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame^] | 478 | static int NCR5380_poll_politely2(struct Scsi_Host *instance, |
| 479 | int reg1, int bit1, int val1, |
| 480 | int reg2, int bit2, int val2, int wait) |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 481 | { |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 482 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 483 | unsigned long deadline = jiffies + wait; |
| 484 | unsigned long n; |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 485 | |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 486 | /* Busy-wait for up to 10 ms */ |
| 487 | n = min(10000U, jiffies_to_usecs(wait)); |
| 488 | n *= hostdata->accesses_per_ms; |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame^] | 489 | n /= 2000; |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 490 | do { |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame^] | 491 | if ((NCR5380_read(reg1) & bit1) == val1) |
| 492 | return 0; |
| 493 | if ((NCR5380_read(reg2) & bit2) == val2) |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 494 | return 0; |
| 495 | cpu_relax(); |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 496 | } while (n--); |
| 497 | |
| 498 | if (irqs_disabled() || in_interrupt()) |
| 499 | return -ETIMEDOUT; |
| 500 | |
| 501 | /* Repeatedly sleep for 1 ms until deadline */ |
| 502 | while (time_is_after_jiffies(deadline)) { |
| 503 | schedule_timeout_uninterruptible(1); |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame^] | 504 | if ((NCR5380_read(reg1) & bit1) == val1) |
| 505 | return 0; |
| 506 | if ((NCR5380_read(reg2) & bit2) == val2) |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 507 | return 0; |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 508 | } |
| 509 | |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 510 | return -ETIMEDOUT; |
| 511 | } |
| 512 | |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame^] | 513 | static inline int NCR5380_poll_politely(struct Scsi_Host *instance, |
| 514 | int reg, int bit, int val, int wait) |
| 515 | { |
| 516 | return NCR5380_poll_politely2(instance, reg, bit, val, |
| 517 | reg, bit, val, wait); |
| 518 | } |
| 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | #include <linux/delay.h> |
| 521 | |
| 522 | #if NDEBUG |
| 523 | static struct { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 524 | unsigned char mask; |
| 525 | const char *name; |
| 526 | } signals[] = { |
| 527 | { SR_DBP, "PARITY"}, { SR_RST, "RST" }, { SR_BSY, "BSY" }, |
| 528 | { SR_REQ, "REQ" }, { SR_MSG, "MSG" }, { SR_CD, "CD" }, { SR_IO, "IO" }, |
| 529 | { SR_SEL, "SEL" }, {0, NULL} |
| 530 | }, basrs[] = { |
| 531 | {BASR_ATN, "ATN"}, {BASR_ACK, "ACK"}, {0, NULL} |
| 532 | }, icrs[] = { |
| 533 | {ICR_ASSERT_RST, "ASSERT RST"},{ICR_ASSERT_ACK, "ASSERT ACK"}, |
| 534 | {ICR_ASSERT_BSY, "ASSERT BSY"}, {ICR_ASSERT_SEL, "ASSERT SEL"}, |
| 535 | {ICR_ASSERT_ATN, "ASSERT ATN"}, {ICR_ASSERT_DATA, "ASSERT DATA"}, |
| 536 | {0, NULL} |
| 537 | }, mrs[] = { |
| 538 | {MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"}, |
| 539 | {MR_ENABLE_PAR_CHECK, "MODE PARITY CHECK"}, {MR_ENABLE_PAR_INTR, |
| 540 | "MODE PARITY INTR"}, {MR_ENABLE_EOP_INTR,"MODE EOP INTR"}, |
| 541 | {MR_MONITOR_BSY, "MODE MONITOR BSY"}, |
| 542 | {MR_DMA_MODE, "MODE DMA"}, {MR_ARBITRATE, "MODE ARBITRATION"}, |
| 543 | {0, NULL} |
| 544 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 546 | /** |
| 547 | * NCR5380_print - print scsi bus signals |
| 548 | * @instance: adapter state to dump |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 550 | * Print the SCSI bus signals for debugging purposes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | */ |
| 552 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 553 | static void NCR5380_print(struct Scsi_Host *instance) |
| 554 | { |
| 555 | unsigned char status, data, basr, mr, icr, i; |
| 556 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 558 | local_irq_save(flags); |
| 559 | data = NCR5380_read(CURRENT_SCSI_DATA_REG); |
| 560 | status = NCR5380_read(STATUS_REG); |
| 561 | mr = NCR5380_read(MODE_REG); |
| 562 | icr = NCR5380_read(INITIATOR_COMMAND_REG); |
| 563 | basr = NCR5380_read(BUS_AND_STATUS_REG); |
| 564 | local_irq_restore(flags); |
| 565 | printk("STATUS_REG: %02x ", status); |
| 566 | for (i = 0; signals[i].mask; ++i) |
| 567 | if (status & signals[i].mask) |
| 568 | printk(",%s", signals[i].name); |
| 569 | printk("\nBASR: %02x ", basr); |
| 570 | for (i = 0; basrs[i].mask; ++i) |
| 571 | if (basr & basrs[i].mask) |
| 572 | printk(",%s", basrs[i].name); |
| 573 | printk("\nICR: %02x ", icr); |
| 574 | for (i = 0; icrs[i].mask; ++i) |
| 575 | if (icr & icrs[i].mask) |
| 576 | printk(",%s", icrs[i].name); |
| 577 | printk("\nMODE: %02x ", mr); |
| 578 | for (i = 0; mrs[i].mask; ++i) |
| 579 | if (mr & mrs[i].mask) |
| 580 | printk(",%s", mrs[i].name); |
| 581 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | static struct { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 585 | unsigned char value; |
| 586 | const char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } phases[] = { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 588 | {PHASE_DATAOUT, "DATAOUT"}, {PHASE_DATAIN, "DATAIN"}, {PHASE_CMDOUT, "CMDOUT"}, |
| 589 | {PHASE_STATIN, "STATIN"}, {PHASE_MSGOUT, "MSGOUT"}, {PHASE_MSGIN, "MSGIN"}, |
| 590 | {PHASE_UNKNOWN, "UNKNOWN"} |
| 591 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 593 | /** |
| 594 | * NCR5380_print_phase - show SCSI phase |
| 595 | * @instance: adapter to dump |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 597 | * Print the current SCSI phase for debugging purposes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 599 | * Locks: none |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | */ |
| 601 | |
| 602 | static void NCR5380_print_phase(struct Scsi_Host *instance) |
| 603 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 604 | unsigned char status; |
| 605 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 607 | status = NCR5380_read(STATUS_REG); |
| 608 | if (!(status & SR_REQ)) |
| 609 | printk(KERN_DEBUG "scsi%d: REQ not asserted, phase unknown.\n", HOSTNO); |
| 610 | else { |
| 611 | for (i = 0; (phases[i].value != PHASE_UNKNOWN) && |
| 612 | (phases[i].value != (status & PHASE_MASK)); ++i) |
| 613 | ; |
| 614 | printk(KERN_DEBUG "scsi%d: phase %s\n", HOSTNO, phases[i].name); |
| 615 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | #endif |
| 619 | |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 620 | /** |
| 621 | * NCR58380_info - report driver and host information |
| 622 | * @instance: relevant scsi host instance |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | * |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 624 | * For use as the host template info() handler. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | * |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 626 | * Locks: none |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | */ |
| 628 | |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 629 | static const char *NCR5380_info(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 631 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 632 | |
| 633 | return hostdata->info; |
| 634 | } |
| 635 | |
| 636 | static void prepare_info(struct Scsi_Host *instance) |
| 637 | { |
| 638 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 639 | |
| 640 | snprintf(hostdata->info, sizeof(hostdata->info), |
| 641 | "%s, io_port 0x%lx, n_io_port %d, " |
| 642 | "base 0x%lx, irq %d, " |
| 643 | "can_queue %d, cmd_per_lun %d, " |
| 644 | "sg_tablesize %d, this_id %d, " |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 645 | "flags { %s%s}, " |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 646 | "options { %s} ", |
| 647 | instance->hostt->name, instance->io_port, instance->n_io_port, |
| 648 | instance->base, instance->irq, |
| 649 | instance->can_queue, instance->cmd_per_lun, |
| 650 | instance->sg_tablesize, instance->this_id, |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 651 | hostdata->flags & FLAG_TAGGED_QUEUING ? "TAGGED_QUEUING " : "", |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 652 | hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : "", |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 653 | #ifdef DIFFERENTIAL |
| 654 | "DIFFERENTIAL " |
| 655 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | #ifdef REAL_DMA |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 657 | "REAL_DMA " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | #endif |
| 659 | #ifdef PARITY |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 660 | "PARITY " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | #endif |
| 662 | #ifdef SUPPORT_TAGS |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 663 | "SUPPORT_TAGS " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | #endif |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 665 | ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 668 | /** |
| 669 | * NCR5380_print_status - dump controller info |
| 670 | * @instance: controller to dump |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 672 | * Print commands in the various queues, called from NCR5380_abort |
| 673 | * to aid debugging. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | */ |
| 675 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 676 | static void lprint_Scsi_Cmnd(struct scsi_cmnd *cmd) |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 677 | { |
| 678 | int i, s; |
| 679 | unsigned char *command; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 680 | printk("scsi%d: destination target %d, lun %llu\n", |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 681 | H_NO(cmd), cmd->device->id, cmd->device->lun); |
| 682 | printk(KERN_CONT " command = "); |
| 683 | command = cmd->cmnd; |
| 684 | printk(KERN_CONT "%2d (0x%02x)", command[0], command[0]); |
| 685 | for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i) |
| 686 | printk(KERN_CONT " %02x", command[i]); |
| 687 | printk("\n"); |
| 688 | } |
| 689 | |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 690 | static void __maybe_unused NCR5380_print_status(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | { |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 692 | struct NCR5380_hostdata *hostdata; |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 693 | struct scsi_cmnd *ptr; |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 694 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
Finn Thain | 8ad3a59 | 2014-03-18 11:42:19 +1100 | [diff] [blame] | 696 | NCR5380_dprint(NDEBUG_ANY, instance); |
| 697 | NCR5380_dprint_phase(NDEBUG_ANY, instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 699 | hostdata = (struct NCR5380_hostdata *)instance->hostdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 701 | local_irq_save(flags); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 702 | if (!hostdata->connected) |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 703 | printk("scsi%d: no currently connected command\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 704 | else |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 705 | lprint_Scsi_Cmnd((struct scsi_cmnd *) hostdata->connected); |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 706 | printk("scsi%d: issue_queue\n", HOSTNO); |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 707 | for (ptr = (struct scsi_cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr)) |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 708 | lprint_Scsi_Cmnd(ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 710 | printk("scsi%d: disconnected_queue\n", HOSTNO); |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 711 | for (ptr = (struct scsi_cmnd *) hostdata->disconnected_queue; ptr; |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 712 | ptr = NEXT(ptr)) |
| 713 | lprint_Scsi_Cmnd(ptr); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 714 | |
| 715 | local_irq_restore(flags); |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 716 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 719 | static void show_Scsi_Cmnd(struct scsi_cmnd *cmd, struct seq_file *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 721 | int i, s; |
| 722 | unsigned char *command; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 723 | seq_printf(m, "scsi%d: destination target %d, lun %llu\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 724 | H_NO(cmd), cmd->device->id, cmd->device->lun); |
Rasmus Villemoes | 91c40f2 | 2014-12-03 00:10:52 +0100 | [diff] [blame] | 725 | seq_puts(m, " command = "); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 726 | command = cmd->cmnd; |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 727 | seq_printf(m, "%2d (0x%02x)", command[0], command[0]); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 728 | for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i) |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 729 | seq_printf(m, " %02x", command[i]); |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 730 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Finn Thain | 4d3d2a5 | 2014-11-12 16:11:52 +1100 | [diff] [blame] | 733 | static int __maybe_unused NCR5380_show_info(struct seq_file *m, |
| 734 | struct Scsi_Host *instance) |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 735 | { |
| 736 | struct NCR5380_hostdata *hostdata; |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 737 | struct scsi_cmnd *ptr; |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 738 | unsigned long flags; |
| 739 | |
| 740 | hostdata = (struct NCR5380_hostdata *)instance->hostdata; |
| 741 | |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 742 | local_irq_save(flags); |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 743 | if (!hostdata->connected) |
| 744 | seq_printf(m, "scsi%d: no currently connected command\n", HOSTNO); |
| 745 | else |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 746 | show_Scsi_Cmnd((struct scsi_cmnd *) hostdata->connected, m); |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 747 | seq_printf(m, "scsi%d: issue_queue\n", HOSTNO); |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 748 | for (ptr = (struct scsi_cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr)) |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 749 | show_Scsi_Cmnd(ptr, m); |
| 750 | |
| 751 | seq_printf(m, "scsi%d: disconnected_queue\n", HOSTNO); |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 752 | for (ptr = (struct scsi_cmnd *) hostdata->disconnected_queue; ptr; |
Al Viro | d89537e | 2013-03-31 13:24:44 -0400 | [diff] [blame] | 753 | ptr = NEXT(ptr)) |
| 754 | show_Scsi_Cmnd(ptr, m); |
| 755 | |
| 756 | local_irq_restore(flags); |
| 757 | return 0; |
| 758 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 760 | /** |
| 761 | * NCR5380_init - initialise an NCR5380 |
| 762 | * @instance: adapter to configure |
| 763 | * @flags: control flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 765 | * Initializes *instance and corresponding 5380 chip, |
| 766 | * with flags OR'd into the initial flags value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | * |
| 768 | * Notes : I assume that the host, hostno, and id bits have been |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 769 | * set correctly. I don't care about the irq and other fields. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 770 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 771 | * Returns 0 for success |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | */ |
| 773 | |
Michael Schmitz | 95fde7a | 2009-01-18 03:22:15 +0100 | [diff] [blame] | 774 | static int __init NCR5380_init(struct Scsi_Host *instance, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 776 | int i; |
| 777 | SETUP_HOSTDATA(instance); |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 778 | unsigned long deadline; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 780 | hostdata->host = instance; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 781 | hostdata->id_mask = 1 << instance->this_id; |
| 782 | hostdata->id_higher_mask = 0; |
| 783 | for (i = hostdata->id_mask; i <= 0x80; i <<= 1) |
| 784 | if (i > hostdata->id_mask) |
| 785 | hostdata->id_higher_mask |= i; |
| 786 | for (i = 0; i < 8; ++i) |
| 787 | hostdata->busy[i] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | #ifdef SUPPORT_TAGS |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 789 | init_tags(hostdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | #endif |
| 791 | #if defined (REAL_DMA) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 792 | hostdata->dma_len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 794 | hostdata->connected = NULL; |
| 795 | hostdata->issue_queue = NULL; |
| 796 | hostdata->disconnected_queue = NULL; |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 797 | hostdata->flags = flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 799 | INIT_WORK(&hostdata->main_task, NCR5380_main); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 800 | hostdata->work_q = alloc_workqueue("ncr5380_%d", |
| 801 | WQ_UNBOUND | WQ_MEM_RECLAIM, |
| 802 | 1, instance->host_no); |
| 803 | if (!hostdata->work_q) |
| 804 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 806 | prepare_info(instance); |
| 807 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 808 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 809 | NCR5380_write(MODE_REG, MR_BASE); |
| 810 | NCR5380_write(TARGET_COMMAND_REG, 0); |
| 811 | NCR5380_write(SELECT_ENABLE_REG, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Finn Thain | 2f854b8 | 2016-01-03 16:05:22 +1100 | [diff] [blame] | 813 | /* Calibrate register polling loop */ |
| 814 | i = 0; |
| 815 | deadline = jiffies + 1; |
| 816 | do { |
| 817 | cpu_relax(); |
| 818 | } while (time_is_after_jiffies(deadline)); |
| 819 | deadline += msecs_to_jiffies(256); |
| 820 | do { |
| 821 | NCR5380_read(STATUS_REG); |
| 822 | ++i; |
| 823 | cpu_relax(); |
| 824 | } while (time_is_after_jiffies(deadline)); |
| 825 | hostdata->accesses_per_ms = i / 256; |
| 826 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 827 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 830 | /** |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 831 | * NCR5380_maybe_reset_bus - Detect and correct bus wedge problems. |
| 832 | * @instance: adapter to check |
| 833 | * |
| 834 | * If the system crashed, it may have crashed with a connected target and |
| 835 | * the SCSI bus busy. Check for BUS FREE phase. If not, try to abort the |
| 836 | * currently established nexus, which we know nothing about. Failing that |
| 837 | * do a bus reset. |
| 838 | * |
| 839 | * Note that a bus reset will cause the chip to assert IRQ. |
| 840 | * |
| 841 | * Returns 0 if successful, otherwise -ENXIO. |
| 842 | */ |
| 843 | |
| 844 | static int NCR5380_maybe_reset_bus(struct Scsi_Host *instance) |
| 845 | { |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 846 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 847 | int pass; |
| 848 | |
| 849 | for (pass = 1; (NCR5380_read(STATUS_REG) & SR_BSY) && pass <= 6; ++pass) { |
| 850 | switch (pass) { |
| 851 | case 1: |
| 852 | case 3: |
| 853 | case 5: |
| 854 | shost_printk(KERN_ERR, instance, "SCSI bus busy, waiting up to five seconds\n"); |
| 855 | NCR5380_poll_politely(instance, |
| 856 | STATUS_REG, SR_BSY, 0, 5 * HZ); |
| 857 | break; |
| 858 | case 2: |
| 859 | shost_printk(KERN_ERR, instance, "bus busy, attempting abort\n"); |
| 860 | do_abort(instance); |
| 861 | break; |
| 862 | case 4: |
| 863 | shost_printk(KERN_ERR, instance, "bus busy, attempting reset\n"); |
| 864 | do_reset(instance); |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 865 | /* Wait after a reset; the SCSI standard calls for |
| 866 | * 250ms, we wait 500ms to be on the safe side. |
| 867 | * But some Toshiba CD-ROMs need ten times that. |
| 868 | */ |
| 869 | if (hostdata->flags & FLAG_TOSHIBA_DELAY) |
| 870 | msleep(2500); |
| 871 | else |
| 872 | msleep(500); |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 873 | break; |
| 874 | case 6: |
| 875 | shost_printk(KERN_ERR, instance, "bus locked solid\n"); |
| 876 | return -ENXIO; |
| 877 | } |
| 878 | } |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | /** |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 883 | * NCR5380_exit - remove an NCR5380 |
| 884 | * @instance: adapter to remove |
| 885 | * |
| 886 | * Assumes that no more work can be queued (e.g. by NCR5380_intr). |
| 887 | */ |
| 888 | |
Geert Uytterhoeven | 6323e4f | 2011-06-13 20:39:15 +0200 | [diff] [blame] | 889 | static void NCR5380_exit(struct Scsi_Host *instance) |
| 890 | { |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 891 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 892 | |
| 893 | cancel_work_sync(&hostdata->main_task); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 894 | destroy_workqueue(hostdata->work_q); |
Geert Uytterhoeven | 6323e4f | 2011-06-13 20:39:15 +0200 | [diff] [blame] | 895 | } |
| 896 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 897 | /** |
| 898 | * NCR5380_queue_command - queue a command |
| 899 | * @instance: the relevant SCSI adapter |
| 900 | * @cmd: SCSI command |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | * |
Finn Thain | 1bb4058 | 2016-01-03 16:05:29 +1100 | [diff] [blame] | 902 | * cmd is added to the per-instance issue queue, with minor |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 903 | * twiddling done to the host specific fields of cmd. If the |
| 904 | * main coroutine is not running, it is restarted. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | */ |
| 906 | |
Finn Thain | 16b29e7 | 2014-11-12 16:12:08 +1100 | [diff] [blame] | 907 | static int NCR5380_queue_command(struct Scsi_Host *instance, |
| 908 | struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | { |
Finn Thain | 16b29e7 | 2014-11-12 16:12:08 +1100 | [diff] [blame] | 910 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 911 | struct scsi_cmnd *tmp; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 912 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | #if (NDEBUG & NDEBUG_NO_WRITE) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 915 | switch (cmd->cmnd[0]) { |
| 916 | case WRITE_6: |
| 917 | case WRITE_10: |
| 918 | printk(KERN_NOTICE "scsi%d: WRITE attempted with NO_WRITE debugging flag set\n", |
| 919 | H_NO(cmd)); |
| 920 | cmd->result = (DID_ERROR << 16); |
Finn Thain | 16b29e7 | 2014-11-12 16:12:08 +1100 | [diff] [blame] | 921 | cmd->scsi_done(cmd); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 922 | return 0; |
| 923 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | #endif /* (NDEBUG & NDEBUG_NO_WRITE) */ |
| 925 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 926 | /* |
| 927 | * We use the host_scribble field as a pointer to the next command |
| 928 | * in a queue |
| 929 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 931 | SET_NEXT(cmd, NULL); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 932 | cmd->result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 934 | /* |
| 935 | * Insert the cmd into the issue queue. Note that REQUEST SENSE |
| 936 | * commands are added to the head of the queue since any command will |
| 937 | * clear the contingent allegiance condition that exists and the |
| 938 | * sense data is only guaranteed to be valid while the condition exists. |
| 939 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 941 | /* ++guenther: now that the issue queue is being set up, we can lock ST-DMA. |
| 942 | * Otherwise a running NCR5380_main may steal the lock. |
| 943 | * Lock before actually inserting due to fairness reasons explained in |
| 944 | * atari_scsi.c. If we insert first, then it's impossible for this driver |
| 945 | * to release the lock. |
| 946 | * Stop timer for this command while waiting for the lock, or timeouts |
| 947 | * may happen (and they really do), and it's no good if the command doesn't |
| 948 | * appear in any of the queues. |
| 949 | * ++roman: Just disabling the NCR interrupt isn't sufficient here, |
| 950 | * because also a timer int can trigger an abort or reset, which would |
| 951 | * alter queues and touch the lock. |
| 952 | */ |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 953 | if (!NCR5380_acquire_dma_irq(instance)) |
Finn Thain | 16b29e7 | 2014-11-12 16:12:08 +1100 | [diff] [blame] | 954 | return SCSI_MLQUEUE_HOST_BUSY; |
| 955 | |
| 956 | local_irq_save(flags); |
| 957 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 958 | /* |
| 959 | * Insert the cmd into the issue queue. Note that REQUEST SENSE |
| 960 | * commands are added to the head of the queue since any command will |
| 961 | * clear the contingent allegiance condition that exists and the |
| 962 | * sense data is only guaranteed to be valid while the condition exists. |
| 963 | */ |
| 964 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 965 | if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) { |
| 966 | LIST(cmd, hostdata->issue_queue); |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 967 | SET_NEXT(cmd, hostdata->issue_queue); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 968 | hostdata->issue_queue = cmd; |
| 969 | } else { |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 970 | for (tmp = (struct scsi_cmnd *)hostdata->issue_queue; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 971 | NEXT(tmp); tmp = NEXT(tmp)) |
| 972 | ; |
| 973 | LIST(cmd, tmp); |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 974 | SET_NEXT(tmp, cmd); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 975 | } |
| 976 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 978 | dprintk(NDEBUG_QUEUES, "scsi%d: command added to %s of queue\n", H_NO(cmd), |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 979 | (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
Finn Thain | 010e89d | 2016-01-03 16:05:38 +1100 | [diff] [blame] | 981 | /* Kick off command processing */ |
| 982 | queue_work(hostdata->work_q, &hostdata->main_task); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 983 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 986 | static inline void maybe_release_dma_irq(struct Scsi_Host *instance) |
| 987 | { |
| 988 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 989 | |
| 990 | /* Caller does the locking needed to set & test these data atomically */ |
| 991 | if (!hostdata->disconnected_queue && |
| 992 | !hostdata->issue_queue && |
| 993 | !hostdata->connected && |
| 994 | !hostdata->retain_dma_intr) |
| 995 | NCR5380_release_dma_irq(instance); |
| 996 | } |
| 997 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 998 | /** |
| 999 | * NCR5380_main - NCR state machines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 1001 | * NCR5380_main is a coroutine that runs as long as more work can |
| 1002 | * be done on the NCR5380 host adapters in a system. Both |
| 1003 | * NCR5380_queue_command() and NCR5380_intr() will try to start it |
| 1004 | * in case it is not running. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1005 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 1006 | * Locks: called as its own thread with no locks held. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1007 | */ |
| 1008 | |
Geert Uytterhoeven | b312b38 | 2007-05-01 22:32:48 +0200 | [diff] [blame] | 1009 | static void NCR5380_main(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | { |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 1011 | struct NCR5380_hostdata *hostdata = |
| 1012 | container_of(work, struct NCR5380_hostdata, main_task); |
| 1013 | struct Scsi_Host *instance = hostdata->host; |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 1014 | struct scsi_cmnd *tmp, *prev; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1015 | int done; |
| 1016 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1018 | /* |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1019 | * ++roman: Just disabling the NCR interrupt isn't sufficient here, |
| 1020 | * because also a timer int can trigger an abort or reset, which can |
| 1021 | * alter queues and touch the Falcon lock. |
| 1022 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1024 | local_save_flags(flags); |
| 1025 | do { |
| 1026 | local_irq_disable(); /* Freeze request queues */ |
| 1027 | done = 1; |
| 1028 | |
| 1029 | if (!hostdata->connected) { |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1030 | dprintk(NDEBUG_MAIN, "scsi%d: not connected\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1031 | /* |
| 1032 | * Search through the issue_queue for a command destined |
| 1033 | * for a target that's not busy. |
| 1034 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | #if (NDEBUG & NDEBUG_LISTS) |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 1036 | for (tmp = (struct scsi_cmnd *) hostdata->issue_queue, prev = NULL; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1037 | tmp && (tmp != prev); prev = tmp, tmp = NEXT(tmp)) |
| 1038 | ; |
| 1039 | /*printk("%p ", tmp);*/ |
| 1040 | if ((tmp == prev) && tmp) |
| 1041 | printk(" LOOP\n"); |
| 1042 | /* else printk("\n"); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | #endif |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 1044 | for (tmp = (struct scsi_cmnd *) hostdata->issue_queue, |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1045 | prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp)) { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 1046 | u8 lun = tmp->device->lun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1048 | dprintk(NDEBUG_LISTS, |
| 1049 | "MAIN tmp=%p target=%d busy=%d lun=%d\n", |
| 1050 | tmp, scmd_id(tmp), hostdata->busy[scmd_id(tmp)], |
| 1051 | lun); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1052 | /* When we find one, remove it from the issue queue. */ |
| 1053 | /* ++guenther: possible race with Falcon locking */ |
| 1054 | if ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | #ifdef SUPPORT_TAGS |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1056 | !is_lun_busy( tmp, tmp->cmnd[0] != REQUEST_SENSE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | #else |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 1058 | !(hostdata->busy[tmp->device->id] & (1 << lun)) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1059 | #endif |
| 1060 | ) { |
| 1061 | /* ++guenther: just to be sure, this must be atomic */ |
| 1062 | local_irq_disable(); |
| 1063 | if (prev) { |
| 1064 | REMOVE(prev, NEXT(prev), tmp, NEXT(tmp)); |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 1065 | SET_NEXT(prev, NEXT(tmp)); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1066 | } else { |
| 1067 | REMOVE(-1, hostdata->issue_queue, tmp, NEXT(tmp)); |
| 1068 | hostdata->issue_queue = NEXT(tmp); |
| 1069 | } |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 1070 | SET_NEXT(tmp, NULL); |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 1071 | hostdata->retain_dma_intr++; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1072 | |
| 1073 | /* reenable interrupts after finding one */ |
| 1074 | local_irq_restore(flags); |
| 1075 | |
| 1076 | /* |
| 1077 | * Attempt to establish an I_T_L nexus here. |
| 1078 | * On success, instance->hostdata->connected is set. |
| 1079 | * On failure, we must add the command back to the |
| 1080 | * issue queue so we can keep trying. |
| 1081 | */ |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1082 | dprintk(NDEBUG_MAIN, "scsi%d: main(): command for target %d " |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1083 | "lun %d removed from issue_queue\n", |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 1084 | HOSTNO, tmp->device->id, lun); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1085 | /* |
| 1086 | * REQUEST SENSE commands are issued without tagged |
| 1087 | * queueing, even on SCSI-II devices because the |
| 1088 | * contingent allegiance condition exists for the |
| 1089 | * entire unit. |
| 1090 | */ |
| 1091 | /* ++roman: ...and the standard also requires that |
| 1092 | * REQUEST SENSE command are untagged. |
| 1093 | */ |
| 1094 | |
| 1095 | #ifdef SUPPORT_TAGS |
| 1096 | cmd_get_tag(tmp, tmp->cmnd[0] != REQUEST_SENSE); |
| 1097 | #endif |
Finn Thain | 76f13b9 | 2014-11-12 16:11:53 +1100 | [diff] [blame] | 1098 | if (!NCR5380_select(instance, tmp)) { |
Finn Thain | 1f1b0c7 | 2016-01-03 16:05:17 +1100 | [diff] [blame] | 1099 | /* OK or bad target */ |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 1100 | local_irq_disable(); |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 1101 | hostdata->retain_dma_intr--; |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 1102 | maybe_release_dma_irq(instance); |
| 1103 | local_irq_restore(flags); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1104 | } else { |
Finn Thain | 1f1b0c7 | 2016-01-03 16:05:17 +1100 | [diff] [blame] | 1105 | /* Need to retry */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1106 | local_irq_disable(); |
| 1107 | LIST(tmp, hostdata->issue_queue); |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 1108 | SET_NEXT(tmp, hostdata->issue_queue); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1109 | hostdata->issue_queue = tmp; |
| 1110 | #ifdef SUPPORT_TAGS |
| 1111 | cmd_free_tag(tmp); |
| 1112 | #endif |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 1113 | hostdata->retain_dma_intr--; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1114 | local_irq_restore(flags); |
Finn Thain | 1d3db59 | 2016-01-03 16:05:24 +1100 | [diff] [blame] | 1115 | done = 0; |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1116 | dprintk(NDEBUG_MAIN, "scsi%d: main(): select() failed, " |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1117 | "returned to issue_queue\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1118 | } |
Finn Thain | 1f1b0c7 | 2016-01-03 16:05:17 +1100 | [diff] [blame] | 1119 | if (hostdata->connected) |
| 1120 | break; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1121 | } /* if target/lun/target queue is not busy */ |
| 1122 | } /* for issue_queue */ |
| 1123 | } /* if (!hostdata->connected) */ |
| 1124 | |
| 1125 | if (hostdata->connected |
| 1126 | #ifdef REAL_DMA |
| 1127 | && !hostdata->dma_len |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | #endif |
| 1129 | ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | local_irq_restore(flags); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1131 | dprintk(NDEBUG_MAIN, "scsi%d: main: performing information transfer\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1132 | HOSTNO); |
| 1133 | NCR5380_information_transfer(instance); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1134 | dprintk(NDEBUG_MAIN, "scsi%d: main: done set false\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1135 | done = 0; |
| 1136 | } |
| 1137 | } while (!done); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1138 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | #ifdef REAL_DMA |
| 1143 | /* |
| 1144 | * Function : void NCR5380_dma_complete (struct Scsi_Host *instance) |
| 1145 | * |
| 1146 | * Purpose : Called by interrupt handler when DMA finishes or a phase |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1147 | * mismatch occurs (which would finish the DMA transfer). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | * |
| 1149 | * Inputs : instance - this instance of the NCR5380. |
| 1150 | * |
| 1151 | */ |
| 1152 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1153 | static void NCR5380_dma_complete(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1155 | SETUP_HOSTDATA(instance); |
Finn Thain | 01bd908 | 2014-11-12 16:12:23 +1100 | [diff] [blame] | 1156 | int transferred; |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1157 | unsigned char **data; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1158 | volatile int *count; |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1159 | int saved_data = 0, overrun = 0; |
| 1160 | unsigned char p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 1162 | if (hostdata->read_overruns) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1163 | p = hostdata->connected->SCp.phase; |
| 1164 | if (p & SR_IO) { |
| 1165 | udelay(10); |
| 1166 | if ((NCR5380_read(BUS_AND_STATUS_REG) & |
| 1167 | (BASR_PHASE_MATCH|BASR_ACK)) == |
| 1168 | (BASR_PHASE_MATCH|BASR_ACK)) { |
| 1169 | saved_data = NCR5380_read(INPUT_DATA_REG); |
| 1170 | overrun = 1; |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1171 | dprintk(NDEBUG_DMA, "scsi%d: read overrun handled\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1172 | } |
| 1173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | } |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1175 | |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1176 | #if defined(CONFIG_SUN3) |
| 1177 | if ((sun3scsi_dma_finish(rq_data_dir(hostdata->connected->request)))) { |
| 1178 | pr_err("scsi%d: overrun in UDC counter -- not prepared to deal with this!\n", |
| 1179 | instance->host_no); |
| 1180 | BUG(); |
| 1181 | } |
| 1182 | |
| 1183 | /* make sure we're not stuck in a data phase */ |
| 1184 | if ((NCR5380_read(BUS_AND_STATUS_REG) & (BASR_PHASE_MATCH | BASR_ACK)) == |
| 1185 | (BASR_PHASE_MATCH | BASR_ACK)) { |
| 1186 | pr_err("scsi%d: BASR %02x\n", instance->host_no, |
| 1187 | NCR5380_read(BUS_AND_STATUS_REG)); |
| 1188 | pr_err("scsi%d: bus stuck in data phase -- probably a single byte overrun!\n", |
| 1189 | instance->host_no); |
| 1190 | BUG(); |
| 1191 | } |
| 1192 | #endif |
| 1193 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1194 | NCR5380_write(MODE_REG, MR_BASE); |
| 1195 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1196 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1197 | |
Finn Thain | 01bd908 | 2014-11-12 16:12:23 +1100 | [diff] [blame] | 1198 | transferred = hostdata->dma_len - NCR5380_dma_residual(instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1199 | hostdata->dma_len = 0; |
| 1200 | |
| 1201 | data = (unsigned char **)&hostdata->connected->SCp.ptr; |
| 1202 | count = &hostdata->connected->SCp.this_residual; |
Finn Thain | 01bd908 | 2014-11-12 16:12:23 +1100 | [diff] [blame] | 1203 | *data += transferred; |
| 1204 | *count -= transferred; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1205 | |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 1206 | if (hostdata->read_overruns) { |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1207 | int cnt, toPIO; |
| 1208 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1209 | if ((NCR5380_read(STATUS_REG) & PHASE_MASK) == p && (p & SR_IO)) { |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 1210 | cnt = toPIO = hostdata->read_overruns; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1211 | if (overrun) { |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1212 | dprintk(NDEBUG_DMA, "Got an input overrun, using saved byte\n"); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1213 | *(*data)++ = saved_data; |
| 1214 | (*count)--; |
| 1215 | cnt--; |
| 1216 | toPIO--; |
| 1217 | } |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1218 | dprintk(NDEBUG_DMA, "Doing %d-byte PIO to 0x%08lx\n", cnt, (long)*data); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1219 | NCR5380_transfer_pio(instance, &p, &cnt, data); |
| 1220 | *count -= toPIO - cnt; |
| 1221 | } |
| 1222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | } |
| 1224 | #endif /* REAL_DMA */ |
| 1225 | |
| 1226 | |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 1227 | /** |
| 1228 | * NCR5380_intr - generic NCR5380 irq handler |
| 1229 | * @irq: interrupt number |
| 1230 | * @dev_id: device info |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1231 | * |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 1232 | * Handle interrupts, reestablishing I_T_L or I_T_L_Q nexuses |
| 1233 | * from the disconnected queue, and restarting NCR5380_main() |
| 1234 | * as required. |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1235 | * |
| 1236 | * The chip can assert IRQ in any of six different conditions. The IRQ flag |
| 1237 | * is then cleared by reading the Reset Parity/Interrupt Register (RPIR). |
| 1238 | * Three of these six conditions are latched in the Bus and Status Register: |
| 1239 | * - End of DMA (cleared by ending DMA Mode) |
| 1240 | * - Parity error (cleared by reading RPIR) |
| 1241 | * - Loss of BSY (cleared by reading RPIR) |
| 1242 | * Two conditions have flag bits that are not latched: |
| 1243 | * - Bus phase mismatch (non-maskable in DMA Mode, cleared by ending DMA Mode) |
| 1244 | * - Bus reset (non-maskable) |
| 1245 | * The remaining condition has no flag bit at all: |
| 1246 | * - Selection/reselection |
| 1247 | * |
| 1248 | * Hence, establishing the cause(s) of any interrupt is partly guesswork. |
| 1249 | * In "The DP8490 and DP5380 Comparison Guide", National Semiconductor |
| 1250 | * claimed that "the design of the [DP8490] interrupt logic ensures |
| 1251 | * interrupts will not be lost (they can be on the DP5380)." |
| 1252 | * The L5380/53C80 datasheet from LOGIC Devices has more details. |
| 1253 | * |
| 1254 | * Checking for bus reset by reading RST is futile because of interrupt |
| 1255 | * latency, but a bus reset will reset chip logic. Checking for parity error |
| 1256 | * is unnecessary because that interrupt is never enabled. A Loss of BSY |
| 1257 | * condition will clear DMA Mode. We can tell when this occurs because the |
| 1258 | * the Busy Monitor interrupt is enabled together with DMA Mode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | */ |
| 1260 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1261 | static irqreturn_t NCR5380_intr(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | { |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 1263 | struct Scsi_Host *instance = dev_id; |
Finn Thain | 010e89d | 2016-01-03 16:05:38 +1100 | [diff] [blame] | 1264 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1265 | int handled = 0; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1266 | unsigned char basr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1268 | basr = NCR5380_read(BUS_AND_STATUS_REG); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1269 | if (basr & BASR_IRQ) { |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1270 | unsigned char mr = NCR5380_read(MODE_REG); |
| 1271 | unsigned char sr = NCR5380_read(STATUS_REG); |
| 1272 | |
| 1273 | dprintk(NDEBUG_INTR, "scsi%d: IRQ %d, BASR 0x%02x, SR 0x%02x, MR 0x%02x\n", |
| 1274 | HOSTNO, irq, basr, sr, mr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | |
| 1276 | #if defined(REAL_DMA) |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1277 | if ((mr & MR_DMA_MODE) || (mr & MR_MONITOR_BSY)) { |
| 1278 | /* Probably End of DMA, Phase Mismatch or Loss of BSY. |
| 1279 | * We ack IRQ after clearing Mode Register. Workarounds |
| 1280 | * for End of DMA errata need to happen in DMA Mode. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1281 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1283 | dprintk(NDEBUG_INTR, "scsi%d: interrupt in DMA mode\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1284 | |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1285 | if (hostdata->connected) { |
| 1286 | NCR5380_dma_complete(instance); |
| 1287 | queue_work(hostdata->work_q, &hostdata->main_task); |
| 1288 | } else { |
| 1289 | NCR5380_write(MODE_REG, MR_BASE); |
| 1290 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1291 | } |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1292 | } else |
| 1293 | #endif /* REAL_DMA */ |
| 1294 | if ((NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_mask) && |
| 1295 | (sr & (SR_SEL | SR_IO | SR_BSY | SR_RST)) == (SR_SEL | SR_IO)) { |
| 1296 | /* Probably reselected */ |
| 1297 | NCR5380_write(SELECT_ENABLE_REG, 0); |
| 1298 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 1299 | |
| 1300 | dprintk(NDEBUG_INTR, "scsi%d: interrupt with SEL and IO\n", |
| 1301 | HOSTNO); |
| 1302 | |
| 1303 | if (!hostdata->connected) { |
| 1304 | NCR5380_reselect(instance); |
| 1305 | queue_work(hostdata->work_q, &hostdata->main_task); |
| 1306 | } |
| 1307 | if (!hostdata->connected) |
| 1308 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
| 1309 | } else { |
| 1310 | /* Probably Bus Reset */ |
| 1311 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 1312 | |
| 1313 | dprintk(NDEBUG_INTR, "scsi%d: unknown interrupt\n", HOSTNO); |
| 1314 | #ifdef SUN3_SCSI_VME |
| 1315 | dregs->csr |= CSR_DMA_ENABLE; |
| 1316 | #endif |
| 1317 | } |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1318 | handled = 1; |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1319 | } else { |
| 1320 | shost_printk(KERN_NOTICE, instance, "interrupt without IRQ bit\n"); |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1321 | #ifdef SUN3_SCSI_VME |
| 1322 | dregs->csr |= CSR_DMA_ENABLE; |
| 1323 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1324 | } |
| 1325 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1326 | return IRQ_RETVAL(handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1329 | /* |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 1330 | * Function : int NCR5380_select(struct Scsi_Host *instance, |
| 1331 | * struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | * |
| 1333 | * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command, |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1334 | * including ARBITRATION, SELECTION, and initial message out for |
| 1335 | * IDENTIFY and queue messages. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1337 | * Inputs : instance - instantiation of the 5380 driver on which this |
Finn Thain | 76f13b9 | 2014-11-12 16:11:53 +1100 | [diff] [blame] | 1338 | * target lives, cmd - SCSI command to execute. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | * |
Finn Thain | 6323876 | 2016-01-03 16:05:15 +1100 | [diff] [blame] | 1340 | * Returns : -1 if selection failed but should be retried. |
| 1341 | * 0 if selection failed and should not be retried. |
| 1342 | * 0 if selection succeeded completely (hostdata->connected == cmd). |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1343 | * |
| 1344 | * Side effects : |
| 1345 | * If bus busy, arbitration failed, etc, NCR5380_select() will exit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | * with registers as they should have been on entry - ie |
| 1347 | * SELECT_ENABLE will be set appropriately, the NCR5380 |
| 1348 | * will cease to drive any SCSI bus signals. |
| 1349 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1350 | * If successful : I_T_L or I_T_L_Q nexus will be established, |
| 1351 | * instance->connected will be set to cmd. |
| 1352 | * SELECT interrupt will be disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1354 | * If failed (no target) : cmd->scsi_done() will be called, and the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | * cmd->result host byte set to DID_BAD_TARGET. |
| 1356 | */ |
| 1357 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 1358 | static int NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1360 | SETUP_HOSTDATA(instance); |
| 1361 | unsigned char tmp[3], phase; |
| 1362 | unsigned char *data; |
| 1363 | int len; |
Finn Thain | ae753a3 | 2016-01-03 16:05:23 +1100 | [diff] [blame] | 1364 | int err; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1365 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | |
Finn Thain | 8ad3a59 | 2014-03-18 11:42:19 +1100 | [diff] [blame] | 1367 | NCR5380_dprint(NDEBUG_ARBITRATION, instance); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1368 | dprintk(NDEBUG_ARBITRATION, "scsi%d: starting arbitration, id = %d\n", HOSTNO, |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1369 | instance->this_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1371 | /* |
| 1372 | * Set the phase bits to 0, otherwise the NCR5380 won't drive the |
| 1373 | * data bus during SELECTION. |
| 1374 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1376 | local_irq_save(flags); |
| 1377 | if (hostdata->connected) { |
| 1378 | local_irq_restore(flags); |
| 1379 | return -1; |
| 1380 | } |
| 1381 | NCR5380_write(TARGET_COMMAND_REG, 0); |
| 1382 | |
| 1383 | /* |
| 1384 | * Start arbitration. |
| 1385 | */ |
| 1386 | |
| 1387 | NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask); |
| 1388 | NCR5380_write(MODE_REG, MR_ARBITRATE); |
| 1389 | |
Finn Thain | 55500d9 | 2016-01-03 16:05:35 +1100 | [diff] [blame] | 1390 | /* The chip now waits for BUS FREE phase. Then after the 800 ns |
| 1391 | * Bus Free Delay, arbitration will begin. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1392 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
Finn Thain | 55500d9 | 2016-01-03 16:05:35 +1100 | [diff] [blame] | 1394 | local_irq_restore(flags); |
Finn Thain | b32ade1 | 2016-01-03 16:05:41 +1100 | [diff] [blame^] | 1395 | err = NCR5380_poll_politely2(instance, MODE_REG, MR_ARBITRATE, 0, |
| 1396 | INITIATOR_COMMAND_REG, ICR_ARBITRATION_PROGRESS, |
| 1397 | ICR_ARBITRATION_PROGRESS, HZ); |
| 1398 | if (!(NCR5380_read(MODE_REG) & MR_ARBITRATE)) { |
| 1399 | /* Reselection interrupt */ |
| 1400 | return -1; |
| 1401 | } |
| 1402 | if (err < 0) { |
| 1403 | NCR5380_write(MODE_REG, MR_BASE); |
| 1404 | shost_printk(KERN_ERR, instance, |
| 1405 | "select: arbitration timeout\n"); |
| 1406 | return -1; |
Finn Thain | 55500d9 | 2016-01-03 16:05:35 +1100 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | /* The SCSI-2 arbitration delay is 2.4 us */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1410 | udelay(3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1412 | /* Check for lost arbitration */ |
| 1413 | if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) || |
| 1414 | (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) || |
| 1415 | (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) || |
| 1416 | hostdata->connected) { |
| 1417 | NCR5380_write(MODE_REG, MR_BASE); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1418 | dprintk(NDEBUG_ARBITRATION, "scsi%d: lost arbitration, deasserting MR_ARBITRATE\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1419 | HOSTNO); |
| 1420 | return -1; |
| 1421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Finn Thain | cf13b08 | 2016-01-03 16:05:18 +1100 | [diff] [blame] | 1423 | /* After/during arbitration, BSY should be asserted. |
| 1424 | * IBM DPES-31080 Version S31Q works now |
| 1425 | * Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman) |
| 1426 | */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1427 | NCR5380_write(INITIATOR_COMMAND_REG, |
| 1428 | ICR_BASE | ICR_ASSERT_SEL | ICR_ASSERT_BSY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1430 | if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) || |
| 1431 | hostdata->connected) { |
| 1432 | NCR5380_write(MODE_REG, MR_BASE); |
| 1433 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1434 | dprintk(NDEBUG_ARBITRATION, "scsi%d: lost arbitration, deasserting ICR_ASSERT_SEL\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1435 | HOSTNO); |
| 1436 | return -1; |
| 1437 | } |
| 1438 | |
| 1439 | /* |
| 1440 | * Again, bus clear + bus settle time is 1.2us, however, this is |
| 1441 | * a minimum so we'll udelay ceil(1.2) |
| 1442 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | |
Finn Thain | 9c3f0e2 | 2016-01-03 16:05:11 +1100 | [diff] [blame] | 1444 | if (hostdata->flags & FLAG_TOSHIBA_DELAY) |
| 1445 | udelay(15); |
| 1446 | else |
| 1447 | udelay(2); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1448 | |
| 1449 | if (hostdata->connected) { |
| 1450 | NCR5380_write(MODE_REG, MR_BASE); |
| 1451 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1452 | return -1; |
| 1453 | } |
| 1454 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1455 | dprintk(NDEBUG_ARBITRATION, "scsi%d: won arbitration\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1456 | |
| 1457 | /* |
| 1458 | * Now that we have won arbitration, start Selection process, asserting |
| 1459 | * the host and target ID's on the SCSI bus. |
| 1460 | */ |
| 1461 | |
| 1462 | NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->device->id))); |
| 1463 | |
| 1464 | /* |
| 1465 | * Raise ATN while SEL is true before BSY goes false from arbitration, |
| 1466 | * since this is the only way to guarantee that we'll get a MESSAGE OUT |
| 1467 | * phase immediately after selection. |
| 1468 | */ |
| 1469 | |
| 1470 | NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_BSY | |
| 1471 | ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL )); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | NCR5380_write(MODE_REG, MR_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1474 | /* |
| 1475 | * Reselect interrupts must be turned off prior to the dropping of BSY, |
| 1476 | * otherwise we will trigger an interrupt. |
| 1477 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1479 | if (hostdata->connected) { |
| 1480 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1481 | return -1; |
| 1482 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1484 | NCR5380_write(SELECT_ENABLE_REG, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1486 | /* |
| 1487 | * The initiator shall then wait at least two deskew delays and release |
| 1488 | * the BSY signal. |
| 1489 | */ |
| 1490 | udelay(1); /* wingel -- wait two bus deskew delay >2*45ns */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1492 | /* Reset BSY */ |
| 1493 | NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_DATA | |
| 1494 | ICR_ASSERT_ATN | ICR_ASSERT_SEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1496 | /* |
| 1497 | * Something weird happens when we cease to drive BSY - looks |
| 1498 | * like the board/chip is letting us do another read before the |
| 1499 | * appropriate propagation delay has expired, and we're confusing |
| 1500 | * a BSY signal from ourselves as the target's response to SELECTION. |
| 1501 | * |
| 1502 | * A small delay (the 'C++' frontend breaks the pipeline with an |
| 1503 | * unnecessary jump, making it work on my 386-33/Trantor T128, the |
| 1504 | * tighter 'C' code breaks and requires this) solves the problem - |
| 1505 | * the 1 us delay is arbitrary, and only used because this delay will |
| 1506 | * be the same on other platforms and since it works here, it should |
| 1507 | * work there. |
| 1508 | * |
| 1509 | * wingel suggests that this could be due to failing to wait |
| 1510 | * one deskew delay. |
| 1511 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1513 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1515 | dprintk(NDEBUG_SELECTION, "scsi%d: selecting target %d\n", HOSTNO, cmd->device->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1517 | /* |
| 1518 | * The SCSI specification calls for a 250 ms timeout for the actual |
| 1519 | * selection. |
| 1520 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | |
Finn Thain | ae753a3 | 2016-01-03 16:05:23 +1100 | [diff] [blame] | 1522 | err = NCR5380_poll_politely(instance, STATUS_REG, SR_BSY, SR_BSY, |
| 1523 | msecs_to_jiffies(250)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1525 | if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) { |
| 1526 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1527 | NCR5380_reselect(instance); |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1528 | if (!hostdata->connected) |
| 1529 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1530 | printk(KERN_ERR "scsi%d: reselection after won arbitration?\n", |
| 1531 | HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1532 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | } |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1534 | |
Finn Thain | ae753a3 | 2016-01-03 16:05:23 +1100 | [diff] [blame] | 1535 | if (err < 0) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1536 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1537 | cmd->result = DID_BAD_TARGET << 16; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1538 | #ifdef SUPPORT_TAGS |
| 1539 | cmd_free_tag(cmd); |
| 1540 | #endif |
| 1541 | cmd->scsi_done(cmd); |
| 1542 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1543 | dprintk(NDEBUG_SELECTION, "scsi%d: target did not respond within 250ms\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1544 | return 0; |
| 1545 | } |
| 1546 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1547 | /* |
Finn Thain | ae753a3 | 2016-01-03 16:05:23 +1100 | [diff] [blame] | 1548 | * No less than two deskew delays after the initiator detects the |
| 1549 | * BSY signal is true, it shall release the SEL signal and may |
| 1550 | * change the DATA BUS. -wingel |
| 1551 | */ |
| 1552 | |
| 1553 | udelay(1); |
| 1554 | |
| 1555 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
| 1556 | |
| 1557 | /* |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1558 | * Since we followed the SCSI spec, and raised ATN while SEL |
| 1559 | * was true but before BSY was false during selection, the information |
| 1560 | * transfer phase should be a MESSAGE OUT phase so that we can send the |
| 1561 | * IDENTIFY message. |
| 1562 | * |
| 1563 | * If SCSI-II tagged queuing is enabled, we also send a SIMPLE_QUEUE_TAG |
| 1564 | * message (2 bytes) with a tag ID that we increment with every command |
| 1565 | * until it wraps back to 0. |
| 1566 | * |
| 1567 | * XXX - it turns out that there are some broken SCSI-II devices, |
| 1568 | * which claim to support tagged queuing but fail when more than |
| 1569 | * some number of commands are issued at once. |
| 1570 | */ |
| 1571 | |
| 1572 | /* Wait for start of REQ/ACK handshake */ |
Finn Thain | 55500d9 | 2016-01-03 16:05:35 +1100 | [diff] [blame] | 1573 | |
| 1574 | err = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ); |
| 1575 | if (err < 0) { |
| 1576 | shost_printk(KERN_ERR, instance, "select: REQ timeout\n"); |
| 1577 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1578 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
| 1579 | return -1; |
| 1580 | } |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1581 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1582 | dprintk(NDEBUG_SELECTION, "scsi%d: target %d selected, going into MESSAGE OUT phase.\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1583 | HOSTNO, cmd->device->id); |
| 1584 | tmp[0] = IDENTIFY(1, cmd->device->lun); |
| 1585 | |
| 1586 | #ifdef SUPPORT_TAGS |
| 1587 | if (cmd->tag != TAG_NONE) { |
| 1588 | tmp[1] = hostdata->last_message = SIMPLE_QUEUE_TAG; |
| 1589 | tmp[2] = cmd->tag; |
| 1590 | len = 3; |
| 1591 | } else |
| 1592 | len = 1; |
| 1593 | #else |
| 1594 | len = 1; |
| 1595 | cmd->tag = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | #endif /* SUPPORT_TAGS */ |
| 1597 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1598 | /* Send message(s) */ |
| 1599 | data = tmp; |
| 1600 | phase = PHASE_MSGOUT; |
| 1601 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1602 | dprintk(NDEBUG_SELECTION, "scsi%d: nexus established.\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1603 | /* XXX need to handle errors here */ |
| 1604 | hostdata->connected = cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | #ifndef SUPPORT_TAGS |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1606 | hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun); |
| 1607 | #endif |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1608 | #ifdef SUN3_SCSI_VME |
| 1609 | dregs->csr |= CSR_INTR; |
| 1610 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1612 | initialize_SCp(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1614 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1617 | /* |
| 1618 | * Function : int NCR5380_transfer_pio (struct Scsi_Host *instance, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | * unsigned char *phase, int *count, unsigned char **data) |
| 1620 | * |
| 1621 | * Purpose : transfers data in given phase using polled I/O |
| 1622 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1623 | * Inputs : instance - instance of driver, *phase - pointer to |
| 1624 | * what phase is expected, *count - pointer to number of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | * bytes to transfer, **data - pointer to data pointer. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1626 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | * Returns : -1 when different phase is entered without transferring |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1628 | * maximum number of bytes, 0 if all bytes are transferred or exit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | * is in same phase. |
| 1630 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1631 | * Also, *phase, *count, *data are modified in place. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | * |
| 1633 | * XXX Note : handling for bus free may be useful. |
| 1634 | */ |
| 1635 | |
| 1636 | /* |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1637 | * 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] | 1638 | * IS 100% reliable, and for the actual data transfer where speed |
| 1639 | * counts, we will always do a pseudo DMA or DMA transfer. |
| 1640 | */ |
| 1641 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1642 | static int NCR5380_transfer_pio(struct Scsi_Host *instance, |
| 1643 | unsigned char *phase, int *count, |
| 1644 | unsigned char **data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1646 | register unsigned char p = *phase, tmp; |
| 1647 | register int c = *count; |
| 1648 | register unsigned char *d = *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1650 | /* |
| 1651 | * The NCR5380 chip will only drive the SCSI bus when the |
| 1652 | * phase specified in the appropriate bits of the TARGET COMMAND |
| 1653 | * REGISTER match the STATUS REGISTER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | */ |
| 1655 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1656 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1658 | do { |
| 1659 | /* |
| 1660 | * Wait for assertion of REQ, after which the phase bits will be |
| 1661 | * valid |
| 1662 | */ |
Finn Thain | 686f399 | 2016-01-03 16:05:26 +1100 | [diff] [blame] | 1663 | |
| 1664 | if (NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ) < 0) |
| 1665 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1667 | dprintk(NDEBUG_HANDSHAKE, "scsi%d: REQ detected\n", HOSTNO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1669 | /* Check for phase mismatch */ |
Finn Thain | 686f399 | 2016-01-03 16:05:26 +1100 | [diff] [blame] | 1670 | if ((NCR5380_read(STATUS_REG) & PHASE_MASK) != p) { |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1671 | dprintk(NDEBUG_PIO, "scsi%d: phase mismatch\n", HOSTNO); |
Finn Thain | 8ad3a59 | 2014-03-18 11:42:19 +1100 | [diff] [blame] | 1672 | NCR5380_dprint_phase(NDEBUG_PIO, instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1673 | break; |
| 1674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1676 | /* Do actual transfer from SCSI bus to / from memory */ |
| 1677 | if (!(p & SR_IO)) |
| 1678 | NCR5380_write(OUTPUT_DATA_REG, *d); |
| 1679 | else |
| 1680 | *d = NCR5380_read(CURRENT_SCSI_DATA_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1682 | ++d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1684 | /* |
| 1685 | * The SCSI standard suggests that in MSGOUT phase, the initiator |
| 1686 | * should drop ATN on the last byte of the message phase |
| 1687 | * after REQ has been asserted for the handshake but before |
| 1688 | * the initiator raises ACK. |
| 1689 | */ |
| 1690 | |
| 1691 | if (!(p & SR_IO)) { |
| 1692 | if (!((p & SR_MSG) && c > 1)) { |
| 1693 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA); |
Finn Thain | 8ad3a59 | 2014-03-18 11:42:19 +1100 | [diff] [blame] | 1694 | NCR5380_dprint(NDEBUG_PIO, instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1695 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | |
| 1696 | ICR_ASSERT_DATA | ICR_ASSERT_ACK); |
| 1697 | } else { |
| 1698 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | |
| 1699 | ICR_ASSERT_DATA | ICR_ASSERT_ATN); |
Finn Thain | 8ad3a59 | 2014-03-18 11:42:19 +1100 | [diff] [blame] | 1700 | NCR5380_dprint(NDEBUG_PIO, instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1701 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | |
| 1702 | ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_ACK); |
| 1703 | } |
| 1704 | } else { |
Finn Thain | 8ad3a59 | 2014-03-18 11:42:19 +1100 | [diff] [blame] | 1705 | NCR5380_dprint(NDEBUG_PIO, instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1706 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK); |
| 1707 | } |
| 1708 | |
Finn Thain | a2edc4a | 2016-01-03 16:05:27 +1100 | [diff] [blame] | 1709 | if (NCR5380_poll_politely(instance, |
| 1710 | STATUS_REG, SR_REQ, 0, 5 * HZ) < 0) |
| 1711 | break; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1712 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1713 | dprintk(NDEBUG_HANDSHAKE, "scsi%d: req false, handshake complete\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1714 | |
| 1715 | /* |
| 1716 | * We have several special cases to consider during REQ/ACK handshaking : |
| 1717 | * 1. We were in MSGOUT phase, and we are on the last byte of the |
| 1718 | * message. ATN must be dropped as ACK is dropped. |
| 1719 | * |
| 1720 | * 2. We are in a MSGIN phase, and we are on the last byte of the |
| 1721 | * message. We must exit with ACK asserted, so that the calling |
| 1722 | * code may raise ATN before dropping ACK to reject the message. |
| 1723 | * |
| 1724 | * 3. ACK and ATN are clear and the target may proceed as normal. |
| 1725 | */ |
| 1726 | if (!(p == PHASE_MSGIN && c == 1)) { |
| 1727 | if (p == PHASE_MSGOUT && c > 1) |
| 1728 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
| 1729 | else |
| 1730 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1731 | } |
| 1732 | } while (--c); |
| 1733 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1734 | dprintk(NDEBUG_PIO, "scsi%d: residual %d\n", HOSTNO, c); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1735 | |
| 1736 | *count = c; |
| 1737 | *data = d; |
| 1738 | tmp = NCR5380_read(STATUS_REG); |
| 1739 | /* The phase read from the bus is valid if either REQ is (already) |
Finn Thain | a2edc4a | 2016-01-03 16:05:27 +1100 | [diff] [blame] | 1740 | * asserted or if ACK hasn't been released yet. The latter applies if |
| 1741 | * we're in MSG IN, DATA IN or STATUS and all bytes have been received. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1742 | */ |
Finn Thain | a2edc4a | 2016-01-03 16:05:27 +1100 | [diff] [blame] | 1743 | if ((tmp & SR_REQ) || ((tmp & SR_IO) && c == 0)) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1744 | *phase = tmp & PHASE_MASK; |
| 1745 | else |
| 1746 | *phase = PHASE_UNKNOWN; |
| 1747 | |
| 1748 | if (!c || (*phase == p)) |
| 1749 | return 0; |
| 1750 | else |
| 1751 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Finn Thain | 636b1ec | 2016-01-03 16:05:10 +1100 | [diff] [blame] | 1754 | /** |
| 1755 | * do_reset - issue a reset command |
| 1756 | * @instance: adapter to reset |
| 1757 | * |
| 1758 | * Issue a reset sequence to the NCR5380 and try and get the bus |
| 1759 | * back into sane shape. |
| 1760 | * |
| 1761 | * This clears the reset interrupt flag because there may be no handler for |
| 1762 | * it. When the driver is initialized, the NCR5380_intr() handler has not yet |
| 1763 | * been installed. And when in EH we may have released the ST DMA interrupt. |
| 1764 | */ |
| 1765 | |
| 1766 | static void do_reset(struct Scsi_Host *instance) |
| 1767 | { |
| 1768 | unsigned long flags; |
| 1769 | |
| 1770 | local_irq_save(flags); |
| 1771 | NCR5380_write(TARGET_COMMAND_REG, |
| 1772 | PHASE_SR_TO_TCR(NCR5380_read(STATUS_REG) & PHASE_MASK)); |
| 1773 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST); |
| 1774 | udelay(50); |
| 1775 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1776 | (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 1777 | local_irq_restore(flags); |
| 1778 | } |
| 1779 | |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1780 | /** |
| 1781 | * do_abort - abort the currently established nexus by going to |
| 1782 | * MESSAGE OUT phase and sending an ABORT message. |
| 1783 | * @instance: relevant scsi host instance |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1784 | * |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1785 | * Returns 0 on success, -1 on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | */ |
| 1787 | |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 1788 | static int do_abort(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1790 | unsigned char tmp, *msgptr, phase; |
| 1791 | int len; |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1792 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1794 | /* Request message out phase */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1797 | /* |
| 1798 | * Wait for the target to indicate a valid phase by asserting |
| 1799 | * REQ. Once this happens, we'll have either a MSGOUT phase |
| 1800 | * and can immediately send the ABORT message, or we'll have some |
| 1801 | * other phase and will have to source/sink data. |
| 1802 | * |
| 1803 | * We really don't care what value was on the bus or what value |
| 1804 | * the target sees, so we just handshake. |
| 1805 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1807 | rc = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, 10 * HZ); |
| 1808 | if (rc < 0) |
| 1809 | goto timeout; |
| 1810 | |
| 1811 | tmp = NCR5380_read(STATUS_REG) & PHASE_MASK; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1812 | |
| 1813 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp)); |
| 1814 | |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1815 | if (tmp != PHASE_MSGOUT) { |
| 1816 | NCR5380_write(INITIATOR_COMMAND_REG, |
| 1817 | ICR_BASE | ICR_ASSERT_ATN | ICR_ASSERT_ACK); |
| 1818 | rc = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, 0, 3 * HZ); |
| 1819 | if (rc < 0) |
| 1820 | goto timeout; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1821 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
| 1822 | } |
| 1823 | |
| 1824 | tmp = ABORT; |
| 1825 | msgptr = &tmp; |
| 1826 | len = 1; |
| 1827 | phase = PHASE_MSGOUT; |
Finn Thain | a53a21e | 2014-11-12 16:12:21 +1100 | [diff] [blame] | 1828 | NCR5380_transfer_pio(instance, &phase, &len, &msgptr); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1829 | |
| 1830 | /* |
| 1831 | * If we got here, and the command completed successfully, |
| 1832 | * we're about to go into bus free state. |
| 1833 | */ |
| 1834 | |
| 1835 | return len ? -1 : 0; |
Finn Thain | 80d3eb6 | 2016-01-03 16:05:34 +1100 | [diff] [blame] | 1836 | |
| 1837 | timeout: |
| 1838 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 1839 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | #if defined(REAL_DMA) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1843 | /* |
| 1844 | * Function : int NCR5380_transfer_dma (struct Scsi_Host *instance, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | * unsigned char *phase, int *count, unsigned char **data) |
| 1846 | * |
| 1847 | * Purpose : transfers data in given phase using either real |
| 1848 | * or pseudo DMA. |
| 1849 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1850 | * Inputs : instance - instance of driver, *phase - pointer to |
| 1851 | * what phase is expected, *count - pointer to number of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | * bytes to transfer, **data - pointer to data pointer. |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1853 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | * Returns : -1 when different phase is entered without transferring |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1855 | * maximum number of bytes, 0 if all bytes or transferred or exit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | * is in same phase. |
| 1857 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1858 | * Also, *phase, *count, *data are modified in place. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | * |
| 1860 | */ |
| 1861 | |
| 1862 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1863 | static int NCR5380_transfer_dma(struct Scsi_Host *instance, |
| 1864 | unsigned char *phase, int *count, |
| 1865 | unsigned char **data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1867 | SETUP_HOSTDATA(instance); |
| 1868 | register int c = *count; |
| 1869 | register unsigned char p = *phase; |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1870 | unsigned long flags; |
| 1871 | |
| 1872 | #if defined(CONFIG_SUN3) |
| 1873 | /* sanity check */ |
| 1874 | if (!sun3_dma_setup_done) { |
| 1875 | pr_err("scsi%d: transfer_dma without setup!\n", |
| 1876 | instance->host_no); |
| 1877 | BUG(); |
| 1878 | } |
| 1879 | hostdata->dma_len = c; |
| 1880 | |
| 1881 | dprintk(NDEBUG_DMA, "scsi%d: initializing DMA for %s, %d bytes %s %p\n", |
| 1882 | instance->host_no, (p & SR_IO) ? "reading" : "writing", |
| 1883 | c, (p & SR_IO) ? "to" : "from", *data); |
| 1884 | |
| 1885 | /* netbsd turns off ints here, why not be safe and do it too */ |
| 1886 | local_irq_save(flags); |
| 1887 | |
| 1888 | /* send start chain */ |
| 1889 | sun3scsi_dma_start(c, *data); |
| 1890 | |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1891 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p)); |
| 1892 | NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_MONITOR_BSY | |
| 1893 | MR_ENABLE_EOP_INTR); |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1894 | if (p & SR_IO) { |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1895 | NCR5380_write(INITIATOR_COMMAND_REG, 0); |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1896 | NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0); |
| 1897 | } else { |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1898 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_DATA); |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1899 | NCR5380_write(START_DMA_SEND_REG, 0); |
| 1900 | } |
| 1901 | |
| 1902 | #ifdef SUN3_SCSI_VME |
| 1903 | dregs->csr |= CSR_DMA_ENABLE; |
| 1904 | #endif |
| 1905 | |
| 1906 | local_irq_restore(flags); |
| 1907 | |
| 1908 | sun3_dma_active = 1; |
| 1909 | |
| 1910 | #else /* !defined(CONFIG_SUN3) */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1911 | register unsigned char *d = *data; |
| 1912 | unsigned char tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1914 | if ((tmp = (NCR5380_read(STATUS_REG) & PHASE_MASK)) != p) { |
| 1915 | *phase = tmp; |
| 1916 | return -1; |
| 1917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 1919 | if (hostdata->read_overruns && (p & SR_IO)) |
| 1920 | c -= hostdata->read_overruns; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 1922 | dprintk(NDEBUG_DMA, "scsi%d: initializing DMA for %s, %d bytes %s %p\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1923 | HOSTNO, (p & SR_IO) ? "reading" : "writing", |
| 1924 | c, (p & SR_IO) ? "to" : "from", d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1926 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p)); |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 1927 | NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_MONITOR_BSY | |
| 1928 | MR_ENABLE_EOP_INTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 1930 | if (!(hostdata->flags & FLAG_LATE_DMA_SETUP)) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1931 | /* On the Medusa, it is a must to initialize the DMA before |
| 1932 | * starting the NCR. This is also the cleaner way for the TT. |
| 1933 | */ |
| 1934 | local_irq_save(flags); |
| 1935 | hostdata->dma_len = (p & SR_IO) ? |
| 1936 | NCR5380_dma_read_setup(instance, d, c) : |
| 1937 | NCR5380_dma_write_setup(instance, d, c); |
| 1938 | local_irq_restore(flags); |
| 1939 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1941 | if (p & SR_IO) |
| 1942 | NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0); |
| 1943 | else { |
| 1944 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA); |
| 1945 | NCR5380_write(START_DMA_SEND_REG, 0); |
| 1946 | } |
| 1947 | |
Finn Thain | ef1081c | 2014-11-12 16:12:14 +1100 | [diff] [blame] | 1948 | if (hostdata->flags & FLAG_LATE_DMA_SETUP) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1949 | /* On the Falcon, the DMA setup must be done after the last */ |
| 1950 | /* NCR access, else the DMA setup gets trashed! |
| 1951 | */ |
| 1952 | local_irq_save(flags); |
| 1953 | hostdata->dma_len = (p & SR_IO) ? |
| 1954 | NCR5380_dma_read_setup(instance, d, c) : |
| 1955 | NCR5380_dma_write_setup(instance, d, c); |
| 1956 | local_irq_restore(flags); |
| 1957 | } |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1958 | #endif /* !defined(CONFIG_SUN3) */ |
| 1959 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1960 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | } |
| 1962 | #endif /* defined(REAL_DMA) */ |
| 1963 | |
| 1964 | /* |
| 1965 | * Function : NCR5380_information_transfer (struct Scsi_Host *instance) |
| 1966 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1967 | * Purpose : run through the various SCSI phases and do as the target |
| 1968 | * directs us to. Operates on the currently connected command, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | * instance->connected. |
| 1970 | * |
| 1971 | * Inputs : instance, instance for which we are doing commands |
| 1972 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1973 | * Side effects : SCSI things happen, the disconnected queue will be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | * modified if a command disconnects, *instance->connected will |
| 1975 | * change. |
| 1976 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1977 | * XXX Note : we need to watch for bus free or a reset condition here |
| 1978 | * to recover from an unexpected bus free condition. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1980 | |
| 1981 | static void NCR5380_information_transfer(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1983 | SETUP_HOSTDATA(instance); |
| 1984 | unsigned long flags; |
| 1985 | unsigned char msgout = NOP; |
| 1986 | int sink = 0; |
| 1987 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | #if defined(REAL_DMA) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1989 | int transfersize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1991 | unsigned char *data; |
| 1992 | unsigned char phase, tmp, extended_msg[10], old_phase = 0xff; |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 1993 | struct scsi_cmnd *cmd = (struct scsi_cmnd *) hostdata->connected; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 1995 | #ifdef SUN3_SCSI_VME |
| 1996 | dregs->csr |= CSR_INTR; |
| 1997 | #endif |
| 1998 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 1999 | while (1) { |
| 2000 | tmp = NCR5380_read(STATUS_REG); |
| 2001 | /* We only have a valid SCSI phase when REQ is asserted */ |
| 2002 | if (tmp & SR_REQ) { |
| 2003 | phase = (tmp & PHASE_MASK); |
| 2004 | if (phase != old_phase) { |
| 2005 | old_phase = phase; |
Finn Thain | 8ad3a59 | 2014-03-18 11:42:19 +1100 | [diff] [blame] | 2006 | NCR5380_dprint_phase(NDEBUG_INFORMATION, instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | } |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2008 | #if defined(CONFIG_SUN3) |
| 2009 | if (phase == PHASE_CMDOUT) { |
| 2010 | #if defined(REAL_DMA) |
| 2011 | void *d; |
| 2012 | unsigned long count; |
| 2013 | |
| 2014 | if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) { |
| 2015 | count = cmd->SCp.buffer->length; |
| 2016 | d = sg_virt(cmd->SCp.buffer); |
| 2017 | } else { |
| 2018 | count = cmd->SCp.this_residual; |
| 2019 | d = cmd->SCp.ptr; |
| 2020 | } |
| 2021 | /* this command setup for dma yet? */ |
| 2022 | if ((count >= DMA_MIN_SIZE) && (sun3_dma_setup_done != cmd)) { |
| 2023 | if (cmd->request->cmd_type == REQ_TYPE_FS) { |
| 2024 | sun3scsi_dma_setup(d, count, |
| 2025 | rq_data_dir(cmd->request)); |
| 2026 | sun3_dma_setup_done = cmd; |
| 2027 | } |
| 2028 | } |
| 2029 | #endif |
| 2030 | #ifdef SUN3_SCSI_VME |
| 2031 | dregs->csr |= CSR_INTR; |
| 2032 | #endif |
| 2033 | } |
| 2034 | #endif /* CONFIG_SUN3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2036 | if (sink && (phase != PHASE_MSGOUT)) { |
| 2037 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2039 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN | |
| 2040 | ICR_ASSERT_ACK); |
| 2041 | while (NCR5380_read(STATUS_REG) & SR_REQ) |
| 2042 | ; |
| 2043 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | |
| 2044 | ICR_ASSERT_ATN); |
| 2045 | sink = 0; |
| 2046 | continue; |
| 2047 | } |
| 2048 | |
| 2049 | switch (phase) { |
| 2050 | case PHASE_DATAOUT: |
| 2051 | #if (NDEBUG & NDEBUG_NO_DATAOUT) |
| 2052 | printk("scsi%d: NDEBUG_NO_DATAOUT set, attempted DATAOUT " |
| 2053 | "aborted\n", HOSTNO); |
| 2054 | sink = 1; |
| 2055 | do_abort(instance); |
| 2056 | cmd->result = DID_ERROR << 16; |
Matthew Wilcox | cce99c6 | 2007-09-25 12:42:01 -0400 | [diff] [blame] | 2057 | cmd->scsi_done(cmd); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2058 | return; |
| 2059 | #endif |
| 2060 | case PHASE_DATAIN: |
| 2061 | /* |
| 2062 | * If there is no room left in the current buffer in the |
| 2063 | * scatter-gather list, move onto the next one. |
| 2064 | */ |
| 2065 | |
| 2066 | if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) { |
| 2067 | ++cmd->SCp.buffer; |
| 2068 | --cmd->SCp.buffers_residual; |
| 2069 | cmd->SCp.this_residual = cmd->SCp.buffer->length; |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 2070 | cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2071 | /* ++roman: Try to merge some scatter-buffers if |
| 2072 | * they are at contiguous physical addresses. |
| 2073 | */ |
| 2074 | merge_contiguous_buffers(cmd); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2075 | dprintk(NDEBUG_INFORMATION, "scsi%d: %d bytes and %d buffers left\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2076 | HOSTNO, cmd->SCp.this_residual, |
| 2077 | cmd->SCp.buffers_residual); |
| 2078 | } |
| 2079 | |
| 2080 | /* |
| 2081 | * The preferred transfer method is going to be |
| 2082 | * PSEUDO-DMA for systems that are strictly PIO, |
| 2083 | * since we can let the hardware do the handshaking. |
| 2084 | * |
| 2085 | * For this to work, we need to know the transfersize |
| 2086 | * ahead of time, since the pseudo-DMA code will sit |
| 2087 | * in an unconditional loop. |
| 2088 | */ |
| 2089 | |
| 2090 | /* ++roman: I suggest, this should be |
| 2091 | * #if def(REAL_DMA) |
| 2092 | * instead of leaving REAL_DMA out. |
| 2093 | */ |
| 2094 | |
| 2095 | #if defined(REAL_DMA) |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2096 | #if !defined(CONFIG_SUN3) |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 2097 | transfersize = 0; |
| 2098 | if (!cmd->device->borken) |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2099 | #endif |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 2100 | transfersize = NCR5380_dma_xfer_len(instance, cmd, phase); |
| 2101 | |
| 2102 | if (transfersize >= DMA_MIN_SIZE) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2103 | len = transfersize; |
| 2104 | cmd->SCp.phase = phase; |
| 2105 | if (NCR5380_transfer_dma(instance, &phase, |
| 2106 | &len, (unsigned char **)&cmd->SCp.ptr)) { |
| 2107 | /* |
| 2108 | * If the watchdog timer fires, all future |
| 2109 | * accesses to this device will use the |
| 2110 | * polled-IO. */ |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 2111 | scmd_printk(KERN_INFO, cmd, |
| 2112 | "switching to slow handshake\n"); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2113 | cmd->device->borken = 1; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2114 | sink = 1; |
| 2115 | do_abort(instance); |
| 2116 | cmd->result = DID_ERROR << 16; |
Matthew Wilcox | cce99c6 | 2007-09-25 12:42:01 -0400 | [diff] [blame] | 2117 | cmd->scsi_done(cmd); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2118 | /* XXX - need to source or sink data here, as appropriate */ |
| 2119 | } else { |
| 2120 | #ifdef REAL_DMA |
| 2121 | /* ++roman: When using real DMA, |
| 2122 | * information_transfer() should return after |
| 2123 | * starting DMA since it has nothing more to |
| 2124 | * do. |
| 2125 | */ |
| 2126 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | #else |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2128 | cmd->SCp.this_residual -= transfersize - len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2130 | } |
| 2131 | } else |
| 2132 | #endif /* defined(REAL_DMA) */ |
| 2133 | NCR5380_transfer_pio(instance, &phase, |
| 2134 | (int *)&cmd->SCp.this_residual, |
| 2135 | (unsigned char **)&cmd->SCp.ptr); |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2136 | #if defined(CONFIG_SUN3) && defined(REAL_DMA) |
| 2137 | /* if we had intended to dma that command clear it */ |
| 2138 | if (sun3_dma_setup_done == cmd) |
| 2139 | sun3_dma_setup_done = NULL; |
| 2140 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2141 | break; |
| 2142 | case PHASE_MSGIN: |
| 2143 | len = 1; |
| 2144 | data = &tmp; |
| 2145 | NCR5380_write(SELECT_ENABLE_REG, 0); /* disable reselects */ |
| 2146 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
| 2147 | cmd->SCp.Message = tmp; |
| 2148 | |
| 2149 | switch (tmp) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2150 | case ABORT: |
| 2151 | case COMMAND_COMPLETE: |
| 2152 | /* Accept message by clearing ACK */ |
| 2153 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 2154 | dprintk(NDEBUG_QUEUES, "scsi%d: command for target %d, lun %llu " |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2155 | "completed\n", HOSTNO, cmd->device->id, cmd->device->lun); |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2156 | |
| 2157 | local_irq_save(flags); |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2158 | hostdata->connected = NULL; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2159 | #ifdef SUPPORT_TAGS |
| 2160 | cmd_free_tag(cmd); |
| 2161 | if (status_byte(cmd->SCp.Status) == QUEUE_FULL) { |
| 2162 | /* Turn a QUEUE FULL status into BUSY, I think the |
| 2163 | * mid level cannot handle QUEUE FULL :-( (The |
| 2164 | * command is retried after BUSY). Also update our |
| 2165 | * queue size to the number of currently issued |
| 2166 | * commands now. |
| 2167 | */ |
| 2168 | /* ++Andreas: the mid level code knows about |
| 2169 | QUEUE_FULL now. */ |
Finn Thain | 61d739a | 2014-11-12 16:12:20 +1100 | [diff] [blame] | 2170 | struct tag_alloc *ta = &hostdata->TagAlloc[scmd_id(cmd)][cmd->device->lun]; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 2171 | dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %llu returned " |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2172 | "QUEUE_FULL after %d commands\n", |
| 2173 | HOSTNO, cmd->device->id, cmd->device->lun, |
| 2174 | ta->nr_allocated); |
| 2175 | if (ta->queue_size > ta->nr_allocated) |
| 2176 | ta->nr_allocated = ta->queue_size; |
| 2177 | } |
| 2178 | #else |
| 2179 | hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); |
| 2180 | #endif |
| 2181 | /* Enable reselect interrupts */ |
| 2182 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
| 2183 | |
| 2184 | /* |
| 2185 | * I'm not sure what the correct thing to do here is : |
| 2186 | * |
| 2187 | * If the command that just executed is NOT a request |
| 2188 | * sense, the obvious thing to do is to set the result |
| 2189 | * code to the values of the stored parameters. |
| 2190 | * |
| 2191 | * If it was a REQUEST SENSE command, we need some way to |
| 2192 | * differentiate between the failure code of the original |
| 2193 | * and the failure code of the REQUEST sense - the obvious |
| 2194 | * case is success, where we fall through and leave the |
| 2195 | * result code unchanged. |
| 2196 | * |
| 2197 | * The non-obvious place is where the REQUEST SENSE failed |
| 2198 | */ |
| 2199 | |
| 2200 | if (cmd->cmnd[0] != REQUEST_SENSE) |
| 2201 | cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8); |
| 2202 | else if (status_byte(cmd->SCp.Status) != GOOD) |
| 2203 | cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16); |
| 2204 | |
Boaz Harrosh | 28424d3 | 2007-09-10 22:37:45 +0300 | [diff] [blame] | 2205 | if ((cmd->cmnd[0] == REQUEST_SENSE) && |
| 2206 | hostdata->ses.cmd_len) { |
| 2207 | scsi_eh_restore_cmnd(cmd, &hostdata->ses); |
| 2208 | hostdata->ses.cmd_len = 0 ; |
| 2209 | } |
| 2210 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2211 | if ((cmd->cmnd[0] != REQUEST_SENSE) && |
| 2212 | (status_byte(cmd->SCp.Status) == CHECK_CONDITION)) { |
Boaz Harrosh | 28424d3 | 2007-09-10 22:37:45 +0300 | [diff] [blame] | 2213 | scsi_eh_prep_cmnd(cmd, &hostdata->ses, NULL, 0, ~0); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2214 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2215 | dprintk(NDEBUG_AUTOSENSE, "scsi%d: performing request sense\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2216 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2217 | LIST(cmd,hostdata->issue_queue); |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 2218 | SET_NEXT(cmd, hostdata->issue_queue); |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2219 | hostdata->issue_queue = (struct scsi_cmnd *) cmd; |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2220 | dprintk(NDEBUG_QUEUES, "scsi%d: REQUEST SENSE added to head of " |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2221 | "issue queue\n", H_NO(cmd)); |
Finn Thain | 997acab | 2014-11-12 16:11:54 +1100 | [diff] [blame] | 2222 | } else { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2223 | cmd->scsi_done(cmd); |
| 2224 | } |
| 2225 | |
| 2226 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
| 2227 | /* |
| 2228 | * Restore phase bits to 0 so an interrupted selection, |
| 2229 | * arbitration can resume. |
| 2230 | */ |
| 2231 | NCR5380_write(TARGET_COMMAND_REG, 0); |
| 2232 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2233 | /* ++roman: For Falcon SCSI, release the lock on the |
| 2234 | * ST-DMA here if no other commands are waiting on the |
| 2235 | * disconnected queue. |
| 2236 | */ |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2237 | maybe_release_dma_irq(instance); |
| 2238 | local_irq_restore(flags); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2239 | return; |
| 2240 | case MESSAGE_REJECT: |
| 2241 | /* Accept message by clearing ACK */ |
| 2242 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2243 | /* Enable reselect interrupts */ |
| 2244 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
| 2245 | switch (hostdata->last_message) { |
| 2246 | case HEAD_OF_QUEUE_TAG: |
| 2247 | case ORDERED_QUEUE_TAG: |
| 2248 | case SIMPLE_QUEUE_TAG: |
| 2249 | /* The target obviously doesn't support tagged |
| 2250 | * queuing, even though it announced this ability in |
| 2251 | * its INQUIRY data ?!? (maybe only this LUN?) Ok, |
| 2252 | * clear 'tagged_supported' and lock the LUN, since |
| 2253 | * the command is treated as untagged further on. |
| 2254 | */ |
| 2255 | cmd->device->tagged_supported = 0; |
| 2256 | hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun); |
| 2257 | cmd->tag = TAG_NONE; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 2258 | dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %llu rejected " |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2259 | "QUEUE_TAG message; tagged queuing " |
| 2260 | "disabled\n", |
| 2261 | HOSTNO, cmd->device->id, cmd->device->lun); |
| 2262 | break; |
| 2263 | } |
| 2264 | break; |
| 2265 | case DISCONNECT: |
| 2266 | /* Accept message by clearing ACK */ |
| 2267 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2268 | local_irq_save(flags); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2269 | LIST(cmd,hostdata->disconnected_queue); |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 2270 | SET_NEXT(cmd, hostdata->disconnected_queue); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2271 | hostdata->connected = NULL; |
| 2272 | hostdata->disconnected_queue = cmd; |
| 2273 | local_irq_restore(flags); |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 2274 | dprintk(NDEBUG_QUEUES, "scsi%d: command for target %d lun %llu was " |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2275 | "moved from connected to the " |
| 2276 | "disconnected_queue\n", HOSTNO, |
| 2277 | cmd->device->id, cmd->device->lun); |
| 2278 | /* |
| 2279 | * Restore phase bits to 0 so an interrupted selection, |
| 2280 | * arbitration can resume. |
| 2281 | */ |
| 2282 | NCR5380_write(TARGET_COMMAND_REG, 0); |
| 2283 | |
| 2284 | /* Enable reselect interrupts */ |
| 2285 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2286 | #ifdef SUN3_SCSI_VME |
| 2287 | dregs->csr |= CSR_DMA_ENABLE; |
| 2288 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2289 | return; |
| 2290 | /* |
| 2291 | * The SCSI data pointer is *IMPLICITLY* saved on a disconnect |
| 2292 | * operation, in violation of the SCSI spec so we can safely |
| 2293 | * ignore SAVE/RESTORE pointers calls. |
| 2294 | * |
| 2295 | * Unfortunately, some disks violate the SCSI spec and |
| 2296 | * don't issue the required SAVE_POINTERS message before |
| 2297 | * disconnecting, and we have to break spec to remain |
| 2298 | * compatible. |
| 2299 | */ |
| 2300 | case SAVE_POINTERS: |
| 2301 | case RESTORE_POINTERS: |
| 2302 | /* Accept message by clearing ACK */ |
| 2303 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2304 | /* Enable reselect interrupts */ |
| 2305 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
| 2306 | break; |
| 2307 | case EXTENDED_MESSAGE: |
| 2308 | /* |
| 2309 | * Extended messages are sent in the following format : |
| 2310 | * Byte |
| 2311 | * 0 EXTENDED_MESSAGE == 1 |
| 2312 | * 1 length (includes one byte for code, doesn't |
| 2313 | * include first two bytes) |
| 2314 | * 2 code |
| 2315 | * 3..length+1 arguments |
| 2316 | * |
| 2317 | * Start the extended message buffer with the EXTENDED_MESSAGE |
| 2318 | * byte, since spi_print_msg() wants the whole thing. |
| 2319 | */ |
| 2320 | extended_msg[0] = EXTENDED_MESSAGE; |
| 2321 | /* Accept first byte by clearing ACK */ |
| 2322 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2323 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2324 | dprintk(NDEBUG_EXTENDED, "scsi%d: receiving extended message\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2325 | |
| 2326 | len = 2; |
| 2327 | data = extended_msg + 1; |
| 2328 | phase = PHASE_MSGIN; |
| 2329 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2330 | dprintk(NDEBUG_EXTENDED, "scsi%d: length=%d, code=0x%02x\n", HOSTNO, |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2331 | (int)extended_msg[1], (int)extended_msg[2]); |
| 2332 | |
| 2333 | if (!len && extended_msg[1] <= |
| 2334 | (sizeof(extended_msg) - 1)) { |
| 2335 | /* Accept third byte by clearing ACK */ |
| 2336 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2337 | len = extended_msg[1] - 1; |
| 2338 | data = extended_msg + 3; |
| 2339 | phase = PHASE_MSGIN; |
| 2340 | |
| 2341 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2342 | dprintk(NDEBUG_EXTENDED, "scsi%d: message received, residual %d\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2343 | HOSTNO, len); |
| 2344 | |
| 2345 | switch (extended_msg[2]) { |
| 2346 | case EXTENDED_SDTR: |
| 2347 | case EXTENDED_WDTR: |
| 2348 | case EXTENDED_MODIFY_DATA_POINTER: |
| 2349 | case EXTENDED_EXTENDED_IDENTIFY: |
| 2350 | tmp = 0; |
| 2351 | } |
| 2352 | } else if (len) { |
| 2353 | printk(KERN_NOTICE "scsi%d: error receiving " |
| 2354 | "extended message\n", HOSTNO); |
| 2355 | tmp = 0; |
| 2356 | } else { |
| 2357 | printk(KERN_NOTICE "scsi%d: extended message " |
| 2358 | "code %02x length %d is too long\n", |
| 2359 | HOSTNO, extended_msg[2], extended_msg[1]); |
| 2360 | tmp = 0; |
| 2361 | } |
| 2362 | /* Fall through to reject message */ |
| 2363 | |
| 2364 | /* |
| 2365 | * If we get something weird that we aren't expecting, |
| 2366 | * reject it. |
| 2367 | */ |
| 2368 | default: |
| 2369 | if (!tmp) { |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 2370 | printk(KERN_INFO "scsi%d: rejecting message ", |
| 2371 | instance->host_no); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2372 | spi_print_msg(extended_msg); |
| 2373 | printk("\n"); |
| 2374 | } else if (tmp != EXTENDED_MESSAGE) |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 2375 | scmd_printk(KERN_INFO, cmd, |
| 2376 | "rejecting unknown message %02x\n", |
| 2377 | tmp); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2378 | else |
Finn Thain | ff50f9e | 2014-11-12 16:12:18 +1100 | [diff] [blame] | 2379 | scmd_printk(KERN_INFO, cmd, |
| 2380 | "rejecting unknown extended message code %02x, length %d\n", |
| 2381 | extended_msg[1], extended_msg[0]); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2382 | |
| 2383 | msgout = MESSAGE_REJECT; |
| 2384 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); |
| 2385 | break; |
| 2386 | } /* switch (tmp) */ |
| 2387 | break; |
| 2388 | case PHASE_MSGOUT: |
| 2389 | len = 1; |
| 2390 | data = &msgout; |
| 2391 | hostdata->last_message = msgout; |
| 2392 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
| 2393 | if (msgout == ABORT) { |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2394 | local_irq_save(flags); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2395 | #ifdef SUPPORT_TAGS |
| 2396 | cmd_free_tag(cmd); |
| 2397 | #else |
| 2398 | hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); |
| 2399 | #endif |
| 2400 | hostdata->connected = NULL; |
| 2401 | cmd->result = DID_ERROR << 16; |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2402 | maybe_release_dma_irq(instance); |
| 2403 | local_irq_restore(flags); |
| 2404 | cmd->scsi_done(cmd); |
Finn Thain | cd40082 | 2016-01-03 16:05:40 +1100 | [diff] [blame] | 2405 | NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2406 | return; |
| 2407 | } |
| 2408 | msgout = NOP; |
| 2409 | break; |
| 2410 | case PHASE_CMDOUT: |
| 2411 | len = cmd->cmd_len; |
| 2412 | data = cmd->cmnd; |
| 2413 | /* |
| 2414 | * XXX for performance reasons, on machines with a |
| 2415 | * PSEUDO-DMA architecture we should probably |
| 2416 | * use the dma transfer function. |
| 2417 | */ |
| 2418 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
| 2419 | break; |
| 2420 | case PHASE_STATIN: |
| 2421 | len = 1; |
| 2422 | data = &tmp; |
| 2423 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
| 2424 | cmd->SCp.Status = tmp; |
| 2425 | break; |
| 2426 | default: |
| 2427 | printk("scsi%d: unknown phase\n", HOSTNO); |
Finn Thain | 8ad3a59 | 2014-03-18 11:42:19 +1100 | [diff] [blame] | 2428 | NCR5380_dprint(NDEBUG_ANY, instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2429 | } /* switch(phase) */ |
Finn Thain | 686f399 | 2016-01-03 16:05:26 +1100 | [diff] [blame] | 2430 | } else { |
| 2431 | NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ); |
| 2432 | } |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2433 | } /* while (1) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | /* |
| 2437 | * Function : void NCR5380_reselect (struct Scsi_Host *instance) |
| 2438 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2439 | * Purpose : does reselection, initializing the instance->connected |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2440 | * field to point to the scsi_cmnd for which the I_T_L or I_T_L_Q |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | * nexus has been reestablished, |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2442 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | * Inputs : instance - this instance of the NCR5380. |
| 2444 | * |
| 2445 | */ |
| 2446 | |
| 2447 | |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2448 | /* it might eventually prove necessary to do a dma setup on |
| 2449 | reselection, but it doesn't seem to be needed now -- sam */ |
| 2450 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2451 | static void NCR5380_reselect(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2453 | SETUP_HOSTDATA(instance); |
| 2454 | unsigned char target_mask; |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2455 | unsigned char lun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | #ifdef SUPPORT_TAGS |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2457 | unsigned char tag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2459 | unsigned char msg[3]; |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2460 | int __maybe_unused len; |
| 2461 | unsigned char __maybe_unused *data, __maybe_unused phase; |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2462 | struct scsi_cmnd *tmp = NULL, *prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2464 | /* |
| 2465 | * Disable arbitration, etc. since the host adapter obviously |
| 2466 | * lost, and tell an interrupted NCR5380_select() to restart. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2469 | NCR5380_write(MODE_REG, MR_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2471 | target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask); |
| 2472 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2473 | dprintk(NDEBUG_RESELECTION, "scsi%d: reselect\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2474 | |
| 2475 | /* |
| 2476 | * At this point, we have detected that our SCSI ID is on the bus, |
| 2477 | * SEL is true and BSY was false for at least one bus settle delay |
| 2478 | * (400 ns). |
| 2479 | * |
| 2480 | * We must assert BSY ourselves, until the target drops the SEL |
| 2481 | * signal. |
| 2482 | */ |
| 2483 | |
| 2484 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY); |
| 2485 | |
| 2486 | while (NCR5380_read(STATUS_REG) & SR_SEL) |
| 2487 | ; |
| 2488 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2489 | |
| 2490 | /* |
| 2491 | * Wait for target to go into MSGIN. |
| 2492 | */ |
| 2493 | |
| 2494 | while (!(NCR5380_read(STATUS_REG) & SR_REQ)) |
| 2495 | ; |
| 2496 | |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2497 | #if defined(CONFIG_SUN3) && defined(REAL_DMA) |
| 2498 | /* acknowledge toggle to MSGIN */ |
| 2499 | NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(PHASE_MSGIN)); |
| 2500 | |
| 2501 | /* peek at the byte without really hitting the bus */ |
| 2502 | msg[0] = NCR5380_read(CURRENT_SCSI_DATA_REG); |
| 2503 | #else |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2504 | len = 1; |
| 2505 | data = msg; |
| 2506 | phase = PHASE_MSGIN; |
| 2507 | NCR5380_transfer_pio(instance, &phase, &len, &data); |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2508 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2509 | |
| 2510 | if (!(msg[0] & 0x80)) { |
| 2511 | printk(KERN_DEBUG "scsi%d: expecting IDENTIFY message, got ", HOSTNO); |
| 2512 | spi_print_msg(msg); |
| 2513 | do_abort(instance); |
| 2514 | return; |
| 2515 | } |
| 2516 | lun = (msg[0] & 0x07); |
| 2517 | |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2518 | #if defined(SUPPORT_TAGS) && !defined(CONFIG_SUN3) |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2519 | /* If the phase is still MSGIN, the target wants to send some more |
| 2520 | * messages. In case it supports tagged queuing, this is probably a |
| 2521 | * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus. |
| 2522 | */ |
| 2523 | tag = TAG_NONE; |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 2524 | if (phase == PHASE_MSGIN && (hostdata->flags & FLAG_TAGGED_QUEUING)) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2525 | /* Accept previous IDENTIFY message by clearing ACK */ |
| 2526 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2527 | len = 2; |
| 2528 | data = msg + 1; |
| 2529 | if (!NCR5380_transfer_pio(instance, &phase, &len, &data) && |
| 2530 | msg[1] == SIMPLE_QUEUE_TAG) |
| 2531 | tag = msg[2]; |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2532 | dprintk(NDEBUG_TAGS, "scsi%d: target mask %02x, lun %d sent tag %d at " |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2533 | "reselection\n", HOSTNO, target_mask, lun, tag); |
| 2534 | } |
| 2535 | #endif |
| 2536 | |
| 2537 | /* |
| 2538 | * Find the command corresponding to the I_T_L or I_T_L_Q nexus we |
| 2539 | * just reestablished, and remove it from the disconnected queue. |
| 2540 | */ |
| 2541 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2542 | for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue, prev = NULL; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2543 | tmp; prev = tmp, tmp = NEXT(tmp)) { |
| 2544 | if ((target_mask == (1 << tmp->device->id)) && (lun == tmp->device->lun) |
| 2545 | #ifdef SUPPORT_TAGS |
| 2546 | && (tag == tmp->tag) |
| 2547 | #endif |
| 2548 | ) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2549 | if (prev) { |
| 2550 | REMOVE(prev, NEXT(prev), tmp, NEXT(tmp)); |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 2551 | SET_NEXT(prev, NEXT(tmp)); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2552 | } else { |
| 2553 | REMOVE(-1, hostdata->disconnected_queue, tmp, NEXT(tmp)); |
| 2554 | hostdata->disconnected_queue = NEXT(tmp); |
| 2555 | } |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 2556 | SET_NEXT(tmp, NULL); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2557 | break; |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | if (!tmp) { |
| 2562 | printk(KERN_WARNING "scsi%d: warning: target bitmask %02x lun %d " |
| 2563 | #ifdef SUPPORT_TAGS |
| 2564 | "tag %d " |
| 2565 | #endif |
| 2566 | "not in disconnected_queue.\n", |
| 2567 | HOSTNO, target_mask, lun |
| 2568 | #ifdef SUPPORT_TAGS |
| 2569 | , tag |
| 2570 | #endif |
| 2571 | ); |
| 2572 | /* |
| 2573 | * Since we have an established nexus that we can't do anything |
| 2574 | * with, we must abort it. |
| 2575 | */ |
| 2576 | do_abort(instance); |
| 2577 | return; |
| 2578 | } |
| 2579 | |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2580 | #if defined(CONFIG_SUN3) && defined(REAL_DMA) |
| 2581 | /* engage dma setup for the command we just saw */ |
| 2582 | { |
| 2583 | void *d; |
| 2584 | unsigned long count; |
| 2585 | |
| 2586 | if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) { |
| 2587 | count = tmp->SCp.buffer->length; |
| 2588 | d = sg_virt(tmp->SCp.buffer); |
| 2589 | } else { |
| 2590 | count = tmp->SCp.this_residual; |
| 2591 | d = tmp->SCp.ptr; |
| 2592 | } |
| 2593 | /* setup this command for dma if not already */ |
| 2594 | if ((count >= DMA_MIN_SIZE) && (sun3_dma_setup_done != tmp)) { |
| 2595 | sun3scsi_dma_setup(d, count, rq_data_dir(tmp->request)); |
| 2596 | sun3_dma_setup_done = tmp; |
| 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK); |
| 2601 | #endif |
| 2602 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2603 | /* Accept message by clearing ACK */ |
| 2604 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2605 | |
Finn Thain | e3f463b | 2014-11-12 16:12:16 +1100 | [diff] [blame] | 2606 | #if defined(SUPPORT_TAGS) && defined(CONFIG_SUN3) |
| 2607 | /* If the phase is still MSGIN, the target wants to send some more |
| 2608 | * messages. In case it supports tagged queuing, this is probably a |
| 2609 | * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus. |
| 2610 | */ |
| 2611 | tag = TAG_NONE; |
| 2612 | if (phase == PHASE_MSGIN && setup_use_tagged_queuing) { |
| 2613 | /* Accept previous IDENTIFY message by clearing ACK */ |
| 2614 | NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); |
| 2615 | len = 2; |
| 2616 | data = msg + 1; |
| 2617 | if (!NCR5380_transfer_pio(instance, &phase, &len, &data) && |
| 2618 | msg[1] == SIMPLE_QUEUE_TAG) |
| 2619 | tag = msg[2]; |
| 2620 | dprintk(NDEBUG_TAGS, "scsi%d: target mask %02x, lun %d sent tag %d at reselection\n" |
| 2621 | HOSTNO, target_mask, lun, tag); |
| 2622 | } |
| 2623 | #endif |
| 2624 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2625 | hostdata->connected = tmp; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 2626 | dprintk(NDEBUG_RESELECTION, "scsi%d: nexus established, target = %d, lun = %llu, tag = %d\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2627 | HOSTNO, tmp->device->id, tmp->device->lun, tmp->tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | |
| 2631 | /* |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2632 | * Function : int NCR5380_abort (struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | * |
| 2634 | * Purpose : abort a command |
| 2635 | * |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2636 | * Inputs : cmd - the scsi_cmnd to abort, code - code to set the |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2637 | * host byte of the result field to, if zero DID_ABORTED is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | * used. |
| 2639 | * |
Hannes Reinecke | b6c92b7 | 2014-10-30 09:44:36 +0100 | [diff] [blame] | 2640 | * Returns : SUCCESS - success, FAILED on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | * |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2642 | * XXX - there is no way to abort the command that is currently |
| 2643 | * connected, you have to wait for it to complete. If this is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | * a problem, we could implement longjmp() / setjmp(), setjmp() |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2645 | * called where the loop started in NCR5380_main(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | */ |
| 2647 | |
| 2648 | static |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2649 | int NCR5380_abort(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2651 | struct Scsi_Host *instance = cmd->device->host; |
| 2652 | SETUP_HOSTDATA(instance); |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2653 | struct scsi_cmnd *tmp, **prev; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2654 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | |
Hannes Reinecke | 1fa6b5f | 2014-10-24 14:26:58 +0200 | [diff] [blame] | 2656 | scmd_printk(KERN_NOTICE, cmd, "aborting command\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2658 | NCR5380_print_status(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2660 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2662 | dprintk(NDEBUG_ABORT, "scsi%d: abort called basr 0x%02x, sr 0x%02x\n", HOSTNO, |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2663 | NCR5380_read(BUS_AND_STATUS_REG), |
| 2664 | NCR5380_read(STATUS_REG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | |
| 2666 | #if 1 |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2667 | /* |
| 2668 | * Case 1 : If the command is the currently executing command, |
| 2669 | * we'll set the aborted flag and return control so that |
| 2670 | * information transfer routine can exit cleanly. |
| 2671 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2673 | if (hostdata->connected == cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2675 | dprintk(NDEBUG_ABORT, "scsi%d: aborting connected command\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2676 | /* |
| 2677 | * We should perform BSY checking, and make sure we haven't slipped |
| 2678 | * into BUS FREE. |
| 2679 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2681 | /* NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN); */ |
| 2682 | /* |
| 2683 | * Since we can't change phases until we've completed the current |
| 2684 | * handshake, we have to source or sink a byte of data if the current |
| 2685 | * phase is not MSGOUT. |
| 2686 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2688 | /* |
| 2689 | * Return control to the executing NCR drive so we can clear the |
| 2690 | * aborted flag and get back into our main loop. |
| 2691 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2693 | if (do_abort(instance) == 0) { |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2694 | hostdata->connected = NULL; |
| 2695 | cmd->result = DID_ABORT << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | #ifdef SUPPORT_TAGS |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2697 | cmd_free_tag(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | #else |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2699 | hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | #endif |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2701 | maybe_release_dma_irq(instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2702 | local_irq_restore(flags); |
| 2703 | cmd->scsi_done(cmd); |
Michael Schmitz | 2b0f834 | 2014-05-02 20:43:01 +1200 | [diff] [blame] | 2704 | return SUCCESS; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2705 | } else { |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2706 | local_irq_restore(flags); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2707 | printk("scsi%d: abort of connected command failed!\n", HOSTNO); |
Michael Schmitz | 2b0f834 | 2014-05-02 20:43:01 +1200 | [diff] [blame] | 2708 | return FAILED; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2712 | |
| 2713 | /* |
| 2714 | * Case 2 : If the command hasn't been issued yet, we simply remove it |
| 2715 | * from the issue queue. |
| 2716 | */ |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2717 | for (prev = (struct scsi_cmnd **)&(hostdata->issue_queue), |
| 2718 | tmp = (struct scsi_cmnd *)hostdata->issue_queue; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2719 | tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) { |
| 2720 | if (cmd == tmp) { |
| 2721 | REMOVE(5, *prev, tmp, NEXT(tmp)); |
| 2722 | (*prev) = NEXT(tmp); |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 2723 | SET_NEXT(tmp, NULL); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2724 | tmp->result = DID_ABORT << 16; |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2725 | maybe_release_dma_irq(instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2726 | local_irq_restore(flags); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2727 | dprintk(NDEBUG_ABORT, "scsi%d: abort removed command from issue queue.\n", |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2728 | HOSTNO); |
| 2729 | /* Tagged queuing note: no tag to free here, hasn't been assigned |
| 2730 | * yet... */ |
| 2731 | tmp->scsi_done(tmp); |
Michael Schmitz | 2b0f834 | 2014-05-02 20:43:01 +1200 | [diff] [blame] | 2732 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | } |
| 2734 | } |
| 2735 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2736 | /* |
| 2737 | * Case 3 : If any commands are connected, we're going to fail the abort |
| 2738 | * and let the high level SCSI driver retry at a later time or |
| 2739 | * issue a reset. |
| 2740 | * |
| 2741 | * Timeouts, and therefore aborted commands, will be highly unlikely |
| 2742 | * and handling them cleanly in this situation would make the common |
| 2743 | * case of noresets less efficient, and would pollute our code. So, |
| 2744 | * we fail. |
| 2745 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2747 | if (hostdata->connected) { |
| 2748 | local_irq_restore(flags); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2749 | dprintk(NDEBUG_ABORT, "scsi%d: abort failed, command connected.\n", HOSTNO); |
Michael Schmitz | 2b0f834 | 2014-05-02 20:43:01 +1200 | [diff] [blame] | 2750 | return FAILED; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2751 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2753 | /* |
| 2754 | * Case 4: If the command is currently disconnected from the bus, and |
| 2755 | * there are no connected commands, we reconnect the I_T_L or |
| 2756 | * I_T_L_Q nexus associated with it, go into message out, and send |
| 2757 | * an abort message. |
| 2758 | * |
| 2759 | * This case is especially ugly. In order to reestablish the nexus, we |
| 2760 | * need to call NCR5380_select(). The easiest way to implement this |
| 2761 | * function was to abort if the bus was busy, and let the interrupt |
| 2762 | * handler triggered on the SEL for reselect take care of lost arbitrations |
| 2763 | * where necessary, meaning interrupts need to be enabled. |
| 2764 | * |
| 2765 | * When interrupts are enabled, the queues may change - so we |
| 2766 | * can't remove it from the disconnected queue before selecting it |
| 2767 | * because that could cause a failure in hashing the nexus if that |
| 2768 | * device reselected. |
| 2769 | * |
| 2770 | * Since the queues may change, we can't use the pointers from when we |
| 2771 | * first locate it. |
| 2772 | * |
| 2773 | * So, we must first locate the command, and if NCR5380_select() |
| 2774 | * succeeds, then issue the abort, relocate the command and remove |
| 2775 | * it from the disconnected queue. |
| 2776 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2778 | for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue; tmp; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2779 | tmp = NEXT(tmp)) { |
| 2780 | if (cmd == tmp) { |
| 2781 | local_irq_restore(flags); |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2782 | dprintk(NDEBUG_ABORT, "scsi%d: aborting disconnected command.\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2783 | |
Finn Thain | 76f13b9 | 2014-11-12 16:11:53 +1100 | [diff] [blame] | 2784 | if (NCR5380_select(instance, cmd)) |
Michael Schmitz | 2b0f834 | 2014-05-02 20:43:01 +1200 | [diff] [blame] | 2785 | return FAILED; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2786 | |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2787 | dprintk(NDEBUG_ABORT, "scsi%d: nexus reestablished.\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2788 | |
| 2789 | do_abort(instance); |
| 2790 | |
| 2791 | local_irq_save(flags); |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2792 | for (prev = (struct scsi_cmnd **)&(hostdata->disconnected_queue), |
| 2793 | tmp = (struct scsi_cmnd *)hostdata->disconnected_queue; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2794 | tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) { |
| 2795 | if (cmd == tmp) { |
| 2796 | REMOVE(5, *prev, tmp, NEXT(tmp)); |
| 2797 | *prev = NEXT(tmp); |
Roman Zippel | 3130d90 | 2007-05-01 22:32:37 +0200 | [diff] [blame] | 2798 | SET_NEXT(tmp, NULL); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2799 | tmp->result = DID_ABORT << 16; |
| 2800 | /* We must unlock the tag/LUN immediately here, since the |
| 2801 | * target goes to BUS FREE and doesn't send us another |
| 2802 | * message (COMMAND_COMPLETE or the like) |
| 2803 | */ |
| 2804 | #ifdef SUPPORT_TAGS |
| 2805 | cmd_free_tag(tmp); |
| 2806 | #else |
| 2807 | hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); |
| 2808 | #endif |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2809 | maybe_release_dma_irq(instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2810 | local_irq_restore(flags); |
| 2811 | tmp->scsi_done(tmp); |
Michael Schmitz | 2b0f834 | 2014-05-02 20:43:01 +1200 | [diff] [blame] | 2812 | return SUCCESS; |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2813 | } |
| 2814 | } |
| 2815 | } |
| 2816 | } |
| 2817 | |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2818 | /* Maybe it is sufficient just to release the ST-DMA lock... (if |
| 2819 | * possible at all) At least, we should check if the lock could be |
| 2820 | * released after the abort, in case it is kept due to some bug. |
| 2821 | */ |
| 2822 | maybe_release_dma_irq(instance); |
| 2823 | local_irq_restore(flags); |
| 2824 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2825 | /* |
| 2826 | * Case 5 : If we reached this point, the command was not found in any of |
| 2827 | * the queues. |
| 2828 | * |
| 2829 | * We probably reached this point because of an unlikely race condition |
| 2830 | * between the command completing successfully and the abortion code, |
| 2831 | * so we won't panic, but we will notify the user in case something really |
| 2832 | * broke. |
| 2833 | */ |
| 2834 | |
Joe Perches | ad361c9 | 2009-07-06 13:05:40 -0700 | [diff] [blame] | 2835 | printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully before abortion\n", HOSTNO); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2836 | |
Michael Schmitz | 2b0f834 | 2014-05-02 20:43:01 +1200 | [diff] [blame] | 2837 | return FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2841 | /** |
| 2842 | * NCR5380_bus_reset - reset the SCSI bus |
| 2843 | * @cmd: SCSI command undergoing EH |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2844 | * |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2845 | * Returns SUCCESS |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2846 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | |
Finn Thain | 710ddd0 | 2014-11-12 16:12:02 +1100 | [diff] [blame] | 2848 | static int NCR5380_bus_reset(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | { |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2850 | struct Scsi_Host *instance = cmd->device->host; |
| 2851 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2852 | int i; |
| 2853 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2855 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | |
Finn Thain | 3be1b3e | 2016-01-03 16:05:12 +1100 | [diff] [blame] | 2857 | #if (NDEBUG & NDEBUG_ANY) |
| 2858 | scmd_printk(KERN_INFO, cmd, "performing bus reset\n"); |
| 2859 | NCR5380_print_status(instance); |
| 2860 | #endif |
| 2861 | |
| 2862 | do_reset(instance); |
| 2863 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2864 | /* reset NCR registers */ |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2865 | NCR5380_write(MODE_REG, MR_BASE); |
| 2866 | NCR5380_write(TARGET_COMMAND_REG, 0); |
| 2867 | NCR5380_write(SELECT_ENABLE_REG, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2869 | /* After the reset, there are no more connected or disconnected commands |
| 2870 | * and no busy units; so clear the low-level status here to avoid |
| 2871 | * conflicts when the mid-level code tries to wake up the affected |
| 2872 | * commands! |
| 2873 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2875 | if (hostdata->issue_queue) |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2876 | dprintk(NDEBUG_ABORT, "scsi%d: reset aborted issued command(s)\n", H_NO(cmd)); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2877 | if (hostdata->connected) |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2878 | dprintk(NDEBUG_ABORT, "scsi%d: reset aborted a connected command\n", H_NO(cmd)); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2879 | if (hostdata->disconnected_queue) |
Finn Thain | d65e634 | 2014-03-18 11:42:20 +1100 | [diff] [blame] | 2880 | dprintk(NDEBUG_ABORT, "scsi%d: reset aborted disconnected command(s)\n", H_NO(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2882 | hostdata->issue_queue = NULL; |
| 2883 | hostdata->connected = NULL; |
| 2884 | hostdata->disconnected_queue = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | #ifdef SUPPORT_TAGS |
Finn Thain | ca513fc | 2014-11-12 16:12:19 +1100 | [diff] [blame] | 2886 | free_all_tags(hostdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | #endif |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2888 | for (i = 0; i < 8; ++i) |
| 2889 | hostdata->busy[i] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | #ifdef REAL_DMA |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2891 | hostdata->dma_len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | #endif |
Finn Thain | e3c3da6 | 2014-11-12 16:12:15 +1100 | [diff] [blame] | 2893 | |
| 2894 | maybe_release_dma_irq(instance); |
Roman Zippel | c28bda2 | 2007-05-01 22:32:36 +0200 | [diff] [blame] | 2895 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | |
Michael Schmitz | 2b0f834 | 2014-05-02 20:43:01 +1200 | [diff] [blame] | 2897 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | } |