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