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