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