blob: a01921dfed0b1d05ce0bac0ecfce4fba4d7af3e4 [file] [log] [blame]
Roman Zippelc28bda22007-05-01 22:32:36 +02001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * NCR 5380 generic driver routines. These should make it *trivial*
Roman Zippelc28bda22007-05-01 22:32:36 +02003 * to implement 5380 SCSI drivers under Linux with a non-trantor
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * architecture.
5 *
6 * Note that these routines also work with NR53c400 family chips.
7 *
8 * Copyright 1993, Drew Eckhardt
Roman Zippelc28bda22007-05-01 22:32:36 +02009 * Visionary Computing
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * (Unix and Linux consulting and custom programming)
Roman Zippelc28bda22007-05-01 22:32:36 +020011 * drew@colorado.edu
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * +1 (303) 666-5836
13 *
Roman Zippelc28bda22007-05-01 22:32:36 +020014 * For more information, please consult
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 *
16 * NCR 5380 Family
17 * SCSI Protocol Controller
18 * Databook
19 *
20 * NCR Microelectronics
21 * 1635 Aeroplaza Drive
22 * Colorado Springs, CO 80916
23 * 1+ (719) 578-3400
24 * 1+ (800) 334-5454
25 */
26
27/*
28 * ++roman: To port the 5380 driver to the Atari, I had to do some changes in
29 * this file, too:
30 *
31 * - Some of the debug statements were incorrect (undefined variables and the
32 * like). I fixed that.
33 *
34 * - In information_transfer(), I think a #ifdef was wrong. Looking at the
35 * possible DMA transfer size should also happen for REAL_DMA. I added this
36 * in the #if statement.
37 *
38 * - When using real DMA, information_transfer() should return in a DATAOUT
39 * phase after starting the DMA. It has nothing more to do.
40 *
41 * - The interrupt service routine should run main after end of DMA, too (not
42 * only after RESELECTION interrupts). Additionally, it should _not_ test
43 * for more interrupts after running main, since a DMA process may have
44 * been started and interrupts are turned on now. The new int could happen
45 * inside the execution of NCR5380_intr(), leading to recursive
46 * calls.
47 *
48 * - I've added a function merge_contiguous_buffers() that tries to
49 * merge scatter-gather buffers that are located at contiguous
50 * physical addresses and can be processed with the same DMA setup.
51 * Since most scatter-gather operations work on a page (4K) of
52 * 4 buffers (1K), in more than 90% of all cases three interrupts and
53 * DMA setup actions are saved.
54 *
55 * - I've deleted all the stuff for AUTOPROBE_IRQ, REAL_DMA_POLL, PSEUDO_DMA
56 * and USLEEP, because these were messing up readability and will never be
57 * needed for Atari SCSI.
Roman Zippelc28bda22007-05-01 22:32:36 +020058 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 * - I've revised the NCR5380_main() calling scheme (relax the 'main_running'
60 * stuff), and 'main' is executed in a bottom half if awoken by an
61 * interrupt.
62 *
63 * - The code was quite cluttered up by "#if (NDEBUG & NDEBUG_*) printk..."
64 * constructs. In my eyes, this made the source rather unreadable, so I
65 * finally replaced that by the *_PRINTK() macros.
66 *
67 */
68
Finn Thaine3f463b2014-11-12 16:12:16 +110069/* Adapted for the sun3 by Sam Creasey. */
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/*
72 * Design
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 *
Roman Zippelc28bda22007-05-01 22:32:36 +020074 * This is a generic 5380 driver. To use it on a different platform,
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 * one simply writes appropriate system specific macros (ie, data
Roman Zippelc28bda22007-05-01 22:32:36 +020076 * transfer - some PC's will use the I/O bus, 68K's must use
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 * memory mapped) and drops this file in their 'C' wrapper.
78 *
Roman Zippelc28bda22007-05-01 22:32:36 +020079 * As far as command queueing, two queues are maintained for
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 * each 5380 in the system - commands that haven't been issued yet,
Roman Zippelc28bda22007-05-01 22:32:36 +020081 * and commands that are currently executing. This means that an
82 * unlimited number of commands may be queued, letting
83 * more commands propagate from the higher driver levels giving higher
84 * throughput. Note that both I_T_L and I_T_L_Q nexuses are supported,
85 * allowing multiple commands to propagate all the way to a SCSI-II device
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 * while a command is already executing.
87 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 *
Roman Zippelc28bda22007-05-01 22:32:36 +020089 * Issues specific to the NCR5380 :
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 *
Roman Zippelc28bda22007-05-01 22:32:36 +020091 * When used in a PIO or pseudo-dma mode, the NCR5380 is a braindead
92 * piece of hardware that requires you to sit in a loop polling for
93 * the REQ signal as long as you are connected. Some devices are
94 * brain dead (ie, many TEXEL CD ROM drives) and won't disconnect
Finn Thain686f3992016-01-03 16:05:26 +110095 * while doing long seek operations. [...] These
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 * broken devices are the exception rather than the rule and I'd rather
97 * spend my time optimizing for the normal case.
98 *
99 * Architecture :
100 *
101 * At the heart of the design is a coroutine, NCR5380_main,
Finn Thainff50f9e2014-11-12 16:12:18 +1100102 * which is started from a workqueue for each NCR5380 host in the
103 * system. It attempts to establish I_T_L or I_T_L_Q nexuses by
104 * removing the commands from the issue queue and calling
105 * NCR5380_select() if a nexus is not established.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 *
107 * Once a nexus is established, the NCR5380_information_transfer()
108 * phase goes through the various phases as instructed by the target.
109 * if the target goes into MSG IN and sends a DISCONNECT message,
110 * the command structure is placed into the per instance disconnected
Finn Thainff50f9e2014-11-12 16:12:18 +1100111 * queue, and NCR5380_main tries to find more work. If the target is
112 * idle for too long, the system will try to sleep.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 *
114 * If a command has disconnected, eventually an interrupt will trigger,
115 * calling NCR5380_intr() which will in turn call NCR5380_reselect
116 * to reestablish a nexus. This will run main if necessary.
117 *
Roman Zippelc28bda22007-05-01 22:32:36 +0200118 * On command termination, the done function will be called as
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 * appropriate.
120 *
Roman Zippelc28bda22007-05-01 22:32:36 +0200121 * SCSI pointers are maintained in the SCp field of SCSI command
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 * structures, being initialized after the command is connected
123 * in NCR5380_select, and set as appropriate in NCR5380_information_transfer.
124 * Note that in violation of the standard, an implicit SAVE POINTERS operation
125 * is done, since some BROKEN disks fail to issue an explicit SAVE POINTERS.
126 */
127
128/*
129 * Using this file :
130 * This file a skeleton Linux SCSI driver for the NCR 5380 series
Roman Zippelc28bda22007-05-01 22:32:36 +0200131 * of chips. To use it, you write an architecture specific functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 * and macros and include this file in your driver.
133 *
Roman Zippelc28bda22007-05-01 22:32:36 +0200134 * These macros control options :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
Roman Zippelc28bda22007-05-01 22:32:36 +0200136 * for commands that return with a CHECK CONDITION status.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100138 * DIFFERENTIAL - if defined, NCR53c81 chips will use external differential
139 * transceivers.
140 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 * REAL_DMA - if defined, REAL DMA is used during the data transfer phases.
142 *
143 * SUPPORT_TAGS - if defined, SCSI-2 tagged queuing is used where possible
144 *
145 * These macros MUST be defined :
Roman Zippelc28bda22007-05-01 22:32:36 +0200146 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 * NCR5380_read(register) - read from the specified register
148 *
Roman Zippelc28bda22007-05-01 22:32:36 +0200149 * NCR5380_write(register, value) - write to the specific register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100151 * NCR5380_implementation_fields - additional fields needed for this
152 * specific implementation of the NCR5380
153 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 * Either real DMA *or* pseudo DMA may be implemented
Roman Zippelc28bda22007-05-01 22:32:36 +0200155 * REAL functions :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 * NCR5380_REAL_DMA should be defined if real DMA is to be used.
Roman Zippelc28bda22007-05-01 22:32:36 +0200157 * Note that the DMA setup functions should return the number of bytes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 * that they were able to program the controller for.
159 *
Roman Zippelc28bda22007-05-01 22:32:36 +0200160 * Also note that generic i386/PC versions of these macros are
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 * available as NCR5380_i386_dma_write_setup,
162 * NCR5380_i386_dma_read_setup, and NCR5380_i386_dma_residual.
163 *
164 * NCR5380_dma_write_setup(instance, src, count) - initialize
165 * NCR5380_dma_read_setup(instance, dst, count) - initialize
166 * NCR5380_dma_residual(instance); - residual count
167 *
168 * PSEUDO functions :
169 * NCR5380_pwrite(instance, src, count)
170 * NCR5380_pread(instance, dst, count);
171 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 * The generic driver is initialized by calling NCR5380_init(instance),
Roman Zippelc28bda22007-05-01 22:32:36 +0200173 * after setting the appropriate host specific fields and ID. If the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance,
Finn Thain8c325132014-11-12 16:11:58 +1100175 * possible) function may be used.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 */
177
Finn Thain636b1ec2016-01-03 16:05:10 +1100178static int do_abort(struct Scsi_Host *);
179static void do_reset(struct Scsi_Host *);
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#ifdef SUPPORT_TAGS
182
183/*
184 * Functions for handling tagged queuing
185 * =====================================
186 *
187 * ++roman (01/96): Now I've implemented SCSI-2 tagged queuing. Some notes:
188 *
189 * Using consecutive numbers for the tags is no good idea in my eyes. There
190 * could be wrong re-usings if the counter (8 bit!) wraps and some early
191 * command has been preempted for a long time. My solution: a bitfield for
192 * remembering used tags.
193 *
194 * There's also the problem that each target has a certain queue size, but we
195 * cannot know it in advance :-( We just see a QUEUE_FULL status being
196 * returned. So, in this case, the driver internal queue size assumption is
197 * reduced to the number of active tags if QUEUE_FULL is returned by the
Finn Thaine42d0152016-01-03 16:05:49 +1100198 * target.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 *
200 * We're also not allowed running tagged commands as long as an untagged
201 * command is active. And REQUEST SENSE commands after a contingent allegiance
202 * condition _must_ be untagged. To keep track whether an untagged command has
203 * been issued, the host->busy array is still employed, as it is without
204 * support for tagged queuing.
205 *
206 * One could suspect that there are possible race conditions between
207 * is_lun_busy(), cmd_get_tag() and cmd_free_tag(). But I think this isn't the
208 * case: is_lun_busy() and cmd_get_tag() are both called from NCR5380_main(),
209 * which already guaranteed to be running at most once. It is also the only
210 * place where tags/LUNs are allocated. So no other allocation can slip
211 * between that pair, there could only happen a reselection, which can free a
212 * tag, but that doesn't hurt. Only the sequence in cmd_free_tag() becomes
213 * important: the tag bit must be cleared before 'nr_allocated' is decreased.
214 */
215
Finn Thainca513fc2014-11-12 16:12:19 +1100216static void __init init_tags(struct NCR5380_hostdata *hostdata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Roman Zippelc28bda22007-05-01 22:32:36 +0200218 int target, lun;
Finn Thain61d739a2014-11-12 16:12:20 +1100219 struct tag_alloc *ta;
Roman Zippelc28bda22007-05-01 22:32:36 +0200220
Finn Thainca513fc2014-11-12 16:12:19 +1100221 if (!(hostdata->flags & FLAG_TAGGED_QUEUING))
Roman Zippelc28bda22007-05-01 22:32:36 +0200222 return;
223
224 for (target = 0; target < 8; ++target) {
225 for (lun = 0; lun < 8; ++lun) {
Finn Thain61d739a2014-11-12 16:12:20 +1100226 ta = &hostdata->TagAlloc[target][lun];
Roman Zippelc28bda22007-05-01 22:32:36 +0200227 bitmap_zero(ta->allocated, MAX_TAGS);
228 ta->nr_allocated = 0;
229 /* At the beginning, assume the maximum queue size we could
230 * support (MAX_TAGS). This value will be decreased if the target
231 * returns QUEUE_FULL status.
232 */
233 ta->queue_size = MAX_TAGS;
234 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
238
239/* Check if we can issue a command to this LUN: First see if the LUN is marked
240 * busy by an untagged command. If the command should use tagged queuing, also
241 * check that there is a free tag and the target's queue won't overflow. This
242 * function should be called with interrupts disabled to avoid race
243 * conditions.
Roman Zippelc28bda22007-05-01 22:32:36 +0200244 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Finn Thain710ddd02014-11-12 16:12:02 +1100246static int is_lun_busy(struct scsi_cmnd *cmd, int should_be_tagged)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200248 u8 lun = cmd->device->lun;
Finn Thaindbb6b352016-01-03 16:05:53 +1100249 struct Scsi_Host *instance = cmd->device->host;
250 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200252 if (hostdata->busy[cmd->device->id] & (1 << lun))
Roman Zippelc28bda22007-05-01 22:32:36 +0200253 return 1;
254 if (!should_be_tagged ||
Finn Thainca513fc2014-11-12 16:12:19 +1100255 !(hostdata->flags & FLAG_TAGGED_QUEUING) ||
256 !cmd->device->tagged_supported)
Roman Zippelc28bda22007-05-01 22:32:36 +0200257 return 0;
Finn Thain61d739a2014-11-12 16:12:20 +1100258 if (hostdata->TagAlloc[scmd_id(cmd)][lun].nr_allocated >=
259 hostdata->TagAlloc[scmd_id(cmd)][lun].queue_size) {
Finn Thaindbb6b352016-01-03 16:05:53 +1100260 dsprintk(NDEBUG_TAGS, instance, "target %d lun %d: no free tags\n",
261 scmd_id(cmd), lun);
Roman Zippelc28bda22007-05-01 22:32:36 +0200262 return 1;
263 }
264 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265}
266
267
268/* Allocate a tag for a command (there are no checks anymore, check_lun_busy()
269 * must be called before!), or reserve the LUN in 'busy' if the command is
270 * untagged.
271 */
272
Finn Thain710ddd02014-11-12 16:12:02 +1100273static void cmd_get_tag(struct scsi_cmnd *cmd, int should_be_tagged)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200275 u8 lun = cmd->device->lun;
Finn Thaindbb6b352016-01-03 16:05:53 +1100276 struct Scsi_Host *instance = cmd->device->host;
277 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Roman Zippelc28bda22007-05-01 22:32:36 +0200279 /* If we or the target don't support tagged queuing, allocate the LUN for
280 * an untagged command.
281 */
282 if (!should_be_tagged ||
Finn Thainca513fc2014-11-12 16:12:19 +1100283 !(hostdata->flags & FLAG_TAGGED_QUEUING) ||
284 !cmd->device->tagged_supported) {
Roman Zippelc28bda22007-05-01 22:32:36 +0200285 cmd->tag = TAG_NONE;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200286 hostdata->busy[cmd->device->id] |= (1 << lun);
Finn Thaindbb6b352016-01-03 16:05:53 +1100287 dsprintk(NDEBUG_TAGS, instance, "target %d lun %d now allocated by untagged command\n",
288 scmd_id(cmd), lun);
Roman Zippelc28bda22007-05-01 22:32:36 +0200289 } else {
Finn Thain61d739a2014-11-12 16:12:20 +1100290 struct tag_alloc *ta = &hostdata->TagAlloc[scmd_id(cmd)][lun];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Roman Zippelc28bda22007-05-01 22:32:36 +0200292 cmd->tag = find_first_zero_bit(ta->allocated, MAX_TAGS);
293 set_bit(cmd->tag, ta->allocated);
294 ta->nr_allocated++;
Finn Thaindbb6b352016-01-03 16:05:53 +1100295 dsprintk(NDEBUG_TAGS, instance, "using tag %d for target %d lun %d (%d tags allocated)\n",
296 cmd->tag, scmd_id(cmd), lun, ta->nr_allocated);
Roman Zippelc28bda22007-05-01 22:32:36 +0200297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
300
301/* Mark the tag of command 'cmd' as free, or in case of an untagged command,
302 * unlock the LUN.
303 */
304
Finn Thain710ddd02014-11-12 16:12:02 +1100305static void cmd_free_tag(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200307 u8 lun = cmd->device->lun;
Finn Thaindbb6b352016-01-03 16:05:53 +1100308 struct Scsi_Host *instance = cmd->device->host;
309 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Roman Zippelc28bda22007-05-01 22:32:36 +0200311 if (cmd->tag == TAG_NONE) {
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200312 hostdata->busy[cmd->device->id] &= ~(1 << lun);
Finn Thaindbb6b352016-01-03 16:05:53 +1100313 dsprintk(NDEBUG_TAGS, instance, "target %d lun %d untagged cmd freed\n",
314 scmd_id(cmd), lun);
Roman Zippelc28bda22007-05-01 22:32:36 +0200315 } else if (cmd->tag >= MAX_TAGS) {
Finn Thaindbb6b352016-01-03 16:05:53 +1100316 shost_printk(KERN_NOTICE, instance,
317 "trying to free bad tag %d!\n", cmd->tag);
Roman Zippelc28bda22007-05-01 22:32:36 +0200318 } else {
Finn Thain61d739a2014-11-12 16:12:20 +1100319 struct tag_alloc *ta = &hostdata->TagAlloc[scmd_id(cmd)][lun];
Roman Zippelc28bda22007-05-01 22:32:36 +0200320 clear_bit(cmd->tag, ta->allocated);
321 ta->nr_allocated--;
Finn Thaindbb6b352016-01-03 16:05:53 +1100322 dsprintk(NDEBUG_TAGS, instance, "freed tag %d for target %d lun %d\n",
323 cmd->tag, scmd_id(cmd), lun);
Roman Zippelc28bda22007-05-01 22:32:36 +0200324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
327
Finn Thainca513fc2014-11-12 16:12:19 +1100328static void free_all_tags(struct NCR5380_hostdata *hostdata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Roman Zippelc28bda22007-05-01 22:32:36 +0200330 int target, lun;
Finn Thain61d739a2014-11-12 16:12:20 +1100331 struct tag_alloc *ta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Finn Thainca513fc2014-11-12 16:12:19 +1100333 if (!(hostdata->flags & FLAG_TAGGED_QUEUING))
Roman Zippelc28bda22007-05-01 22:32:36 +0200334 return;
335
336 for (target = 0; target < 8; ++target) {
337 for (lun = 0; lun < 8; ++lun) {
Finn Thain61d739a2014-11-12 16:12:20 +1100338 ta = &hostdata->TagAlloc[target][lun];
Roman Zippelc28bda22007-05-01 22:32:36 +0200339 bitmap_zero(ta->allocated, MAX_TAGS);
340 ta->nr_allocated = 0;
341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
345#endif /* SUPPORT_TAGS */
346
347
348/*
Finn Thain710ddd02014-11-12 16:12:02 +1100349 * Function: void merge_contiguous_buffers( struct scsi_cmnd *cmd )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 *
351 * Purpose: Try to merge several scatter-gather requests into one DMA
352 * transfer. This is possible if the scatter buffers lie on
353 * physical contiguous addresses.
354 *
Finn Thain710ddd02014-11-12 16:12:02 +1100355 * Parameters: struct scsi_cmnd *cmd
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 * The command to work on. The first scatter buffer's data are
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300357 * assumed to be already transferred into ptr/this_residual.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 */
359
Finn Thain710ddd02014-11-12 16:12:02 +1100360static void merge_contiguous_buffers(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Finn Thaine3f463b2014-11-12 16:12:16 +1100362#if !defined(CONFIG_SUN3)
Roman Zippelc28bda22007-05-01 22:32:36 +0200363 unsigned long endaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364#if (NDEBUG & NDEBUG_MERGING)
Roman Zippelc28bda22007-05-01 22:32:36 +0200365 unsigned long oldlen = cmd->SCp.this_residual;
366 int cnt = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#endif
368
Roman Zippelc28bda22007-05-01 22:32:36 +0200369 for (endaddr = virt_to_phys(cmd->SCp.ptr + cmd->SCp.this_residual - 1) + 1;
370 cmd->SCp.buffers_residual &&
Geert Uytterhoeven5a1cb472007-10-24 08:55:40 +0200371 virt_to_phys(sg_virt(&cmd->SCp.buffer[1])) == endaddr;) {
Finn Thaind65e6342014-03-18 11:42:20 +1100372 dprintk(NDEBUG_MERGING, "VTOP(%p) == %08lx -> merging\n",
Geert Uytterhoeven5a1cb472007-10-24 08:55:40 +0200373 page_address(sg_page(&cmd->SCp.buffer[1])), endaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374#if (NDEBUG & NDEBUG_MERGING)
Roman Zippelc28bda22007-05-01 22:32:36 +0200375 ++cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376#endif
Roman Zippelc28bda22007-05-01 22:32:36 +0200377 ++cmd->SCp.buffer;
378 --cmd->SCp.buffers_residual;
379 cmd->SCp.this_residual += cmd->SCp.buffer->length;
380 endaddr += cmd->SCp.buffer->length;
381 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#if (NDEBUG & NDEBUG_MERGING)
Roman Zippelc28bda22007-05-01 22:32:36 +0200383 if (oldlen != cmd->SCp.this_residual)
Finn Thaind65e6342014-03-18 11:42:20 +1100384 dprintk(NDEBUG_MERGING, "merged %d buffers from %p, new length %08x\n",
Roman Zippelc28bda22007-05-01 22:32:36 +0200385 cnt, cmd->SCp.ptr, cmd->SCp.this_residual);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386#endif
Finn Thaine3f463b2014-11-12 16:12:16 +1100387#endif /* !defined(CONFIG_SUN3) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388}
389
Finn Thainff50f9e2014-11-12 16:12:18 +1100390/**
391 * initialize_SCp - init the scsi pointer field
392 * @cmd: command block to set up
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100394 * Set up the internal fields in the SCSI command.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 */
396
Finn Thain710ddd02014-11-12 16:12:02 +1100397static inline void initialize_SCp(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Roman Zippelc28bda22007-05-01 22:32:36 +0200399 /*
400 * Initialize the Scsi Pointer field so that all of the commands in the
401 * various queues are valid.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 */
Roman Zippelc28bda22007-05-01 22:32:36 +0200403
Boaz Harrosh9e0fe442007-11-05 11:23:35 +0200404 if (scsi_bufflen(cmd)) {
405 cmd->SCp.buffer = scsi_sglist(cmd);
406 cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
Jens Axboe45711f12007-10-22 21:19:53 +0200407 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
Roman Zippelc28bda22007-05-01 22:32:36 +0200408 cmd->SCp.this_residual = cmd->SCp.buffer->length;
409 /* ++roman: Try to merge some scatter-buffers if they are at
410 * contiguous physical addresses.
411 */
412 merge_contiguous_buffers(cmd);
413 } else {
414 cmd->SCp.buffer = NULL;
415 cmd->SCp.buffers_residual = 0;
Boaz Harrosh9e0fe442007-11-05 11:23:35 +0200416 cmd->SCp.ptr = NULL;
417 cmd->SCp.this_residual = 0;
Roman Zippelc28bda22007-05-01 22:32:36 +0200418 }
Finn Thainf27db8e2016-01-03 16:06:00 +1100419
420 cmd->SCp.Status = 0;
421 cmd->SCp.Message = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
Finn Thain636b1ec2016-01-03 16:05:10 +1100424/**
Finn Thainb32ade12016-01-03 16:05:41 +1100425 * NCR5380_poll_politely2 - wait for two chip register values
Finn Thain636b1ec2016-01-03 16:05:10 +1100426 * @instance: controller to poll
Finn Thainb32ade12016-01-03 16:05:41 +1100427 * @reg1: 5380 register to poll
428 * @bit1: Bitmask to check
429 * @val1: Expected value
430 * @reg2: Second 5380 register to poll
431 * @bit2: Second bitmask to check
432 * @val2: Second expected value
Finn Thain2f854b82016-01-03 16:05:22 +1100433 * @wait: Time-out in jiffies
Finn Thain636b1ec2016-01-03 16:05:10 +1100434 *
Finn Thain2f854b82016-01-03 16:05:22 +1100435 * Polls the chip in a reasonably efficient manner waiting for an
436 * event to occur. After a short quick poll we begin to yield the CPU
437 * (if possible). In irq contexts the time-out is arbitrarily limited.
438 * Callers may hold locks as long as they are held in irq mode.
Finn Thain636b1ec2016-01-03 16:05:10 +1100439 *
Finn Thainb32ade12016-01-03 16:05:41 +1100440 * Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT.
Finn Thain636b1ec2016-01-03 16:05:10 +1100441 */
442
Finn Thainb32ade12016-01-03 16:05:41 +1100443static int NCR5380_poll_politely2(struct Scsi_Host *instance,
444 int reg1, int bit1, int val1,
445 int reg2, int bit2, int val2, int wait)
Finn Thain636b1ec2016-01-03 16:05:10 +1100446{
Finn Thain2f854b82016-01-03 16:05:22 +1100447 struct NCR5380_hostdata *hostdata = shost_priv(instance);
448 unsigned long deadline = jiffies + wait;
449 unsigned long n;
Finn Thain636b1ec2016-01-03 16:05:10 +1100450
Finn Thain2f854b82016-01-03 16:05:22 +1100451 /* Busy-wait for up to 10 ms */
452 n = min(10000U, jiffies_to_usecs(wait));
453 n *= hostdata->accesses_per_ms;
Finn Thainb32ade12016-01-03 16:05:41 +1100454 n /= 2000;
Finn Thain2f854b82016-01-03 16:05:22 +1100455 do {
Finn Thainb32ade12016-01-03 16:05:41 +1100456 if ((NCR5380_read(reg1) & bit1) == val1)
457 return 0;
458 if ((NCR5380_read(reg2) & bit2) == val2)
Finn Thain636b1ec2016-01-03 16:05:10 +1100459 return 0;
460 cpu_relax();
Finn Thain2f854b82016-01-03 16:05:22 +1100461 } while (n--);
462
463 if (irqs_disabled() || in_interrupt())
464 return -ETIMEDOUT;
465
466 /* Repeatedly sleep for 1 ms until deadline */
467 while (time_is_after_jiffies(deadline)) {
468 schedule_timeout_uninterruptible(1);
Finn Thainb32ade12016-01-03 16:05:41 +1100469 if ((NCR5380_read(reg1) & bit1) == val1)
470 return 0;
471 if ((NCR5380_read(reg2) & bit2) == val2)
Finn Thain2f854b82016-01-03 16:05:22 +1100472 return 0;
Finn Thain636b1ec2016-01-03 16:05:10 +1100473 }
474
Finn Thain636b1ec2016-01-03 16:05:10 +1100475 return -ETIMEDOUT;
476}
477
Finn Thainb32ade12016-01-03 16:05:41 +1100478static inline int NCR5380_poll_politely(struct Scsi_Host *instance,
479 int reg, int bit, int val, int wait)
480{
481 return NCR5380_poll_politely2(instance, reg, bit, val,
482 reg, bit, val, wait);
483}
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485#if NDEBUG
486static struct {
Roman Zippelc28bda22007-05-01 22:32:36 +0200487 unsigned char mask;
488 const char *name;
489} signals[] = {
490 { SR_DBP, "PARITY"}, { SR_RST, "RST" }, { SR_BSY, "BSY" },
491 { SR_REQ, "REQ" }, { SR_MSG, "MSG" }, { SR_CD, "CD" }, { SR_IO, "IO" },
492 { SR_SEL, "SEL" }, {0, NULL}
493}, basrs[] = {
494 {BASR_ATN, "ATN"}, {BASR_ACK, "ACK"}, {0, NULL}
495}, icrs[] = {
496 {ICR_ASSERT_RST, "ASSERT RST"},{ICR_ASSERT_ACK, "ASSERT ACK"},
497 {ICR_ASSERT_BSY, "ASSERT BSY"}, {ICR_ASSERT_SEL, "ASSERT SEL"},
498 {ICR_ASSERT_ATN, "ASSERT ATN"}, {ICR_ASSERT_DATA, "ASSERT DATA"},
499 {0, NULL}
500}, mrs[] = {
501 {MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"},
502 {MR_ENABLE_PAR_CHECK, "MODE PARITY CHECK"}, {MR_ENABLE_PAR_INTR,
503 "MODE PARITY INTR"}, {MR_ENABLE_EOP_INTR,"MODE EOP INTR"},
504 {MR_MONITOR_BSY, "MODE MONITOR BSY"},
505 {MR_DMA_MODE, "MODE DMA"}, {MR_ARBITRATE, "MODE ARBITRATION"},
506 {0, NULL}
507};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Finn Thainff50f9e2014-11-12 16:12:18 +1100509/**
510 * NCR5380_print - print scsi bus signals
511 * @instance: adapter state to dump
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100513 * Print the SCSI bus signals for debugging purposes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 */
515
Roman Zippelc28bda22007-05-01 22:32:36 +0200516static void NCR5380_print(struct Scsi_Host *instance)
517{
518 unsigned char status, data, basr, mr, icr, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Roman Zippelc28bda22007-05-01 22:32:36 +0200520 data = NCR5380_read(CURRENT_SCSI_DATA_REG);
521 status = NCR5380_read(STATUS_REG);
522 mr = NCR5380_read(MODE_REG);
523 icr = NCR5380_read(INITIATOR_COMMAND_REG);
524 basr = NCR5380_read(BUS_AND_STATUS_REG);
Finn Thain11d2f632016-01-03 16:05:51 +1100525
Roman Zippelc28bda22007-05-01 22:32:36 +0200526 printk("STATUS_REG: %02x ", status);
527 for (i = 0; signals[i].mask; ++i)
528 if (status & signals[i].mask)
529 printk(",%s", signals[i].name);
530 printk("\nBASR: %02x ", basr);
531 for (i = 0; basrs[i].mask; ++i)
532 if (basr & basrs[i].mask)
533 printk(",%s", basrs[i].name);
534 printk("\nICR: %02x ", icr);
535 for (i = 0; icrs[i].mask; ++i)
536 if (icr & icrs[i].mask)
537 printk(",%s", icrs[i].name);
538 printk("\nMODE: %02x ", mr);
539 for (i = 0; mrs[i].mask; ++i)
540 if (mr & mrs[i].mask)
541 printk(",%s", mrs[i].name);
542 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
545static struct {
Roman Zippelc28bda22007-05-01 22:32:36 +0200546 unsigned char value;
547 const char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548} phases[] = {
Roman Zippelc28bda22007-05-01 22:32:36 +0200549 {PHASE_DATAOUT, "DATAOUT"}, {PHASE_DATAIN, "DATAIN"}, {PHASE_CMDOUT, "CMDOUT"},
550 {PHASE_STATIN, "STATIN"}, {PHASE_MSGOUT, "MSGOUT"}, {PHASE_MSGIN, "MSGIN"},
551 {PHASE_UNKNOWN, "UNKNOWN"}
552};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Finn Thainff50f9e2014-11-12 16:12:18 +1100554/**
555 * NCR5380_print_phase - show SCSI phase
556 * @instance: adapter to dump
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100558 * Print the current SCSI phase for debugging purposes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100560 * Locks: none
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 */
562
563static void NCR5380_print_phase(struct Scsi_Host *instance)
564{
Roman Zippelc28bda22007-05-01 22:32:36 +0200565 unsigned char status;
566 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Roman Zippelc28bda22007-05-01 22:32:36 +0200568 status = NCR5380_read(STATUS_REG);
569 if (!(status & SR_REQ))
Finn Thain6a6ff4a2016-01-03 16:06:04 +1100570 shost_printk(KERN_DEBUG, instance, "REQ not asserted, phase unknown.\n");
Roman Zippelc28bda22007-05-01 22:32:36 +0200571 else {
572 for (i = 0; (phases[i].value != PHASE_UNKNOWN) &&
573 (phases[i].value != (status & PHASE_MASK)); ++i)
574 ;
Finn Thain6a6ff4a2016-01-03 16:06:04 +1100575 shost_printk(KERN_DEBUG, instance, "phase %s\n", phases[i].name);
Roman Zippelc28bda22007-05-01 22:32:36 +0200576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#endif
580
Finn Thain8c325132014-11-12 16:11:58 +1100581/**
582 * NCR58380_info - report driver and host information
583 * @instance: relevant scsi host instance
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 *
Finn Thain8c325132014-11-12 16:11:58 +1100585 * For use as the host template info() handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 *
Finn Thain8c325132014-11-12 16:11:58 +1100587 * Locks: none
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 */
589
Finn Thain8c325132014-11-12 16:11:58 +1100590static const char *NCR5380_info(struct Scsi_Host *instance)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Finn Thain8c325132014-11-12 16:11:58 +1100592 struct NCR5380_hostdata *hostdata = shost_priv(instance);
593
594 return hostdata->info;
595}
596
597static void prepare_info(struct Scsi_Host *instance)
598{
599 struct NCR5380_hostdata *hostdata = shost_priv(instance);
600
601 snprintf(hostdata->info, sizeof(hostdata->info),
602 "%s, io_port 0x%lx, n_io_port %d, "
603 "base 0x%lx, irq %d, "
604 "can_queue %d, cmd_per_lun %d, "
605 "sg_tablesize %d, this_id %d, "
Finn Thain9c3f0e22016-01-03 16:05:11 +1100606 "flags { %s%s}, "
Finn Thain8c325132014-11-12 16:11:58 +1100607 "options { %s} ",
608 instance->hostt->name, instance->io_port, instance->n_io_port,
609 instance->base, instance->irq,
610 instance->can_queue, instance->cmd_per_lun,
611 instance->sg_tablesize, instance->this_id,
Finn Thainca513fc2014-11-12 16:12:19 +1100612 hostdata->flags & FLAG_TAGGED_QUEUING ? "TAGGED_QUEUING " : "",
Finn Thain9c3f0e22016-01-03 16:05:11 +1100613 hostdata->flags & FLAG_TOSHIBA_DELAY ? "TOSHIBA_DELAY " : "",
Finn Thain8c325132014-11-12 16:11:58 +1100614#ifdef DIFFERENTIAL
615 "DIFFERENTIAL "
616#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#ifdef REAL_DMA
Finn Thain8c325132014-11-12 16:11:58 +1100618 "REAL_DMA "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#endif
620#ifdef PARITY
Finn Thain8c325132014-11-12 16:11:58 +1100621 "PARITY "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622#endif
623#ifdef SUPPORT_TAGS
Finn Thain8c325132014-11-12 16:11:58 +1100624 "SUPPORT_TAGS "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#endif
Finn Thain8c325132014-11-12 16:11:58 +1100626 "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
Finn Thainff50f9e2014-11-12 16:12:18 +1100629/**
Finn Thainff50f9e2014-11-12 16:12:18 +1100630 * NCR5380_init - initialise an NCR5380
631 * @instance: adapter to configure
632 * @flags: control flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100634 * Initializes *instance and corresponding 5380 chip,
635 * with flags OR'd into the initial flags value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 *
637 * Notes : I assume that the host, hostno, and id bits have been
Finn Thainff50f9e2014-11-12 16:12:18 +1100638 * set correctly. I don't care about the irq and other fields.
Roman Zippelc28bda22007-05-01 22:32:36 +0200639 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100640 * Returns 0 for success
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 */
642
Michael Schmitz95fde7a2009-01-18 03:22:15 +0100643static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644{
Finn Thaine8a60142016-01-03 16:05:54 +1100645 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +0200646 int i;
Finn Thain2f854b82016-01-03 16:05:22 +1100647 unsigned long deadline;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Finn Thaina53a21e2014-11-12 16:12:21 +1100649 hostdata->host = instance;
Roman Zippelc28bda22007-05-01 22:32:36 +0200650 hostdata->id_mask = 1 << instance->this_id;
651 hostdata->id_higher_mask = 0;
652 for (i = hostdata->id_mask; i <= 0x80; i <<= 1)
653 if (i > hostdata->id_mask)
654 hostdata->id_higher_mask |= i;
655 for (i = 0; i < 8; ++i)
656 hostdata->busy[i] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#ifdef SUPPORT_TAGS
Finn Thainca513fc2014-11-12 16:12:19 +1100658 init_tags(hostdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#endif
660#if defined (REAL_DMA)
Roman Zippelc28bda22007-05-01 22:32:36 +0200661 hostdata->dma_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#endif
Finn Thain11d2f632016-01-03 16:05:51 +1100663 spin_lock_init(&hostdata->lock);
Roman Zippelc28bda22007-05-01 22:32:36 +0200664 hostdata->connected = NULL;
Finn Thainf27db8e2016-01-03 16:06:00 +1100665 hostdata->sensing = NULL;
666 INIT_LIST_HEAD(&hostdata->autosense);
Finn Thain32b26a12016-01-03 16:05:58 +1100667 INIT_LIST_HEAD(&hostdata->unissued);
668 INIT_LIST_HEAD(&hostdata->disconnected);
669
Finn Thainef1081c2014-11-12 16:12:14 +1100670 hostdata->flags = flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Finn Thaina53a21e2014-11-12 16:12:21 +1100672 INIT_WORK(&hostdata->main_task, NCR5380_main);
Finn Thain0ad0eff2016-01-03 16:05:21 +1100673 hostdata->work_q = alloc_workqueue("ncr5380_%d",
674 WQ_UNBOUND | WQ_MEM_RECLAIM,
675 1, instance->host_no);
676 if (!hostdata->work_q)
677 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Finn Thain8c325132014-11-12 16:11:58 +1100679 prepare_info(instance);
680
Roman Zippelc28bda22007-05-01 22:32:36 +0200681 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
682 NCR5380_write(MODE_REG, MR_BASE);
683 NCR5380_write(TARGET_COMMAND_REG, 0);
684 NCR5380_write(SELECT_ENABLE_REG, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Finn Thain2f854b82016-01-03 16:05:22 +1100686 /* Calibrate register polling loop */
687 i = 0;
688 deadline = jiffies + 1;
689 do {
690 cpu_relax();
691 } while (time_is_after_jiffies(deadline));
692 deadline += msecs_to_jiffies(256);
693 do {
694 NCR5380_read(STATUS_REG);
695 ++i;
696 cpu_relax();
697 } while (time_is_after_jiffies(deadline));
698 hostdata->accesses_per_ms = i / 256;
699
Roman Zippelc28bda22007-05-01 22:32:36 +0200700 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}
702
Finn Thainff50f9e2014-11-12 16:12:18 +1100703/**
Finn Thain636b1ec2016-01-03 16:05:10 +1100704 * NCR5380_maybe_reset_bus - Detect and correct bus wedge problems.
705 * @instance: adapter to check
706 *
707 * If the system crashed, it may have crashed with a connected target and
708 * the SCSI bus busy. Check for BUS FREE phase. If not, try to abort the
709 * currently established nexus, which we know nothing about. Failing that
710 * do a bus reset.
711 *
712 * Note that a bus reset will cause the chip to assert IRQ.
713 *
714 * Returns 0 if successful, otherwise -ENXIO.
715 */
716
717static int NCR5380_maybe_reset_bus(struct Scsi_Host *instance)
718{
Finn Thain9c3f0e22016-01-03 16:05:11 +1100719 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Finn Thain636b1ec2016-01-03 16:05:10 +1100720 int pass;
721
722 for (pass = 1; (NCR5380_read(STATUS_REG) & SR_BSY) && pass <= 6; ++pass) {
723 switch (pass) {
724 case 1:
725 case 3:
726 case 5:
727 shost_printk(KERN_ERR, instance, "SCSI bus busy, waiting up to five seconds\n");
728 NCR5380_poll_politely(instance,
729 STATUS_REG, SR_BSY, 0, 5 * HZ);
730 break;
731 case 2:
732 shost_printk(KERN_ERR, instance, "bus busy, attempting abort\n");
733 do_abort(instance);
734 break;
735 case 4:
736 shost_printk(KERN_ERR, instance, "bus busy, attempting reset\n");
737 do_reset(instance);
Finn Thain9c3f0e22016-01-03 16:05:11 +1100738 /* Wait after a reset; the SCSI standard calls for
739 * 250ms, we wait 500ms to be on the safe side.
740 * But some Toshiba CD-ROMs need ten times that.
741 */
742 if (hostdata->flags & FLAG_TOSHIBA_DELAY)
743 msleep(2500);
744 else
745 msleep(500);
Finn Thain636b1ec2016-01-03 16:05:10 +1100746 break;
747 case 6:
748 shost_printk(KERN_ERR, instance, "bus locked solid\n");
749 return -ENXIO;
750 }
751 }
752 return 0;
753}
754
755/**
Finn Thainff50f9e2014-11-12 16:12:18 +1100756 * NCR5380_exit - remove an NCR5380
757 * @instance: adapter to remove
758 *
759 * Assumes that no more work can be queued (e.g. by NCR5380_intr).
760 */
761
Geert Uytterhoeven6323e4f2011-06-13 20:39:15 +0200762static void NCR5380_exit(struct Scsi_Host *instance)
763{
Finn Thaina53a21e2014-11-12 16:12:21 +1100764 struct NCR5380_hostdata *hostdata = shost_priv(instance);
765
766 cancel_work_sync(&hostdata->main_task);
Finn Thain0ad0eff2016-01-03 16:05:21 +1100767 destroy_workqueue(hostdata->work_q);
Geert Uytterhoeven6323e4f2011-06-13 20:39:15 +0200768}
769
Finn Thainff50f9e2014-11-12 16:12:18 +1100770/**
Finn Thain677e0192016-01-03 16:05:59 +1100771 * complete_cmd - finish processing a command and return it to the SCSI ML
772 * @instance: the host instance
773 * @cmd: command to complete
774 */
775
776static void complete_cmd(struct Scsi_Host *instance,
777 struct scsi_cmnd *cmd)
778{
779 struct NCR5380_hostdata *hostdata = shost_priv(instance);
780
781 dsprintk(NDEBUG_QUEUES, instance, "complete_cmd: cmd %p\n", cmd);
782
Finn Thainf27db8e2016-01-03 16:06:00 +1100783 if (hostdata->sensing == cmd) {
784 /* Autosense processing ends here */
785 if ((cmd->result & 0xff) != SAM_STAT_GOOD) {
786 scsi_eh_restore_cmnd(cmd, &hostdata->ses);
787 set_host_byte(cmd, DID_ERROR);
788 } else
789 scsi_eh_restore_cmnd(cmd, &hostdata->ses);
790 hostdata->sensing = NULL;
791 }
792
Finn Thain677e0192016-01-03 16:05:59 +1100793#ifdef SUPPORT_TAGS
794 cmd_free_tag(cmd);
795#else
796 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
797#endif
798 cmd->scsi_done(cmd);
799}
800
801/**
Finn Thainff50f9e2014-11-12 16:12:18 +1100802 * NCR5380_queue_command - queue a command
803 * @instance: the relevant SCSI adapter
804 * @cmd: SCSI command
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 *
Finn Thain1bb40582016-01-03 16:05:29 +1100806 * cmd is added to the per-instance issue queue, with minor
Finn Thainff50f9e2014-11-12 16:12:18 +1100807 * twiddling done to the host specific fields of cmd. If the
808 * main coroutine is not running, it is restarted.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 */
810
Finn Thain16b29e72014-11-12 16:12:08 +1100811static int NCR5380_queue_command(struct Scsi_Host *instance,
812 struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Finn Thain16b29e72014-11-12 16:12:08 +1100814 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Finn Thain32b26a12016-01-03 16:05:58 +1100815 struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
Roman Zippelc28bda22007-05-01 22:32:36 +0200816 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818#if (NDEBUG & NDEBUG_NO_WRITE)
Roman Zippelc28bda22007-05-01 22:32:36 +0200819 switch (cmd->cmnd[0]) {
820 case WRITE_6:
821 case WRITE_10:
Finn Thaindbb6b352016-01-03 16:05:53 +1100822 shost_printk(KERN_DEBUG, instance, "WRITE attempted with NDEBUG_NO_WRITE set\n");
Roman Zippelc28bda22007-05-01 22:32:36 +0200823 cmd->result = (DID_ERROR << 16);
Finn Thain16b29e72014-11-12 16:12:08 +1100824 cmd->scsi_done(cmd);
Roman Zippelc28bda22007-05-01 22:32:36 +0200825 return 0;
826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827#endif /* (NDEBUG & NDEBUG_NO_WRITE) */
828
Roman Zippelc28bda22007-05-01 22:32:36 +0200829 cmd->result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Roman Zippelc28bda22007-05-01 22:32:36 +0200831 /*
832 * Insert the cmd into the issue queue. Note that REQUEST SENSE
833 * commands are added to the head of the queue since any command will
834 * clear the contingent allegiance condition that exists and the
835 * sense data is only guaranteed to be valid while the condition exists.
836 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Roman Zippelc28bda22007-05-01 22:32:36 +0200838 /* ++guenther: now that the issue queue is being set up, we can lock ST-DMA.
839 * Otherwise a running NCR5380_main may steal the lock.
840 * Lock before actually inserting due to fairness reasons explained in
841 * atari_scsi.c. If we insert first, then it's impossible for this driver
842 * to release the lock.
843 * Stop timer for this command while waiting for the lock, or timeouts
844 * may happen (and they really do), and it's no good if the command doesn't
845 * appear in any of the queues.
846 * ++roman: Just disabling the NCR interrupt isn't sufficient here,
847 * because also a timer int can trigger an abort or reset, which would
848 * alter queues and touch the lock.
849 */
Finn Thaine3c3da62014-11-12 16:12:15 +1100850 if (!NCR5380_acquire_dma_irq(instance))
Finn Thain16b29e72014-11-12 16:12:08 +1100851 return SCSI_MLQUEUE_HOST_BUSY;
852
Finn Thain11d2f632016-01-03 16:05:51 +1100853 spin_lock_irqsave(&hostdata->lock, flags);
Finn Thain16b29e72014-11-12 16:12:08 +1100854
Finn Thainff50f9e2014-11-12 16:12:18 +1100855 /*
856 * Insert the cmd into the issue queue. Note that REQUEST SENSE
857 * commands are added to the head of the queue since any command will
858 * clear the contingent allegiance condition that exists and the
859 * sense data is only guaranteed to be valid while the condition exists.
860 */
861
Finn Thain32b26a12016-01-03 16:05:58 +1100862 if (cmd->cmnd[0] == REQUEST_SENSE)
863 list_add(&ncmd->list, &hostdata->unissued);
864 else
865 list_add_tail(&ncmd->list, &hostdata->unissued);
866
Finn Thain11d2f632016-01-03 16:05:51 +1100867 spin_unlock_irqrestore(&hostdata->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Finn Thaindbb6b352016-01-03 16:05:53 +1100869 dsprintk(NDEBUG_QUEUES, instance, "command %p added to %s of queue\n",
870 cmd, (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Finn Thain010e89d2016-01-03 16:05:38 +1100872 /* Kick off command processing */
873 queue_work(hostdata->work_q, &hostdata->main_task);
Roman Zippelc28bda22007-05-01 22:32:36 +0200874 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
876
Finn Thaine3c3da62014-11-12 16:12:15 +1100877static inline void maybe_release_dma_irq(struct Scsi_Host *instance)
878{
879 struct NCR5380_hostdata *hostdata = shost_priv(instance);
880
881 /* Caller does the locking needed to set & test these data atomically */
Finn Thain32b26a12016-01-03 16:05:58 +1100882 if (list_empty(&hostdata->disconnected) &&
883 list_empty(&hostdata->unissued) &&
Finn Thainf27db8e2016-01-03 16:06:00 +1100884 list_empty(&hostdata->autosense) &&
Finn Thaine3c3da62014-11-12 16:12:15 +1100885 !hostdata->connected &&
Finn Thain707d62b2016-01-03 16:06:02 +1100886 !hostdata->selecting)
Finn Thaine3c3da62014-11-12 16:12:15 +1100887 NCR5380_release_dma_irq(instance);
888}
889
Finn Thainff50f9e2014-11-12 16:12:18 +1100890/**
Finn Thainf27db8e2016-01-03 16:06:00 +1100891 * dequeue_next_cmd - dequeue a command for processing
892 * @instance: the scsi host instance
893 *
894 * Priority is given to commands on the autosense queue. These commands
895 * need autosense because of a CHECK CONDITION result.
896 *
897 * Returns a command pointer if a command is found for a target that is
898 * not already busy. Otherwise returns NULL.
899 */
900
901static struct scsi_cmnd *dequeue_next_cmd(struct Scsi_Host *instance)
902{
903 struct NCR5380_hostdata *hostdata = shost_priv(instance);
904 struct NCR5380_cmd *ncmd;
905 struct scsi_cmnd *cmd;
906
907 if (list_empty(&hostdata->autosense)) {
908 list_for_each_entry(ncmd, &hostdata->unissued, list) {
909 cmd = NCR5380_to_scmd(ncmd);
910 dsprintk(NDEBUG_QUEUES, instance, "dequeue: cmd=%p target=%d busy=0x%02x lun=%llu\n",
911 cmd, scmd_id(cmd), hostdata->busy[scmd_id(cmd)], cmd->device->lun);
912
913 if (
914#ifdef SUPPORT_TAGS
915 !is_lun_busy(cmd, 1)
916#else
917 !(hostdata->busy[scmd_id(cmd)] & (1 << cmd->device->lun))
918#endif
919 ) {
920 list_del(&ncmd->list);
921 dsprintk(NDEBUG_QUEUES, instance,
922 "dequeue: removed %p from issue queue\n", cmd);
923 return cmd;
924 }
925 }
926 } else {
927 /* Autosense processing begins here */
928 ncmd = list_first_entry(&hostdata->autosense,
929 struct NCR5380_cmd, list);
930 list_del(&ncmd->list);
931 cmd = NCR5380_to_scmd(ncmd);
932 dsprintk(NDEBUG_QUEUES, instance,
933 "dequeue: removed %p from autosense queue\n", cmd);
934 scsi_eh_prep_cmnd(cmd, &hostdata->ses, NULL, 0, ~0);
935 hostdata->sensing = cmd;
936 return cmd;
937 }
938 return NULL;
939}
940
941static void requeue_cmd(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
942{
943 struct NCR5380_hostdata *hostdata = shost_priv(instance);
944 struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
945
946 if (hostdata->sensing) {
947 scsi_eh_restore_cmnd(cmd, &hostdata->ses);
948 list_add(&ncmd->list, &hostdata->autosense);
949 hostdata->sensing = NULL;
950 } else
951 list_add(&ncmd->list, &hostdata->unissued);
952}
953
954/**
Finn Thainff50f9e2014-11-12 16:12:18 +1100955 * NCR5380_main - NCR state machines
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100957 * NCR5380_main is a coroutine that runs as long as more work can
958 * be done on the NCR5380 host adapters in a system. Both
959 * NCR5380_queue_command() and NCR5380_intr() will try to start it
960 * in case it is not running.
Roman Zippelc28bda22007-05-01 22:32:36 +0200961 *
Finn Thainff50f9e2014-11-12 16:12:18 +1100962 * Locks: called as its own thread with no locks held.
Roman Zippelc28bda22007-05-01 22:32:36 +0200963 */
964
Geert Uytterhoevenb312b382007-05-01 22:32:48 +0200965static void NCR5380_main(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
Finn Thaina53a21e2014-11-12 16:12:21 +1100967 struct NCR5380_hostdata *hostdata =
968 container_of(work, struct NCR5380_hostdata, main_task);
969 struct Scsi_Host *instance = hostdata->host;
Finn Thainf27db8e2016-01-03 16:06:00 +1100970 struct scsi_cmnd *cmd;
Roman Zippelc28bda22007-05-01 22:32:36 +0200971 int done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Roman Zippelc28bda22007-05-01 22:32:36 +0200973 /*
Roman Zippelc28bda22007-05-01 22:32:36 +0200974 * ++roman: Just disabling the NCR interrupt isn't sufficient here,
975 * because also a timer int can trigger an abort or reset, which can
976 * alter queues and touch the Falcon lock.
977 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Roman Zippelc28bda22007-05-01 22:32:36 +0200979 do {
Roman Zippelc28bda22007-05-01 22:32:36 +0200980 done = 1;
981
Finn Thain0a4e3612016-01-03 16:06:07 +1100982 spin_lock_irq(&hostdata->lock);
Finn Thainf27db8e2016-01-03 16:06:00 +1100983 while (!hostdata->connected &&
984 (cmd = dequeue_next_cmd(instance))) {
985
986 dsprintk(NDEBUG_MAIN, instance, "main: dequeued %p\n", cmd);
987
Roman Zippelc28bda22007-05-01 22:32:36 +0200988 /*
Finn Thainf27db8e2016-01-03 16:06:00 +1100989 * Attempt to establish an I_T_L nexus here.
990 * On success, instance->hostdata->connected is set.
991 * On failure, we must add the command back to the
992 * issue queue so we can keep trying.
Roman Zippelc28bda22007-05-01 22:32:36 +0200993 */
Finn Thainf27db8e2016-01-03 16:06:00 +1100994 /*
995 * REQUEST SENSE commands are issued without tagged
996 * queueing, even on SCSI-II devices because the
997 * contingent allegiance condition exists for the
998 * entire unit.
999 */
1000 /* ++roman: ...and the standard also requires that
1001 * REQUEST SENSE command are untagged.
1002 */
Roman Zippelc28bda22007-05-01 22:32:36 +02001003
1004#ifdef SUPPORT_TAGS
Finn Thainf27db8e2016-01-03 16:06:00 +11001005 cmd_get_tag(cmd, cmd->cmnd[0] != REQUEST_SENSE);
Roman Zippelc28bda22007-05-01 22:32:36 +02001006#endif
Finn Thain707d62b2016-01-03 16:06:02 +11001007 cmd = NCR5380_select(instance, cmd);
1008 if (!cmd) {
1009 dsprintk(NDEBUG_MAIN, instance, "main: select complete\n");
Finn Thainf27db8e2016-01-03 16:06:00 +11001010 maybe_release_dma_irq(instance);
1011 } else {
Finn Thainf27db8e2016-01-03 16:06:00 +11001012 dsprintk(NDEBUG_MAIN | NDEBUG_QUEUES, instance,
1013 "main: select failed, returning %p to queue\n", cmd);
1014 requeue_cmd(instance, cmd);
Roman Zippelc28bda22007-05-01 22:32:36 +02001015#ifdef SUPPORT_TAGS
Finn Thainf27db8e2016-01-03 16:06:00 +11001016 cmd_free_tag(cmd);
Roman Zippelc28bda22007-05-01 22:32:36 +02001017#endif
Finn Thainf27db8e2016-01-03 16:06:00 +11001018 }
1019 }
Roman Zippelc28bda22007-05-01 22:32:36 +02001020 if (hostdata->connected
1021#ifdef REAL_DMA
1022 && !hostdata->dma_len
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023#endif
1024 ) {
Finn Thainb7465452016-01-03 16:06:05 +11001025 dsprintk(NDEBUG_MAIN, instance, "main: performing information transfer\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02001026 NCR5380_information_transfer(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02001027 done = 0;
1028 }
Finn Thain0a4e3612016-01-03 16:06:07 +11001029 spin_unlock_irq(&hostdata->lock);
1030 if (!done)
1031 cond_resched();
Roman Zippelc28bda22007-05-01 22:32:36 +02001032 } while (!done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033}
1034
1035
1036#ifdef REAL_DMA
1037/*
1038 * Function : void NCR5380_dma_complete (struct Scsi_Host *instance)
1039 *
1040 * Purpose : Called by interrupt handler when DMA finishes or a phase
Roman Zippelc28bda22007-05-01 22:32:36 +02001041 * mismatch occurs (which would finish the DMA transfer).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 *
1043 * Inputs : instance - this instance of the NCR5380.
1044 *
1045 */
1046
Roman Zippelc28bda22007-05-01 22:32:36 +02001047static void NCR5380_dma_complete(struct Scsi_Host *instance)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
Finn Thaine8a60142016-01-03 16:05:54 +11001049 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Finn Thain01bd9082014-11-12 16:12:23 +11001050 int transferred;
Finn Thaine3f463b2014-11-12 16:12:16 +11001051 unsigned char **data;
Finn Thain5299b3c2016-01-03 16:05:57 +11001052 int *count;
Finn Thaine3f463b2014-11-12 16:12:16 +11001053 int saved_data = 0, overrun = 0;
1054 unsigned char p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Finn Thainef1081c2014-11-12 16:12:14 +11001056 if (hostdata->read_overruns) {
Roman Zippelc28bda22007-05-01 22:32:36 +02001057 p = hostdata->connected->SCp.phase;
1058 if (p & SR_IO) {
1059 udelay(10);
1060 if ((NCR5380_read(BUS_AND_STATUS_REG) &
1061 (BASR_PHASE_MATCH|BASR_ACK)) ==
1062 (BASR_PHASE_MATCH|BASR_ACK)) {
1063 saved_data = NCR5380_read(INPUT_DATA_REG);
1064 overrun = 1;
Finn Thainb7465452016-01-03 16:06:05 +11001065 dsprintk(NDEBUG_DMA, instance, "read overrun handled\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02001066 }
1067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
Roman Zippelc28bda22007-05-01 22:32:36 +02001069
Finn Thaine3f463b2014-11-12 16:12:16 +11001070#if defined(CONFIG_SUN3)
1071 if ((sun3scsi_dma_finish(rq_data_dir(hostdata->connected->request)))) {
1072 pr_err("scsi%d: overrun in UDC counter -- not prepared to deal with this!\n",
1073 instance->host_no);
1074 BUG();
1075 }
1076
1077 /* make sure we're not stuck in a data phase */
1078 if ((NCR5380_read(BUS_AND_STATUS_REG) & (BASR_PHASE_MATCH | BASR_ACK)) ==
1079 (BASR_PHASE_MATCH | BASR_ACK)) {
1080 pr_err("scsi%d: BASR %02x\n", instance->host_no,
1081 NCR5380_read(BUS_AND_STATUS_REG));
1082 pr_err("scsi%d: bus stuck in data phase -- probably a single byte overrun!\n",
1083 instance->host_no);
1084 BUG();
1085 }
1086#endif
1087
Roman Zippelc28bda22007-05-01 22:32:36 +02001088 NCR5380_write(MODE_REG, MR_BASE);
1089 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
Finn Thaincd400822016-01-03 16:05:40 +11001090 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
Roman Zippelc28bda22007-05-01 22:32:36 +02001091
Finn Thain01bd9082014-11-12 16:12:23 +11001092 transferred = hostdata->dma_len - NCR5380_dma_residual(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02001093 hostdata->dma_len = 0;
1094
1095 data = (unsigned char **)&hostdata->connected->SCp.ptr;
1096 count = &hostdata->connected->SCp.this_residual;
Finn Thain01bd9082014-11-12 16:12:23 +11001097 *data += transferred;
1098 *count -= transferred;
Roman Zippelc28bda22007-05-01 22:32:36 +02001099
Finn Thainef1081c2014-11-12 16:12:14 +11001100 if (hostdata->read_overruns) {
Finn Thaine3f463b2014-11-12 16:12:16 +11001101 int cnt, toPIO;
1102
Roman Zippelc28bda22007-05-01 22:32:36 +02001103 if ((NCR5380_read(STATUS_REG) & PHASE_MASK) == p && (p & SR_IO)) {
Finn Thainef1081c2014-11-12 16:12:14 +11001104 cnt = toPIO = hostdata->read_overruns;
Roman Zippelc28bda22007-05-01 22:32:36 +02001105 if (overrun) {
Finn Thaind65e6342014-03-18 11:42:20 +11001106 dprintk(NDEBUG_DMA, "Got an input overrun, using saved byte\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02001107 *(*data)++ = saved_data;
1108 (*count)--;
1109 cnt--;
1110 toPIO--;
1111 }
Finn Thaind65e6342014-03-18 11:42:20 +11001112 dprintk(NDEBUG_DMA, "Doing %d-byte PIO to 0x%08lx\n", cnt, (long)*data);
Roman Zippelc28bda22007-05-01 22:32:36 +02001113 NCR5380_transfer_pio(instance, &p, &cnt, data);
1114 *count -= toPIO - cnt;
1115 }
1116 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118#endif /* REAL_DMA */
1119
1120
Finn Thainff50f9e2014-11-12 16:12:18 +11001121/**
1122 * NCR5380_intr - generic NCR5380 irq handler
1123 * @irq: interrupt number
1124 * @dev_id: device info
Roman Zippelc28bda22007-05-01 22:32:36 +02001125 *
Finn Thainff50f9e2014-11-12 16:12:18 +11001126 * Handle interrupts, reestablishing I_T_L or I_T_L_Q nexuses
1127 * from the disconnected queue, and restarting NCR5380_main()
1128 * as required.
Finn Thaincd400822016-01-03 16:05:40 +11001129 *
1130 * The chip can assert IRQ in any of six different conditions. The IRQ flag
1131 * is then cleared by reading the Reset Parity/Interrupt Register (RPIR).
1132 * Three of these six conditions are latched in the Bus and Status Register:
1133 * - End of DMA (cleared by ending DMA Mode)
1134 * - Parity error (cleared by reading RPIR)
1135 * - Loss of BSY (cleared by reading RPIR)
1136 * Two conditions have flag bits that are not latched:
1137 * - Bus phase mismatch (non-maskable in DMA Mode, cleared by ending DMA Mode)
1138 * - Bus reset (non-maskable)
1139 * The remaining condition has no flag bit at all:
1140 * - Selection/reselection
1141 *
1142 * Hence, establishing the cause(s) of any interrupt is partly guesswork.
1143 * In "The DP8490 and DP5380 Comparison Guide", National Semiconductor
1144 * claimed that "the design of the [DP8490] interrupt logic ensures
1145 * interrupts will not be lost (they can be on the DP5380)."
1146 * The L5380/53C80 datasheet from LOGIC Devices has more details.
1147 *
1148 * Checking for bus reset by reading RST is futile because of interrupt
1149 * latency, but a bus reset will reset chip logic. Checking for parity error
1150 * is unnecessary because that interrupt is never enabled. A Loss of BSY
1151 * condition will clear DMA Mode. We can tell when this occurs because the
1152 * the Busy Monitor interrupt is enabled together with DMA Mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 */
1154
Roman Zippelc28bda22007-05-01 22:32:36 +02001155static irqreturn_t NCR5380_intr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156{
Finn Thaina53a21e2014-11-12 16:12:21 +11001157 struct Scsi_Host *instance = dev_id;
Finn Thain010e89d2016-01-03 16:05:38 +11001158 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Finn Thaincd400822016-01-03 16:05:40 +11001159 int handled = 0;
Roman Zippelc28bda22007-05-01 22:32:36 +02001160 unsigned char basr;
Finn Thain11d2f632016-01-03 16:05:51 +11001161 unsigned long flags;
1162
1163 spin_lock_irqsave(&hostdata->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Roman Zippelc28bda22007-05-01 22:32:36 +02001165 basr = NCR5380_read(BUS_AND_STATUS_REG);
Roman Zippelc28bda22007-05-01 22:32:36 +02001166 if (basr & BASR_IRQ) {
Finn Thaincd400822016-01-03 16:05:40 +11001167 unsigned char mr = NCR5380_read(MODE_REG);
1168 unsigned char sr = NCR5380_read(STATUS_REG);
1169
Finn Thainb7465452016-01-03 16:06:05 +11001170 dsprintk(NDEBUG_INTR, instance, "IRQ %d, BASR 0x%02x, SR 0x%02x, MR 0x%02x\n",
1171 irq, basr, sr, mr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173#if defined(REAL_DMA)
Finn Thaincd400822016-01-03 16:05:40 +11001174 if ((mr & MR_DMA_MODE) || (mr & MR_MONITOR_BSY)) {
1175 /* Probably End of DMA, Phase Mismatch or Loss of BSY.
1176 * We ack IRQ after clearing Mode Register. Workarounds
1177 * for End of DMA errata need to happen in DMA Mode.
Roman Zippelc28bda22007-05-01 22:32:36 +02001178 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Finn Thainb7465452016-01-03 16:06:05 +11001180 dsprintk(NDEBUG_INTR, instance, "interrupt in DMA mode\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02001181
Finn Thaincd400822016-01-03 16:05:40 +11001182 if (hostdata->connected) {
1183 NCR5380_dma_complete(instance);
1184 queue_work(hostdata->work_q, &hostdata->main_task);
1185 } else {
1186 NCR5380_write(MODE_REG, MR_BASE);
1187 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
Roman Zippelc28bda22007-05-01 22:32:36 +02001188 }
Finn Thaincd400822016-01-03 16:05:40 +11001189 } else
1190#endif /* REAL_DMA */
1191 if ((NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_mask) &&
1192 (sr & (SR_SEL | SR_IO | SR_BSY | SR_RST)) == (SR_SEL | SR_IO)) {
1193 /* Probably reselected */
1194 NCR5380_write(SELECT_ENABLE_REG, 0);
1195 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1196
Finn Thainb7465452016-01-03 16:06:05 +11001197 dsprintk(NDEBUG_INTR, instance, "interrupt with SEL and IO\n");
Finn Thaincd400822016-01-03 16:05:40 +11001198
1199 if (!hostdata->connected) {
1200 NCR5380_reselect(instance);
1201 queue_work(hostdata->work_q, &hostdata->main_task);
1202 }
1203 if (!hostdata->connected)
1204 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1205 } else {
1206 /* Probably Bus Reset */
1207 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1208
Finn Thainb7465452016-01-03 16:06:05 +11001209 dsprintk(NDEBUG_INTR, instance, "unknown interrupt\n");
Finn Thaincd400822016-01-03 16:05:40 +11001210#ifdef SUN3_SCSI_VME
1211 dregs->csr |= CSR_DMA_ENABLE;
1212#endif
1213 }
Roman Zippelc28bda22007-05-01 22:32:36 +02001214 handled = 1;
Finn Thaincd400822016-01-03 16:05:40 +11001215 } else {
1216 shost_printk(KERN_NOTICE, instance, "interrupt without IRQ bit\n");
Finn Thaine3f463b2014-11-12 16:12:16 +11001217#ifdef SUN3_SCSI_VME
1218 dregs->csr |= CSR_DMA_ENABLE;
1219#endif
Roman Zippelc28bda22007-05-01 22:32:36 +02001220 }
1221
Finn Thain11d2f632016-01-03 16:05:51 +11001222 spin_unlock_irqrestore(&hostdata->lock, flags);
1223
Roman Zippelc28bda22007-05-01 22:32:36 +02001224 return IRQ_RETVAL(handled);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225}
1226
Roman Zippelc28bda22007-05-01 22:32:36 +02001227/*
Finn Thain710ddd02014-11-12 16:12:02 +11001228 * Function : int NCR5380_select(struct Scsi_Host *instance,
1229 * struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 *
1231 * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command,
Roman Zippelc28bda22007-05-01 22:32:36 +02001232 * including ARBITRATION, SELECTION, and initial message out for
1233 * IDENTIFY and queue messages.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001235 * Inputs : instance - instantiation of the 5380 driver on which this
Finn Thain76f13b92014-11-12 16:11:53 +11001236 * target lives, cmd - SCSI command to execute.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 *
Finn Thain707d62b2016-01-03 16:06:02 +11001238 * Returns cmd if selection failed but should be retried,
1239 * NULL if selection failed and should not be retried, or
1240 * NULL if selection succeeded (hostdata->connected == cmd).
Roman Zippelc28bda22007-05-01 22:32:36 +02001241 *
1242 * Side effects :
1243 * If bus busy, arbitration failed, etc, NCR5380_select() will exit
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 * with registers as they should have been on entry - ie
1245 * SELECT_ENABLE will be set appropriately, the NCR5380
1246 * will cease to drive any SCSI bus signals.
1247 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001248 * If successful : I_T_L or I_T_L_Q nexus will be established,
1249 * instance->connected will be set to cmd.
1250 * SELECT interrupt will be disabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001252 * If failed (no target) : cmd->scsi_done() will be called, and the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 * cmd->result host byte set to DID_BAD_TARGET.
1254 */
1255
Finn Thain707d62b2016-01-03 16:06:02 +11001256static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance,
1257 struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Finn Thaine8a60142016-01-03 16:05:54 +11001259 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02001260 unsigned char tmp[3], phase;
1261 unsigned char *data;
1262 int len;
Finn Thainae753a32016-01-03 16:05:23 +11001263 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Finn Thain8ad3a592014-03-18 11:42:19 +11001265 NCR5380_dprint(NDEBUG_ARBITRATION, instance);
Finn Thainb7465452016-01-03 16:06:05 +11001266 dsprintk(NDEBUG_ARBITRATION, instance, "starting arbitration, id = %d\n",
1267 instance->this_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Roman Zippelc28bda22007-05-01 22:32:36 +02001269 /*
Finn Thain707d62b2016-01-03 16:06:02 +11001270 * Arbitration and selection phases are slow and involve dropping the
1271 * lock, so we have to watch out for EH. An exception handler may
1272 * change 'selecting' to NULL. This function will then return NULL
1273 * so that the caller will forget about 'cmd'. (During information
1274 * transfer phases, EH may change 'connected' to NULL.)
1275 */
1276 hostdata->selecting = cmd;
1277
1278 /*
Roman Zippelc28bda22007-05-01 22:32:36 +02001279 * Set the phase bits to 0, otherwise the NCR5380 won't drive the
1280 * data bus during SELECTION.
1281 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
Roman Zippelc28bda22007-05-01 22:32:36 +02001283 NCR5380_write(TARGET_COMMAND_REG, 0);
1284
1285 /*
1286 * Start arbitration.
1287 */
1288
1289 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
1290 NCR5380_write(MODE_REG, MR_ARBITRATE);
1291
Finn Thain55500d92016-01-03 16:05:35 +11001292 /* The chip now waits for BUS FREE phase. Then after the 800 ns
1293 * Bus Free Delay, arbitration will begin.
Roman Zippelc28bda22007-05-01 22:32:36 +02001294 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Finn Thain11d2f632016-01-03 16:05:51 +11001296 spin_unlock_irq(&hostdata->lock);
Finn Thainb32ade12016-01-03 16:05:41 +11001297 err = NCR5380_poll_politely2(instance, MODE_REG, MR_ARBITRATE, 0,
1298 INITIATOR_COMMAND_REG, ICR_ARBITRATION_PROGRESS,
1299 ICR_ARBITRATION_PROGRESS, HZ);
Finn Thain11d2f632016-01-03 16:05:51 +11001300 spin_lock_irq(&hostdata->lock);
Finn Thainb32ade12016-01-03 16:05:41 +11001301 if (!(NCR5380_read(MODE_REG) & MR_ARBITRATE)) {
1302 /* Reselection interrupt */
Finn Thain707d62b2016-01-03 16:06:02 +11001303 goto out;
Finn Thainb32ade12016-01-03 16:05:41 +11001304 }
1305 if (err < 0) {
1306 NCR5380_write(MODE_REG, MR_BASE);
1307 shost_printk(KERN_ERR, instance,
1308 "select: arbitration timeout\n");
Finn Thain707d62b2016-01-03 16:06:02 +11001309 goto out;
Finn Thain55500d92016-01-03 16:05:35 +11001310 }
Finn Thain11d2f632016-01-03 16:05:51 +11001311 spin_unlock_irq(&hostdata->lock);
Finn Thain55500d92016-01-03 16:05:35 +11001312
1313 /* The SCSI-2 arbitration delay is 2.4 us */
Roman Zippelc28bda22007-05-01 22:32:36 +02001314 udelay(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Roman Zippelc28bda22007-05-01 22:32:36 +02001316 /* Check for lost arbitration */
1317 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1318 (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) ||
Finn Thain11d2f632016-01-03 16:05:51 +11001319 (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST)) {
Roman Zippelc28bda22007-05-01 22:32:36 +02001320 NCR5380_write(MODE_REG, MR_BASE);
Finn Thainb7465452016-01-03 16:06:05 +11001321 dsprintk(NDEBUG_ARBITRATION, instance, "lost arbitration, deasserting MR_ARBITRATE\n");
Finn Thain11d2f632016-01-03 16:05:51 +11001322 spin_lock_irq(&hostdata->lock);
Finn Thain707d62b2016-01-03 16:06:02 +11001323 goto out;
Roman Zippelc28bda22007-05-01 22:32:36 +02001324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Finn Thaincf13b082016-01-03 16:05:18 +11001326 /* After/during arbitration, BSY should be asserted.
1327 * IBM DPES-31080 Version S31Q works now
1328 * Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman)
1329 */
Roman Zippelc28bda22007-05-01 22:32:36 +02001330 NCR5380_write(INITIATOR_COMMAND_REG,
1331 ICR_BASE | ICR_ASSERT_SEL | ICR_ASSERT_BSY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Roman Zippelc28bda22007-05-01 22:32:36 +02001333 /*
1334 * Again, bus clear + bus settle time is 1.2us, however, this is
1335 * a minimum so we'll udelay ceil(1.2)
1336 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Finn Thain9c3f0e22016-01-03 16:05:11 +11001338 if (hostdata->flags & FLAG_TOSHIBA_DELAY)
1339 udelay(15);
1340 else
1341 udelay(2);
Roman Zippelc28bda22007-05-01 22:32:36 +02001342
Finn Thain11d2f632016-01-03 16:05:51 +11001343 spin_lock_irq(&hostdata->lock);
1344
Finn Thain72064a72016-01-03 16:05:44 +11001345 /* NCR5380_reselect() clears MODE_REG after a reselection interrupt */
1346 if (!(NCR5380_read(MODE_REG) & MR_ARBITRATE))
Finn Thain707d62b2016-01-03 16:06:02 +11001347 goto out;
1348
1349 if (!hostdata->selecting) {
1350 NCR5380_write(MODE_REG, MR_BASE);
1351 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1352 goto out;
1353 }
Roman Zippelc28bda22007-05-01 22:32:36 +02001354
Finn Thainb7465452016-01-03 16:06:05 +11001355 dsprintk(NDEBUG_ARBITRATION, instance, "won arbitration\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02001356
1357 /*
1358 * Now that we have won arbitration, start Selection process, asserting
1359 * the host and target ID's on the SCSI bus.
1360 */
1361
1362 NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->device->id)));
1363
1364 /*
1365 * Raise ATN while SEL is true before BSY goes false from arbitration,
1366 * since this is the only way to guarantee that we'll get a MESSAGE OUT
1367 * phase immediately after selection.
1368 */
1369
1370 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_BSY |
1371 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 NCR5380_write(MODE_REG, MR_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Roman Zippelc28bda22007-05-01 22:32:36 +02001374 /*
1375 * Reselect interrupts must be turned off prior to the dropping of BSY,
1376 * otherwise we will trigger an interrupt.
1377 */
Roman Zippelc28bda22007-05-01 22:32:36 +02001378 NCR5380_write(SELECT_ENABLE_REG, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Finn Thain11d2f632016-01-03 16:05:51 +11001380 spin_unlock_irq(&hostdata->lock);
1381
Roman Zippelc28bda22007-05-01 22:32:36 +02001382 /*
1383 * The initiator shall then wait at least two deskew delays and release
1384 * the BSY signal.
1385 */
1386 udelay(1); /* wingel -- wait two bus deskew delay >2*45ns */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Roman Zippelc28bda22007-05-01 22:32:36 +02001388 /* Reset BSY */
1389 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_DATA |
1390 ICR_ASSERT_ATN | ICR_ASSERT_SEL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Roman Zippelc28bda22007-05-01 22:32:36 +02001392 /*
1393 * Something weird happens when we cease to drive BSY - looks
1394 * like the board/chip is letting us do another read before the
1395 * appropriate propagation delay has expired, and we're confusing
1396 * a BSY signal from ourselves as the target's response to SELECTION.
1397 *
1398 * A small delay (the 'C++' frontend breaks the pipeline with an
1399 * unnecessary jump, making it work on my 386-33/Trantor T128, the
1400 * tighter 'C' code breaks and requires this) solves the problem -
1401 * the 1 us delay is arbitrary, and only used because this delay will
1402 * be the same on other platforms and since it works here, it should
1403 * work there.
1404 *
1405 * wingel suggests that this could be due to failing to wait
1406 * one deskew delay.
1407 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Roman Zippelc28bda22007-05-01 22:32:36 +02001409 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Finn Thainb7465452016-01-03 16:06:05 +11001411 dsprintk(NDEBUG_SELECTION, instance, "selecting target %d\n", scmd_id(cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
Roman Zippelc28bda22007-05-01 22:32:36 +02001413 /*
1414 * The SCSI specification calls for a 250 ms timeout for the actual
1415 * selection.
1416 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Finn Thainae753a32016-01-03 16:05:23 +11001418 err = NCR5380_poll_politely(instance, STATUS_REG, SR_BSY, SR_BSY,
1419 msecs_to_jiffies(250));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Roman Zippelc28bda22007-05-01 22:32:36 +02001421 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) {
Finn Thain11d2f632016-01-03 16:05:51 +11001422 spin_lock_irq(&hostdata->lock);
Roman Zippelc28bda22007-05-01 22:32:36 +02001423 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1424 NCR5380_reselect(instance);
Finn Thaincd400822016-01-03 16:05:40 +11001425 if (!hostdata->connected)
1426 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
Finn Thain6a6ff4a2016-01-03 16:06:04 +11001427 shost_printk(KERN_ERR, instance, "reselection after won arbitration?\n");
Finn Thain707d62b2016-01-03 16:06:02 +11001428 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
Roman Zippelc28bda22007-05-01 22:32:36 +02001430
Finn Thainae753a32016-01-03 16:05:23 +11001431 if (err < 0) {
Finn Thain11d2f632016-01-03 16:05:51 +11001432 spin_lock_irq(&hostdata->lock);
Roman Zippelc28bda22007-05-01 22:32:36 +02001433 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
Roman Zippelc28bda22007-05-01 22:32:36 +02001434 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
Finn Thain707d62b2016-01-03 16:06:02 +11001435 /* Can't touch cmd if it has been reclaimed by the scsi ML */
1436 if (hostdata->selecting) {
1437 cmd->result = DID_BAD_TARGET << 16;
1438 complete_cmd(instance, cmd);
1439 dsprintk(NDEBUG_SELECTION, instance, "target did not respond within 250ms\n");
1440 cmd = NULL;
1441 }
1442 goto out;
Roman Zippelc28bda22007-05-01 22:32:36 +02001443 }
1444
Roman Zippelc28bda22007-05-01 22:32:36 +02001445 /*
Finn Thainae753a32016-01-03 16:05:23 +11001446 * No less than two deskew delays after the initiator detects the
1447 * BSY signal is true, it shall release the SEL signal and may
1448 * change the DATA BUS. -wingel
1449 */
1450
1451 udelay(1);
1452
1453 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1454
1455 /*
Roman Zippelc28bda22007-05-01 22:32:36 +02001456 * Since we followed the SCSI spec, and raised ATN while SEL
1457 * was true but before BSY was false during selection, the information
1458 * transfer phase should be a MESSAGE OUT phase so that we can send the
1459 * IDENTIFY message.
1460 *
1461 * If SCSI-II tagged queuing is enabled, we also send a SIMPLE_QUEUE_TAG
1462 * message (2 bytes) with a tag ID that we increment with every command
1463 * until it wraps back to 0.
1464 *
1465 * XXX - it turns out that there are some broken SCSI-II devices,
1466 * which claim to support tagged queuing but fail when more than
1467 * some number of commands are issued at once.
1468 */
1469
1470 /* Wait for start of REQ/ACK handshake */
Finn Thain55500d92016-01-03 16:05:35 +11001471
1472 err = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ);
Finn Thain11d2f632016-01-03 16:05:51 +11001473 spin_lock_irq(&hostdata->lock);
Finn Thain55500d92016-01-03 16:05:35 +11001474 if (err < 0) {
1475 shost_printk(KERN_ERR, instance, "select: REQ timeout\n");
1476 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1477 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
Finn Thain707d62b2016-01-03 16:06:02 +11001478 goto out;
1479 }
1480 if (!hostdata->selecting) {
1481 do_abort(instance);
1482 goto out;
Finn Thain55500d92016-01-03 16:05:35 +11001483 }
Roman Zippelc28bda22007-05-01 22:32:36 +02001484
Finn Thainb7465452016-01-03 16:06:05 +11001485 dsprintk(NDEBUG_SELECTION, instance, "target %d selected, going into MESSAGE OUT phase.\n",
1486 scmd_id(cmd));
Roman Zippelc28bda22007-05-01 22:32:36 +02001487 tmp[0] = IDENTIFY(1, cmd->device->lun);
1488
1489#ifdef SUPPORT_TAGS
1490 if (cmd->tag != TAG_NONE) {
1491 tmp[1] = hostdata->last_message = SIMPLE_QUEUE_TAG;
1492 tmp[2] = cmd->tag;
1493 len = 3;
1494 } else
1495 len = 1;
1496#else
1497 len = 1;
1498 cmd->tag = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499#endif /* SUPPORT_TAGS */
1500
Roman Zippelc28bda22007-05-01 22:32:36 +02001501 /* Send message(s) */
1502 data = tmp;
1503 phase = PHASE_MSGOUT;
1504 NCR5380_transfer_pio(instance, &phase, &len, &data);
Finn Thainb7465452016-01-03 16:06:05 +11001505 dsprintk(NDEBUG_SELECTION, instance, "nexus established.\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02001506 /* XXX need to handle errors here */
Finn Thain11d2f632016-01-03 16:05:51 +11001507
Roman Zippelc28bda22007-05-01 22:32:36 +02001508 hostdata->connected = cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509#ifndef SUPPORT_TAGS
Roman Zippelc28bda22007-05-01 22:32:36 +02001510 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
1511#endif
Finn Thaine3f463b2014-11-12 16:12:16 +11001512#ifdef SUN3_SCSI_VME
1513 dregs->csr |= CSR_INTR;
1514#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Roman Zippelc28bda22007-05-01 22:32:36 +02001516 initialize_SCp(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Finn Thain707d62b2016-01-03 16:06:02 +11001518 cmd = NULL;
1519
1520out:
1521 if (!hostdata->selecting)
1522 return NULL;
1523 hostdata->selecting = NULL;
1524 return cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Roman Zippelc28bda22007-05-01 22:32:36 +02001527/*
1528 * Function : int NCR5380_transfer_pio (struct Scsi_Host *instance,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 * unsigned char *phase, int *count, unsigned char **data)
1530 *
1531 * Purpose : transfers data in given phase using polled I/O
1532 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001533 * Inputs : instance - instance of driver, *phase - pointer to
1534 * what phase is expected, *count - pointer to number of
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 * bytes to transfer, **data - pointer to data pointer.
Roman Zippelc28bda22007-05-01 22:32:36 +02001536 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 * Returns : -1 when different phase is entered without transferring
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001538 * maximum number of bytes, 0 if all bytes are transferred or exit
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 * is in same phase.
1540 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001541 * Also, *phase, *count, *data are modified in place.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 *
1543 * XXX Note : handling for bus free may be useful.
1544 */
1545
1546/*
Roman Zippelc28bda22007-05-01 22:32:36 +02001547 * Note : this code is not as quick as it could be, however it
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 * IS 100% reliable, and for the actual data transfer where speed
1549 * counts, we will always do a pseudo DMA or DMA transfer.
1550 */
1551
Roman Zippelc28bda22007-05-01 22:32:36 +02001552static int NCR5380_transfer_pio(struct Scsi_Host *instance,
1553 unsigned char *phase, int *count,
1554 unsigned char **data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Roman Zippelc28bda22007-05-01 22:32:36 +02001556 register unsigned char p = *phase, tmp;
1557 register int c = *count;
1558 register unsigned char *d = *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Roman Zippelc28bda22007-05-01 22:32:36 +02001560 /*
1561 * The NCR5380 chip will only drive the SCSI bus when the
1562 * phase specified in the appropriate bits of the TARGET COMMAND
1563 * REGISTER match the STATUS REGISTER
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 */
1565
Roman Zippelc28bda22007-05-01 22:32:36 +02001566 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Roman Zippelc28bda22007-05-01 22:32:36 +02001568 do {
1569 /*
1570 * Wait for assertion of REQ, after which the phase bits will be
1571 * valid
1572 */
Finn Thain686f3992016-01-03 16:05:26 +11001573
1574 if (NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ) < 0)
1575 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Finn Thainb7465452016-01-03 16:06:05 +11001577 dsprintk(NDEBUG_HANDSHAKE, instance, "REQ asserted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Roman Zippelc28bda22007-05-01 22:32:36 +02001579 /* Check for phase mismatch */
Finn Thain686f3992016-01-03 16:05:26 +11001580 if ((NCR5380_read(STATUS_REG) & PHASE_MASK) != p) {
Finn Thainb7465452016-01-03 16:06:05 +11001581 dsprintk(NDEBUG_PIO, instance, "phase mismatch\n");
Finn Thain8ad3a592014-03-18 11:42:19 +11001582 NCR5380_dprint_phase(NDEBUG_PIO, instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02001583 break;
1584 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Roman Zippelc28bda22007-05-01 22:32:36 +02001586 /* Do actual transfer from SCSI bus to / from memory */
1587 if (!(p & SR_IO))
1588 NCR5380_write(OUTPUT_DATA_REG, *d);
1589 else
1590 *d = NCR5380_read(CURRENT_SCSI_DATA_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
Roman Zippelc28bda22007-05-01 22:32:36 +02001592 ++d;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
Roman Zippelc28bda22007-05-01 22:32:36 +02001594 /*
1595 * The SCSI standard suggests that in MSGOUT phase, the initiator
1596 * should drop ATN on the last byte of the message phase
1597 * after REQ has been asserted for the handshake but before
1598 * the initiator raises ACK.
1599 */
1600
1601 if (!(p & SR_IO)) {
1602 if (!((p & SR_MSG) && c > 1)) {
1603 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA);
Finn Thain8ad3a592014-03-18 11:42:19 +11001604 NCR5380_dprint(NDEBUG_PIO, instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02001605 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1606 ICR_ASSERT_DATA | ICR_ASSERT_ACK);
1607 } else {
1608 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1609 ICR_ASSERT_DATA | ICR_ASSERT_ATN);
Finn Thain8ad3a592014-03-18 11:42:19 +11001610 NCR5380_dprint(NDEBUG_PIO, instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02001611 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1612 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_ACK);
1613 }
1614 } else {
Finn Thain8ad3a592014-03-18 11:42:19 +11001615 NCR5380_dprint(NDEBUG_PIO, instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02001616 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
1617 }
1618
Finn Thaina2edc4a2016-01-03 16:05:27 +11001619 if (NCR5380_poll_politely(instance,
1620 STATUS_REG, SR_REQ, 0, 5 * HZ) < 0)
1621 break;
Roman Zippelc28bda22007-05-01 22:32:36 +02001622
Finn Thainb7465452016-01-03 16:06:05 +11001623 dsprintk(NDEBUG_HANDSHAKE, instance, "REQ negated, handshake complete\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02001624
1625 /*
1626 * We have several special cases to consider during REQ/ACK handshaking :
1627 * 1. We were in MSGOUT phase, and we are on the last byte of the
1628 * message. ATN must be dropped as ACK is dropped.
1629 *
1630 * 2. We are in a MSGIN phase, and we are on the last byte of the
1631 * message. We must exit with ACK asserted, so that the calling
1632 * code may raise ATN before dropping ACK to reject the message.
1633 *
1634 * 3. ACK and ATN are clear and the target may proceed as normal.
1635 */
1636 if (!(p == PHASE_MSGIN && c == 1)) {
1637 if (p == PHASE_MSGOUT && c > 1)
1638 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1639 else
1640 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1641 }
1642 } while (--c);
1643
Finn Thainb7465452016-01-03 16:06:05 +11001644 dsprintk(NDEBUG_PIO, instance, "residual %d\n", c);
Roman Zippelc28bda22007-05-01 22:32:36 +02001645
1646 *count = c;
1647 *data = d;
1648 tmp = NCR5380_read(STATUS_REG);
1649 /* The phase read from the bus is valid if either REQ is (already)
Finn Thaina2edc4a2016-01-03 16:05:27 +11001650 * asserted or if ACK hasn't been released yet. The latter applies if
1651 * we're in MSG IN, DATA IN or STATUS and all bytes have been received.
Roman Zippelc28bda22007-05-01 22:32:36 +02001652 */
Finn Thaina2edc4a2016-01-03 16:05:27 +11001653 if ((tmp & SR_REQ) || ((tmp & SR_IO) && c == 0))
Roman Zippelc28bda22007-05-01 22:32:36 +02001654 *phase = tmp & PHASE_MASK;
1655 else
1656 *phase = PHASE_UNKNOWN;
1657
1658 if (!c || (*phase == p))
1659 return 0;
1660 else
1661 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662}
1663
Finn Thain636b1ec2016-01-03 16:05:10 +11001664/**
1665 * do_reset - issue a reset command
1666 * @instance: adapter to reset
1667 *
1668 * Issue a reset sequence to the NCR5380 and try and get the bus
1669 * back into sane shape.
1670 *
1671 * This clears the reset interrupt flag because there may be no handler for
1672 * it. When the driver is initialized, the NCR5380_intr() handler has not yet
1673 * been installed. And when in EH we may have released the ST DMA interrupt.
1674 */
1675
1676static void do_reset(struct Scsi_Host *instance)
1677{
1678 unsigned long flags;
1679
1680 local_irq_save(flags);
1681 NCR5380_write(TARGET_COMMAND_REG,
1682 PHASE_SR_TO_TCR(NCR5380_read(STATUS_REG) & PHASE_MASK));
1683 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST);
1684 udelay(50);
1685 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1686 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1687 local_irq_restore(flags);
1688}
1689
Finn Thain80d3eb62016-01-03 16:05:34 +11001690/**
1691 * do_abort - abort the currently established nexus by going to
1692 * MESSAGE OUT phase and sending an ABORT message.
1693 * @instance: relevant scsi host instance
Roman Zippelc28bda22007-05-01 22:32:36 +02001694 *
Finn Thain80d3eb62016-01-03 16:05:34 +11001695 * Returns 0 on success, -1 on failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 */
1697
Finn Thaina53a21e2014-11-12 16:12:21 +11001698static int do_abort(struct Scsi_Host *instance)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699{
Roman Zippelc28bda22007-05-01 22:32:36 +02001700 unsigned char tmp, *msgptr, phase;
1701 int len;
Finn Thain80d3eb62016-01-03 16:05:34 +11001702 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Roman Zippelc28bda22007-05-01 22:32:36 +02001704 /* Request message out phase */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Roman Zippelc28bda22007-05-01 22:32:36 +02001707 /*
1708 * Wait for the target to indicate a valid phase by asserting
1709 * REQ. Once this happens, we'll have either a MSGOUT phase
1710 * and can immediately send the ABORT message, or we'll have some
1711 * other phase and will have to source/sink data.
1712 *
1713 * We really don't care what value was on the bus or what value
1714 * the target sees, so we just handshake.
1715 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Finn Thain80d3eb62016-01-03 16:05:34 +11001717 rc = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, 10 * HZ);
1718 if (rc < 0)
1719 goto timeout;
1720
1721 tmp = NCR5380_read(STATUS_REG) & PHASE_MASK;
Roman Zippelc28bda22007-05-01 22:32:36 +02001722
1723 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1724
Finn Thain80d3eb62016-01-03 16:05:34 +11001725 if (tmp != PHASE_MSGOUT) {
1726 NCR5380_write(INITIATOR_COMMAND_REG,
1727 ICR_BASE | ICR_ASSERT_ATN | ICR_ASSERT_ACK);
1728 rc = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, 0, 3 * HZ);
1729 if (rc < 0)
1730 goto timeout;
Roman Zippelc28bda22007-05-01 22:32:36 +02001731 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1732 }
1733
1734 tmp = ABORT;
1735 msgptr = &tmp;
1736 len = 1;
1737 phase = PHASE_MSGOUT;
Finn Thaina53a21e2014-11-12 16:12:21 +11001738 NCR5380_transfer_pio(instance, &phase, &len, &msgptr);
Roman Zippelc28bda22007-05-01 22:32:36 +02001739
1740 /*
1741 * If we got here, and the command completed successfully,
1742 * we're about to go into bus free state.
1743 */
1744
1745 return len ? -1 : 0;
Finn Thain80d3eb62016-01-03 16:05:34 +11001746
1747timeout:
1748 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1749 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750}
1751
1752#if defined(REAL_DMA)
Roman Zippelc28bda22007-05-01 22:32:36 +02001753/*
1754 * Function : int NCR5380_transfer_dma (struct Scsi_Host *instance,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 * unsigned char *phase, int *count, unsigned char **data)
1756 *
1757 * Purpose : transfers data in given phase using either real
1758 * or pseudo DMA.
1759 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001760 * Inputs : instance - instance of driver, *phase - pointer to
1761 * what phase is expected, *count - pointer to number of
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 * bytes to transfer, **data - pointer to data pointer.
Roman Zippelc28bda22007-05-01 22:32:36 +02001763 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 * Returns : -1 when different phase is entered without transferring
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001765 * maximum number of bytes, 0 if all bytes or transferred or exit
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 * is in same phase.
1767 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001768 * Also, *phase, *count, *data are modified in place.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 *
1770 */
1771
1772
Roman Zippelc28bda22007-05-01 22:32:36 +02001773static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1774 unsigned char *phase, int *count,
1775 unsigned char **data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776{
Finn Thaine8a60142016-01-03 16:05:54 +11001777 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02001778 register int c = *count;
1779 register unsigned char p = *phase;
Finn Thaine3f463b2014-11-12 16:12:16 +11001780
1781#if defined(CONFIG_SUN3)
1782 /* sanity check */
1783 if (!sun3_dma_setup_done) {
1784 pr_err("scsi%d: transfer_dma without setup!\n",
1785 instance->host_no);
1786 BUG();
1787 }
1788 hostdata->dma_len = c;
1789
Finn Thainb7465452016-01-03 16:06:05 +11001790 dsprintk(NDEBUG_DMA, instance, "initializing DMA %s: length %d, address %p\n",
1791 (p & SR_IO) ? "receive" : "send", c, *data);
Finn Thaine3f463b2014-11-12 16:12:16 +11001792
1793 /* netbsd turns off ints here, why not be safe and do it too */
Finn Thaine3f463b2014-11-12 16:12:16 +11001794
1795 /* send start chain */
1796 sun3scsi_dma_start(c, *data);
1797
Finn Thaincd400822016-01-03 16:05:40 +11001798 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1799 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_MONITOR_BSY |
1800 MR_ENABLE_EOP_INTR);
Finn Thaine3f463b2014-11-12 16:12:16 +11001801 if (p & SR_IO) {
Finn Thaine3f463b2014-11-12 16:12:16 +11001802 NCR5380_write(INITIATOR_COMMAND_REG, 0);
Finn Thaine3f463b2014-11-12 16:12:16 +11001803 NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0);
1804 } else {
Finn Thaine3f463b2014-11-12 16:12:16 +11001805 NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_DATA);
Finn Thaine3f463b2014-11-12 16:12:16 +11001806 NCR5380_write(START_DMA_SEND_REG, 0);
1807 }
1808
1809#ifdef SUN3_SCSI_VME
1810 dregs->csr |= CSR_DMA_ENABLE;
1811#endif
1812
Finn Thaine3f463b2014-11-12 16:12:16 +11001813 sun3_dma_active = 1;
1814
1815#else /* !defined(CONFIG_SUN3) */
Roman Zippelc28bda22007-05-01 22:32:36 +02001816 register unsigned char *d = *data;
1817 unsigned char tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Roman Zippelc28bda22007-05-01 22:32:36 +02001819 if ((tmp = (NCR5380_read(STATUS_REG) & PHASE_MASK)) != p) {
1820 *phase = tmp;
1821 return -1;
1822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
Finn Thainef1081c2014-11-12 16:12:14 +11001824 if (hostdata->read_overruns && (p & SR_IO))
1825 c -= hostdata->read_overruns;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
Finn Thainb7465452016-01-03 16:06:05 +11001827 dsprintk(NDEBUG_DMA, instance, "initializing DMA %s: length %d, address %p\n",
1828 (p & SR_IO) ? "receive" : "send", c, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
Roman Zippelc28bda22007-05-01 22:32:36 +02001830 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
Finn Thaincd400822016-01-03 16:05:40 +11001831 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_MONITOR_BSY |
1832 MR_ENABLE_EOP_INTR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
Finn Thainef1081c2014-11-12 16:12:14 +11001834 if (!(hostdata->flags & FLAG_LATE_DMA_SETUP)) {
Roman Zippelc28bda22007-05-01 22:32:36 +02001835 /* On the Medusa, it is a must to initialize the DMA before
1836 * starting the NCR. This is also the cleaner way for the TT.
1837 */
Roman Zippelc28bda22007-05-01 22:32:36 +02001838 hostdata->dma_len = (p & SR_IO) ?
1839 NCR5380_dma_read_setup(instance, d, c) :
1840 NCR5380_dma_write_setup(instance, d, c);
Roman Zippelc28bda22007-05-01 22:32:36 +02001841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Roman Zippelc28bda22007-05-01 22:32:36 +02001843 if (p & SR_IO)
1844 NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0);
1845 else {
1846 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA);
1847 NCR5380_write(START_DMA_SEND_REG, 0);
1848 }
1849
Finn Thainef1081c2014-11-12 16:12:14 +11001850 if (hostdata->flags & FLAG_LATE_DMA_SETUP) {
Roman Zippelc28bda22007-05-01 22:32:36 +02001851 /* On the Falcon, the DMA setup must be done after the last */
1852 /* NCR access, else the DMA setup gets trashed!
1853 */
Roman Zippelc28bda22007-05-01 22:32:36 +02001854 hostdata->dma_len = (p & SR_IO) ?
1855 NCR5380_dma_read_setup(instance, d, c) :
1856 NCR5380_dma_write_setup(instance, d, c);
Roman Zippelc28bda22007-05-01 22:32:36 +02001857 }
Finn Thaine3f463b2014-11-12 16:12:16 +11001858#endif /* !defined(CONFIG_SUN3) */
1859
Roman Zippelc28bda22007-05-01 22:32:36 +02001860 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861}
1862#endif /* defined(REAL_DMA) */
1863
1864/*
1865 * Function : NCR5380_information_transfer (struct Scsi_Host *instance)
1866 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001867 * Purpose : run through the various SCSI phases and do as the target
1868 * directs us to. Operates on the currently connected command,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 * instance->connected.
1870 *
1871 * Inputs : instance, instance for which we are doing commands
1872 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001873 * Side effects : SCSI things happen, the disconnected queue will be
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 * modified if a command disconnects, *instance->connected will
1875 * change.
1876 *
Roman Zippelc28bda22007-05-01 22:32:36 +02001877 * XXX Note : we need to watch for bus free or a reset condition here
1878 * to recover from an unexpected bus free condition.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 */
Roman Zippelc28bda22007-05-01 22:32:36 +02001880
1881static void NCR5380_information_transfer(struct Scsi_Host *instance)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882{
Finn Thaine8a60142016-01-03 16:05:54 +11001883 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02001884 unsigned char msgout = NOP;
1885 int sink = 0;
1886 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887#if defined(REAL_DMA)
Roman Zippelc28bda22007-05-01 22:32:36 +02001888 int transfersize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889#endif
Roman Zippelc28bda22007-05-01 22:32:36 +02001890 unsigned char *data;
1891 unsigned char phase, tmp, extended_msg[10], old_phase = 0xff;
Finn Thain11d2f632016-01-03 16:05:51 +11001892 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Finn Thaine3f463b2014-11-12 16:12:16 +11001894#ifdef SUN3_SCSI_VME
1895 dregs->csr |= CSR_INTR;
1896#endif
1897
Finn Thain11d2f632016-01-03 16:05:51 +11001898 while ((cmd = hostdata->connected)) {
Finn Thain32b26a12016-01-03 16:05:58 +11001899 struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
1900
Roman Zippelc28bda22007-05-01 22:32:36 +02001901 tmp = NCR5380_read(STATUS_REG);
1902 /* We only have a valid SCSI phase when REQ is asserted */
1903 if (tmp & SR_REQ) {
1904 phase = (tmp & PHASE_MASK);
1905 if (phase != old_phase) {
1906 old_phase = phase;
Finn Thain8ad3a592014-03-18 11:42:19 +11001907 NCR5380_dprint_phase(NDEBUG_INFORMATION, instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 }
Finn Thaine3f463b2014-11-12 16:12:16 +11001909#if defined(CONFIG_SUN3)
1910 if (phase == PHASE_CMDOUT) {
1911#if defined(REAL_DMA)
1912 void *d;
1913 unsigned long count;
1914
1915 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1916 count = cmd->SCp.buffer->length;
1917 d = sg_virt(cmd->SCp.buffer);
1918 } else {
1919 count = cmd->SCp.this_residual;
1920 d = cmd->SCp.ptr;
1921 }
1922 /* this command setup for dma yet? */
1923 if ((count >= DMA_MIN_SIZE) && (sun3_dma_setup_done != cmd)) {
1924 if (cmd->request->cmd_type == REQ_TYPE_FS) {
Finn Thaincd461402016-01-03 16:06:06 +11001925 sun3scsi_dma_setup(instance, d, count,
Finn Thaine3f463b2014-11-12 16:12:16 +11001926 rq_data_dir(cmd->request));
1927 sun3_dma_setup_done = cmd;
1928 }
1929 }
1930#endif
1931#ifdef SUN3_SCSI_VME
1932 dregs->csr |= CSR_INTR;
1933#endif
1934 }
1935#endif /* CONFIG_SUN3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Roman Zippelc28bda22007-05-01 22:32:36 +02001937 if (sink && (phase != PHASE_MSGOUT)) {
1938 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
Roman Zippelc28bda22007-05-01 22:32:36 +02001940 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1941 ICR_ASSERT_ACK);
1942 while (NCR5380_read(STATUS_REG) & SR_REQ)
1943 ;
1944 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1945 ICR_ASSERT_ATN);
1946 sink = 0;
1947 continue;
1948 }
1949
1950 switch (phase) {
1951 case PHASE_DATAOUT:
1952#if (NDEBUG & NDEBUG_NO_DATAOUT)
Finn Thain6a6ff4a2016-01-03 16:06:04 +11001953 shost_printk(KERN_DEBUG, instance, "NDEBUG_NO_DATAOUT set, attempted DATAOUT aborted\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02001954 sink = 1;
1955 do_abort(instance);
1956 cmd->result = DID_ERROR << 16;
Finn Thain677e0192016-01-03 16:05:59 +11001957 complete_cmd(instance, cmd);
Roman Zippelc28bda22007-05-01 22:32:36 +02001958 return;
1959#endif
1960 case PHASE_DATAIN:
1961 /*
1962 * If there is no room left in the current buffer in the
1963 * scatter-gather list, move onto the next one.
1964 */
1965
1966 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1967 ++cmd->SCp.buffer;
1968 --cmd->SCp.buffers_residual;
1969 cmd->SCp.this_residual = cmd->SCp.buffer->length;
Jens Axboe45711f12007-10-22 21:19:53 +02001970 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
Roman Zippelc28bda22007-05-01 22:32:36 +02001971 /* ++roman: Try to merge some scatter-buffers if
1972 * they are at contiguous physical addresses.
1973 */
1974 merge_contiguous_buffers(cmd);
Finn Thainb7465452016-01-03 16:06:05 +11001975 dsprintk(NDEBUG_INFORMATION, instance, "%d bytes and %d buffers left\n",
1976 cmd->SCp.this_residual,
1977 cmd->SCp.buffers_residual);
Roman Zippelc28bda22007-05-01 22:32:36 +02001978 }
1979
1980 /*
1981 * The preferred transfer method is going to be
1982 * PSEUDO-DMA for systems that are strictly PIO,
1983 * since we can let the hardware do the handshaking.
1984 *
1985 * For this to work, we need to know the transfersize
1986 * ahead of time, since the pseudo-DMA code will sit
1987 * in an unconditional loop.
1988 */
1989
1990 /* ++roman: I suggest, this should be
1991 * #if def(REAL_DMA)
1992 * instead of leaving REAL_DMA out.
1993 */
1994
1995#if defined(REAL_DMA)
Finn Thaine3f463b2014-11-12 16:12:16 +11001996#if !defined(CONFIG_SUN3)
Finn Thainff3d4572016-01-03 16:05:25 +11001997 transfersize = 0;
1998 if (!cmd->device->borken)
Finn Thaine3f463b2014-11-12 16:12:16 +11001999#endif
Finn Thainff3d4572016-01-03 16:05:25 +11002000 transfersize = NCR5380_dma_xfer_len(instance, cmd, phase);
2001
2002 if (transfersize >= DMA_MIN_SIZE) {
Roman Zippelc28bda22007-05-01 22:32:36 +02002003 len = transfersize;
2004 cmd->SCp.phase = phase;
2005 if (NCR5380_transfer_dma(instance, &phase,
2006 &len, (unsigned char **)&cmd->SCp.ptr)) {
2007 /*
2008 * If the watchdog timer fires, all future
2009 * accesses to this device will use the
2010 * polled-IO. */
Finn Thainff50f9e2014-11-12 16:12:18 +11002011 scmd_printk(KERN_INFO, cmd,
2012 "switching to slow handshake\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02002013 cmd->device->borken = 1;
Roman Zippelc28bda22007-05-01 22:32:36 +02002014 sink = 1;
2015 do_abort(instance);
2016 cmd->result = DID_ERROR << 16;
Finn Thain677e0192016-01-03 16:05:59 +11002017 complete_cmd(instance, cmd);
Roman Zippelc28bda22007-05-01 22:32:36 +02002018 /* XXX - need to source or sink data here, as appropriate */
2019 } else {
2020#ifdef REAL_DMA
2021 /* ++roman: When using real DMA,
2022 * information_transfer() should return after
2023 * starting DMA since it has nothing more to
2024 * do.
2025 */
2026 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027#else
Roman Zippelc28bda22007-05-01 22:32:36 +02002028 cmd->SCp.this_residual -= transfersize - len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029#endif
Roman Zippelc28bda22007-05-01 22:32:36 +02002030 }
2031 } else
2032#endif /* defined(REAL_DMA) */
Finn Thain11d2f632016-01-03 16:05:51 +11002033 {
2034 spin_unlock_irq(&hostdata->lock);
Roman Zippelc28bda22007-05-01 22:32:36 +02002035 NCR5380_transfer_pio(instance, &phase,
2036 (int *)&cmd->SCp.this_residual,
2037 (unsigned char **)&cmd->SCp.ptr);
Finn Thain11d2f632016-01-03 16:05:51 +11002038 spin_lock_irq(&hostdata->lock);
2039 }
Finn Thaine3f463b2014-11-12 16:12:16 +11002040#if defined(CONFIG_SUN3) && defined(REAL_DMA)
2041 /* if we had intended to dma that command clear it */
2042 if (sun3_dma_setup_done == cmd)
2043 sun3_dma_setup_done = NULL;
2044#endif
Roman Zippelc28bda22007-05-01 22:32:36 +02002045 break;
2046 case PHASE_MSGIN:
2047 len = 1;
2048 data = &tmp;
Roman Zippelc28bda22007-05-01 22:32:36 +02002049 NCR5380_transfer_pio(instance, &phase, &len, &data);
2050 cmd->SCp.Message = tmp;
2051
2052 switch (tmp) {
Roman Zippelc28bda22007-05-01 22:32:36 +02002053 case ABORT:
2054 case COMMAND_COMPLETE:
2055 /* Accept message by clearing ACK */
2056 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
Finn Thain0d3d9a42016-01-03 16:05:55 +11002057 dsprintk(NDEBUG_QUEUES, instance,
2058 "COMMAND COMPLETE %p target %d lun %llu\n",
2059 cmd, scmd_id(cmd), cmd->device->lun);
Finn Thaine3c3da62014-11-12 16:12:15 +11002060
Finn Thaine3c3da62014-11-12 16:12:15 +11002061 hostdata->connected = NULL;
Roman Zippelc28bda22007-05-01 22:32:36 +02002062#ifdef SUPPORT_TAGS
2063 cmd_free_tag(cmd);
2064 if (status_byte(cmd->SCp.Status) == QUEUE_FULL) {
Finn Thainb7465452016-01-03 16:06:05 +11002065 u8 lun = cmd->device->lun;
2066 struct tag_alloc *ta = &hostdata->TagAlloc[scmd_id(cmd)][lun];
2067
2068 dsprintk(NDEBUG_TAGS, instance,
2069 "QUEUE_FULL %p target %d lun %d nr_allocated %d\n",
2070 cmd, scmd_id(cmd), lun, ta->nr_allocated);
Roman Zippelc28bda22007-05-01 22:32:36 +02002071 if (ta->queue_size > ta->nr_allocated)
Finn Thaine42d0152016-01-03 16:05:49 +11002072 ta->queue_size = ta->nr_allocated;
Roman Zippelc28bda22007-05-01 22:32:36 +02002073 }
Roman Zippelc28bda22007-05-01 22:32:36 +02002074#endif
Roman Zippelc28bda22007-05-01 22:32:36 +02002075
Finn Thainf27db8e2016-01-03 16:06:00 +11002076 cmd->result &= ~0xffff;
2077 cmd->result |= cmd->SCp.Status;
2078 cmd->result |= cmd->SCp.Message << 8;
Roman Zippelc28bda22007-05-01 22:32:36 +02002079
Finn Thainf27db8e2016-01-03 16:06:00 +11002080 if (cmd->cmnd[0] == REQUEST_SENSE)
Finn Thain677e0192016-01-03 16:05:59 +11002081 complete_cmd(instance, cmd);
Finn Thainf27db8e2016-01-03 16:06:00 +11002082 else {
2083 if (cmd->SCp.Status == SAM_STAT_CHECK_CONDITION ||
2084 cmd->SCp.Status == SAM_STAT_COMMAND_TERMINATED) {
2085 dsprintk(NDEBUG_QUEUES, instance, "autosense: adding cmd %p to tail of autosense queue\n",
2086 cmd);
2087 list_add_tail(&ncmd->list,
2088 &hostdata->autosense);
2089 } else
2090 complete_cmd(instance, cmd);
Roman Zippelc28bda22007-05-01 22:32:36 +02002091 }
2092
Roman Zippelc28bda22007-05-01 22:32:36 +02002093 /*
2094 * Restore phase bits to 0 so an interrupted selection,
2095 * arbitration can resume.
2096 */
2097 NCR5380_write(TARGET_COMMAND_REG, 0);
2098
Finn Thain72064a72016-01-03 16:05:44 +11002099 /* Enable reselect interrupts */
2100 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2101
Roman Zippelc28bda22007-05-01 22:32:36 +02002102 /* ++roman: For Falcon SCSI, release the lock on the
2103 * ST-DMA here if no other commands are waiting on the
2104 * disconnected queue.
2105 */
Finn Thaine3c3da62014-11-12 16:12:15 +11002106 maybe_release_dma_irq(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02002107 return;
2108 case MESSAGE_REJECT:
2109 /* Accept message by clearing ACK */
2110 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
Roman Zippelc28bda22007-05-01 22:32:36 +02002111 switch (hostdata->last_message) {
2112 case HEAD_OF_QUEUE_TAG:
2113 case ORDERED_QUEUE_TAG:
2114 case SIMPLE_QUEUE_TAG:
2115 /* The target obviously doesn't support tagged
2116 * queuing, even though it announced this ability in
2117 * its INQUIRY data ?!? (maybe only this LUN?) Ok,
2118 * clear 'tagged_supported' and lock the LUN, since
2119 * the command is treated as untagged further on.
2120 */
2121 cmd->device->tagged_supported = 0;
2122 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
2123 cmd->tag = TAG_NONE;
Finn Thainb7465452016-01-03 16:06:05 +11002124 dsprintk(NDEBUG_TAGS, instance, "target %d lun %llu rejected QUEUE_TAG message; tagged queuing disabled\n",
2125 scmd_id(cmd), cmd->device->lun);
Roman Zippelc28bda22007-05-01 22:32:36 +02002126 break;
2127 }
2128 break;
2129 case DISCONNECT:
2130 /* Accept message by clearing ACK */
2131 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
Roman Zippelc28bda22007-05-01 22:32:36 +02002132 hostdata->connected = NULL;
Finn Thain32b26a12016-01-03 16:05:58 +11002133 list_add(&ncmd->list, &hostdata->disconnected);
Finn Thain0d3d9a42016-01-03 16:05:55 +11002134 dsprintk(NDEBUG_INFORMATION | NDEBUG_QUEUES,
2135 instance, "connected command %p for target %d lun %llu moved to disconnected queue\n",
2136 cmd, scmd_id(cmd), cmd->device->lun);
2137
Roman Zippelc28bda22007-05-01 22:32:36 +02002138 /*
2139 * Restore phase bits to 0 so an interrupted selection,
2140 * arbitration can resume.
2141 */
2142 NCR5380_write(TARGET_COMMAND_REG, 0);
2143
2144 /* Enable reselect interrupts */
2145 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
Finn Thaine3f463b2014-11-12 16:12:16 +11002146#ifdef SUN3_SCSI_VME
2147 dregs->csr |= CSR_DMA_ENABLE;
2148#endif
Roman Zippelc28bda22007-05-01 22:32:36 +02002149 return;
2150 /*
2151 * The SCSI data pointer is *IMPLICITLY* saved on a disconnect
2152 * operation, in violation of the SCSI spec so we can safely
2153 * ignore SAVE/RESTORE pointers calls.
2154 *
2155 * Unfortunately, some disks violate the SCSI spec and
2156 * don't issue the required SAVE_POINTERS message before
2157 * disconnecting, and we have to break spec to remain
2158 * compatible.
2159 */
2160 case SAVE_POINTERS:
2161 case RESTORE_POINTERS:
2162 /* Accept message by clearing ACK */
2163 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
Roman Zippelc28bda22007-05-01 22:32:36 +02002164 break;
2165 case EXTENDED_MESSAGE:
2166 /*
2167 * Extended messages are sent in the following format :
2168 * Byte
2169 * 0 EXTENDED_MESSAGE == 1
2170 * 1 length (includes one byte for code, doesn't
2171 * include first two bytes)
2172 * 2 code
2173 * 3..length+1 arguments
2174 *
2175 * Start the extended message buffer with the EXTENDED_MESSAGE
2176 * byte, since spi_print_msg() wants the whole thing.
2177 */
2178 extended_msg[0] = EXTENDED_MESSAGE;
2179 /* Accept first byte by clearing ACK */
2180 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2181
Finn Thain11d2f632016-01-03 16:05:51 +11002182 spin_unlock_irq(&hostdata->lock);
2183
Finn Thainb7465452016-01-03 16:06:05 +11002184 dsprintk(NDEBUG_EXTENDED, instance, "receiving extended message\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02002185
2186 len = 2;
2187 data = extended_msg + 1;
2188 phase = PHASE_MSGIN;
2189 NCR5380_transfer_pio(instance, &phase, &len, &data);
Finn Thainb7465452016-01-03 16:06:05 +11002190 dsprintk(NDEBUG_EXTENDED, instance, "length %d, code 0x%02x\n",
2191 (int)extended_msg[1],
2192 (int)extended_msg[2]);
Roman Zippelc28bda22007-05-01 22:32:36 +02002193
Finn Thaine0783ed2016-01-03 16:05:45 +11002194 if (!len && extended_msg[1] > 0 &&
2195 extended_msg[1] <= sizeof(extended_msg) - 2) {
Roman Zippelc28bda22007-05-01 22:32:36 +02002196 /* Accept third byte by clearing ACK */
2197 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2198 len = extended_msg[1] - 1;
2199 data = extended_msg + 3;
2200 phase = PHASE_MSGIN;
2201
2202 NCR5380_transfer_pio(instance, &phase, &len, &data);
Finn Thainb7465452016-01-03 16:06:05 +11002203 dsprintk(NDEBUG_EXTENDED, instance, "message received, residual %d\n",
2204 len);
Roman Zippelc28bda22007-05-01 22:32:36 +02002205
2206 switch (extended_msg[2]) {
2207 case EXTENDED_SDTR:
2208 case EXTENDED_WDTR:
2209 case EXTENDED_MODIFY_DATA_POINTER:
2210 case EXTENDED_EXTENDED_IDENTIFY:
2211 tmp = 0;
2212 }
2213 } else if (len) {
Finn Thain6a6ff4a2016-01-03 16:06:04 +11002214 shost_printk(KERN_ERR, instance, "error receiving extended message\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02002215 tmp = 0;
2216 } else {
Finn Thain6a6ff4a2016-01-03 16:06:04 +11002217 shost_printk(KERN_NOTICE, instance, "extended message code %02x length %d is too long\n",
2218 extended_msg[2], extended_msg[1]);
Roman Zippelc28bda22007-05-01 22:32:36 +02002219 tmp = 0;
2220 }
Finn Thain11d2f632016-01-03 16:05:51 +11002221
2222 spin_lock_irq(&hostdata->lock);
2223 if (!hostdata->connected)
2224 return;
2225
Roman Zippelc28bda22007-05-01 22:32:36 +02002226 /* Fall through to reject message */
2227
2228 /*
2229 * If we get something weird that we aren't expecting,
2230 * reject it.
2231 */
2232 default:
2233 if (!tmp) {
Finn Thain6a6ff4a2016-01-03 16:06:04 +11002234 shost_printk(KERN_ERR, instance, "rejecting message ");
Roman Zippelc28bda22007-05-01 22:32:36 +02002235 spi_print_msg(extended_msg);
2236 printk("\n");
2237 } else if (tmp != EXTENDED_MESSAGE)
Finn Thainff50f9e2014-11-12 16:12:18 +11002238 scmd_printk(KERN_INFO, cmd,
2239 "rejecting unknown message %02x\n",
2240 tmp);
Roman Zippelc28bda22007-05-01 22:32:36 +02002241 else
Finn Thainff50f9e2014-11-12 16:12:18 +11002242 scmd_printk(KERN_INFO, cmd,
2243 "rejecting unknown extended message code %02x, length %d\n",
2244 extended_msg[1], extended_msg[0]);
Roman Zippelc28bda22007-05-01 22:32:36 +02002245
2246 msgout = MESSAGE_REJECT;
2247 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
2248 break;
2249 } /* switch (tmp) */
2250 break;
2251 case PHASE_MSGOUT:
2252 len = 1;
2253 data = &msgout;
2254 hostdata->last_message = msgout;
2255 NCR5380_transfer_pio(instance, &phase, &len, &data);
2256 if (msgout == ABORT) {
Roman Zippelc28bda22007-05-01 22:32:36 +02002257 hostdata->connected = NULL;
2258 cmd->result = DID_ERROR << 16;
Finn Thain677e0192016-01-03 16:05:59 +11002259 complete_cmd(instance, cmd);
Finn Thaine3c3da62014-11-12 16:12:15 +11002260 maybe_release_dma_irq(instance);
Finn Thaincd400822016-01-03 16:05:40 +11002261 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
Roman Zippelc28bda22007-05-01 22:32:36 +02002262 return;
2263 }
2264 msgout = NOP;
2265 break;
2266 case PHASE_CMDOUT:
2267 len = cmd->cmd_len;
2268 data = cmd->cmnd;
2269 /*
2270 * XXX for performance reasons, on machines with a
2271 * PSEUDO-DMA architecture we should probably
2272 * use the dma transfer function.
2273 */
2274 NCR5380_transfer_pio(instance, &phase, &len, &data);
2275 break;
2276 case PHASE_STATIN:
2277 len = 1;
2278 data = &tmp;
2279 NCR5380_transfer_pio(instance, &phase, &len, &data);
2280 cmd->SCp.Status = tmp;
2281 break;
2282 default:
Finn Thain6a6ff4a2016-01-03 16:06:04 +11002283 shost_printk(KERN_ERR, instance, "unknown phase\n");
Finn Thain8ad3a592014-03-18 11:42:19 +11002284 NCR5380_dprint(NDEBUG_ANY, instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02002285 } /* switch(phase) */
Finn Thain686f3992016-01-03 16:05:26 +11002286 } else {
Finn Thain11d2f632016-01-03 16:05:51 +11002287 spin_unlock_irq(&hostdata->lock);
Finn Thain686f3992016-01-03 16:05:26 +11002288 NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ);
Finn Thain11d2f632016-01-03 16:05:51 +11002289 spin_lock_irq(&hostdata->lock);
Finn Thain686f3992016-01-03 16:05:26 +11002290 }
Finn Thain11d2f632016-01-03 16:05:51 +11002291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292}
2293
2294/*
2295 * Function : void NCR5380_reselect (struct Scsi_Host *instance)
2296 *
Roman Zippelc28bda22007-05-01 22:32:36 +02002297 * Purpose : does reselection, initializing the instance->connected
Finn Thain710ddd02014-11-12 16:12:02 +11002298 * field to point to the scsi_cmnd for which the I_T_L or I_T_L_Q
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 * nexus has been reestablished,
Roman Zippelc28bda22007-05-01 22:32:36 +02002300 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 * Inputs : instance - this instance of the NCR5380.
2302 *
2303 */
2304
2305
Finn Thaine3f463b2014-11-12 16:12:16 +11002306/* it might eventually prove necessary to do a dma setup on
2307 reselection, but it doesn't seem to be needed now -- sam */
2308
Roman Zippelc28bda22007-05-01 22:32:36 +02002309static void NCR5380_reselect(struct Scsi_Host *instance)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310{
Finn Thaine8a60142016-01-03 16:05:54 +11002311 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02002312 unsigned char target_mask;
Finn Thaine3f463b2014-11-12 16:12:16 +11002313 unsigned char lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314#ifdef SUPPORT_TAGS
Roman Zippelc28bda22007-05-01 22:32:36 +02002315 unsigned char tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316#endif
Roman Zippelc28bda22007-05-01 22:32:36 +02002317 unsigned char msg[3];
Finn Thaine3f463b2014-11-12 16:12:16 +11002318 int __maybe_unused len;
2319 unsigned char __maybe_unused *data, __maybe_unused phase;
Finn Thain32b26a12016-01-03 16:05:58 +11002320 struct NCR5380_cmd *ncmd;
2321 struct scsi_cmnd *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Roman Zippelc28bda22007-05-01 22:32:36 +02002323 /*
2324 * Disable arbitration, etc. since the host adapter obviously
2325 * lost, and tell an interrupted NCR5380_select() to restart.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Roman Zippelc28bda22007-05-01 22:32:36 +02002328 NCR5380_write(MODE_REG, MR_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
Roman Zippelc28bda22007-05-01 22:32:36 +02002330 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask);
2331
Finn Thainb7465452016-01-03 16:06:05 +11002332 dsprintk(NDEBUG_RESELECTION, instance, "reselect\n");
Roman Zippelc28bda22007-05-01 22:32:36 +02002333
2334 /*
2335 * At this point, we have detected that our SCSI ID is on the bus,
2336 * SEL is true and BSY was false for at least one bus settle delay
2337 * (400 ns).
2338 *
2339 * We must assert BSY ourselves, until the target drops the SEL
2340 * signal.
2341 */
2342
2343 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
Finn Thain72064a72016-01-03 16:05:44 +11002344 if (NCR5380_poll_politely(instance,
2345 STATUS_REG, SR_SEL, 0, 2 * HZ) < 0) {
2346 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2347 return;
2348 }
Roman Zippelc28bda22007-05-01 22:32:36 +02002349 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2350
2351 /*
2352 * Wait for target to go into MSGIN.
2353 */
2354
Finn Thain72064a72016-01-03 16:05:44 +11002355 if (NCR5380_poll_politely(instance,
2356 STATUS_REG, SR_REQ, SR_REQ, 2 * HZ) < 0) {
2357 do_abort(instance);
2358 return;
2359 }
Roman Zippelc28bda22007-05-01 22:32:36 +02002360
Finn Thaine3f463b2014-11-12 16:12:16 +11002361#if defined(CONFIG_SUN3) && defined(REAL_DMA)
2362 /* acknowledge toggle to MSGIN */
2363 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(PHASE_MSGIN));
2364
2365 /* peek at the byte without really hitting the bus */
2366 msg[0] = NCR5380_read(CURRENT_SCSI_DATA_REG);
2367#else
Roman Zippelc28bda22007-05-01 22:32:36 +02002368 len = 1;
2369 data = msg;
2370 phase = PHASE_MSGIN;
2371 NCR5380_transfer_pio(instance, &phase, &len, &data);
2372
Finn Thain72064a72016-01-03 16:05:44 +11002373 if (len) {
Roman Zippelc28bda22007-05-01 22:32:36 +02002374 do_abort(instance);
2375 return;
2376 }
Finn Thain72064a72016-01-03 16:05:44 +11002377#endif
2378
2379 if (!(msg[0] & 0x80)) {
2380 shost_printk(KERN_ERR, instance, "expecting IDENTIFY message, got ");
2381 spi_print_msg(msg);
2382 printk("\n");
2383 do_abort(instance);
2384 return;
2385 }
2386 lun = msg[0] & 0x07;
Roman Zippelc28bda22007-05-01 22:32:36 +02002387
Finn Thaine3f463b2014-11-12 16:12:16 +11002388#if defined(SUPPORT_TAGS) && !defined(CONFIG_SUN3)
Roman Zippelc28bda22007-05-01 22:32:36 +02002389 /* If the phase is still MSGIN, the target wants to send some more
2390 * messages. In case it supports tagged queuing, this is probably a
2391 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus.
2392 */
2393 tag = TAG_NONE;
Finn Thainca513fc2014-11-12 16:12:19 +11002394 if (phase == PHASE_MSGIN && (hostdata->flags & FLAG_TAGGED_QUEUING)) {
Roman Zippelc28bda22007-05-01 22:32:36 +02002395 /* Accept previous IDENTIFY message by clearing ACK */
2396 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2397 len = 2;
2398 data = msg + 1;
2399 if (!NCR5380_transfer_pio(instance, &phase, &len, &data) &&
2400 msg[1] == SIMPLE_QUEUE_TAG)
2401 tag = msg[2];
Finn Thainb7465452016-01-03 16:06:05 +11002402 dsprintk(NDEBUG_TAGS, instance, "reselect: target mask %02x, lun %d sent tag %d\n",
2403 target_mask, lun, tag);
Roman Zippelc28bda22007-05-01 22:32:36 +02002404 }
2405#endif
2406
2407 /*
2408 * Find the command corresponding to the I_T_L or I_T_L_Q nexus we
2409 * just reestablished, and remove it from the disconnected queue.
2410 */
2411
Finn Thain32b26a12016-01-03 16:05:58 +11002412 tmp = NULL;
2413 list_for_each_entry(ncmd, &hostdata->disconnected, list) {
2414 struct scsi_cmnd *cmd = NCR5380_to_scmd(ncmd);
2415
2416 if (target_mask == (1 << scmd_id(cmd)) &&
2417 lun == (u8)cmd->device->lun
Roman Zippelc28bda22007-05-01 22:32:36 +02002418#ifdef SUPPORT_TAGS
Finn Thain32b26a12016-01-03 16:05:58 +11002419 && (tag == cmd->tag)
Roman Zippelc28bda22007-05-01 22:32:36 +02002420#endif
2421 ) {
Finn Thain32b26a12016-01-03 16:05:58 +11002422 list_del(&ncmd->list);
2423 tmp = cmd;
Roman Zippelc28bda22007-05-01 22:32:36 +02002424 break;
2425 }
2426 }
2427
Finn Thain0d3d9a42016-01-03 16:05:55 +11002428 if (tmp) {
2429 dsprintk(NDEBUG_RESELECTION | NDEBUG_QUEUES, instance,
2430 "reselect: removed %p from disconnected queue\n", tmp);
2431 } else {
2432
Roman Zippelc28bda22007-05-01 22:32:36 +02002433#ifdef SUPPORT_TAGS
Finn Thain72064a72016-01-03 16:05:44 +11002434 shost_printk(KERN_ERR, instance, "target bitmask 0x%02x lun %d tag %d not in disconnected queue.\n",
2435 target_mask, lun, tag);
2436#else
2437 shost_printk(KERN_ERR, instance, "target bitmask 0x%02x lun %d not in disconnected queue.\n",
2438 target_mask, lun);
Roman Zippelc28bda22007-05-01 22:32:36 +02002439#endif
Roman Zippelc28bda22007-05-01 22:32:36 +02002440 /*
2441 * Since we have an established nexus that we can't do anything
2442 * with, we must abort it.
2443 */
2444 do_abort(instance);
2445 return;
2446 }
2447
Finn Thaine3f463b2014-11-12 16:12:16 +11002448#if defined(CONFIG_SUN3) && defined(REAL_DMA)
2449 /* engage dma setup for the command we just saw */
2450 {
2451 void *d;
2452 unsigned long count;
2453
2454 if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) {
2455 count = tmp->SCp.buffer->length;
2456 d = sg_virt(tmp->SCp.buffer);
2457 } else {
2458 count = tmp->SCp.this_residual;
2459 d = tmp->SCp.ptr;
2460 }
2461 /* setup this command for dma if not already */
2462 if ((count >= DMA_MIN_SIZE) && (sun3_dma_setup_done != tmp)) {
Finn Thaincd461402016-01-03 16:06:06 +11002463 sun3scsi_dma_setup(instance, d, count,
2464 rq_data_dir(tmp->request));
Finn Thaine3f463b2014-11-12 16:12:16 +11002465 sun3_dma_setup_done = tmp;
2466 }
2467 }
2468
2469 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
2470#endif
2471
Roman Zippelc28bda22007-05-01 22:32:36 +02002472 /* Accept message by clearing ACK */
2473 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2474
Finn Thaine3f463b2014-11-12 16:12:16 +11002475#if defined(SUPPORT_TAGS) && defined(CONFIG_SUN3)
2476 /* If the phase is still MSGIN, the target wants to send some more
2477 * messages. In case it supports tagged queuing, this is probably a
2478 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus.
2479 */
2480 tag = TAG_NONE;
2481 if (phase == PHASE_MSGIN && setup_use_tagged_queuing) {
2482 /* Accept previous IDENTIFY message by clearing ACK */
2483 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2484 len = 2;
2485 data = msg + 1;
2486 if (!NCR5380_transfer_pio(instance, &phase, &len, &data) &&
2487 msg[1] == SIMPLE_QUEUE_TAG)
2488 tag = msg[2];
Finn Thainb7465452016-01-03 16:06:05 +11002489 dsprintk(NDEBUG_TAGS, instance, "reselect: target mask %02x, lun %d sent tag %d\n"
2490 target_mask, lun, tag);
Finn Thaine3f463b2014-11-12 16:12:16 +11002491 }
2492#endif
2493
Roman Zippelc28bda22007-05-01 22:32:36 +02002494 hostdata->connected = tmp;
Finn Thainb7465452016-01-03 16:06:05 +11002495 dsprintk(NDEBUG_RESELECTION, instance, "nexus established, target %d, lun %llu, tag %d\n",
2496 scmd_id(tmp), tmp->device->lun, tmp->tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497}
2498
2499
Finn Thain8b00c3d2016-01-03 16:06:01 +11002500/**
2501 * list_find_cmd - test for presence of a command in a linked list
2502 * @haystack: list of commands
2503 * @needle: command to search for
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 */
2505
Finn Thain8b00c3d2016-01-03 16:06:01 +11002506static bool list_find_cmd(struct list_head *haystack,
2507 struct scsi_cmnd *needle)
2508{
2509 struct NCR5380_cmd *ncmd;
2510
2511 list_for_each_entry(ncmd, haystack, list)
2512 if (NCR5380_to_scmd(ncmd) == needle)
2513 return true;
2514 return false;
2515}
2516
2517/**
2518 * list_remove_cmd - remove a command from linked list
2519 * @haystack: list of commands
2520 * @needle: command to remove
2521 */
2522
2523static bool list_del_cmd(struct list_head *haystack,
2524 struct scsi_cmnd *needle)
2525{
2526 if (list_find_cmd(haystack, needle)) {
2527 struct NCR5380_cmd *ncmd = scsi_cmd_priv(needle);
2528
2529 list_del(&ncmd->list);
2530 return true;
2531 }
2532 return false;
2533}
2534
2535/**
2536 * NCR5380_abort - scsi host eh_abort_handler() method
2537 * @cmd: the command to be aborted
2538 *
2539 * Try to abort a given command by removing it from queues and/or sending
2540 * the target an abort message. This may not succeed in causing a target
2541 * to abort the command. Nonetheless, the low-level driver must forget about
2542 * the command because the mid-layer reclaims it and it may be re-issued.
2543 *
2544 * The normal path taken by a command is as follows. For EH we trace this
2545 * same path to locate and abort the command.
2546 *
2547 * unissued -> selecting -> [unissued -> selecting ->]... connected ->
2548 * [disconnected -> connected ->]...
2549 * [autosense -> connected ->] done
2550 *
2551 * If cmd is unissued then just remove it.
2552 * If cmd is disconnected, try to select the target.
2553 * If cmd is connected, try to send an abort message.
2554 * If cmd is waiting for autosense, give it a chance to complete but check
2555 * that it isn't left connected.
2556 * If cmd was not found at all then presumably it has already been completed,
2557 * in which case return SUCCESS to try to avoid further EH measures.
2558 * If the command has not completed yet, we must not fail to find it.
2559 */
2560
2561static int NCR5380_abort(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562{
Roman Zippelc28bda22007-05-01 22:32:36 +02002563 struct Scsi_Host *instance = cmd->device->host;
Finn Thaine8a60142016-01-03 16:05:54 +11002564 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02002565 unsigned long flags;
Finn Thain8b00c3d2016-01-03 16:06:01 +11002566 int result = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
Finn Thain11d2f632016-01-03 16:05:51 +11002568 spin_lock_irqsave(&hostdata->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
Finn Thain32b26a12016-01-03 16:05:58 +11002570#if (NDEBUG & NDEBUG_ANY)
Finn Thain8b00c3d2016-01-03 16:06:01 +11002571 scmd_printk(KERN_INFO, cmd, __func__);
Finn Thain32b26a12016-01-03 16:05:58 +11002572#endif
Finn Thaine5c3fdd2016-01-03 16:05:52 +11002573 NCR5380_dprint(NDEBUG_ANY, instance);
2574 NCR5380_dprint_phase(NDEBUG_ANY, instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
Finn Thain8b00c3d2016-01-03 16:06:01 +11002576 if (list_del_cmd(&hostdata->unissued, cmd)) {
2577 dsprintk(NDEBUG_ABORT, instance,
2578 "abort: removed %p from issue queue\n", cmd);
2579 cmd->result = DID_ABORT << 16;
2580 cmd->scsi_done(cmd); /* No tag or busy flag to worry about */
2581 }
2582
Finn Thain707d62b2016-01-03 16:06:02 +11002583 if (hostdata->selecting == cmd) {
2584 dsprintk(NDEBUG_ABORT, instance,
2585 "abort: cmd %p == selecting\n", cmd);
2586 hostdata->selecting = NULL;
2587 cmd->result = DID_ABORT << 16;
2588 complete_cmd(instance, cmd);
2589 goto out;
2590 }
2591
Finn Thain8b00c3d2016-01-03 16:06:01 +11002592 if (list_del_cmd(&hostdata->disconnected, cmd)) {
2593 dsprintk(NDEBUG_ABORT, instance,
2594 "abort: removed %p from disconnected list\n", cmd);
2595 cmd->result = DID_ERROR << 16;
2596 if (!hostdata->connected)
2597 NCR5380_select(instance, cmd);
2598 if (hostdata->connected != cmd) {
2599 complete_cmd(instance, cmd);
2600 result = FAILED;
2601 goto out;
2602 }
2603 }
2604
2605 if (hostdata->connected == cmd) {
2606 dsprintk(NDEBUG_ABORT, instance, "abort: cmd %p is connected\n", cmd);
2607 hostdata->connected = NULL;
2608 if (do_abort(instance)) {
2609 set_host_byte(cmd, DID_ERROR);
2610 complete_cmd(instance, cmd);
2611 result = FAILED;
2612 goto out;
2613 }
2614 set_host_byte(cmd, DID_ABORT);
2615#ifdef REAL_DMA
2616 hostdata->dma_len = 0;
2617#endif
2618 if (cmd->cmnd[0] == REQUEST_SENSE)
2619 complete_cmd(instance, cmd);
2620 else {
2621 struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
2622
2623 /* Perform autosense for this command */
2624 list_add(&ncmd->list, &hostdata->autosense);
2625 }
2626 }
2627
2628 if (list_find_cmd(&hostdata->autosense, cmd)) {
2629 dsprintk(NDEBUG_ABORT, instance,
2630 "abort: found %p on sense queue\n", cmd);
2631 spin_unlock_irqrestore(&hostdata->lock, flags);
2632 queue_work(hostdata->work_q, &hostdata->main_task);
2633 msleep(1000);
2634 spin_lock_irqsave(&hostdata->lock, flags);
2635 if (list_del_cmd(&hostdata->autosense, cmd)) {
2636 dsprintk(NDEBUG_ABORT, instance,
2637 "abort: removed %p from sense queue\n", cmd);
2638 set_host_byte(cmd, DID_ABORT);
2639 complete_cmd(instance, cmd);
2640 goto out;
2641 }
2642 }
2643
2644 if (hostdata->connected == cmd) {
2645 dsprintk(NDEBUG_ABORT, instance, "abort: cmd %p is connected\n", cmd);
2646 hostdata->connected = NULL;
2647 if (do_abort(instance)) {
2648 set_host_byte(cmd, DID_ERROR);
2649 complete_cmd(instance, cmd);
2650 result = FAILED;
2651 goto out;
2652 }
2653 set_host_byte(cmd, DID_ABORT);
2654#ifdef REAL_DMA
2655 hostdata->dma_len = 0;
2656#endif
2657 complete_cmd(instance, cmd);
2658 }
2659
2660out:
2661 if (result == FAILED)
2662 dsprintk(NDEBUG_ABORT, instance, "abort: failed to abort %p\n", cmd);
2663 else
2664 dsprintk(NDEBUG_ABORT, instance, "abort: successfully aborted %p\n", cmd);
2665
2666 queue_work(hostdata->work_q, &hostdata->main_task);
2667 maybe_release_dma_irq(instance);
Finn Thain11d2f632016-01-03 16:05:51 +11002668 spin_unlock_irqrestore(&hostdata->lock, flags);
Finn Thaine3c3da62014-11-12 16:12:15 +11002669
Finn Thain8b00c3d2016-01-03 16:06:01 +11002670 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
2673
Finn Thain3be1b3e2016-01-03 16:05:12 +11002674/**
2675 * NCR5380_bus_reset - reset the SCSI bus
2676 * @cmd: SCSI command undergoing EH
Roman Zippelc28bda22007-05-01 22:32:36 +02002677 *
Finn Thain3be1b3e2016-01-03 16:05:12 +11002678 * Returns SUCCESS
Roman Zippelc28bda22007-05-01 22:32:36 +02002679 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
Finn Thain710ddd02014-11-12 16:12:02 +11002681static int NCR5380_bus_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682{
Finn Thaine3c3da62014-11-12 16:12:15 +11002683 struct Scsi_Host *instance = cmd->device->host;
2684 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Roman Zippelc28bda22007-05-01 22:32:36 +02002685 int i;
2686 unsigned long flags;
Finn Thain62717f52016-01-03 16:06:03 +11002687 struct NCR5380_cmd *ncmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688
Finn Thain11d2f632016-01-03 16:05:51 +11002689 spin_lock_irqsave(&hostdata->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690
Finn Thain3be1b3e2016-01-03 16:05:12 +11002691#if (NDEBUG & NDEBUG_ANY)
Finn Thain62717f52016-01-03 16:06:03 +11002692 scmd_printk(KERN_INFO, cmd, __func__);
Finn Thain3be1b3e2016-01-03 16:05:12 +11002693#endif
Finn Thaine5c3fdd2016-01-03 16:05:52 +11002694 NCR5380_dprint(NDEBUG_ANY, instance);
2695 NCR5380_dprint_phase(NDEBUG_ANY, instance);
Finn Thain3be1b3e2016-01-03 16:05:12 +11002696
2697 do_reset(instance);
2698
Roman Zippelc28bda22007-05-01 22:32:36 +02002699 /* reset NCR registers */
Roman Zippelc28bda22007-05-01 22:32:36 +02002700 NCR5380_write(MODE_REG, MR_BASE);
2701 NCR5380_write(TARGET_COMMAND_REG, 0);
2702 NCR5380_write(SELECT_ENABLE_REG, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703
Roman Zippelc28bda22007-05-01 22:32:36 +02002704 /* After the reset, there are no more connected or disconnected commands
2705 * and no busy units; so clear the low-level status here to avoid
2706 * conflicts when the mid-level code tries to wake up the affected
2707 * commands!
2708 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
Finn Thain707d62b2016-01-03 16:06:02 +11002710 hostdata->selecting = NULL;
2711
Finn Thain62717f52016-01-03 16:06:03 +11002712 list_for_each_entry(ncmd, &hostdata->disconnected, list) {
2713 struct scsi_cmnd *cmd = NCR5380_to_scmd(ncmd);
2714
2715 set_host_byte(cmd, DID_RESET);
2716 cmd->scsi_done(cmd);
2717 }
2718
2719 list_for_each_entry(ncmd, &hostdata->autosense, list) {
2720 struct scsi_cmnd *cmd = NCR5380_to_scmd(ncmd);
2721
2722 set_host_byte(cmd, DID_RESET);
2723 cmd->scsi_done(cmd);
2724 }
2725
2726 if (hostdata->connected) {
2727 set_host_byte(hostdata->connected, DID_RESET);
2728 complete_cmd(instance, hostdata->connected);
2729 hostdata->connected = NULL;
2730 }
Finn Thain32b26a12016-01-03 16:05:58 +11002731
Finn Thainf27db8e2016-01-03 16:06:00 +11002732 if (hostdata->sensing) {
Finn Thain62717f52016-01-03 16:06:03 +11002733 set_host_byte(hostdata->connected, DID_RESET);
Finn Thainf27db8e2016-01-03 16:06:00 +11002734 complete_cmd(instance, hostdata->sensing);
2735 hostdata->sensing = NULL;
2736 }
2737
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738#ifdef SUPPORT_TAGS
Finn Thainca513fc2014-11-12 16:12:19 +11002739 free_all_tags(hostdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740#endif
Roman Zippelc28bda22007-05-01 22:32:36 +02002741 for (i = 0; i < 8; ++i)
2742 hostdata->busy[i] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743#ifdef REAL_DMA
Roman Zippelc28bda22007-05-01 22:32:36 +02002744 hostdata->dma_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745#endif
Finn Thaine3c3da62014-11-12 16:12:15 +11002746
Finn Thain62717f52016-01-03 16:06:03 +11002747 queue_work(hostdata->work_q, &hostdata->main_task);
Finn Thaine3c3da62014-11-12 16:12:15 +11002748 maybe_release_dma_irq(instance);
Finn Thain11d2f632016-01-03 16:05:51 +11002749 spin_unlock_irqrestore(&hostdata->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750
Michael Schmitz2b0f8342014-05-02 20:43:01 +12002751 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752}