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