blob: 301b3cad15f88f6d4c9022d3e763a625a35172ff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* aha152x.c -- Adaptec AHA-152x driver
Jan Engelhardt96de0e22007-10-19 23:21:04 +02002 * Author: Jürgen E. Fischer, fischer@norbit.de
3 * Copyright 1993-2004 Jürgen E. Fischer
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
8 * later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 *
16 * $Id: aha152x.c,v 2.7 2004/01/24 11:42:59 fischer Exp $
17 *
18 * $Log: aha152x.c,v $
19 * Revision 2.7 2004/01/24 11:42:59 fischer
20 * - gather code that is not used by PCMCIA at the end
21 * - move request_region for !PCMCIA case to detection
22 * - migration to new scsi host api (remove legacy code)
23 * - free host scribble before scsi_done
24 * - fix error handling
25 * - one isapnp device added to id_table
26 *
27 * Revision 2.6 2003/10/30 20:52:47 fischer
28 * - interfaces changes for kernel 2.6
29 * - aha152x_probe_one introduced for pcmcia stub
30 * - fixed pnpdev handling
31 * - instead of allocation a new one, reuse command for request sense after check condition and reset
32 * - fixes race in is_complete
33 *
34 * Revision 2.5 2002/04/14 11:24:53 fischer
35 * - isapnp support
36 * - abort fixed
37 * - 2.5 support
38 *
39 * Revision 2.4 2000/12/16 12:53:56 fischer
40 * - allow REQUEST SENSE to be queued
41 * - handle shared PCI interrupts
42 *
43 * Revision 2.3 2000/11/04 16:40:26 fischer
44 * - handle data overruns
45 * - extend timeout for data phases
46 *
47 * Revision 2.2 2000/08/08 19:54:53 fischer
48 * - minor changes
49 *
50 * Revision 2.1 2000/05/17 16:23:17 fischer
51 * - signature update
52 * - fix for data out w/o scatter gather
53 *
54 * Revision 2.0 1999/12/25 15:07:32 fischer
55 * - interrupt routine completly reworked
56 * - basic support for new eh code
57 *
58 * Revision 1.21 1999/11/10 23:46:36 fischer
59 * - default to synchronous operation
60 * - synchronous negotiation fixed
61 * - added timeout to loops
62 * - debugging output can be controlled through procfs
63 *
64 * Revision 1.20 1999/11/07 18:37:31 fischer
65 * - synchronous operation works
66 * - resid support for sg driver
67 *
68 * Revision 1.19 1999/11/02 22:39:59 fischer
69 * - moved leading comments to README.aha152x
70 * - new additional module parameters
71 * - updates for 2.3
72 * - support for the Tripace TC1550 controller
73 * - interrupt handling changed
74 *
75 * Revision 1.18 1996/09/07 20:10:40 fischer
76 * - fixed can_queue handling (multiple outstanding commands working again)
77 *
78 * Revision 1.17 1996/08/17 16:05:14 fischer
79 * - biosparam improved
80 * - interrupt verification
81 * - updated documentation
82 * - cleanups
83 *
84 * Revision 1.16 1996/06/09 00:04:56 root
85 * - added configuration symbols for insmod (aha152x/aha152x1)
86 *
87 * Revision 1.15 1996/04/30 14:52:06 fischer
88 * - proc info fixed
89 * - support for extended translation for >1GB disks
90 *
91 * Revision 1.14 1996/01/17 15:11:20 fischer
92 * - fixed lockup in MESSAGE IN phase after reconnection
93 *
94 * Revision 1.13 1996/01/09 02:15:53 fischer
95 * - some cleanups
96 * - moved request_irq behind controller initialization
97 * (to avoid spurious interrupts)
98 *
99 * Revision 1.12 1995/12/16 12:26:07 fischer
100 * - barrier()s added
101 * - configurable RESET delay added
102 *
103 * Revision 1.11 1995/12/06 21:18:35 fischer
104 * - some minor updates
105 *
106 * Revision 1.10 1995/07/22 19:18:45 fischer
107 * - support for 2 controllers
108 * - started synchronous data transfers (not working yet)
109 *
110 * Revision 1.9 1995/03/18 09:20:24 root
111 * - patches for PCMCIA and modules
112 *
113 * Revision 1.8 1995/01/21 22:07:19 root
114 * - snarf_region => request_region
115 * - aha152x_intr interface change
116 *
117 * Revision 1.7 1995/01/02 23:19:36 root
118 * - updated COMMAND_SIZE to cmd_len
119 * - changed sti() to restore_flags()
120 * - fixed some #ifdef which generated warnings
121 *
122 * Revision 1.6 1994/11/24 20:35:27 root
123 * - problem with odd number of bytes in fifo fixed
124 *
125 * Revision 1.5 1994/10/30 14:39:56 root
126 * - abort code fixed
127 * - debugging improved
128 *
129 * Revision 1.4 1994/09/12 11:33:01 root
130 * - irqaction to request_irq
131 * - abortion updated
132 *
133 * Revision 1.3 1994/08/04 13:53:05 root
134 * - updates for mid-level-driver changes
135 * - accept unexpected BUSFREE phase as error condition
136 * - parity check now configurable
137 *
138 * Revision 1.2 1994/07/03 12:56:36 root
139 * - cleaned up debugging code
140 * - more tweaking on reset delays
141 * - updated abort/reset code (pretty untested...)
142 *
143 * Revision 1.1 1994/05/28 21:18:49 root
144 * - update for mid-level interface change (abort-reset)
145 * - delays after resets adjusted for some slow devices
146 *
147 * Revision 1.0 1994/03/25 12:52:00 root
148 * - Fixed "more data than expected" problem
149 * - added new BIOS signatures
150 *
151 * Revision 0.102 1994/01/31 20:44:12 root
152 * - minor changes in insw/outsw handling
153 *
154 * Revision 0.101 1993/12/13 01:16:27 root
155 * - fixed STATUS phase (non-GOOD stati were dropped sometimes;
156 * fixes problems with CD-ROM sector size detection & media change)
157 *
158 * Revision 0.100 1993/12/10 16:58:47 root
159 * - fix for unsuccessful selections in case of non-continuous id assignments
160 * on the scsi bus.
161 *
162 * Revision 0.99 1993/10/24 16:19:59 root
163 * - fixed DATA IN (rare read errors gone)
164 *
165 * Revision 0.98 1993/10/17 12:54:44 root
166 * - fixed some recent fixes (shame on me)
167 * - moved initialization of scratch area to aha152x_queue
168 *
169 * Revision 0.97 1993/10/09 18:53:53 root
170 * - DATA IN fixed. Rarely left data in the fifo.
171 *
172 * Revision 0.96 1993/10/03 00:53:59 root
173 * - minor changes on DATA IN
174 *
175 * Revision 0.95 1993/09/24 10:36:01 root
176 * - change handling of MSGI after reselection
177 * - fixed sti/cli
178 * - minor changes
179 *
180 * Revision 0.94 1993/09/18 14:08:22 root
181 * - fixed bug in multiple outstanding command code
182 * - changed detection
183 * - support for kernel command line configuration
184 * - reset corrected
185 * - changed message handling
186 *
187 * Revision 0.93 1993/09/15 20:41:19 root
188 * - fixed bugs with multiple outstanding commands
189 *
190 * Revision 0.92 1993/09/13 02:46:33 root
191 * - multiple outstanding commands work (no problems with IBM drive)
192 *
193 * Revision 0.91 1993/09/12 20:51:46 root
194 * added multiple outstanding commands
195 * (some problem with this $%&? IBM device remain)
196 *
197 * Revision 0.9 1993/09/12 11:11:22 root
198 * - corrected auto-configuration
199 * - changed the auto-configuration (added some '#define's)
200 * - added support for dis-/reconnection
201 *
202 * Revision 0.8 1993/09/06 23:09:39 root
203 * - added support for the drive activity light
204 * - minor changes
205 *
206 * Revision 0.7 1993/09/05 14:30:15 root
207 * - improved phase detection
208 * - now using the new snarf_region code of 0.99pl13
209 *
210 * Revision 0.6 1993/09/02 11:01:38 root
211 * first public release; added some signatures and biosparam()
212 *
213 * Revision 0.5 1993/08/30 10:23:30 root
214 * fixed timing problems with my IBM drive
215 *
216 * Revision 0.4 1993/08/29 14:06:52 root
217 * fixed some problems with timeouts due incomplete commands
218 *
219 * Revision 0.3 1993/08/28 15:55:03 root
220 * writing data works too. mounted and worked on a dos partition
221 *
222 * Revision 0.2 1993/08/27 22:42:07 root
223 * reading data works. Mounted a msdos partition.
224 *
225 * Revision 0.1 1993/08/25 13:38:30 root
226 * first "damn thing doesn't work" version
227 *
228 * Revision 0.0 1993/08/14 19:54:25 root
229 * empty function bodies; detect() works.
230 *
231 *
232 **************************************************************************
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 see Documentation/scsi/aha152x.txt for configuration details
235
236 **************************************************************************/
237
238#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239#include <asm/irq.h>
Matthew Wilcox53d5ed62006-10-11 01:22:01 -0700240#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241#include <linux/blkdev.h>
Christoph Hellwig0f06bb32007-05-13 17:52:12 +0200242#include <linux/completion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#include <linux/errno.h>
244#include <linux/string.h>
245#include <linux/wait.h>
246#include <linux/ioport.h>
247#include <linux/delay.h>
248#include <linux/proc_fs.h>
249#include <linux/interrupt.h>
250#include <linux/init.h>
251#include <linux/kernel.h>
252#include <linux/isapnp.h>
253#include <linux/spinlock.h>
254#include <linux/workqueue.h>
James Bottomley5fcda422006-09-14 17:04:58 -0500255#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +0900256#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#include <scsi/scsicam.h>
258
259#include "scsi.h"
db9dff32005-04-03 14:53:59 -0500260#include <scsi/scsi_dbg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#include <scsi/scsi_host.h>
Matthew Wilcox1abfd372005-12-15 16:22:01 -0500262#include <scsi/scsi_transport_spi.h>
Boaz Harrosh73d2cb12007-11-01 18:54:44 +0200263#include <scsi/scsi_eh.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#include "aha152x.h"
265
James Bottomley5fcda422006-09-14 17:04:58 -0500266static LIST_HEAD(aha152x_host_list);
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269/* DEFINES */
270
271/* For PCMCIA cards, always use AUTOCONF */
Christoph Hellwig3eb2ebc2018-10-19 14:09:44 +0200272#if defined(AHA152X_PCMCIA) || defined(MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273#if !defined(AUTOCONF)
274#define AUTOCONF
275#endif
276#endif
277
278#if !defined(AUTOCONF) && !defined(SETUP0)
279#error define AUTOCONF or SETUP0
280#endif
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags)
283#define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285#define LEAD "(scsi%d:%d:%d) "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286#define INFO_LEAD KERN_INFO LEAD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287#define CMDINFO(cmd) \
288 (cmd) ? ((cmd)->device->host->host_no) : -1, \
289 (cmd) ? ((cmd)->device->id & 0x0f) : -1, \
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200290 (cmd) ? ((u8)(cmd)->device->lun & 0x07) : -1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Boaz Harrosh23385452007-07-29 22:29:02 +0300292static inline void
293CMD_INC_RESID(struct scsi_cmnd *cmd, int inc)
294{
295 scsi_set_resid(cmd, scsi_get_resid(cmd) + inc);
296}
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298#define DELAY_DEFAULT 1000
299
Christoph Hellwig3eb2ebc2018-10-19 14:09:44 +0200300#if defined(AHA152X_PCMCIA)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301#define IRQ_MIN 0
302#define IRQ_MAX 16
303#else
304#define IRQ_MIN 9
305#if defined(__PPC)
Yinghai Lu171ac6a2008-08-19 20:49:54 -0700306#define IRQ_MAX (nr_irqs-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307#else
308#define IRQ_MAX 12
309#endif
310#endif
311
312enum {
313 not_issued = 0x0001, /* command not yet issued */
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200314 selecting = 0x0002, /* target is being selected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 identified = 0x0004, /* IDENTIFY was sent */
316 disconnected = 0x0008, /* target disconnected */
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200317 completed = 0x0010, /* target sent COMMAND COMPLETE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 aborted = 0x0020, /* ABORT was sent */
319 resetted = 0x0040, /* BUS DEVICE RESET was sent */
320 spiordy = 0x0080, /* waiting for SPIORDY to raise */
321 syncneg = 0x0100, /* synchronous negotiation in progress */
322 aborting = 0x0200, /* ABORT is pending */
323 resetting = 0x0400, /* BUS DEVICE RESET is pending */
324 check_condition = 0x0800, /* requesting sense after CHECK CONDITION */
325};
326
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200327MODULE_AUTHOR("Jürgen Fischer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328MODULE_DESCRIPTION(AHA152X_REVID);
329MODULE_LICENSE("GPL");
330
Christoph Hellwig3eb2ebc2018-10-19 14:09:44 +0200331#if !defined(AHA152X_PCMCIA)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#if defined(MODULE)
333static int io[] = {0, 0};
David Howells88f06b72017-04-04 16:54:27 +0100334module_param_hw_array(io, int, ioport, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335MODULE_PARM_DESC(io,"base io address of controller");
336
337static int irq[] = {0, 0};
David Howells88f06b72017-04-04 16:54:27 +0100338module_param_hw_array(irq, int, irq, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339MODULE_PARM_DESC(irq,"interrupt for controller");
340
341static int scsiid[] = {7, 7};
342module_param_array(scsiid, int, NULL, 0);
343MODULE_PARM_DESC(scsiid,"scsi id of controller");
344
345static int reconnect[] = {1, 1};
346module_param_array(reconnect, int, NULL, 0);
347MODULE_PARM_DESC(reconnect,"allow targets to disconnect");
348
349static int parity[] = {1, 1};
350module_param_array(parity, int, NULL, 0);
351MODULE_PARM_DESC(parity,"use scsi parity");
352
353static int sync[] = {1, 1};
354module_param_array(sync, int, NULL, 0);
355MODULE_PARM_DESC(sync,"use synchronous transfers");
356
357static int delay[] = {DELAY_DEFAULT, DELAY_DEFAULT};
358module_param_array(delay, int, NULL, 0);
359MODULE_PARM_DESC(delay,"scsi reset delay");
360
361static int exttrans[] = {0, 0};
362module_param_array(exttrans, int, NULL, 0);
363MODULE_PARM_DESC(exttrans,"use extended translation");
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
366module_param_array(aha152x, int, NULL, 0);
367MODULE_PARM_DESC(aha152x, "parameters for first controller");
368
369static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
370module_param_array(aha152x1, int, NULL, 0);
371MODULE_PARM_DESC(aha152x1, "parameters for second controller");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372#endif /* MODULE */
373
374#ifdef __ISAPNP__
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -0800375static struct isapnp_device_id id_table[] = {
Ondrej Zary50f87f92011-06-09 21:21:23 +0200376 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1502), 0 },
377 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1505), 0 },
378 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1510), 0 },
379 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1515), 0 },
380 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1520), 0 },
381 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2015), 0 },
382 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1522), 0 },
383 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2215), 0 },
384 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1530), 0 },
385 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3015), 0 },
386 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1532), 0 },
387 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3215), 0 },
388 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x6360), 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 { ISAPNP_DEVICE_SINGLE_END, }
390};
391MODULE_DEVICE_TABLE(isapnp, id_table);
392#endif /* ISAPNP */
393
Christoph Hellwig3eb2ebc2018-10-19 14:09:44 +0200394#endif /* !AHA152X_PCMCIA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100396static struct scsi_host_template aha152x_driver_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398/*
399 * internal states of the host
400 *
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200401 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402enum aha152x_state {
403 idle=0,
404 unknown,
405 seldo,
406 seldi,
407 selto,
408 busfree,
409 msgo,
410 cmd,
411 msgi,
412 status,
413 datai,
414 datao,
415 parerr,
416 rsti,
417 maxstate
418};
419
420/*
421 * current state information of the host
422 *
423 */
424struct aha152x_hostdata {
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200425 struct scsi_cmnd *issue_SC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /* pending commands to issue */
427
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200428 struct scsi_cmnd *current_SC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* current command on the bus */
430
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200431 struct scsi_cmnd *disconnected_SC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 /* commands that disconnected */
433
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200434 struct scsi_cmnd *done_SC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 /* command that was completed */
436
437 spinlock_t lock;
438 /* host lock */
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#if defined(AHA152X_STAT)
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200441 int total_commands;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 int disconnections;
443 int busfree_without_any_action;
444 int busfree_without_old_command;
445 int busfree_without_new_command;
446 int busfree_without_done_command;
447 int busfree_with_check_condition;
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200448 int count[maxstate];
449 int count_trans[maxstate];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 unsigned long time[maxstate];
451#endif
452
453 int commands; /* current number of commands */
454
455 int reconnect; /* disconnection allowed */
456 int parity; /* parity checking enabled */
457 int synchronous; /* synchronous transferes enabled */
458 int delay; /* reset out delay */
459 int ext_trans; /* extended translation enabled */
460
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200461 int swint; /* software-interrupt was fired during detect() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 int service; /* bh needs to be run */
463 int in_intr; /* bh is running */
464
465 /* current state,
466 previous state,
467 last state different from current state */
468 enum aha152x_state state, prevstate, laststate;
469
470 int target;
471 /* reconnecting target */
472
473 unsigned char syncrate[8];
474 /* current synchronous transfer agreements */
475
476 unsigned char syncneg[8];
477 /* 0: no negotiation;
478 * 1: negotiation in progress;
479 * 2: negotiation completed
480 */
481
482 int cmd_i;
483 /* number of sent bytes of current command */
484
485 int msgi_len;
486 /* number of received message bytes */
487 unsigned char msgi[256];
488 /* received message bytes */
489
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200490 int msgo_i, msgo_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 /* number of sent bytes and length of current messages */
492 unsigned char msgo[256];
493 /* pending messages */
494
495 int data_len;
496 /* number of sent/received bytes in dataphase */
497
498 unsigned long io_port0;
499 unsigned long io_port1;
500
501#ifdef __ISAPNP__
502 struct pnp_dev *pnpdev;
503#endif
James Bottomley5fcda422006-09-14 17:04:58 -0500504 struct list_head host_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505};
506
507
508/*
509 * host specific command extension
510 *
511 */
512struct aha152x_scdata {
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200513 struct scsi_cmnd *next; /* next sc in queue */
Christoph Hellwig0f06bb32007-05-13 17:52:12 +0200514 struct completion *done;/* semaphore to block on */
Boaz Harrosh73d2cb12007-11-01 18:54:44 +0200515 struct scsi_eh_save ses;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516};
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518/* access macros for hostdata */
519
520#define HOSTDATA(shpnt) ((struct aha152x_hostdata *) &shpnt->hostdata)
521
522#define HOSTNO ((shpnt)->host_no)
523
524#define CURRENT_SC (HOSTDATA(shpnt)->current_SC)
525#define DONE_SC (HOSTDATA(shpnt)->done_SC)
526#define ISSUE_SC (HOSTDATA(shpnt)->issue_SC)
527#define DISCONNECTED_SC (HOSTDATA(shpnt)->disconnected_SC)
528#define QLOCK (HOSTDATA(shpnt)->lock)
529#define QLOCKER (HOSTDATA(shpnt)->locker)
530#define QLOCKERL (HOSTDATA(shpnt)->lockerl)
531
532#define STATE (HOSTDATA(shpnt)->state)
533#define PREVSTATE (HOSTDATA(shpnt)->prevstate)
534#define LASTSTATE (HOSTDATA(shpnt)->laststate)
535
536#define RECONN_TARGET (HOSTDATA(shpnt)->target)
537
538#define CMD_I (HOSTDATA(shpnt)->cmd_i)
539
540#define MSGO(i) (HOSTDATA(shpnt)->msgo[i])
541#define MSGO_I (HOSTDATA(shpnt)->msgo_i)
542#define MSGOLEN (HOSTDATA(shpnt)->msgo_len)
543#define ADDMSGO(x) (MSGOLEN<256 ? (void)(MSGO(MSGOLEN++)=x) : aha152x_error(shpnt,"MSGO overflow"))
544
545#define MSGI(i) (HOSTDATA(shpnt)->msgi[i])
546#define MSGILEN (HOSTDATA(shpnt)->msgi_len)
547#define ADDMSGI(x) (MSGILEN<256 ? (void)(MSGI(MSGILEN++)=x) : aha152x_error(shpnt,"MSGI overflow"))
548
549#define DATA_LEN (HOSTDATA(shpnt)->data_len)
550
551#define SYNCRATE (HOSTDATA(shpnt)->syncrate[CURRENT_SC->device->id])
552#define SYNCNEG (HOSTDATA(shpnt)->syncneg[CURRENT_SC->device->id])
553
554#define DELAY (HOSTDATA(shpnt)->delay)
555#define EXT_TRANS (HOSTDATA(shpnt)->ext_trans)
556#define TC1550 (HOSTDATA(shpnt)->tc1550)
557#define RECONNECT (HOSTDATA(shpnt)->reconnect)
558#define PARITY (HOSTDATA(shpnt)->parity)
559#define SYNCHRONOUS (HOSTDATA(shpnt)->synchronous)
560
561#define HOSTIOPORT0 (HOSTDATA(shpnt)->io_port0)
562#define HOSTIOPORT1 (HOSTDATA(shpnt)->io_port1)
563
564#define SCDATA(SCpnt) ((struct aha152x_scdata *) (SCpnt)->host_scribble)
565#define SCNEXT(SCpnt) SCDATA(SCpnt)->next
Christoph Hellwig0f06bb32007-05-13 17:52:12 +0200566#define SCSEM(SCpnt) SCDATA(SCpnt)->done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Jens Axboe45711f12007-10-22 21:19:53 +0200568#define SG_ADDRESS(buffer) ((char *) sg_virt((buffer)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570/* state handling */
571static void seldi_run(struct Scsi_Host *shpnt);
572static void seldo_run(struct Scsi_Host *shpnt);
573static void selto_run(struct Scsi_Host *shpnt);
574static void busfree_run(struct Scsi_Host *shpnt);
575
576static void msgo_init(struct Scsi_Host *shpnt);
577static void msgo_run(struct Scsi_Host *shpnt);
578static void msgo_end(struct Scsi_Host *shpnt);
579
580static void cmd_init(struct Scsi_Host *shpnt);
581static void cmd_run(struct Scsi_Host *shpnt);
582static void cmd_end(struct Scsi_Host *shpnt);
583
584static void datai_init(struct Scsi_Host *shpnt);
585static void datai_run(struct Scsi_Host *shpnt);
586static void datai_end(struct Scsi_Host *shpnt);
587
588static void datao_init(struct Scsi_Host *shpnt);
589static void datao_run(struct Scsi_Host *shpnt);
590static void datao_end(struct Scsi_Host *shpnt);
591
592static void status_run(struct Scsi_Host *shpnt);
593
594static void msgi_run(struct Scsi_Host *shpnt);
595static void msgi_end(struct Scsi_Host *shpnt);
596
597static void parerr_run(struct Scsi_Host *shpnt);
598static void rsti_run(struct Scsi_Host *shpnt);
599
600static void is_complete(struct Scsi_Host *shpnt);
601
602/*
603 * driver states
604 *
605 */
606static struct {
607 char *name;
608 void (*init)(struct Scsi_Host *);
609 void (*run)(struct Scsi_Host *);
610 void (*end)(struct Scsi_Host *);
611 int spio;
612} states[] = {
613 { "idle", NULL, NULL, NULL, 0},
614 { "unknown", NULL, NULL, NULL, 0},
615 { "seldo", NULL, seldo_run, NULL, 0},
616 { "seldi", NULL, seldi_run, NULL, 0},
617 { "selto", NULL, selto_run, NULL, 0},
618 { "busfree", NULL, busfree_run, NULL, 0},
619 { "msgo", msgo_init, msgo_run, msgo_end, 1},
620 { "cmd", cmd_init, cmd_run, cmd_end, 1},
621 { "msgi", NULL, msgi_run, msgi_end, 1},
622 { "status", NULL, status_run, NULL, 1},
623 { "datai", datai_init, datai_run, datai_end, 0},
624 { "datao", datao_init, datao_run, datao_end, 0},
625 { "parerr", NULL, parerr_run, NULL, 0},
626 { "rsti", NULL, rsti_run, NULL, 0},
627};
628
629/* setup & interrupt */
David Howells7d12e782006-10-05 14:55:46 +0100630static irqreturn_t intr(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631static void reset_ports(struct Scsi_Host *shpnt);
632static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
633static void done(struct Scsi_Host *shpnt, int error);
634
635/* diagnostics */
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200636static void show_command(struct scsi_cmnd * ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637static void show_queues(struct Scsi_Host *shpnt);
638static void disp_enintr(struct Scsi_Host *shpnt);
639
640
641/*
642 * queue services:
643 *
644 */
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200645static inline void append_SC(struct scsi_cmnd **SC, struct scsi_cmnd *new_SC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646{
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200647 struct scsi_cmnd *end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 SCNEXT(new_SC) = NULL;
650 if (!*SC)
651 *SC = new_SC;
652 else {
653 for (end = *SC; SCNEXT(end); end = SCNEXT(end))
654 ;
655 SCNEXT(end) = new_SC;
656 }
657}
658
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200659static inline struct scsi_cmnd *remove_first_SC(struct scsi_cmnd ** SC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200661 struct scsi_cmnd *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 ptr = *SC;
664 if (ptr) {
665 *SC = SCNEXT(*SC);
666 SCNEXT(ptr)=NULL;
667 }
668 return ptr;
669}
670
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200671static inline struct scsi_cmnd *remove_lun_SC(struct scsi_cmnd ** SC,
672 int target, int lun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200674 struct scsi_cmnd *ptr, *prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 for (ptr = *SC, prev = NULL;
677 ptr && ((ptr->device->id != target) || (ptr->device->lun != lun));
678 prev = ptr, ptr = SCNEXT(ptr))
679 ;
680
681 if (ptr) {
682 if (prev)
683 SCNEXT(prev) = SCNEXT(ptr);
684 else
685 *SC = SCNEXT(ptr);
686
687 SCNEXT(ptr)=NULL;
688 }
689
690 return ptr;
691}
692
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200693static inline struct scsi_cmnd *remove_SC(struct scsi_cmnd **SC,
694 struct scsi_cmnd *SCp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200696 struct scsi_cmnd *ptr, *prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 for (ptr = *SC, prev = NULL;
699 ptr && SCp!=ptr;
700 prev = ptr, ptr = SCNEXT(ptr))
701 ;
702
703 if (ptr) {
704 if (prev)
705 SCNEXT(prev) = SCNEXT(ptr);
706 else
707 *SC = SCNEXT(ptr);
708
709 SCNEXT(ptr)=NULL;
710 }
711
712 return ptr;
713}
714
David Howells7d12e782006-10-05 14:55:46 +0100715static irqreturn_t swintr(int irqno, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716{
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400717 struct Scsi_Host *shpnt = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 HOSTDATA(shpnt)->swint++;
720
721 SETPORT(DMACNTRL0, INTEN);
722 return IRQ_HANDLED;
723}
724
725struct Scsi_Host *aha152x_probe_one(struct aha152x_setup *setup)
726{
727 struct Scsi_Host *shpnt;
728
729 shpnt = scsi_host_alloc(&aha152x_driver_template, sizeof(struct aha152x_hostdata));
730 if (!shpnt) {
731 printk(KERN_ERR "aha152x: scsi_host_alloc failed\n");
732 return NULL;
733 }
734
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 memset(HOSTDATA(shpnt), 0, sizeof *HOSTDATA(shpnt));
James Bottomley5fcda422006-09-14 17:04:58 -0500736 INIT_LIST_HEAD(&HOSTDATA(shpnt)->host_list);
737
738 /* need to have host registered before triggering any interrupt */
739 list_add_tail(&HOSTDATA(shpnt)->host_list, &aha152x_host_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 shpnt->io_port = setup->io_port;
742 shpnt->n_io_port = IO_RANGE;
743 shpnt->irq = setup->irq;
744
745 if (!setup->tc1550) {
746 HOSTIOPORT0 = setup->io_port;
747 HOSTIOPORT1 = setup->io_port;
748 } else {
749 HOSTIOPORT0 = setup->io_port+0x10;
750 HOSTIOPORT1 = setup->io_port-0x10;
751 }
752
753 spin_lock_init(&QLOCK);
754 RECONNECT = setup->reconnect;
755 SYNCHRONOUS = setup->synchronous;
756 PARITY = setup->parity;
757 DELAY = setup->delay;
758 EXT_TRANS = setup->ext_trans;
759
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 SETPORT(SCSIID, setup->scsiid << 4);
761 shpnt->this_id = setup->scsiid;
762
763 if (setup->reconnect)
764 shpnt->can_queue = AHA152X_MAXQUEUE;
765
766 /* RESET OUT */
767 printk("aha152x: resetting bus...\n");
768 SETPORT(SCSISEQ, SCSIRSTO);
769 mdelay(256);
770 SETPORT(SCSISEQ, 0);
771 mdelay(DELAY);
772
773 reset_ports(shpnt);
774
775 printk(KERN_INFO
776 "aha152x%d%s: "
777 "vital data: rev=%x, "
778 "io=0x%03lx (0x%03lx/0x%03lx), "
779 "irq=%d, "
780 "scsiid=%d, "
781 "reconnect=%s, "
782 "parity=%s, "
783 "synchronous=%s, "
784 "delay=%d, "
785 "extended translation=%s\n",
786 shpnt->host_no, setup->tc1550 ? " (tc1550 mode)" : "",
787 GETPORT(REV) & 0x7,
788 shpnt->io_port, HOSTIOPORT0, HOSTIOPORT1,
789 shpnt->irq,
790 shpnt->this_id,
791 RECONNECT ? "enabled" : "disabled",
792 PARITY ? "enabled" : "disabled",
793 SYNCHRONOUS ? "enabled" : "disabled",
794 DELAY,
795 EXT_TRANS ? "enabled" : "disabled");
796
797 /* not expecting any interrupts */
798 SETPORT(SIMODE0, 0);
799 SETPORT(SIMODE1, 0);
800
Michael Opdenacker4909cc22014-03-05 06:09:41 +0100801 if (request_irq(shpnt->irq, swintr, IRQF_SHARED, "aha152x", shpnt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 printk(KERN_ERR "aha152x%d: irq %d busy.\n", shpnt->host_no, shpnt->irq);
803 goto out_host_put;
804 }
805
806 HOSTDATA(shpnt)->swint = 0;
807
808 printk(KERN_INFO "aha152x%d: trying software interrupt, ", shpnt->host_no);
809
810 mb();
811 SETPORT(DMACNTRL0, SWINT|INTEN);
812 mdelay(1000);
813 free_irq(shpnt->irq, shpnt);
814
815 if (!HOSTDATA(shpnt)->swint) {
816 if (TESTHI(DMASTAT, INTSTAT)) {
817 printk("lost.\n");
818 } else {
819 printk("failed.\n");
820 }
821
822 SETPORT(DMACNTRL0, INTEN);
823
824 printk(KERN_ERR "aha152x%d: irq %d possibly wrong. "
825 "Please verify.\n", shpnt->host_no, shpnt->irq);
826 goto out_host_put;
827 }
828 printk("ok.\n");
829
830
831 /* clear interrupts */
832 SETPORT(SSTAT0, 0x7f);
833 SETPORT(SSTAT1, 0xef);
834
Michael Opdenacker4909cc22014-03-05 06:09:41 +0100835 if (request_irq(shpnt->irq, intr, IRQF_SHARED, "aha152x", shpnt)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 printk(KERN_ERR "aha152x%d: failed to reassign irq %d.\n", shpnt->host_no, shpnt->irq);
837 goto out_host_put;
838 }
839
840 if( scsi_add_host(shpnt, NULL) ) {
841 free_irq(shpnt->irq, shpnt);
842 printk(KERN_ERR "aha152x%d: failed to add host.\n", shpnt->host_no);
843 goto out_host_put;
844 }
845
846 scsi_scan_host(shpnt);
847
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 return shpnt;
849
850out_host_put:
James Bottomley5fcda422006-09-14 17:04:58 -0500851 list_del(&HOSTDATA(shpnt)->host_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 scsi_host_put(shpnt);
853
854 return NULL;
855}
856
857void aha152x_release(struct Scsi_Host *shpnt)
858{
Matthew Wilcox1bd40572007-08-15 12:56:57 -0600859 if (!shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 return;
861
Matthew Wilcox1bd40572007-08-15 12:56:57 -0600862 scsi_remove_host(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 if (shpnt->irq)
864 free_irq(shpnt->irq, shpnt);
865
Christoph Hellwig3eb2ebc2018-10-19 14:09:44 +0200866#if !defined(AHA152X_PCMCIA)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 if (shpnt->io_port)
868 release_region(shpnt->io_port, IO_RANGE);
869#endif
870
871#ifdef __ISAPNP__
872 if (HOSTDATA(shpnt)->pnpdev)
873 pnp_device_detach(HOSTDATA(shpnt)->pnpdev);
874#endif
875
James Bottomley5fcda422006-09-14 17:04:58 -0500876 list_del(&HOSTDATA(shpnt)->host_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 scsi_host_put(shpnt);
878}
879
880
881/*
882 * setup controller to generate interrupts depending
883 * on current state (lock has to be acquired)
884 *
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200885 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886static int setup_expected_interrupts(struct Scsi_Host *shpnt)
887{
888 if(CURRENT_SC) {
889 CURRENT_SC->SCp.phase |= 1 << 16;
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 if(CURRENT_SC->SCp.phase & selecting) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 SETPORT(SSTAT1, SELTO);
893 SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0));
894 SETPORT(SIMODE1, ENSELTIMO);
895 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 SETPORT(SIMODE0, (CURRENT_SC->SCp.phase & spiordy) ? ENSPIORDY : 0);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200897 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899 } else if(STATE==seldi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 SETPORT(SIMODE0, 0);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200901 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0);
904 SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0));
905 }
906
907 if(!HOSTDATA(shpnt)->in_intr)
908 SETBITS(DMACNTRL0, INTEN);
909
910 return TESTHI(DMASTAT, INTSTAT);
911}
912
913
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200914/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 * Queue a command and setup interrupts for a free bus.
916 */
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200917static int aha152x_internal_queue(struct scsi_cmnd *SCpnt,
918 struct completion *complete,
919 int phase, void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
921 struct Scsi_Host *shpnt = SCpnt->device->host;
922 unsigned long flags;
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 SCpnt->scsi_done = done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 SCpnt->SCp.phase = not_issued | phase;
Boaz Harrosh0ceb4792007-07-29 22:22:04 +0300926 SCpnt->SCp.Status = 0x1; /* Ilegal status by SCSI standard */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 SCpnt->SCp.Message = 0;
928 SCpnt->SCp.have_data_in = 0;
929 SCpnt->SCp.sent_command = 0;
930
931 if(SCpnt->SCp.phase & (resetting|check_condition)) {
Harvey Harrison172c1222008-04-28 16:50:03 -0700932 if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200933 scmd_printk(KERN_ERR, SCpnt, "cannot reuse command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 return FAILED;
935 }
936 } else {
937 SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC);
Harvey Harrison172c1222008-04-28 16:50:03 -0700938 if(!SCpnt->host_scribble) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +0200939 scmd_printk(KERN_ERR, SCpnt, "allocation failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 return FAILED;
941 }
942 }
943
944 SCNEXT(SCpnt) = NULL;
Christoph Hellwig0f06bb32007-05-13 17:52:12 +0200945 SCSEM(SCpnt) = complete;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 /* setup scratch area
948 SCp.ptr : buffer pointer
949 SCp.this_residual : buffer length
950 SCp.buffer : next buffer
951 SCp.buffers_residual : left buffers in list
952 SCp.phase : current state of the command */
Boaz Harrosh66acdb02007-07-29 22:24:09 +0300953
Boaz Harrosh73d2cb12007-11-01 18:54:44 +0200954 if ((phase & resetting) || !scsi_sglist(SCpnt)) {
955 SCpnt->SCp.ptr = NULL;
956 SCpnt->SCp.this_residual = 0;
957 scsi_set_resid(SCpnt, 0);
Boaz Harrosh66acdb02007-07-29 22:24:09 +0300958 SCpnt->SCp.buffer = NULL;
959 SCpnt->SCp.buffers_residual = 0;
960 } else {
Boaz Harrosh23385452007-07-29 22:29:02 +0300961 scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
962 SCpnt->SCp.buffer = scsi_sglist(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 SCpnt->SCp.ptr = SG_ADDRESS(SCpnt->SCp.buffer);
964 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
Boaz Harrosh23385452007-07-29 22:29:02 +0300965 SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
Boaz Harrosh66acdb02007-07-29 22:24:09 +0300966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 DO_LOCK(flags);
969
970#if defined(AHA152X_STAT)
971 HOSTDATA(shpnt)->total_commands++;
972#endif
973
974 /* Turn led on, when this is the first command. */
975 HOSTDATA(shpnt)->commands++;
976 if (HOSTDATA(shpnt)->commands==1)
977 SETPORT(PORTA, 1);
978
979 append_SC(&ISSUE_SC, SCpnt);
980
981 if(!HOSTDATA(shpnt)->in_intr)
982 setup_expected_interrupts(shpnt);
983
984 DO_UNLOCK(flags);
985
986 return 0;
987}
988
989/*
990 * queue a command
991 *
992 */
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +0200993static int aha152x_queue_lck(struct scsi_cmnd *SCpnt,
994 void (*done)(struct scsi_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 return aha152x_internal_queue(SCpnt, NULL, 0, done);
997}
998
Jeff Garzikf2812332010-11-16 02:10:29 -0500999static DEF_SCSI_QCMD(aha152x_queue)
1000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 *
1004 */
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001005static void reset_done(struct scsi_cmnd *SCpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 if(SCSEM(SCpnt)) {
Christoph Hellwig0f06bb32007-05-13 17:52:12 +02001008 complete(SCSEM(SCpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 } else {
Christoph Hellwig0f06bb32007-05-13 17:52:12 +02001010 printk(KERN_ERR "aha152x: reset_done w/o completion\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012}
1013
1014/*
1015 * Abort a command
1016 *
1017 */
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001018static int aha152x_abort(struct scsi_cmnd *SCpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019{
1020 struct Scsi_Host *shpnt = SCpnt->device->host;
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001021 struct scsi_cmnd *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 unsigned long flags;
1023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 DO_LOCK(flags);
1025
1026 ptr=remove_SC(&ISSUE_SC, SCpnt);
1027
1028 if(ptr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 HOSTDATA(shpnt)->commands--;
1030 if (!HOSTDATA(shpnt)->commands)
1031 SETPORT(PORTA, 0);
1032 DO_UNLOCK(flags);
1033
1034 kfree(SCpnt->host_scribble);
1035 SCpnt->host_scribble=NULL;
1036
1037 return SUCCESS;
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001038 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040 DO_UNLOCK(flags);
1041
1042 /*
1043 * FIXME:
1044 * for current command: queue ABORT for message out and raise ATN
1045 * for disconnected command: pseudo SC with ABORT message or ABORT on reselection?
1046 *
1047 */
1048
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001049 scmd_printk(KERN_ERR, SCpnt,
1050 "cannot abort running or disconnected command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
1052 return FAILED;
1053}
1054
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055/*
1056 * Reset a device
1057 *
1058 */
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001059static int aha152x_device_reset(struct scsi_cmnd * SCpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060{
1061 struct Scsi_Host *shpnt = SCpnt->device->host;
Christoph Hellwig0f06bb32007-05-13 17:52:12 +02001062 DECLARE_COMPLETION(done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 int ret, issued, disconnected;
Christoph Hellwig631c2282006-07-08 20:42:15 +02001064 unsigned char old_cmd_len = SCpnt->cmd_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 unsigned long flags;
Christoph Hellwig0f06bb32007-05-13 17:52:12 +02001066 unsigned long timeleft;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 if(CURRENT_SC==SCpnt) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001069 scmd_printk(KERN_ERR, SCpnt, "cannot reset current device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 return FAILED;
1071 }
1072
1073 DO_LOCK(flags);
Harvey Harrison172c1222008-04-28 16:50:03 -07001074 issued = remove_SC(&ISSUE_SC, SCpnt) == NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 disconnected = issued && remove_SC(&DISCONNECTED_SC, SCpnt);
1076 DO_UNLOCK(flags);
1077
1078 SCpnt->cmd_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Christoph Hellwig0f06bb32007-05-13 17:52:12 +02001080 aha152x_internal_queue(SCpnt, &done, resetting, reset_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Christoph Hellwig0f06bb32007-05-13 17:52:12 +02001082 timeleft = wait_for_completion_timeout(&done, 100*HZ);
1083 if (!timeleft) {
1084 /* remove command from issue queue */
1085 DO_LOCK(flags);
1086 remove_SC(&ISSUE_SC, SCpnt);
1087 DO_UNLOCK(flags);
1088 }
Christoph Hellwig631c2282006-07-08 20:42:15 +02001089
1090 SCpnt->cmd_len = old_cmd_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 DO_LOCK(flags);
1093
1094 if(SCpnt->SCp.phase & resetted) {
1095 HOSTDATA(shpnt)->commands--;
1096 if (!HOSTDATA(shpnt)->commands)
1097 SETPORT(PORTA, 0);
1098 kfree(SCpnt->host_scribble);
1099 SCpnt->host_scribble=NULL;
1100
1101 ret = SUCCESS;
1102 } else {
1103 /* requeue */
1104 if(!issued) {
1105 append_SC(&ISSUE_SC, SCpnt);
1106 } else if(disconnected) {
1107 append_SC(&DISCONNECTED_SC, SCpnt);
1108 }
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 ret = FAILED;
1111 }
1112
1113 DO_UNLOCK(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 return ret;
1115}
1116
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001117static void free_hard_reset_SCs(struct Scsi_Host *shpnt,
1118 struct scsi_cmnd **SCs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001120 struct scsi_cmnd *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
1122 ptr=*SCs;
1123 while(ptr) {
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001124 struct scsi_cmnd *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
1126 if(SCDATA(ptr)) {
1127 next = SCNEXT(ptr);
1128 } else {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001129 scmd_printk(KERN_DEBUG, ptr,
1130 "queue corrupted at %p\n", ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 next = NULL;
1132 }
1133
1134 if (!ptr->device->soft_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 remove_SC(SCs, ptr);
1136 HOSTDATA(shpnt)->commands--;
1137 kfree(ptr->host_scribble);
1138 ptr->host_scribble=NULL;
1139 }
1140
1141 ptr = next;
1142 }
1143}
1144
1145/*
1146 * Reset the bus
1147 *
Hannes Reinecke819f80c2017-08-25 13:57:16 +02001148 * AIC-6260 has a hard reset (MRST signal), but apparently
1149 * one cannot trigger it via software. So live with
1150 * a soft reset; no-one seemed to have cared.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 */
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001152static int aha152x_bus_reset_host(struct Scsi_Host *shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 unsigned long flags;
1155
1156 DO_LOCK(flags);
1157
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 free_hard_reset_SCs(shpnt, &ISSUE_SC);
1159 free_hard_reset_SCs(shpnt, &DISCONNECTED_SC);
1160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 SETPORT(SCSISEQ, SCSIRSTO);
1162 mdelay(256);
1163 SETPORT(SCSISEQ, 0);
1164 mdelay(DELAY);
1165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 setup_expected_interrupts(shpnt);
1167 if(HOSTDATA(shpnt)->commands==0)
1168 SETPORT(PORTA, 0);
1169
1170 DO_UNLOCK(flags);
1171
1172 return SUCCESS;
1173}
1174
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001175/*
1176 * Reset the bus
1177 *
1178 */
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001179static int aha152x_bus_reset(struct scsi_cmnd *SCpnt)
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001180{
1181 return aha152x_bus_reset_host(SCpnt->device->host);
1182}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184/*
1185 * Restore default values to the AIC-6260 registers and reset the fifos
1186 *
1187 */
1188static void reset_ports(struct Scsi_Host *shpnt)
1189{
1190 unsigned long flags;
1191
1192 /* disable interrupts */
1193 SETPORT(DMACNTRL0, RSTFIFO);
1194
1195 SETPORT(SCSISEQ, 0);
1196
1197 SETPORT(SXFRCTL1, 0);
1198 SETPORT(SCSISIG, 0);
1199 SETRATE(0);
1200
1201 /* clear all interrupt conditions */
1202 SETPORT(SSTAT0, 0x7f);
1203 SETPORT(SSTAT1, 0xef);
1204
1205 SETPORT(SSTAT4, SYNCERR | FWERR | FRERR);
1206
1207 SETPORT(DMACNTRL0, 0);
1208 SETPORT(DMACNTRL1, 0);
1209
1210 SETPORT(BRSTCNTRL, 0xf1);
1211
1212 /* clear SCSI fifos and transfer count */
1213 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
1214 SETPORT(SXFRCTL0, CH1);
1215
1216 DO_LOCK(flags);
1217 setup_expected_interrupts(shpnt);
1218 DO_UNLOCK(flags);
1219}
1220
1221/*
1222 * Reset the host (bus and controller)
1223 *
1224 */
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001225int aha152x_host_reset_host(struct Scsi_Host *shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001227 aha152x_bus_reset_host(shpnt);
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001228 reset_ports(shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 return SUCCESS;
1231}
1232
1233/*
1234 * Return the "logical geometry"
1235 *
1236 */
1237static int aha152x_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1238 sector_t capacity, int *info_array)
1239{
1240 struct Scsi_Host *shpnt = sdev->host;
1241
1242 /* try default translation */
1243 info_array[0] = 64;
1244 info_array[1] = 32;
1245 info_array[2] = (unsigned long)capacity / (64 * 32);
1246
1247 /* for disks >1GB do some guessing */
1248 if (info_array[2] >= 1024) {
1249 int info[3];
1250
1251 /* try to figure out the geometry from the partition table */
1252 if (scsicam_bios_param(bdev, capacity, info) < 0 ||
1253 !((info[0] == 64 && info[1] == 32) || (info[0] == 255 && info[1] == 63))) {
1254 if (EXT_TRANS) {
1255 printk(KERN_NOTICE
1256 "aha152x: unable to verify geometry for disk with >1GB.\n"
1257 " using extended translation.\n");
1258 info_array[0] = 255;
1259 info_array[1] = 63;
1260 info_array[2] = (unsigned long)capacity / (255 * 63);
1261 } else {
1262 printk(KERN_NOTICE
1263 "aha152x: unable to verify geometry for disk with >1GB.\n"
1264 " Using default translation. Please verify yourself.\n"
1265 " Perhaps you need to enable extended translation in the driver.\n"
1266 " See Documentation/scsi/aha152x.txt for details.\n");
1267 }
1268 } else {
1269 info_array[0] = info[0];
1270 info_array[1] = info[1];
1271 info_array[2] = info[2];
1272
1273 if (info[0] == 255 && !EXT_TRANS) {
1274 printk(KERN_NOTICE
1275 "aha152x: current partition table is using extended translation.\n"
1276 " using it also, although it's not explicitly enabled.\n");
1277 }
1278 }
1279 }
1280
1281 return 0;
1282}
1283
1284/*
1285 * Internal done function
1286 *
1287 */
1288static void done(struct Scsi_Host *shpnt, int error)
1289{
1290 if (CURRENT_SC) {
1291 if(DONE_SC)
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001292 scmd_printk(KERN_ERR, CURRENT_SC,
1293 "there's already a completed command %p "
1294 "- will cause abort\n", DONE_SC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 DONE_SC = CURRENT_SC;
1297 CURRENT_SC = NULL;
1298 DONE_SC->result = error;
1299 } else
1300 printk(KERN_ERR "aha152x: done() called outside of command\n");
1301}
1302
1303static struct work_struct aha152x_tq;
1304
1305/*
1306 * Run service completions on the card with interrupts enabled.
1307 *
1308 */
David Howellsc4028952006-11-22 14:57:56 +00001309static void run(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310{
James Bottomley5fcda422006-09-14 17:04:58 -05001311 struct aha152x_hostdata *hd;
1312
1313 list_for_each_entry(hd, &aha152x_host_list, host_list) {
1314 struct Scsi_Host *shost = container_of((void *)hd, struct Scsi_Host, hostdata);
1315
1316 is_complete(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 }
1318}
1319
1320/*
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001321 * Interrupt handler
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 *
1323 */
David Howells7d12e782006-10-05 14:55:46 +01001324static irqreturn_t intr(int irqno, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Jeff Garzike19166d2008-04-18 19:22:52 -04001326 struct Scsi_Host *shpnt = dev_id;
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001327 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 unsigned char rev, dmacntrl0;
1329
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 /*
1331 * Read a couple of registers that are known to not be all 1's. If
1332 * we read all 1's (-1), that means that either:
1333 *
1334 * a. The host adapter chip has gone bad, and we cannot control it,
1335 * OR
1336 * b. The host adapter is a PCMCIA card that has been ejected
1337 *
1338 * In either case, we cannot do anything with the host adapter at
1339 * this point in time. So just ignore the interrupt and return.
1340 * In the latter case, the interrupt might actually be meant for
1341 * someone else sharing this IRQ, and that driver will handle it.
1342 */
1343 rev = GETPORT(REV);
1344 dmacntrl0 = GETPORT(DMACNTRL0);
1345 if ((rev == 0xFF) && (dmacntrl0 == 0xFF))
1346 return IRQ_NONE;
1347
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001348 if( TESTLO(DMASTAT, INTSTAT) )
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001349 return IRQ_NONE;
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 /* no more interrupts from the controller, while we're busy.
1352 INTEN is restored by the BH handler */
1353 CLRBITS(DMACNTRL0, INTEN);
1354
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001355 DO_LOCK(flags);
1356 if( HOSTDATA(shpnt)->service==0 ) {
1357 HOSTDATA(shpnt)->service=1;
1358
1359 /* Poke the BH handler */
David Howellsc4028952006-11-22 14:57:56 +00001360 INIT_WORK(&aha152x_tq, run);
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001361 schedule_work(&aha152x_tq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 }
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01001363 DO_UNLOCK(flags);
1364
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 return IRQ_HANDLED;
1366}
1367
1368/*
1369 * busfree phase
1370 * - handle completition/disconnection/error of current command
1371 * - start selection for next command (if any)
1372 */
1373static void busfree_run(struct Scsi_Host *shpnt)
1374{
1375 unsigned long flags;
1376#if defined(AHA152X_STAT)
1377 int action=0;
1378#endif
1379
1380 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
1381 SETPORT(SXFRCTL0, CH1);
1382
1383 SETPORT(SSTAT1, CLRBUSFREE);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 if(CURRENT_SC) {
1386#if defined(AHA152X_STAT)
1387 action++;
1388#endif
1389 CURRENT_SC->SCp.phase &= ~syncneg;
1390
1391 if(CURRENT_SC->SCp.phase & completed) {
1392 /* target sent COMMAND COMPLETE */
1393 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16));
1394
1395 } else if(CURRENT_SC->SCp.phase & aborted) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_ABORT << 16));
1397
1398 } else if(CURRENT_SC->SCp.phase & resetted) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_RESET << 16));
1400
1401 } else if(CURRENT_SC->SCp.phase & disconnected) {
1402 /* target sent DISCONNECT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403#if defined(AHA152X_STAT)
1404 HOSTDATA(shpnt)->disconnections++;
1405#endif
1406 append_SC(&DISCONNECTED_SC, CURRENT_SC);
1407 CURRENT_SC->SCp.phase |= 1 << 16;
1408 CURRENT_SC = NULL;
1409
1410 } else {
1411 done(shpnt, DID_ERROR << 16);
1412 }
1413#if defined(AHA152X_STAT)
1414 } else {
1415 HOSTDATA(shpnt)->busfree_without_old_command++;
1416#endif
1417 }
1418
1419 DO_LOCK(flags);
1420
1421 if(DONE_SC) {
1422#if defined(AHA152X_STAT)
1423 action++;
1424#endif
1425
1426 if(DONE_SC->SCp.phase & check_condition) {
Christoph Hellwig5e13cdf2006-07-08 20:39:30 +02001427 struct scsi_cmnd *cmd = HOSTDATA(shpnt)->done_SC;
1428 struct aha152x_scdata *sc = SCDATA(cmd);
1429
Boaz Harrosh73d2cb12007-11-01 18:54:44 +02001430 scsi_eh_restore_cmnd(cmd, &sc->ses);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Boaz Harrosh0ceb4792007-07-29 22:22:04 +03001432 cmd->SCp.Status = SAM_STAT_CHECK_CONDITION;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 HOSTDATA(shpnt)->commands--;
1435 if (!HOSTDATA(shpnt)->commands)
1436 SETPORT(PORTA, 0); /* turn led off */
Boaz Harrosh0ceb4792007-07-29 22:22:04 +03001437 } else if(DONE_SC->SCp.Status==SAM_STAT_CHECK_CONDITION) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438#if defined(AHA152X_STAT)
1439 HOSTDATA(shpnt)->busfree_with_check_condition++;
1440#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Boaz Harrosh0ceb4792007-07-29 22:22:04 +03001442 if(!(DONE_SC->SCp.phase & not_issued)) {
Boaz Harrosh45333ff2007-07-29 22:27:06 +03001443 struct aha152x_scdata *sc;
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001444 struct scsi_cmnd *ptr = DONE_SC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 DONE_SC=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Boaz Harrosh45333ff2007-07-29 22:27:06 +03001447 sc = SCDATA(ptr);
1448 /* It was allocated in aha152x_internal_queue? */
1449 BUG_ON(!sc);
Boaz Harrosh73d2cb12007-11-01 18:54:44 +02001450 scsi_eh_prep_cmnd(ptr, &sc->ses, NULL, 0, ~0);
Boaz Harrosh45333ff2007-07-29 22:27:06 +03001451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 DO_UNLOCK(flags);
1453 aha152x_internal_queue(ptr, NULL, check_condition, ptr->scsi_done);
1454 DO_LOCK(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 }
1456 }
1457
1458 if(DONE_SC && DONE_SC->scsi_done) {
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02001459 struct scsi_cmnd *ptr = DONE_SC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 DONE_SC=NULL;
1461
1462 /* turn led off, when no commands are in the driver */
1463 HOSTDATA(shpnt)->commands--;
1464 if (!HOSTDATA(shpnt)->commands)
1465 SETPORT(PORTA, 0); /* turn led off */
1466
1467 if(ptr->scsi_done != reset_done) {
1468 kfree(ptr->host_scribble);
1469 ptr->host_scribble=NULL;
1470 }
1471
1472 DO_UNLOCK(flags);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001473 ptr->scsi_done(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 DO_LOCK(flags);
1475 }
1476
1477 DONE_SC=NULL;
1478#if defined(AHA152X_STAT)
1479 } else {
1480 HOSTDATA(shpnt)->busfree_without_done_command++;
1481#endif
1482 }
1483
1484 if(ISSUE_SC)
1485 CURRENT_SC = remove_first_SC(&ISSUE_SC);
1486
1487 DO_UNLOCK(flags);
1488
1489 if(CURRENT_SC) {
1490#if defined(AHA152X_STAT)
1491 action++;
1492#endif
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001493 CURRENT_SC->SCp.phase |= selecting;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495 /* clear selection timeout */
1496 SETPORT(SSTAT1, SELTO);
1497
1498 SETPORT(SCSIID, (shpnt->this_id << OID_) | CURRENT_SC->device->id);
1499 SETPORT(SXFRCTL1, (PARITY ? ENSPCHK : 0 ) | ENSTIMER);
1500 SETPORT(SCSISEQ, ENSELO | ENAUTOATNO | (DISCONNECTED_SC ? ENRESELI : 0));
1501 } else {
1502#if defined(AHA152X_STAT)
1503 HOSTDATA(shpnt)->busfree_without_new_command++;
1504#endif
1505 SETPORT(SCSISEQ, DISCONNECTED_SC ? ENRESELI : 0);
1506 }
1507
1508#if defined(AHA152X_STAT)
1509 if(!action)
1510 HOSTDATA(shpnt)->busfree_without_any_action++;
1511#endif
1512}
1513
1514/*
1515 * Selection done (OUT)
1516 * - queue IDENTIFY message and SDTR to selected target for message out
1517 * (ATN asserted automagically via ENAUTOATNO in busfree())
1518 */
1519static void seldo_run(struct Scsi_Host *shpnt)
1520{
1521 SETPORT(SCSISIG, 0);
1522 SETPORT(SSTAT1, CLRBUSFREE);
1523 SETPORT(SSTAT1, CLRPHASECHG);
1524
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001525 CURRENT_SC->SCp.phase &= ~(selecting|not_issued);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 SETPORT(SCSISEQ, 0);
1528
1529 if (TESTLO(SSTAT0, SELDO)) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001530 scmd_printk(KERN_ERR, CURRENT_SC,
1531 "aha152x: passing bus free condition\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 done(shpnt, DID_NO_CONNECT << 16);
1533 return;
1534 }
1535
1536 SETPORT(SSTAT0, CLRSELDO);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001537
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
1539
1540 if (CURRENT_SC->SCp.phase & aborting) {
1541 ADDMSGO(ABORT);
1542 } else if (CURRENT_SC->SCp.phase & resetting) {
1543 ADDMSGO(BUS_DEVICE_RESET);
1544 } else if (SYNCNEG==0 && SYNCHRONOUS) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001545 CURRENT_SC->SCp.phase |= syncneg;
Matthew Wilcox6ea3c0b2006-02-07 07:54:46 -07001546 MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 SYNCNEG=1; /* negotiation in progress */
1548 }
1549
1550 SETRATE(SYNCRATE);
1551}
1552
1553/*
1554 * Selection timeout
1555 * - return command to mid-level with failure cause
1556 *
1557 */
1558static void selto_run(struct Scsi_Host *shpnt)
1559{
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001560 SETPORT(SCSISEQ, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 SETPORT(SSTAT1, CLRSELTIMO);
1562
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001563 if (!CURRENT_SC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001566 CURRENT_SC->SCp.phase &= ~selecting;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001568 if (CURRENT_SC->SCp.phase & aborted)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 done(shpnt, DID_ABORT << 16);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001570 else if (TESTLO(SSTAT0, SELINGO))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 done(shpnt, DID_BUS_BUSY << 16);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001572 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 /* ARBITRATION won, but SELECTION failed */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 done(shpnt, DID_NO_CONNECT << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575}
1576
1577/*
1578 * Selection in done
1579 * - put current command back to issue queue
1580 * (reconnection of a disconnected nexus instead
1581 * of successful selection out)
1582 *
1583 */
1584static void seldi_run(struct Scsi_Host *shpnt)
1585{
1586 int selid;
1587 int target;
1588 unsigned long flags;
1589
1590 SETPORT(SCSISIG, 0);
1591 SETPORT(SSTAT0, CLRSELDI);
1592 SETPORT(SSTAT1, CLRBUSFREE);
1593 SETPORT(SSTAT1, CLRPHASECHG);
1594
1595 if(CURRENT_SC) {
1596 if(!(CURRENT_SC->SCp.phase & not_issued))
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001597 scmd_printk(KERN_ERR, CURRENT_SC,
1598 "command should not have been issued yet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
1600 DO_LOCK(flags);
1601 append_SC(&ISSUE_SC, CURRENT_SC);
1602 DO_UNLOCK(flags);
1603
1604 CURRENT_SC = NULL;
1605 }
1606
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001607 if (!DISCONNECTED_SC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610 RECONN_TARGET=-1;
1611
1612 selid = GETPORT(SELID) & ~(1 << shpnt->this_id);
1613
1614 if (selid==0) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001615 shost_printk(KERN_INFO, shpnt,
1616 "target id unknown (%02x)\n", selid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 return;
1618 }
1619
1620 for(target=7; !(selid & (1 << target)); target--)
1621 ;
1622
1623 if(selid & ~(1 << target)) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001624 shost_printk(KERN_INFO, shpnt,
1625 "multiple targets reconnected (%02x)\n", selid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 }
1627
1628
1629 SETPORT(SCSIID, (shpnt->this_id << OID_) | target);
1630 SETPORT(SCSISEQ, 0);
1631
1632 SETRATE(HOSTDATA(shpnt)->syncrate[target]);
1633
1634 RECONN_TARGET=target;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635}
1636
1637/*
1638 * message in phase
1639 * - handle initial message after reconnection to identify
1640 * reconnecting nexus
1641 * - queue command on DISCONNECTED_SC on DISCONNECT message
1642 * - set completed flag on COMMAND COMPLETE
1643 * (other completition code moved to busfree_run)
1644 * - handle response to SDTR
1645 * - clear synchronous transfer agreements on BUS RESET
1646 *
1647 * FIXME: what about SAVE POINTERS, RESTORE POINTERS?
1648 *
1649 */
1650static void msgi_run(struct Scsi_Host *shpnt)
1651{
1652 for(;;) {
1653 int sstat1 = GETPORT(SSTAT1);
1654
1655 if(sstat1 & (PHASECHG|PHASEMIS|BUSFREE) || !(sstat1 & REQINIT))
1656 return;
1657
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001658 if (TESTLO(SSTAT0, SPIORDY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661 ADDMSGI(GETPORT(SCSIDAT));
1662
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 if(!CURRENT_SC) {
1664 if(LASTSTATE!=seldi) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001665 shost_printk(KERN_ERR, shpnt,
1666 "message in w/o current command"
1667 " not after reselection\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 }
1669
1670 /*
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001671 * Handle reselection
1672 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 if(!(MSGI(0) & IDENTIFY_BASE)) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001674 shost_printk(KERN_ERR, shpnt,
1675 "target didn't identify after reselection\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 continue;
1677 }
1678
1679 CURRENT_SC = remove_lun_SC(&DISCONNECTED_SC, RECONN_TARGET, MSGI(0) & 0x3f);
1680
1681 if (!CURRENT_SC) {
1682 show_queues(shpnt);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001683 shost_printk(KERN_ERR, shpnt,
1684 "no disconnected command"
1685 " for target %d/%d\n",
1686 RECONN_TARGET, MSGI(0) & 0x3f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 continue;
1688 }
1689
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 CURRENT_SC->SCp.Message = MSGI(0);
1691 CURRENT_SC->SCp.phase &= ~disconnected;
1692
1693 MSGILEN=0;
1694
1695 /* next message if any */
1696 continue;
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
1699 CURRENT_SC->SCp.Message = MSGI(0);
1700
1701 switch (MSGI(0)) {
1702 case DISCONNECT:
1703 if (!RECONNECT)
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001704 scmd_printk(KERN_WARNING, CURRENT_SC,
1705 "target was not allowed to disconnect\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
1707 CURRENT_SC->SCp.phase |= disconnected;
1708 break;
1709
1710 case COMMAND_COMPLETE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 CURRENT_SC->SCp.phase |= completed;
1712 break;
1713
1714 case MESSAGE_REJECT:
1715 if (SYNCNEG==1) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001716 scmd_printk(KERN_INFO, CURRENT_SC,
1717 "Synchronous Data Transfer Request"
1718 " was rejected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 SYNCNEG=2; /* negotiation completed */
1720 } else
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001721 scmd_printk(KERN_INFO, CURRENT_SC,
1722 "inbound message (MESSAGE REJECT)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 break;
1724
1725 case SAVE_POINTERS:
1726 break;
1727
1728 case RESTORE_POINTERS:
1729 break;
1730
1731 case EXTENDED_MESSAGE:
1732 if(MSGILEN<2 || MSGILEN<MSGI(1)+2) {
1733 /* not yet completed */
1734 continue;
1735 }
1736
1737 switch (MSGI(2)) {
1738 case EXTENDED_SDTR:
1739 {
1740 long ticks;
1741
1742 if (MSGI(1) != 3) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001743 scmd_printk(KERN_ERR, CURRENT_SC,
1744 "SDTR message length!=3\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 break;
1746 }
1747
1748 if (!HOSTDATA(shpnt)->synchronous)
1749 break;
1750
1751 printk(INFO_LEAD, CMDINFO(CURRENT_SC));
Matthew Wilcox1abfd372005-12-15 16:22:01 -05001752 spi_print_msg(&MSGI(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 printk("\n");
1754
1755 ticks = (MSGI(3) * 4 + 49) / 50;
1756
1757 if (syncneg) {
1758 /* negotiation in progress */
1759 if (ticks > 9 || MSGI(4) < 1 || MSGI(4) > 8) {
1760 ADDMSGO(MESSAGE_REJECT);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001761 scmd_printk(KERN_INFO,
1762 CURRENT_SC,
1763 "received Synchronous Data Transfer Request invalid - rejected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 break;
1765 }
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
1768 } else if (ticks <= 9 && MSGI(4) >= 1) {
1769 ADDMSGO(EXTENDED_MESSAGE);
1770 ADDMSGO(3);
1771 ADDMSGO(EXTENDED_SDTR);
1772 if (ticks < 4) {
1773 ticks = 4;
1774 ADDMSGO(50);
1775 } else
1776 ADDMSGO(MSGI(3));
1777
1778 if (MSGI(4) > 8)
1779 MSGI(4) = 8;
1780
1781 ADDMSGO(MSGI(4));
1782
1783 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
1784 } else {
1785 /* requested SDTR is too slow, do it asynchronously */
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001786 scmd_printk(KERN_INFO,
1787 CURRENT_SC,
1788 "Synchronous Data Transfer Request too slow - Rejecting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 ADDMSGO(MESSAGE_REJECT);
1790 }
1791
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001792 /* negotiation completed */
1793 SYNCNEG=2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 SETRATE(SYNCRATE);
1795 }
1796 break;
1797
1798 case BUS_DEVICE_RESET:
1799 {
1800 int i;
1801
1802 for(i=0; i<8; i++) {
1803 HOSTDATA(shpnt)->syncrate[i]=0;
1804 HOSTDATA(shpnt)->syncneg[i]=0;
1805 }
1806
1807 }
1808 break;
1809
1810 case EXTENDED_MODIFY_DATA_POINTER:
1811 case EXTENDED_EXTENDED_IDENTIFY:
1812 case EXTENDED_WDTR:
1813 default:
1814 ADDMSGO(MESSAGE_REJECT);
1815 break;
1816 }
1817 break;
1818 }
1819
1820 MSGILEN=0;
1821 }
1822}
1823
1824static void msgi_end(struct Scsi_Host *shpnt)
1825{
1826 if(MSGILEN>0)
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001827 scmd_printk(KERN_WARNING, CURRENT_SC,
1828 "target left before message completed (%d)\n",
1829 MSGILEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001831 if (MSGOLEN > 0 && !(GETPORT(SSTAT1) & BUSFREE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 SETPORT(SCSISIG, P_MSGI | SIG_ATNO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833}
1834
1835/*
1836 * message out phase
1837 *
1838 */
1839static void msgo_init(struct Scsi_Host *shpnt)
1840{
1841 if(MSGOLEN==0) {
1842 if((CURRENT_SC->SCp.phase & syncneg) && SYNCNEG==2 && SYNCRATE==0) {
1843 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
1844 } else {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001845 scmd_printk(KERN_INFO, CURRENT_SC,
1846 "unexpected MESSAGE OUT phase; rejecting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 ADDMSGO(MESSAGE_REJECT);
1848 }
1849 }
1850
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851}
1852
1853/*
1854 * message out phase
1855 *
1856 */
1857static void msgo_run(struct Scsi_Host *shpnt)
1858{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 while(MSGO_I<MSGOLEN) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001860 if (TESTLO(SSTAT0, SPIORDY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
1863 if (MSGO_I==MSGOLEN-1) {
1864 /* Leave MESSAGE OUT after transfer */
1865 SETPORT(SSTAT1, CLRATNO);
1866 }
1867
1868
1869 if (MSGO(MSGO_I) & IDENTIFY_BASE)
1870 CURRENT_SC->SCp.phase |= identified;
1871
1872 if (MSGO(MSGO_I)==ABORT)
1873 CURRENT_SC->SCp.phase |= aborted;
1874
1875 if (MSGO(MSGO_I)==BUS_DEVICE_RESET)
1876 CURRENT_SC->SCp.phase |= resetted;
1877
1878 SETPORT(SCSIDAT, MSGO(MSGO_I++));
1879 }
1880}
1881
1882static void msgo_end(struct Scsi_Host *shpnt)
1883{
1884 if(MSGO_I<MSGOLEN) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001885 scmd_printk(KERN_ERR, CURRENT_SC,
1886 "message sent incompletely (%d/%d)\n",
1887 MSGO_I, MSGOLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 if(SYNCNEG==1) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001889 scmd_printk(KERN_INFO, CURRENT_SC,
1890 "Synchronous Data Transfer Request was rejected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 SYNCNEG=2;
1892 }
1893 }
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001894
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 MSGO_I = 0;
1896 MSGOLEN = 0;
1897}
1898
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001899/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 * command phase
1901 *
1902 */
1903static void cmd_init(struct Scsi_Host *shpnt)
1904{
1905 if (CURRENT_SC->SCp.sent_command) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001906 scmd_printk(KERN_ERR, CURRENT_SC,
1907 "command already sent\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 done(shpnt, DID_ERROR << 16);
1909 return;
1910 }
1911
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 CMD_I=0;
1913}
1914
1915/*
1916 * command phase
1917 *
1918 */
1919static void cmd_run(struct Scsi_Host *shpnt)
1920{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 while(CMD_I<CURRENT_SC->cmd_len) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001922 if (TESTLO(SSTAT0, SPIORDY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
1925 SETPORT(SCSIDAT, CURRENT_SC->cmnd[CMD_I++]);
1926 }
1927}
1928
1929static void cmd_end(struct Scsi_Host *shpnt)
1930{
1931 if(CMD_I<CURRENT_SC->cmd_len)
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001932 scmd_printk(KERN_ERR, CURRENT_SC,
1933 "command sent incompletely (%d/%d)\n",
1934 CMD_I, CURRENT_SC->cmd_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 else
1936 CURRENT_SC->SCp.sent_command++;
1937}
1938
1939/*
1940 * status phase
1941 *
1942 */
1943static void status_run(struct Scsi_Host *shpnt)
1944{
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001945 if (TESTLO(SSTAT0, SPIORDY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
1948 CURRENT_SC->SCp.Status = GETPORT(SCSIDAT);
1949
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950}
1951
1952/*
1953 * data in phase
1954 *
1955 */
1956static void datai_init(struct Scsi_Host *shpnt)
1957{
1958 SETPORT(DMACNTRL0, RSTFIFO);
1959 SETPORT(DMACNTRL0, RSTFIFO|ENDMA);
1960
1961 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
1962 SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
1963
1964 SETPORT(SIMODE0, 0);
1965 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE);
1966
1967 DATA_LEN=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968}
1969
1970static void datai_run(struct Scsi_Host *shpnt)
1971{
1972 unsigned long the_time;
1973 int fifodata, data_count;
1974
1975 /*
1976 * loop while the phase persists or the fifos are not empty
1977 *
1978 */
1979 while(TESTLO(DMASTAT, INTSTAT) || TESTLO(DMASTAT, DFIFOEMP) || TESTLO(SSTAT2, SEMPTY)) {
1980 /* FIXME: maybe this should be done by setting up
1981 * STCNT to trigger ENSWRAP interrupt, instead of
1982 * polling for DFIFOFULL
1983 */
1984 the_time=jiffies + 100*HZ;
1985 while(TESTLO(DMASTAT, DFIFOFULL|INTSTAT) && time_before(jiffies,the_time))
1986 barrier();
1987
1988 if(TESTLO(DMASTAT, DFIFOFULL|INTSTAT)) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02001989 scmd_printk(KERN_ERR, CURRENT_SC, "datai timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 break;
1991 }
1992
1993 if(TESTHI(DMASTAT, DFIFOFULL)) {
1994 fifodata = 128;
1995 } else {
1996 the_time=jiffies + 100*HZ;
1997 while(TESTLO(SSTAT2, SEMPTY) && time_before(jiffies,the_time))
1998 barrier();
1999
2000 if(TESTLO(SSTAT2, SEMPTY)) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002001 scmd_printk(KERN_ERR, CURRENT_SC,
2002 "datai sempty timeout");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 break;
2004 }
2005
2006 fifodata = GETPORT(FIFOSTAT);
2007 }
2008
2009 if(CURRENT_SC->SCp.this_residual>0) {
2010 while(fifodata>0 && CURRENT_SC->SCp.this_residual>0) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002011 data_count = fifodata > CURRENT_SC->SCp.this_residual ?
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 CURRENT_SC->SCp.this_residual :
2013 fifodata;
2014 fifodata -= data_count;
2015
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002016 if (data_count & 1) {
2017 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2018 *CURRENT_SC->SCp.ptr++ = GETPORT(DATAPORT);
2019 CURRENT_SC->SCp.this_residual--;
2020 DATA_LEN++;
2021 SETPORT(DMACNTRL0, ENDMA);
2022 }
2023
2024 if (data_count > 1) {
2025 data_count >>= 1;
2026 insw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
2027 CURRENT_SC->SCp.ptr += 2 * data_count;
2028 CURRENT_SC->SCp.this_residual -= 2 * data_count;
2029 DATA_LEN += 2 * data_count;
2030 }
2031
2032 if (CURRENT_SC->SCp.this_residual == 0 &&
2033 CURRENT_SC->SCp.buffers_residual > 0) {
2034 /* advance to next buffer */
2035 CURRENT_SC->SCp.buffers_residual--;
2036 CURRENT_SC->SCp.buffer++;
2037 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
2038 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
2039 }
2040 }
2041 } else if (fifodata > 0) {
2042 scmd_printk(KERN_ERR, CURRENT_SC,
2043 "no buffers left for %d(%d) bytes"
2044 " (data overrun!?)\n",
2045 fifodata, GETPORT(FIFOSTAT));
2046 SETPORT(DMACNTRL0, ENDMA|_8BIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 while(fifodata>0) {
2048 int data;
2049 data=GETPORT(DATAPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 fifodata--;
2051 DATA_LEN++;
2052 }
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002053 SETPORT(DMACNTRL0, ENDMA|_8BIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 }
2055 }
2056
2057 if(TESTLO(DMASTAT, INTSTAT) ||
2058 TESTLO(DMASTAT, DFIFOEMP) ||
2059 TESTLO(SSTAT2, SEMPTY) ||
2060 GETPORT(FIFOSTAT)>0) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002061 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 * something went wrong, if there's something left in the fifos
2063 * or the phase didn't change
2064 */
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002065 scmd_printk(KERN_ERR, CURRENT_SC,
2066 "fifos should be empty and phase should have changed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 }
2068
2069 if(DATA_LEN!=GETSTCNT()) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002070 scmd_printk(KERN_ERR, CURRENT_SC,
2071 "manual transfer count differs from automatic "
2072 "(count=%d;stcnt=%d;diff=%d;fifostat=%d)",
2073 DATA_LEN, GETSTCNT(), GETSTCNT()-DATA_LEN,
2074 GETPORT(FIFOSTAT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 mdelay(10000);
2076 }
2077}
2078
2079static void datai_end(struct Scsi_Host *shpnt)
2080{
Boaz Harrosh23385452007-07-29 22:29:02 +03002081 CMD_INC_RESID(CURRENT_SC, -GETSTCNT());
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
2084 SETPORT(DMACNTRL0, 0);
2085}
2086
2087/*
2088 * data out phase
2089 *
2090 */
2091static void datao_init(struct Scsi_Host *shpnt)
2092{
2093 SETPORT(DMACNTRL0, WRITE_READ | RSTFIFO);
2094 SETPORT(DMACNTRL0, WRITE_READ | ENDMA);
2095
2096 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
2097 SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
2098
2099 SETPORT(SIMODE0, 0);
2100 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE );
2101
Boaz Harrosh23385452007-07-29 22:29:02 +03002102 DATA_LEN = scsi_get_resid(CURRENT_SC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103}
2104
2105static void datao_run(struct Scsi_Host *shpnt)
2106{
2107 unsigned long the_time;
2108 int data_count;
2109
2110 /* until phase changes or all data sent */
2111 while(TESTLO(DMASTAT, INTSTAT) && CURRENT_SC->SCp.this_residual>0) {
2112 data_count = 128;
2113 if(data_count > CURRENT_SC->SCp.this_residual)
2114 data_count=CURRENT_SC->SCp.this_residual;
2115
2116 if(TESTLO(DMASTAT, DFIFOEMP)) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002117 scmd_printk(KERN_ERR, CURRENT_SC,
2118 "datao fifo not empty (%d)",
2119 GETPORT(FIFOSTAT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 break;
2121 }
2122
2123 if(data_count & 1) {
2124 SETPORT(DMACNTRL0,WRITE_READ|ENDMA|_8BIT);
2125 SETPORT(DATAPORT, *CURRENT_SC->SCp.ptr++);
2126 CURRENT_SC->SCp.this_residual--;
Boaz Harrosh23385452007-07-29 22:29:02 +03002127 CMD_INC_RESID(CURRENT_SC, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 SETPORT(DMACNTRL0,WRITE_READ|ENDMA);
2129 }
2130
2131 if(data_count > 1) {
2132 data_count >>= 1;
2133 outsw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
2134 CURRENT_SC->SCp.ptr += 2 * data_count;
2135 CURRENT_SC->SCp.this_residual -= 2 * data_count;
Boaz Harrosh23385452007-07-29 22:29:02 +03002136 CMD_INC_RESID(CURRENT_SC, -2 * data_count);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
2139 if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) {
2140 /* advance to next buffer */
2141 CURRENT_SC->SCp.buffers_residual--;
2142 CURRENT_SC->SCp.buffer++;
2143 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
2144 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
2145 }
2146
2147 the_time=jiffies + 100*HZ;
2148 while(TESTLO(DMASTAT, DFIFOEMP|INTSTAT) && time_before(jiffies,the_time))
2149 barrier();
2150
2151 if(TESTLO(DMASTAT, DFIFOEMP|INTSTAT)) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002152 scmd_printk(KERN_ERR, CURRENT_SC, "dataout timeout\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 break;
2154 }
2155 }
2156}
2157
2158static void datao_end(struct Scsi_Host *shpnt)
2159{
2160 if(TESTLO(DMASTAT, DFIFOEMP)) {
Boaz Harrosh23385452007-07-29 22:29:02 +03002161 int data_count = (DATA_LEN - scsi_get_resid(CURRENT_SC)) -
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002162 GETSTCNT();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Boaz Harrosh23385452007-07-29 22:29:02 +03002164 CMD_INC_RESID(CURRENT_SC, data_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
Boaz Harrosh23385452007-07-29 22:29:02 +03002166 data_count -= CURRENT_SC->SCp.ptr -
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002167 SG_ADDRESS(CURRENT_SC->SCp.buffer);
Boaz Harrosh23385452007-07-29 22:29:02 +03002168 while(data_count>0) {
2169 CURRENT_SC->SCp.buffer--;
2170 CURRENT_SC->SCp.buffers_residual++;
2171 data_count -= CURRENT_SC->SCp.buffer->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 }
Boaz Harrosh23385452007-07-29 22:29:02 +03002173 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer) -
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002174 data_count;
Boaz Harrosh23385452007-07-29 22:29:02 +03002175 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length +
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002176 data_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 }
2178
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
2180 SETPORT(SXFRCTL0, CH1);
2181
2182 SETPORT(DMACNTRL0, 0);
2183}
2184
2185/*
2186 * figure out what state we're in
2187 *
2188 */
2189static int update_state(struct Scsi_Host *shpnt)
2190{
2191 int dataphase=0;
2192 unsigned int stat0 = GETPORT(SSTAT0);
2193 unsigned int stat1 = GETPORT(SSTAT1);
2194
2195 PREVSTATE = STATE;
2196 STATE=unknown;
2197
2198 if(stat1 & SCSIRSTI) {
2199 STATE=rsti;
2200 SETPORT(SCSISEQ,0);
2201 SETPORT(SSTAT1,SCSIRSTI);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002202 } else if (stat0 & SELDI && PREVSTATE == busfree) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 STATE=seldi;
2204 } else if(stat0 & SELDO && CURRENT_SC && (CURRENT_SC->SCp.phase & selecting)) {
2205 STATE=seldo;
2206 } else if(stat1 & SELTO) {
2207 STATE=selto;
2208 } else if(stat1 & BUSFREE) {
2209 STATE=busfree;
2210 SETPORT(SSTAT1,BUSFREE);
2211 } else if(stat1 & SCSIPERR) {
2212 STATE=parerr;
2213 SETPORT(SSTAT1,SCSIPERR);
2214 } else if(stat1 & REQINIT) {
2215 switch(GETPORT(SCSISIG) & P_MASK) {
2216 case P_MSGI: STATE=msgi; break;
2217 case P_MSGO: STATE=msgo; break;
2218 case P_DATAO: STATE=datao; break;
2219 case P_DATAI: STATE=datai; break;
2220 case P_STATUS: STATE=status; break;
2221 case P_CMD: STATE=cmd; break;
2222 }
2223 dataphase=1;
2224 }
2225
2226 if((stat0 & SELDI) && STATE!=seldi && !dataphase) {
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002227 scmd_printk(KERN_INFO, CURRENT_SC, "reselection missed?");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 }
2229
2230 if(STATE!=PREVSTATE) {
2231 LASTSTATE=PREVSTATE;
2232 }
2233
2234 return dataphase;
2235}
2236
2237/*
2238 * handle parity error
2239 *
2240 * FIXME: in which phase?
2241 *
2242 */
2243static void parerr_run(struct Scsi_Host *shpnt)
2244{
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002245 scmd_printk(KERN_ERR, CURRENT_SC, "parity error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 done(shpnt, DID_PARITY << 16);
2247}
2248
2249/*
2250 * handle reset in
2251 *
2252 */
2253static void rsti_run(struct Scsi_Host *shpnt)
2254{
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02002255 struct scsi_cmnd *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002257 shost_printk(KERN_NOTICE, shpnt, "scsi reset in\n");
2258
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 ptr=DISCONNECTED_SC;
2260 while(ptr) {
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02002261 struct scsi_cmnd *next = SCNEXT(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
2263 if (!ptr->device->soft_reset) {
2264 remove_SC(&DISCONNECTED_SC, ptr);
2265
2266 kfree(ptr->host_scribble);
2267 ptr->host_scribble=NULL;
2268
2269 ptr->result = DID_RESET << 16;
2270 ptr->scsi_done(ptr);
2271 }
2272
2273 ptr = next;
2274 }
2275
2276 if(CURRENT_SC && !CURRENT_SC->device->soft_reset)
2277 done(shpnt, DID_RESET << 16 );
2278}
2279
2280
2281/*
2282 * bottom-half handler
2283 *
2284 */
2285static void is_complete(struct Scsi_Host *shpnt)
2286{
2287 int dataphase;
2288 unsigned long flags;
2289 int pending;
2290
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01002291 if(!shpnt)
2292 return;
2293
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 DO_LOCK(flags);
Jürgen E. Fischere2482fa2006-02-19 00:31:51 +01002295
2296 if( HOSTDATA(shpnt)->service==0 ) {
2297 DO_UNLOCK(flags);
2298 return;
2299 }
2300
2301 HOSTDATA(shpnt)->service = 0;
2302
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 if(HOSTDATA(shpnt)->in_intr) {
2304 DO_UNLOCK(flags);
2305 /* aha152x_error never returns.. */
2306 aha152x_error(shpnt, "bottom-half already running!?");
2307 }
2308 HOSTDATA(shpnt)->in_intr++;
2309
2310 /*
2311 * loop while there are interrupt conditions pending
2312 *
2313 */
2314 do {
2315 unsigned long start = jiffies;
2316 DO_UNLOCK(flags);
2317
2318 dataphase=update_state(shpnt);
2319
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 /*
2321 * end previous state
2322 *
2323 */
2324 if(PREVSTATE!=STATE && states[PREVSTATE].end)
2325 states[PREVSTATE].end(shpnt);
2326
2327 /*
2328 * disable SPIO mode if previous phase used it
2329 * and this one doesn't
2330 *
2331 */
2332 if(states[PREVSTATE].spio && !states[STATE].spio) {
2333 SETPORT(SXFRCTL0, CH1);
2334 SETPORT(DMACNTRL0, 0);
2335 if(CURRENT_SC)
2336 CURRENT_SC->SCp.phase &= ~spiordy;
2337 }
2338
2339 /*
2340 * accept current dataphase phase
2341 *
2342 */
2343 if(dataphase) {
2344 SETPORT(SSTAT0, REQINIT);
2345 SETPORT(SCSISIG, GETPORT(SCSISIG) & P_MASK);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002346 SETPORT(SSTAT1, PHASECHG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 }
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002348
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 /*
2350 * enable SPIO mode if previous didn't use it
2351 * and this one does
2352 *
2353 */
2354 if(!states[PREVSTATE].spio && states[STATE].spio) {
2355 SETPORT(DMACNTRL0, 0);
2356 SETPORT(SXFRCTL0, CH1|SPIOEN);
2357 if(CURRENT_SC)
2358 CURRENT_SC->SCp.phase |= spiordy;
2359 }
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002360
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 /*
2362 * initialize for new state
2363 *
2364 */
2365 if(PREVSTATE!=STATE && states[STATE].init)
2366 states[STATE].init(shpnt);
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002367
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 /*
2369 * handle current state
2370 *
2371 */
2372 if(states[STATE].run)
2373 states[STATE].run(shpnt);
2374 else
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002375 scmd_printk(KERN_ERR, CURRENT_SC,
2376 "unexpected state (%x)\n", STATE);
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 /*
2379 * setup controller to interrupt on
2380 * the next expected condition and
2381 * loop if it's already there
2382 *
2383 */
2384 DO_LOCK(flags);
2385 pending=setup_expected_interrupts(shpnt);
2386#if defined(AHA152X_STAT)
2387 HOSTDATA(shpnt)->count[STATE]++;
2388 if(PREVSTATE!=STATE)
2389 HOSTDATA(shpnt)->count_trans[STATE]++;
2390 HOSTDATA(shpnt)->time[STATE] += jiffies-start;
2391#endif
2392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 } while(pending);
2394
2395 /*
2396 * enable interrupts and leave bottom-half
2397 *
2398 */
2399 HOSTDATA(shpnt)->in_intr--;
2400 SETBITS(DMACNTRL0, INTEN);
2401 DO_UNLOCK(flags);
2402}
2403
2404
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002405/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 * Dump the current driver status and panic
2407 */
2408static void aha152x_error(struct Scsi_Host *shpnt, char *msg)
2409{
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002410 shost_printk(KERN_EMERG, shpnt, "%s\n", msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 show_queues(shpnt);
2412 panic("aha152x panic\n");
2413}
2414
2415/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 * display enabled interrupts
2417 */
2418static void disp_enintr(struct Scsi_Host *shpnt)
2419{
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002420 int s0, s1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002422 s0 = GETPORT(SIMODE0);
2423 s1 = GETPORT(SIMODE1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002425 shost_printk(KERN_DEBUG, shpnt,
2426 "enabled interrupts (%s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n",
2427 (s0 & ENSELDO) ? "ENSELDO " : "",
2428 (s0 & ENSELDI) ? "ENSELDI " : "",
2429 (s0 & ENSELINGO) ? "ENSELINGO " : "",
2430 (s0 & ENSWRAP) ? "ENSWRAP " : "",
2431 (s0 & ENSDONE) ? "ENSDONE " : "",
2432 (s0 & ENSPIORDY) ? "ENSPIORDY " : "",
2433 (s0 & ENDMADONE) ? "ENDMADONE " : "",
2434 (s1 & ENSELTIMO) ? "ENSELTIMO " : "",
2435 (s1 & ENATNTARG) ? "ENATNTARG " : "",
2436 (s1 & ENPHASEMIS) ? "ENPHASEMIS " : "",
2437 (s1 & ENBUSFREE) ? "ENBUSFREE " : "",
2438 (s1 & ENSCSIPERR) ? "ENSCSIPERR " : "",
2439 (s1 & ENPHASECHG) ? "ENPHASECHG " : "",
2440 (s1 & ENREQINIT) ? "ENREQINIT " : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441}
2442
2443/*
2444 * Show the command data of a command
2445 */
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02002446static void show_command(struct scsi_cmnd *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447{
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002448 scsi_print_command(ptr);
2449 scmd_printk(KERN_DEBUG, ptr,
2450 "request_bufflen=%d; resid=%d; "
2451 "phase |%s%s%s%s%s%s%s%s%s; next=0x%p",
2452 scsi_bufflen(ptr), scsi_get_resid(ptr),
2453 (ptr->SCp.phase & not_issued) ? "not issued|" : "",
2454 (ptr->SCp.phase & selecting) ? "selecting|" : "",
2455 (ptr->SCp.phase & identified) ? "identified|" : "",
2456 (ptr->SCp.phase & disconnected) ? "disconnected|" : "",
2457 (ptr->SCp.phase & completed) ? "completed|" : "",
2458 (ptr->SCp.phase & spiordy) ? "spiordy|" : "",
2459 (ptr->SCp.phase & syncneg) ? "syncneg|" : "",
2460 (ptr->SCp.phase & aborted) ? "aborted|" : "",
2461 (ptr->SCp.phase & resetted) ? "resetted|" : "",
2462 (SCDATA(ptr)) ? SCNEXT(ptr) : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
2465/*
2466 * Dump the queued data
2467 */
2468static void show_queues(struct Scsi_Host *shpnt)
2469{
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02002470 struct scsi_cmnd *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 unsigned long flags;
2472
2473 DO_LOCK(flags);
2474 printk(KERN_DEBUG "\nqueue status:\nissue_SC:\n");
2475 for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
2476 show_command(ptr);
2477 DO_UNLOCK(flags);
2478
2479 printk(KERN_DEBUG "current_SC:\n");
2480 if (CURRENT_SC)
2481 show_command(CURRENT_SC);
2482 else
2483 printk(KERN_DEBUG "none\n");
2484
2485 printk(KERN_DEBUG "disconnected_SC:\n");
2486 for (ptr = DISCONNECTED_SC; ptr; ptr = SCDATA(ptr) ? SCNEXT(ptr) : NULL)
2487 show_command(ptr);
2488
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 disp_enintr(shpnt);
2490}
2491
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02002492static void get_command(struct seq_file *m, struct scsi_cmnd * ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 int i;
2495
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002496 seq_printf(m, "%p: target=%d; lun=%d; cmnd=( ",
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002497 ptr, ptr->device->id, (u8)ptr->device->lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
2499 for (i = 0; i < COMMAND_SIZE(ptr->cmnd[0]); i++)
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002500 seq_printf(m, "0x%02x ", ptr->cmnd[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002502 seq_printf(m, "); resid=%d; residual=%d; buffers=%d; phase |",
Boaz Harrosh23385452007-07-29 22:29:02 +03002503 scsi_get_resid(ptr), ptr->SCp.this_residual,
2504 ptr->SCp.buffers_residual);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505
2506 if (ptr->SCp.phase & not_issued)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002507 seq_puts(m, "not issued|");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 if (ptr->SCp.phase & selecting)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002509 seq_puts(m, "selecting|");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 if (ptr->SCp.phase & disconnected)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002511 seq_puts(m, "disconnected|");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 if (ptr->SCp.phase & aborted)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002513 seq_puts(m, "aborted|");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 if (ptr->SCp.phase & identified)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002515 seq_puts(m, "identified|");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 if (ptr->SCp.phase & completed)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002517 seq_puts(m, "completed|");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 if (ptr->SCp.phase & spiordy)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002519 seq_puts(m, "spiordy|");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 if (ptr->SCp.phase & syncneg)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002521 seq_puts(m, "syncneg|");
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002522 seq_printf(m, "; next=0x%p\n", SCNEXT(ptr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523}
2524
Al Viro275084c2013-03-31 03:12:15 -04002525static void get_ports(struct seq_file *m, struct Scsi_Host *shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 int s;
2528
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002529 seq_printf(m, "\n%s: %s(%s) ", CURRENT_SC ? "on bus" : "waiting", states[STATE].name, states[PREVSTATE].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
2531 s = GETPORT(SCSISEQ);
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002532 seq_puts(m, "SCSISEQ( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 if (s & TEMODEO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002534 seq_puts(m, "TARGET MODE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 if (s & ENSELO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002536 seq_puts(m, "SELO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 if (s & ENSELI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002538 seq_puts(m, "SELI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 if (s & ENRESELI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002540 seq_puts(m, "RESELI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 if (s & ENAUTOATNO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002542 seq_puts(m, "AUTOATNO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 if (s & ENAUTOATNI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002544 seq_puts(m, "AUTOATNI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 if (s & ENAUTOATNP)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002546 seq_puts(m, "AUTOATNP ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 if (s & SCSIRSTO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002548 seq_puts(m, "SCSIRSTO ");
2549 seq_puts(m, ");");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002551 seq_puts(m, " SCSISIG(");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 s = GETPORT(SCSISIG);
2553 switch (s & P_MASK) {
2554 case P_DATAO:
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002555 seq_puts(m, "DATA OUT");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 break;
2557 case P_DATAI:
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002558 seq_puts(m, "DATA IN");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 break;
2560 case P_CMD:
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002561 seq_puts(m, "COMMAND");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 break;
2563 case P_STATUS:
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002564 seq_puts(m, "STATUS");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 break;
2566 case P_MSGO:
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002567 seq_puts(m, "MESSAGE OUT");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 break;
2569 case P_MSGI:
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002570 seq_puts(m, "MESSAGE IN");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 break;
2572 default:
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002573 seq_puts(m, "*invalid*");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 break;
2575 }
2576
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002577 seq_puts(m, "); ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002579 seq_printf(m, "INTSTAT (%s); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002581 seq_puts(m, "SSTAT( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 s = GETPORT(SSTAT0);
2583 if (s & TARGET)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002584 seq_puts(m, "TARGET ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 if (s & SELDO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002586 seq_puts(m, "SELDO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 if (s & SELDI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002588 seq_puts(m, "SELDI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 if (s & SELINGO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002590 seq_puts(m, "SELINGO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 if (s & SWRAP)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002592 seq_puts(m, "SWRAP ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 if (s & SDONE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002594 seq_puts(m, "SDONE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 if (s & SPIORDY)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002596 seq_puts(m, "SPIORDY ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 if (s & DMADONE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002598 seq_puts(m, "DMADONE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
2600 s = GETPORT(SSTAT1);
2601 if (s & SELTO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002602 seq_puts(m, "SELTO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 if (s & ATNTARG)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002604 seq_puts(m, "ATNTARG ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 if (s & SCSIRSTI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002606 seq_puts(m, "SCSIRSTI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 if (s & PHASEMIS)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002608 seq_puts(m, "PHASEMIS ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 if (s & BUSFREE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002610 seq_puts(m, "BUSFREE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 if (s & SCSIPERR)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002612 seq_puts(m, "SCSIPERR ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 if (s & PHASECHG)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002614 seq_puts(m, "PHASECHG ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 if (s & REQINIT)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002616 seq_puts(m, "REQINIT ");
2617 seq_puts(m, "); ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
2619
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002620 seq_puts(m, "SSTAT( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
2622 s = GETPORT(SSTAT0) & GETPORT(SIMODE0);
2623
2624 if (s & TARGET)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002625 seq_puts(m, "TARGET ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 if (s & SELDO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002627 seq_puts(m, "SELDO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 if (s & SELDI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002629 seq_puts(m, "SELDI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 if (s & SELINGO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002631 seq_puts(m, "SELINGO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 if (s & SWRAP)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002633 seq_puts(m, "SWRAP ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 if (s & SDONE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002635 seq_puts(m, "SDONE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 if (s & SPIORDY)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002637 seq_puts(m, "SPIORDY ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 if (s & DMADONE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002639 seq_puts(m, "DMADONE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640
2641 s = GETPORT(SSTAT1) & GETPORT(SIMODE1);
2642
2643 if (s & SELTO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002644 seq_puts(m, "SELTO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 if (s & ATNTARG)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002646 seq_puts(m, "ATNTARG ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 if (s & SCSIRSTI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002648 seq_puts(m, "SCSIRSTI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 if (s & PHASEMIS)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002650 seq_puts(m, "PHASEMIS ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 if (s & BUSFREE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002652 seq_puts(m, "BUSFREE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 if (s & SCSIPERR)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002654 seq_puts(m, "SCSIPERR ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 if (s & PHASECHG)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002656 seq_puts(m, "PHASECHG ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 if (s & REQINIT)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002658 seq_puts(m, "REQINIT ");
2659 seq_puts(m, "); ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002661 seq_puts(m, "SXFRCTL0( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
2663 s = GETPORT(SXFRCTL0);
2664 if (s & SCSIEN)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002665 seq_puts(m, "SCSIEN ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 if (s & DMAEN)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002667 seq_puts(m, "DMAEN ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 if (s & CH1)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002669 seq_puts(m, "CH1 ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 if (s & CLRSTCNT)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002671 seq_puts(m, "CLRSTCNT ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 if (s & SPIOEN)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002673 seq_puts(m, "SPIOEN ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 if (s & CLRCH1)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002675 seq_puts(m, "CLRCH1 ");
2676 seq_puts(m, "); ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002678 seq_puts(m, "SIGNAL( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
2680 s = GETPORT(SCSISIG);
2681 if (s & SIG_ATNI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002682 seq_puts(m, "ATNI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 if (s & SIG_SELI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002684 seq_puts(m, "SELI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 if (s & SIG_BSYI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002686 seq_puts(m, "BSYI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 if (s & SIG_REQI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002688 seq_puts(m, "REQI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 if (s & SIG_ACKI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002690 seq_puts(m, "ACKI ");
2691 seq_puts(m, "); ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002693 seq_printf(m, "SELID(%02x), ", GETPORT(SELID));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002695 seq_printf(m, "STCNT(%d), ", GETSTCNT());
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002697 seq_puts(m, "SSTAT2( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
2699 s = GETPORT(SSTAT2);
2700 if (s & SOFFSET)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002701 seq_puts(m, "SOFFSET ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 if (s & SEMPTY)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002703 seq_puts(m, "SEMPTY ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 if (s & SFULL)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002705 seq_puts(m, "SFULL ");
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002706 seq_printf(m, "); SFCNT (%d); ", s & (SFULL | SFCNT));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707
2708 s = GETPORT(SSTAT3);
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002709 seq_printf(m, "SCSICNT (%d), OFFCNT(%d), ", (s & 0xf0) >> 4, s & 0x0f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002711 seq_puts(m, "SSTAT4( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 s = GETPORT(SSTAT4);
2713 if (s & SYNCERR)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002714 seq_puts(m, "SYNCERR ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 if (s & FWERR)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002716 seq_puts(m, "FWERR ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 if (s & FRERR)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002718 seq_puts(m, "FRERR ");
2719 seq_puts(m, "); ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002721 seq_puts(m, "DMACNTRL0( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 s = GETPORT(DMACNTRL0);
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002723 seq_printf(m, "%s ", s & _8BIT ? "8BIT" : "16BIT");
2724 seq_printf(m, "%s ", s & DMA ? "DMA" : "PIO");
2725 seq_printf(m, "%s ", s & WRITE_READ ? "WRITE" : "READ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 if (s & ENDMA)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002727 seq_puts(m, "ENDMA ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 if (s & INTEN)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002729 seq_puts(m, "INTEN ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 if (s & RSTFIFO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002731 seq_puts(m, "RSTFIFO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 if (s & SWINT)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002733 seq_puts(m, "SWINT ");
2734 seq_puts(m, "); ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002736 seq_puts(m, "DMASTAT( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 s = GETPORT(DMASTAT);
2738 if (s & ATDONE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002739 seq_puts(m, "ATDONE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 if (s & WORDRDY)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002741 seq_puts(m, "WORDRDY ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 if (s & DFIFOFULL)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002743 seq_puts(m, "DFIFOFULL ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 if (s & DFIFOEMP)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002745 seq_puts(m, "DFIFOEMP ");
2746 seq_puts(m, ")\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002748 seq_puts(m, "enabled interrupts( ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
2750 s = GETPORT(SIMODE0);
2751 if (s & ENSELDO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002752 seq_puts(m, "ENSELDO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 if (s & ENSELDI)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002754 seq_puts(m, "ENSELDI ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 if (s & ENSELINGO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002756 seq_puts(m, "ENSELINGO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 if (s & ENSWRAP)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002758 seq_puts(m, "ENSWRAP ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 if (s & ENSDONE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002760 seq_puts(m, "ENSDONE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 if (s & ENSPIORDY)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002762 seq_puts(m, "ENSPIORDY ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 if (s & ENDMADONE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002764 seq_puts(m, "ENDMADONE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765
2766 s = GETPORT(SIMODE1);
2767 if (s & ENSELTIMO)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002768 seq_puts(m, "ENSELTIMO ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 if (s & ENATNTARG)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002770 seq_puts(m, "ENATNTARG ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 if (s & ENPHASEMIS)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002772 seq_puts(m, "ENPHASEMIS ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 if (s & ENBUSFREE)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002774 seq_puts(m, "ENBUSFREE ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 if (s & ENSCSIPERR)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002776 seq_puts(m, "ENSCSIPERR ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 if (s & ENPHASECHG)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002778 seq_puts(m, "ENPHASECHG ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 if (s & ENREQINIT)
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002780 seq_puts(m, "ENREQINIT ");
2781 seq_puts(m, ")\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782}
2783
Al Viro275084c2013-03-31 03:12:15 -04002784static int aha152x_set_info(struct Scsi_Host *shpnt, char *buffer, int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785{
2786 if(!shpnt || !buffer || length<8 || strncmp("aha152x ", buffer, 8)!=0)
2787 return -EINVAL;
2788
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789#if defined(AHA152X_STAT)
2790 if(length>13 && strncmp("reset", buffer+8, 5)==0) {
2791 int i;
2792
2793 HOSTDATA(shpnt)->total_commands=0;
2794 HOSTDATA(shpnt)->disconnections=0;
2795 HOSTDATA(shpnt)->busfree_without_any_action=0;
2796 HOSTDATA(shpnt)->busfree_without_old_command=0;
2797 HOSTDATA(shpnt)->busfree_without_new_command=0;
2798 HOSTDATA(shpnt)->busfree_without_done_command=0;
2799 HOSTDATA(shpnt)->busfree_with_check_condition=0;
2800 for (i = idle; i<maxstate; i++) {
2801 HOSTDATA(shpnt)->count[i]=0;
2802 HOSTDATA(shpnt)->count_trans[i]=0;
2803 HOSTDATA(shpnt)->time[i]=0;
2804 }
2805
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002806 shost_printk(KERN_INFO, shpnt, "aha152x: stats reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
2808 } else
2809#endif
2810 {
2811 return -EINVAL;
2812 }
2813
2814
2815 return length;
2816}
2817
Al Viro275084c2013-03-31 03:12:15 -04002818static int aha152x_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819{
2820 int i;
Johannes Thumshirn91ebc1f2018-06-13 09:53:47 +02002821 struct scsi_cmnd *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002824 seq_puts(m, AHA152X_REVID "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002826 seq_printf(m, "ioports 0x%04lx to 0x%04lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 shpnt->io_port, shpnt->io_port + shpnt->n_io_port - 1);
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002828 seq_printf(m, "interrupt 0x%02x\n", shpnt->irq);
2829 seq_printf(m, "disconnection/reconnection %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 RECONNECT ? "enabled" : "disabled");
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002831 seq_printf(m, "parity checking %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 PARITY ? "enabled" : "disabled");
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002833 seq_printf(m, "synchronous transfers %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 SYNCHRONOUS ? "enabled" : "disabled");
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002835 seq_printf(m, "%d commands currently queued\n", HOSTDATA(shpnt)->commands);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836
2837 if(SYNCHRONOUS) {
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002838 seq_puts(m, "synchronously operating targets (tick=50 ns):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 for (i = 0; i < 8; i++)
2840 if (HOSTDATA(shpnt)->syncrate[i] & 0x7f)
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002841 seq_printf(m, "target %d: period %dT/%dns; req/ack offset %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 i,
2843 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2),
2844 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2) * 50,
2845 HOSTDATA(shpnt)->syncrate[i] & 0x0f);
2846 }
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002847 seq_puts(m, "\nqueue status:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 DO_LOCK(flags);
2849 if (ISSUE_SC) {
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002850 seq_puts(m, "not yet issued commands:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
Al Viro275084c2013-03-31 03:12:15 -04002852 get_command(m, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 } else
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002854 seq_puts(m, "no not yet issued commands\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 DO_UNLOCK(flags);
2856
2857 if (CURRENT_SC) {
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002858 seq_puts(m, "current command:\n");
Al Viro275084c2013-03-31 03:12:15 -04002859 get_command(m, CURRENT_SC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 } else
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002861 seq_puts(m, "no current command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862
2863 if (DISCONNECTED_SC) {
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002864 seq_puts(m, "disconnected commands:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 for (ptr = DISCONNECTED_SC; ptr; ptr = SCNEXT(ptr))
Al Viro275084c2013-03-31 03:12:15 -04002866 get_command(m, ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 } else
Rasmus Villemoesee7c7272014-12-03 00:10:51 +01002868 seq_puts(m, "no disconnected commands\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
Al Viro275084c2013-03-31 03:12:15 -04002870 get_ports(m, shpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871
2872#if defined(AHA152X_STAT)
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002873 seq_printf(m, "statistics:\n"
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002874 "total commands: %d\n"
2875 "disconnections: %d\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 "busfree with check condition: %d\n"
2877 "busfree without old command: %d\n"
2878 "busfree without new command: %d\n"
2879 "busfree without done command: %d\n"
2880 "busfree without any action: %d\n"
2881 "state "
2882 "transitions "
2883 "count "
2884 "time\n",
2885 HOSTDATA(shpnt)->total_commands,
2886 HOSTDATA(shpnt)->disconnections,
2887 HOSTDATA(shpnt)->busfree_with_check_condition,
2888 HOSTDATA(shpnt)->busfree_without_old_command,
2889 HOSTDATA(shpnt)->busfree_without_new_command,
2890 HOSTDATA(shpnt)->busfree_without_done_command,
2891 HOSTDATA(shpnt)->busfree_without_any_action);
2892 for(i=0; i<maxstate; i++) {
Rasmus Villemoes0c3de382014-12-03 00:10:49 +01002893 seq_printf(m, "%-10s %-12d %-12d %-12ld\n",
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02002894 states[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 HOSTDATA(shpnt)->count_trans[i],
2896 HOSTDATA(shpnt)->count[i],
2897 HOSTDATA(shpnt)->time[i]);
2898 }
2899#endif
Al Viro275084c2013-03-31 03:12:15 -04002900 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901}
2902
Boaz Harroshb1ee0792007-07-29 22:18:20 +03002903static int aha152x_adjust_queue(struct scsi_device *device)
2904{
2905 blk_queue_bounce_limit(device->request_queue, BLK_BOUNCE_HIGH);
2906 return 0;
2907}
2908
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +01002909static struct scsi_host_template aha152x_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 .module = THIS_MODULE,
2911 .name = AHA152X_REVID,
2912 .proc_name = "aha152x",
Al Viro275084c2013-03-31 03:12:15 -04002913 .show_info = aha152x_show_info,
2914 .write_info = aha152x_set_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 .queuecommand = aha152x_queue,
2916 .eh_abort_handler = aha152x_abort,
2917 .eh_device_reset_handler = aha152x_device_reset,
2918 .eh_bus_reset_handler = aha152x_bus_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 .bios_param = aha152x_biosparam,
2920 .can_queue = 1,
2921 .this_id = 7,
2922 .sg_tablesize = SG_ALL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 .use_clustering = DISABLE_CLUSTERING,
Boaz Harroshb1ee0792007-07-29 22:18:20 +03002924 .slave_alloc = aha152x_adjust_queue,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925};
2926
Christoph Hellwig3eb2ebc2018-10-19 14:09:44 +02002927#if !defined(AHA152X_PCMCIA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928static int setup_count;
2929static struct aha152x_setup setup[2];
2930
2931/* possible i/o addresses for the AIC-6260; default first */
2932static unsigned short ports[] = { 0x340, 0x140 };
2933
2934#if !defined(SKIP_BIOSTEST)
2935/* possible locations for the Adaptec BIOS; defaults first */
2936static unsigned int addresses[] =
2937{
2938 0xdc000, /* default first */
2939 0xc8000,
2940 0xcc000,
2941 0xd0000,
2942 0xd4000,
2943 0xd8000,
2944 0xe0000,
2945 0xeb800, /* VTech Platinum SMP */
2946 0xf0000,
2947};
2948
2949/* signatures for various AIC-6[23]60 based controllers.
2950 The point in detecting signatures is to avoid useless and maybe
2951 harmful probes on ports. I'm not sure that all listed boards pass
2952 auto-configuration. For those which fail the BIOS signature is
2953 obsolete, because user intervention to supply the configuration is
2954 needed anyway. May be an information whether or not the BIOS supports
2955 extended translation could be also useful here. */
2956static struct signature {
2957 unsigned char *signature;
2958 int sig_offset;
2959 int sig_length;
2960} signatures[] =
2961{
2962 { "Adaptec AHA-1520 BIOS", 0x102e, 21 },
2963 /* Adaptec 152x */
2964 { "Adaptec AHA-1520B", 0x000b, 17 },
2965 /* Adaptec 152x rev B */
2966 { "Adaptec AHA-1520B", 0x0026, 17 },
2967 /* Iomega Jaz Jet ISA (AIC6370Q) */
2968 { "Adaptec ASW-B626 BIOS", 0x1029, 21 },
2969 /* on-board controller */
2970 { "Adaptec BIOS: ASW-B626", 0x000f, 22 },
2971 /* on-board controller */
2972 { "Adaptec ASW-B626 S2", 0x2e6c, 19 },
2973 /* on-board controller */
2974 { "Adaptec BIOS:AIC-6360", 0x000c, 21 },
2975 /* on-board controller */
2976 { "ScsiPro SP-360 BIOS", 0x2873, 19 },
2977 /* ScsiPro-Controller */
2978 { "GA-400 LOCAL BUS SCSI BIOS", 0x102e, 26 },
2979 /* Gigabyte Local-Bus-SCSI */
2980 { "Adaptec BIOS:AVA-282X", 0x000c, 21 },
2981 /* Adaptec 282x */
2982 { "Adaptec IBM Dock II SCSI", 0x2edd, 24 },
2983 /* IBM Thinkpad Dock II */
2984 { "Adaptec BIOS:AHA-1532P", 0x001c, 22 },
2985 /* IBM Thinkpad Dock II SCSI */
2986 { "DTC3520A Host Adapter BIOS", 0x318a, 26 },
2987 /* DTC 3520A ISA SCSI */
2988};
2989#endif /* !SKIP_BIOSTEST */
2990
2991/*
2992 * Test, if port_base is valid.
2993 *
2994 */
2995static int aha152x_porttest(int io_port)
2996{
2997 int i;
2998
2999 SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
3000 for (i = 0; i < 16; i++)
3001 SETPORT(io_port + O_STACK, i);
3002
3003 SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
3004 for (i = 0; i < 16 && GETPORT(io_port + O_STACK) == i; i++)
3005 ;
3006
3007 return (i == 16);
3008}
3009
3010static int tc1550_porttest(int io_port)
3011{
3012 int i;
3013
3014 SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
3015 for (i = 0; i < 16; i++)
3016 SETPORT(io_port + O_STACK, i);
3017
3018 SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
3019 for (i = 0; i < 16 && GETPORT(io_port + O_TC_STACK) == i; i++)
3020 ;
3021
3022 return (i == 16);
3023}
3024
3025
3026static int checksetup(struct aha152x_setup *setup)
3027{
3028 int i;
3029 for (i = 0; i < ARRAY_SIZE(ports) && (setup->io_port != ports[i]); i++)
3030 ;
3031
3032 if (i == ARRAY_SIZE(ports))
3033 return 0;
3034
Harvey Harrison9bcf0912008-05-22 15:45:07 -07003035 if (!request_region(setup->io_port, IO_RANGE, "aha152x")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 printk(KERN_ERR "aha152x: io port 0x%x busy.\n", setup->io_port);
3037 return 0;
3038 }
3039
3040 if( aha152x_porttest(setup->io_port) ) {
3041 setup->tc1550=0;
3042 } else if( tc1550_porttest(setup->io_port) ) {
3043 setup->tc1550=1;
3044 } else {
3045 release_region(setup->io_port, IO_RANGE);
3046 return 0;
3047 }
3048
3049 release_region(setup->io_port, IO_RANGE);
3050
3051 if ((setup->irq < IRQ_MIN) || (setup->irq > IRQ_MAX))
3052 return 0;
3053
3054 if ((setup->scsiid < 0) || (setup->scsiid > 7))
3055 return 0;
3056
3057 if ((setup->reconnect < 0) || (setup->reconnect > 1))
3058 return 0;
3059
3060 if ((setup->parity < 0) || (setup->parity > 1))
3061 return 0;
3062
3063 if ((setup->synchronous < 0) || (setup->synchronous > 1))
3064 return 0;
3065
3066 if ((setup->ext_trans < 0) || (setup->ext_trans > 1))
3067 return 0;
3068
3069
3070 return 1;
3071}
3072
3073
3074static int __init aha152x_init(void)
3075{
3076 int i, j, ok;
3077#if defined(AUTOCONF)
3078 aha152x_config conf;
3079#endif
3080#ifdef __ISAPNP__
3081 struct pnp_dev *dev=NULL, *pnpdev[2] = {NULL, NULL};
3082#endif
3083
3084 if ( setup_count ) {
3085 printk(KERN_INFO "aha152x: processing commandline: ");
3086
3087 for (i = 0; i<setup_count; i++) {
3088 if (!checksetup(&setup[i])) {
3089 printk(KERN_ERR "\naha152x: %s\n", setup[i].conf);
3090 printk(KERN_ERR "aha152x: invalid line\n");
3091 }
3092 }
3093 printk("ok\n");
3094 }
3095
3096#if defined(SETUP0)
3097 if (setup_count < ARRAY_SIZE(setup)) {
3098 struct aha152x_setup override = SETUP0;
3099
3100 if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
3101 if (!checksetup(&override)) {
3102 printk(KERN_ERR "\naha152x: invalid override SETUP0={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
3103 override.io_port,
3104 override.irq,
3105 override.scsiid,
3106 override.reconnect,
3107 override.parity,
3108 override.synchronous,
3109 override.delay,
3110 override.ext_trans);
3111 } else
3112 setup[setup_count++] = override;
3113 }
3114 }
3115#endif
3116
3117#if defined(SETUP1)
3118 if (setup_count < ARRAY_SIZE(setup)) {
3119 struct aha152x_setup override = SETUP1;
3120
3121 if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
3122 if (!checksetup(&override)) {
3123 printk(KERN_ERR "\naha152x: invalid override SETUP1={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
3124 override.io_port,
3125 override.irq,
3126 override.scsiid,
3127 override.reconnect,
3128 override.parity,
3129 override.synchronous,
3130 override.delay,
3131 override.ext_trans);
3132 } else
3133 setup[setup_count++] = override;
3134 }
3135 }
3136#endif
3137
3138#if defined(MODULE)
3139 if (setup_count<ARRAY_SIZE(setup) && (aha152x[0]!=0 || io[0]!=0 || irq[0]!=0)) {
3140 if(aha152x[0]!=0) {
3141 setup[setup_count].conf = "";
3142 setup[setup_count].io_port = aha152x[0];
3143 setup[setup_count].irq = aha152x[1];
3144 setup[setup_count].scsiid = aha152x[2];
3145 setup[setup_count].reconnect = aha152x[3];
3146 setup[setup_count].parity = aha152x[4];
3147 setup[setup_count].synchronous = aha152x[5];
3148 setup[setup_count].delay = aha152x[6];
3149 setup[setup_count].ext_trans = aha152x[7];
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02003150 } else if (io[0] != 0 || irq[0] != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 if(io[0]!=0) setup[setup_count].io_port = io[0];
3152 if(irq[0]!=0) setup[setup_count].irq = irq[0];
3153
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02003154 setup[setup_count].scsiid = scsiid[0];
3155 setup[setup_count].reconnect = reconnect[0];
3156 setup[setup_count].parity = parity[0];
3157 setup[setup_count].synchronous = sync[0];
3158 setup[setup_count].delay = delay[0];
3159 setup[setup_count].ext_trans = exttrans[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 }
3161
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02003162 if (checksetup(&setup[setup_count]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 setup_count++;
3164 else
3165 printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
3166 setup[setup_count].io_port,
3167 setup[setup_count].irq,
3168 setup[setup_count].scsiid,
3169 setup[setup_count].reconnect,
3170 setup[setup_count].parity,
3171 setup[setup_count].synchronous,
3172 setup[setup_count].delay,
3173 setup[setup_count].ext_trans);
3174 }
3175
3176 if (setup_count<ARRAY_SIZE(setup) && (aha152x1[0]!=0 || io[1]!=0 || irq[1]!=0)) {
3177 if(aha152x1[0]!=0) {
3178 setup[setup_count].conf = "";
3179 setup[setup_count].io_port = aha152x1[0];
3180 setup[setup_count].irq = aha152x1[1];
3181 setup[setup_count].scsiid = aha152x1[2];
3182 setup[setup_count].reconnect = aha152x1[3];
3183 setup[setup_count].parity = aha152x1[4];
3184 setup[setup_count].synchronous = aha152x1[5];
3185 setup[setup_count].delay = aha152x1[6];
3186 setup[setup_count].ext_trans = aha152x1[7];
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02003187 } else if (io[1] != 0 || irq[1] != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 if(io[1]!=0) setup[setup_count].io_port = io[1];
3189 if(irq[1]!=0) setup[setup_count].irq = irq[1];
3190
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02003191 setup[setup_count].scsiid = scsiid[1];
3192 setup[setup_count].reconnect = reconnect[1];
3193 setup[setup_count].parity = parity[1];
3194 setup[setup_count].synchronous = sync[1];
3195 setup[setup_count].delay = delay[1];
3196 setup[setup_count].ext_trans = exttrans[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 }
3198 if (checksetup(&setup[setup_count]))
3199 setup_count++;
3200 else
3201 printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
3202 setup[setup_count].io_port,
3203 setup[setup_count].irq,
3204 setup[setup_count].scsiid,
3205 setup[setup_count].reconnect,
3206 setup[setup_count].parity,
3207 setup[setup_count].synchronous,
3208 setup[setup_count].delay,
3209 setup[setup_count].ext_trans);
3210 }
3211#endif
3212
3213#ifdef __ISAPNP__
3214 for(i=0; setup_count<ARRAY_SIZE(setup) && id_table[i].vendor; i++) {
3215 while ( setup_count<ARRAY_SIZE(setup) &&
3216 (dev=pnp_find_dev(NULL, id_table[i].vendor, id_table[i].function, dev)) ) {
3217 if (pnp_device_attach(dev) < 0)
3218 continue;
3219
3220 if (pnp_activate_dev(dev) < 0) {
3221 pnp_device_detach(dev);
3222 continue;
3223 }
3224
3225 if (!pnp_port_valid(dev, 0)) {
3226 pnp_device_detach(dev);
3227 continue;
3228 }
3229
3230 if (setup_count==1 && pnp_port_start(dev, 0)==setup[0].io_port) {
3231 pnp_device_detach(dev);
3232 continue;
3233 }
3234
3235 setup[setup_count].io_port = pnp_port_start(dev, 0);
3236 setup[setup_count].irq = pnp_irq(dev, 0);
3237 setup[setup_count].scsiid = 7;
3238 setup[setup_count].reconnect = 1;
3239 setup[setup_count].parity = 1;
3240 setup[setup_count].synchronous = 1;
3241 setup[setup_count].delay = DELAY_DEFAULT;
3242 setup[setup_count].ext_trans = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243#if defined(__ISAPNP__)
3244 pnpdev[setup_count] = dev;
3245#endif
3246 printk (KERN_INFO
3247 "aha152x: found ISAPnP adapter at io=0x%03x, irq=%d\n",
3248 setup[setup_count].io_port, setup[setup_count].irq);
3249 setup_count++;
3250 }
3251 }
3252#endif
3253
3254#if defined(AUTOCONF)
3255 if (setup_count<ARRAY_SIZE(setup)) {
3256#if !defined(SKIP_BIOSTEST)
3257 ok = 0;
3258 for (i = 0; i < ARRAY_SIZE(addresses) && !ok; i++) {
3259 void __iomem *p = ioremap(addresses[i], 0x4000);
3260 if (!p)
3261 continue;
3262 for (j = 0; j<ARRAY_SIZE(signatures) && !ok; j++)
3263 ok = check_signature(p + signatures[j].sig_offset,
3264 signatures[j].signature, signatures[j].sig_length);
3265 iounmap(p);
3266 }
3267 if (!ok && setup_count == 0)
James Bottomleyad2fa422008-05-10 08:33:58 -05003268 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269
3270 printk(KERN_INFO "aha152x: BIOS test: passed, ");
3271#else
3272 printk(KERN_INFO "aha152x: ");
3273#endif /* !SKIP_BIOSTEST */
3274
3275 ok = 0;
3276 for (i = 0; i < ARRAY_SIZE(ports) && setup_count < 2; i++) {
3277 if ((setup_count == 1) && (setup[0].io_port == ports[i]))
3278 continue;
3279
Harvey Harrison9bcf0912008-05-22 15:45:07 -07003280 if (!request_region(ports[i], IO_RANGE, "aha152x")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 printk(KERN_ERR "aha152x: io port 0x%x busy.\n", ports[i]);
3282 continue;
3283 }
3284
3285 if (aha152x_porttest(ports[i])) {
3286 setup[setup_count].tc1550 = 0;
3287
3288 conf.cf_port =
3289 (GETPORT(ports[i] + O_PORTA) << 8) + GETPORT(ports[i] + O_PORTB);
3290 } else if (tc1550_porttest(ports[i])) {
3291 setup[setup_count].tc1550 = 1;
3292
3293 conf.cf_port =
3294 (GETPORT(ports[i] + O_TC_PORTA) << 8) + GETPORT(ports[i] + O_TC_PORTB);
3295 } else {
3296 release_region(ports[i], IO_RANGE);
3297 continue;
3298 }
3299
3300 release_region(ports[i], IO_RANGE);
3301
3302 ok++;
3303 setup[setup_count].io_port = ports[i];
3304 setup[setup_count].irq = IRQ_MIN + conf.cf_irq;
3305 setup[setup_count].scsiid = conf.cf_id;
3306 setup[setup_count].reconnect = conf.cf_tardisc;
3307 setup[setup_count].parity = !conf.cf_parity;
3308 setup[setup_count].synchronous = conf.cf_syncneg;
3309 setup[setup_count].delay = DELAY_DEFAULT;
3310 setup[setup_count].ext_trans = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 setup_count++;
3312
3313 }
3314
3315 if (ok)
3316 printk("auto configuration: ok, ");
3317 }
3318#endif
3319
3320 printk("%d controller(s) configured\n", setup_count);
3321
3322 for (i=0; i<setup_count; i++) {
3323 if ( request_region(setup[i].io_port, IO_RANGE, "aha152x") ) {
3324 struct Scsi_Host *shpnt = aha152x_probe_one(&setup[i]);
3325
3326 if( !shpnt ) {
3327 release_region(setup[i].io_port, IO_RANGE);
3328#if defined(__ISAPNP__)
3329 } else if( pnpdev[i] ) {
3330 HOSTDATA(shpnt)->pnpdev=pnpdev[i];
3331 pnpdev[i]=NULL;
3332#endif
3333 }
3334 } else {
3335 printk(KERN_ERR "aha152x: io port 0x%x busy.\n", setup[i].io_port);
3336 }
3337
3338#if defined(__ISAPNP__)
3339 if( pnpdev[i] )
3340 pnp_device_detach(pnpdev[i]);
3341#endif
3342 }
3343
James Bottomleyad2fa422008-05-10 08:33:58 -05003344 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345}
3346
3347static void __exit aha152x_exit(void)
3348{
James Bottomley64976a02008-05-10 14:08:40 -05003349 struct aha152x_hostdata *hd, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350
James Bottomley64976a02008-05-10 14:08:40 -05003351 list_for_each_entry_safe(hd, tmp, &aha152x_host_list, host_list) {
James Bottomley5fcda422006-09-14 17:04:58 -05003352 struct Scsi_Host *shost = container_of((void *)hd, struct Scsi_Host, hostdata);
3353
3354 aha152x_release(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 }
3356}
3357
3358module_init(aha152x_init);
3359module_exit(aha152x_exit);
3360
3361#if !defined(MODULE)
3362static int __init aha152x_setup(char *str)
3363{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 int ints[10];
Hannes Reineckef75ae8e2014-10-24 14:26:43 +02003365
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 get_options(str, ARRAY_SIZE(ints), ints);
3367
3368 if(setup_count>=ARRAY_SIZE(setup)) {
3369 printk(KERN_ERR "aha152x: you can only configure up to two controllers\n");
3370 return 1;
3371 }
3372
3373 setup[setup_count].conf = str;
3374 setup[setup_count].io_port = ints[0] >= 1 ? ints[1] : 0x340;
3375 setup[setup_count].irq = ints[0] >= 2 ? ints[2] : 11;
3376 setup[setup_count].scsiid = ints[0] >= 3 ? ints[3] : 7;
3377 setup[setup_count].reconnect = ints[0] >= 4 ? ints[4] : 1;
3378 setup[setup_count].parity = ints[0] >= 5 ? ints[5] : 1;
3379 setup[setup_count].synchronous = ints[0] >= 6 ? ints[6] : 1;
3380 setup[setup_count].delay = ints[0] >= 7 ? ints[7] : DELAY_DEFAULT;
3381 setup[setup_count].ext_trans = ints[0] >= 8 ? ints[8] : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 if (ints[0] > 8) { /*}*/
3383 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
3384 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 } else {
3386 setup_count++;
3387 return 0;
3388 }
3389
3390 return 1;
3391}
3392__setup("aha152x=", aha152x_setup);
3393#endif
3394
Christoph Hellwig3eb2ebc2018-10-19 14:09:44 +02003395#endif /* !AHA152X_PCMCIA */