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