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