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