diff options
author | Hannes Reinecke <hare@suse.de> | 2014-11-24 09:37:30 -0500 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2014-11-24 10:13:18 -0500 |
commit | 71bd849dbac99b587cb8a2d34061ecb6abe77c84 (patch) | |
tree | 757d54058e42d783f59881a3e0acf3c00cb98e75 /drivers/scsi | |
parent | e858d930fe6c0baaad60bceb0aa1f44611eaf302 (diff) |
tmscsim: replace by am53c974 driver
The am53c974 is a re-implementation of the tmscsim driver,
and provides the same functionality.
So remove the tmscsim driver and make am53c974 an alias to tmscsim.
Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/Kconfig | 16 | ||||
-rw-r--r-- | drivers/scsi/Makefile | 1 | ||||
-rw-r--r-- | drivers/scsi/am53c974.c | 1 | ||||
-rw-r--r-- | drivers/scsi/tmscsim.c | 2626 | ||||
-rw-r--r-- | drivers/scsi/tmscsim.h | 549 |
5 files changed, 1 insertions, 3192 deletions
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index 519c3ef72fd5..f871a80f38ee 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig | |||
@@ -1341,22 +1341,6 @@ config SCSI_DC395x | |||
1341 | To compile this driver as a module, choose M here: the | 1341 | To compile this driver as a module, choose M here: the |
1342 | module will be called dc395x. | 1342 | module will be called dc395x. |
1343 | 1343 | ||
1344 | config SCSI_DC390T | ||
1345 | tristate "Tekram DC390(T) and Am53/79C974 SCSI support" | ||
1346 | depends on PCI && SCSI | ||
1347 | ---help--- | ||
1348 | This driver supports PCI SCSI host adapters based on the Am53C974A | ||
1349 | chip, e.g. Tekram DC390(T), DawiControl 2974 and some onboard | ||
1350 | PCscsi/PCnet (Am53/79C974) solutions. | ||
1351 | |||
1352 | Documentation can be found in <file:Documentation/scsi/tmscsim.txt>. | ||
1353 | |||
1354 | Note that this driver does NOT support Tekram DC390W/U/F, which are | ||
1355 | based on NCR/Symbios chips. Use "NCR53C8XX SCSI support" for those. | ||
1356 | |||
1357 | To compile this driver as a module, choose M here: the | ||
1358 | module will be called tmscsim. | ||
1359 | |||
1360 | config SCSI_AM53C974 | 1344 | config SCSI_AM53C974 |
1361 | tristate "Tekram DC390(T) and Am53/79C974 SCSI support (new driver)" | 1345 | tristate "Tekram DC390(T) and Am53/79C974 SCSI support (new driver)" |
1362 | depends on PCI && SCSI | 1346 | depends on PCI && SCSI |
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile index 79a6571e33f9..a9f3fa857610 100644 --- a/drivers/scsi/Makefile +++ b/drivers/scsi/Makefile | |||
@@ -100,7 +100,6 @@ obj-$(CONFIG_SCSI_EATA_PIO) += eata_pio.o | |||
100 | obj-$(CONFIG_SCSI_7000FASST) += wd7000.o | 100 | obj-$(CONFIG_SCSI_7000FASST) += wd7000.o |
101 | obj-$(CONFIG_SCSI_EATA) += eata.o | 101 | obj-$(CONFIG_SCSI_EATA) += eata.o |
102 | obj-$(CONFIG_SCSI_DC395x) += dc395x.o | 102 | obj-$(CONFIG_SCSI_DC395x) += dc395x.o |
103 | obj-$(CONFIG_SCSI_DC390T) += tmscsim.o | ||
104 | obj-$(CONFIG_SCSI_AM53C974) += esp_scsi.o am53c974.o | 103 | obj-$(CONFIG_SCSI_AM53C974) += esp_scsi.o am53c974.o |
105 | obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o | 104 | obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o |
106 | obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/ | 105 | obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/ |
diff --git a/drivers/scsi/am53c974.c b/drivers/scsi/am53c974.c index 25f06196643e..aa3e2c7cd83c 100644 --- a/drivers/scsi/am53c974.c +++ b/drivers/scsi/am53c974.c | |||
@@ -574,6 +574,7 @@ MODULE_DESCRIPTION("AM53C974 SCSI driver"); | |||
574 | MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>"); | 574 | MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>"); |
575 | MODULE_LICENSE("GPL"); | 575 | MODULE_LICENSE("GPL"); |
576 | MODULE_VERSION(DRV_MODULE_VERSION); | 576 | MODULE_VERSION(DRV_MODULE_VERSION); |
577 | MODULE_ALIAS("tmscsim"); | ||
577 | 578 | ||
578 | module_param(am53c974_debug, bool, 0644); | 579 | module_param(am53c974_debug, bool, 0644); |
579 | MODULE_PARM_DESC(am53c974_debug, "Enable debugging"); | 580 | MODULE_PARM_DESC(am53c974_debug, "Enable debugging"); |
diff --git a/drivers/scsi/tmscsim.c b/drivers/scsi/tmscsim.c deleted file mode 100644 index 6c3c2cef3891..000000000000 --- a/drivers/scsi/tmscsim.c +++ /dev/null | |||
@@ -1,2626 +0,0 @@ | |||
1 | /************************************************************************ | ||
2 | * FILE NAME : TMSCSIM.C * | ||
3 | * BY : C.L. Huang, ching@tekram.com.tw * | ||
4 | * Description: Device Driver for Tekram DC-390(T) PCI SCSI * | ||
5 | * Bus Master Host Adapter * | ||
6 | * (C)Copyright 1995-1996 Tekram Technology Co., Ltd. * | ||
7 | ************************************************************************ | ||
8 | * (C) Copyright: put under GNU GPL in 10/96 * | ||
9 | * (see Documentation/scsi/tmscsim.txt) * | ||
10 | ************************************************************************ | ||
11 | * $Id: tmscsim.c,v 2.60.2.30 2000/12/20 01:07:12 garloff Exp $ * | ||
12 | * Enhancements and bugfixes by * | ||
13 | * Kurt Garloff <kurt@garloff.de> <garloff@suse.de> * | ||
14 | ************************************************************************ | ||
15 | * HISTORY: * | ||
16 | * * | ||
17 | * REV# DATE NAME DESCRIPTION * | ||
18 | * 1.00 96/04/24 CLH First release * | ||
19 | * 1.01 96/06/12 CLH Fixed bug of Media Change for Removable * | ||
20 | * Device, scan all LUN. Support Pre2.0.10 * | ||
21 | * 1.02 96/06/18 CLH Fixed bug of Command timeout ... * | ||
22 | * 1.03 96/09/25 KG Added tmscsim_proc_info() * | ||
23 | * 1.04 96/10/11 CLH Updating for support KV 2.0.x * | ||
24 | * 1.05 96/10/18 KG Fixed bug in DC390_abort(null ptr deref)* | ||
25 | * 1.06 96/10/25 KG Fixed module support * | ||
26 | * 1.07 96/11/09 KG Fixed tmscsim_proc_info() * | ||
27 | * 1.08 96/11/18 KG Fixed null ptr in DC390_Disconnect() * | ||
28 | * 1.09 96/11/30 KG Added register the allocated IO space * | ||
29 | * 1.10 96/12/05 CLH Modified tmscsim_proc_info(), and reset * | ||
30 | * pending interrupt in DC390_detect() * | ||
31 | * 1.11 97/02/05 KG/CLH Fixeds problem with partitions greater * | ||
32 | * than 1GB * | ||
33 | * 1.12 98/02/15 MJ Rewritten PCI probing * | ||
34 | * 1.13 98/04/08 KG Support for non DC390, __initfunc decls,* | ||
35 | * changed max devs from 10 to 16 * | ||
36 | * 1.14a 98/05/05 KG Dynamic DCB allocation, add-single-dev * | ||
37 | * for LUNs if LUN_SCAN (BIOS) not set * | ||
38 | * runtime config using /proc interface * | ||
39 | * 1.14b 98/05/06 KG eliminated cli (); sti (); spinlocks * | ||
40 | * 1.14c 98/05/07 KG 2.0.x compatibility * | ||
41 | * 1.20a 98/05/07 KG changed names of funcs to be consistent * | ||
42 | * DC390_ (entry points), dc390_ (internal)* | ||
43 | * reworked locking * | ||
44 | * 1.20b 98/05/12 KG bugs: version, kfree, _ctmp * | ||
45 | * debug output * | ||
46 | * 1.20c 98/05/12 KG bugs: kfree, parsing, EEpromDefaults * | ||
47 | * 1.20d 98/05/14 KG bugs: list linkage, clear flag after * | ||
48 | * reset on startup, code cleanup * | ||
49 | * 1.20e 98/05/15 KG spinlock comments, name space cleanup * | ||
50 | * pLastDCB now part of ACB structure * | ||
51 | * added stats, timeout for 2.1, TagQ bug * | ||
52 | * RESET and INQUIRY interface commands * | ||
53 | * 1.20f 98/05/18 KG spinlocks fixes, max_lun fix, free DCBs * | ||
54 | * for missing LUNs, pending int * | ||
55 | * 1.20g 98/05/19 KG Clean up: Avoid short * | ||
56 | * 1.20h 98/05/21 KG Remove AdaptSCSIID, max_lun ... * | ||
57 | * 1.20i 98/05/21 KG Aiiie: Bug with TagQMask * | ||
58 | * 1.20j 98/05/24 KG Handle STAT_BUSY, handle pACB->pLinkDCB * | ||
59 | * == 0 in remove_dev and DoingSRB_Done * | ||
60 | * 1.20k 98/05/25 KG DMA_INT (experimental) * | ||
61 | * 1.20l 98/05/27 KG remove DMA_INT; DMA_IDLE cmds added; * | ||
62 | * 1.20m 98/06/10 KG glitch configurable; made some global * | ||
63 | * vars part of ACB; use DC390_readX * | ||
64 | * 1.20n 98/06/11 KG startup params * | ||
65 | * 1.20o 98/06/15 KG added TagMaxNum to boot/module params * | ||
66 | * Device Nr -> Idx, TagMaxNum power of 2 * | ||
67 | * 1.20p 98/06/17 KG Docu updates. Reset depends on settings * | ||
68 | * pci_set_master added; 2.0.xx: pcibios_* * | ||
69 | * used instead of MechNum things ... * | ||
70 | * 1.20q 98/06/23 KG Changed defaults. Added debug code for * | ||
71 | * removable media and fixed it. TagMaxNum * | ||
72 | * fixed for DC390. Locking: ACB, DRV for * | ||
73 | * better IRQ sharing. Spelling: Queueing * | ||
74 | * Parsing and glitch_cfg changes. Display * | ||
75 | * real SyncSpeed value. Made DisConn * | ||
76 | * functional (!) * | ||
77 | * 1.20r 98/06/30 KG Debug macros, allow disabling DsCn, set * | ||
78 | * BIT4 in CtrlR4, EN_PAGE_INT, 2.0 module * | ||
79 | * param -1 fixed. * | ||
80 | * 1.20s 98/08/20 KG Debug info on abort(), try to check PCI,* | ||
81 | * phys_to_bus instead of phys_to_virt, * | ||
82 | * fixed sel. process, fixed locking, * | ||
83 | * added MODULE_XXX infos, changed IRQ * | ||
84 | * request flags, disable DMA_INT * | ||
85 | * 1.20t 98/09/07 KG TagQ report fixed; Write Erase DMA Stat;* | ||
86 | * initfunc -> __init; better abort; * | ||
87 | * Timeout for XFER_DONE & BLAST_COMPLETE; * | ||
88 | * Allow up to 33 commands being processed * | ||
89 | * 2.0a 98/10/14 KG Max Cmnds back to 17. DMA_Stat clearing * | ||
90 | * all flags. Clear within while() loops * | ||
91 | * in DataIn_0/Out_0. Null ptr in dumpinfo * | ||
92 | * for pSRB==0. Better locking during init.* | ||
93 | * bios_param() now respects part. table. * | ||
94 | * 2.0b 98/10/24 KG Docu fixes. Timeout Msg in DMA Blast. * | ||
95 | * Disallow illegal idx in INQUIRY/REMOVE * | ||
96 | * 2.0c 98/11/19 KG Cleaned up detect/init for SMP boxes, * | ||
97 | * Write Erase DMA (1.20t) caused problems * | ||
98 | * 2.0d 98/12/25 KG Christmas release ;-) Message handling * | ||
99 | * completely reworked. Handle target ini- * | ||
100 | * tiated SDTR correctly. * | ||
101 | * 2.0d1 99/01/25 KG Try to handle RESTORE_PTR * | ||
102 | * 2.0d2 99/02/08 KG Check for failure of kmalloc, correct * | ||
103 | * inclusion of scsicam.h, DelayReset * | ||
104 | * 2.0d3 99/05/31 KG DRIVER_OK -> DID_OK, DID_NO_CONNECT, * | ||
105 | * detect Target mode and warn. * | ||
106 | * pcmd->result handling cleaned up. * | ||
107 | * 2.0d4 99/06/01 KG Cleaned selection process. Found bug * | ||
108 | * which prevented more than 16 tags. Now: * | ||
109 | * 24. SDTR cleanup. Cleaner multi-LUN * | ||
110 | * handling. Don't modify ControlRegs/FIFO * | ||
111 | * when connected. * | ||
112 | * 2.0d5 99/06/01 KG Clear DevID, Fix INQUIRY after cfg chg. * | ||
113 | * 2.0d6 99/06/02 KG Added ADD special command to allow cfg. * | ||
114 | * before detection. Reset SYNC_NEGO_DONE * | ||
115 | * after a bus reset. * | ||
116 | * 2.0d7 99/06/03 KG Fixed bugs wrt add,remove commands * | ||
117 | * 2.0d8 99/06/04 KG Removed copying of cmnd into CmdBlock. * | ||
118 | * Fixed Oops in _release(). * | ||
119 | * 2.0d9 99/06/06 KG Also tag queue INQUIRY, T_U_R, ... * | ||
120 | * Allow arb. no. of Tagged Cmnds. Max 32 * | ||
121 | * 2.0d1099/06/20 KG TagMaxNo changes now honoured! Queueing * | ||
122 | * clearified (renamed ..) TagMask handling* | ||
123 | * cleaned. * | ||
124 | * 2.0d1199/06/28 KG cmd->result now identical to 2.0d2 * | ||
125 | * 2.0d1299/07/04 KG Changed order of processing in IRQ * | ||
126 | * 2.0d1399/07/05 KG Don't update DCB fields if removed * | ||
127 | * 2.0d1499/07/05 KG remove_dev: Move kfree() to the end * | ||
128 | * 2.0d1599/07/12 KG use_new_eh_code: 0, ULONG -> UINT where * | ||
129 | * appropriate * | ||
130 | * 2.0d1699/07/13 KG Reenable StartSCSI interrupt, Retry msg * | ||
131 | * 2.0d1799/07/15 KG Remove debug msg. Disable recfg. when * | ||
132 | * there are queued cmnds * | ||
133 | * 2.0d1899/07/18 KG Selection timeout: Don't requeue * | ||
134 | * 2.0d1999/07/18 KG Abort: Only call scsi_done if dequeued * | ||
135 | * 2.0d2099/07/19 KG Rst_Detect: DoingSRB_Done * | ||
136 | * 2.0d2199/08/15 KG dev_id for request/free_irq, cmnd[0] for* | ||
137 | * RETRY, SRBdone does DID_ABORT for the * | ||
138 | * cmd passed by DC390_reset() * | ||
139 | * 2.0d2299/08/25 KG dev_id fixed. can_queue: 42 * | ||
140 | * 2.0d2399/08/25 KG Removed some debugging code. dev_id * | ||
141 | * now is set to pACB. Use u8,u16,u32. * | ||
142 | * 2.0d2499/11/14 KG Unreg. I/O if failed IRQ alloc. Call * | ||
143 | * done () w/ DID_BAD_TARGET in case of * | ||
144 | * missing DCB. We are old EH!! * | ||
145 | * 2.0d2500/01/15 KG 2.3.3x compat from Andreas Schultz * | ||
146 | * set unique_id. Disable RETRY message. * | ||
147 | * 2.0d2600/01/29 KG Go to new EH. * | ||
148 | * 2.0d2700/01/31 KG ... but maintain 2.0 compat. * | ||
149 | * and fix DCB freeing * | ||
150 | * 2.0d2800/02/14 KG Queue statistics fixed, dump special cmd* | ||
151 | * Waiting_Timer for failed StartSCSI * | ||
152 | * New EH: Don't return cmnds to ML on RST * | ||
153 | * Use old EH (don't have new EH fns yet) * | ||
154 | * Reset: Unlock, but refuse to queue * | ||
155 | * 2.3 __setup function * | ||
156 | * 2.0e 00/05/22 KG Return residual for 2.3 * | ||
157 | * 2.0e1 00/05/25 KG Compile fixes for 2.3.99 * | ||
158 | * 2.0e2 00/05/27 KG Jeff Garzik's pci_enable_device() * | ||
159 | * 2.0e3 00/09/29 KG Some 2.4 changes. Don't try Sync Nego * | ||
160 | * before INQUIRY has reported ability. * | ||
161 | * Recognise INQUIRY as scanning command. * | ||
162 | * 2.0e4 00/10/13 KG Allow compilation into 2.4 kernel * | ||
163 | * 2.0e5 00/11/17 KG Store Inq.flags in DCB * | ||
164 | * 2.0e6 00/11/22 KG 2.4 init function (Thx to O.Schumann) * | ||
165 | * 2.4 PCI device table (Thx to A.Richter) * | ||
166 | * 2.0e7 00/11/28 KG Allow overriding of BIOS settings * | ||
167 | * 2.0f 00/12/20 KG Handle failed INQUIRYs during scan * | ||
168 | * 2.1a 03/11/29 GL, KG Initial fixing for 2.6. Convert to * | ||
169 | * use the current PCI-mapping API, update * | ||
170 | * command-queuing. * | ||
171 | * 2.1b 04/04/13 GL Fix for 64-bit platforms * | ||
172 | * 2.1b1 04/01/31 GL (applied 05.04) Remove internal * | ||
173 | * command-queuing. * | ||
174 | * 2.1b2 04/02/01 CH (applied 05.04) Fix error-handling * | ||
175 | * 2.1c 04/05/23 GL Update to use the new pci_driver API, * | ||
176 | * some scsi EH updates, more cleanup. * | ||
177 | * 2.1d 04/05/27 GL Moved setting of scan_devices to * | ||
178 | * slave_alloc/_configure/_destroy, as * | ||
179 | * suggested by CH. * | ||
180 | ***********************************************************************/ | ||
181 | |||
182 | /* DEBUG options */ | ||
183 | //#define DC390_DEBUG0 | ||
184 | //#define DC390_DEBUG1 | ||
185 | //#define DC390_DCBDEBUG | ||
186 | //#define DC390_PARSEDEBUG | ||
187 | //#define DC390_REMOVABLEDEBUG | ||
188 | //#define DC390_LOCKDEBUG | ||
189 | |||
190 | //#define NOP do{}while(0) | ||
191 | #define C_NOP | ||
192 | |||
193 | /* Debug definitions */ | ||
194 | #ifdef DC390_DEBUG0 | ||
195 | # define DEBUG0(x) x | ||
196 | #else | ||
197 | # define DEBUG0(x) C_NOP | ||
198 | #endif | ||
199 | #ifdef DC390_DEBUG1 | ||
200 | # define DEBUG1(x) x | ||
201 | #else | ||
202 | # define DEBUG1(x) C_NOP | ||
203 | #endif | ||
204 | #ifdef DC390_DCBDEBUG | ||
205 | # define DCBDEBUG(x) x | ||
206 | #else | ||
207 | # define DCBDEBUG(x) C_NOP | ||
208 | #endif | ||
209 | #ifdef DC390_PARSEDEBUG | ||
210 | # define PARSEDEBUG(x) x | ||
211 | #else | ||
212 | # define PARSEDEBUG(x) C_NOP | ||
213 | #endif | ||
214 | #ifdef DC390_REMOVABLEDEBUG | ||
215 | # define REMOVABLEDEBUG(x) x | ||
216 | #else | ||
217 | # define REMOVABLEDEBUG(x) C_NOP | ||
218 | #endif | ||
219 | #define DCBDEBUG1(x) C_NOP | ||
220 | |||
221 | #include <linux/module.h> | ||
222 | #include <linux/delay.h> | ||
223 | #include <linux/signal.h> | ||
224 | #include <linux/errno.h> | ||
225 | #include <linux/kernel.h> | ||
226 | #include <linux/ioport.h> | ||
227 | #include <linux/pci.h> | ||
228 | #include <linux/proc_fs.h> | ||
229 | #include <linux/string.h> | ||
230 | #include <linux/mm.h> | ||
231 | #include <linux/blkdev.h> | ||
232 | #include <linux/timer.h> | ||
233 | #include <linux/interrupt.h> | ||
234 | #include <linux/init.h> | ||
235 | #include <linux/spinlock.h> | ||
236 | #include <linux/slab.h> | ||
237 | #include <asm/io.h> | ||
238 | |||
239 | #include <scsi/scsi.h> | ||
240 | #include <scsi/scsi_cmnd.h> | ||
241 | #include <scsi/scsi_device.h> | ||
242 | #include <scsi/scsi_host.h> | ||
243 | #include <scsi/scsicam.h> | ||
244 | #include <scsi/scsi_tcq.h> | ||
245 | |||
246 | #define DC390_BANNER "Tekram DC390/AM53C974" | ||
247 | #define DC390_VERSION "2.1d 2004-05-27" | ||
248 | |||
249 | #define PCI_DEVICE_ID_AMD53C974 PCI_DEVICE_ID_AMD_SCSI | ||
250 | |||
251 | #include "tmscsim.h" | ||
252 | |||
253 | |||
254 | static void dc390_DataOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
255 | static void dc390_DataIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
256 | static void dc390_Command_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
257 | static void dc390_Status_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
258 | static void dc390_MsgOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
259 | static void dc390_MsgIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
260 | static void dc390_DataOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
261 | static void dc390_DataInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
262 | static void dc390_CommandPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
263 | static void dc390_StatusPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
264 | static void dc390_MsgOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
265 | static void dc390_MsgInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
266 | static void dc390_Nop_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
267 | static void dc390_Nop_1( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus); | ||
268 | |||
269 | static void dc390_SetXferRate( struct dc390_acb* pACB, struct dc390_dcb* pDCB ); | ||
270 | static void dc390_Disconnect( struct dc390_acb* pACB ); | ||
271 | static void dc390_Reselect( struct dc390_acb* pACB ); | ||
272 | static void dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB ); | ||
273 | static void dc390_ScsiRstDetect( struct dc390_acb* pACB ); | ||
274 | static void dc390_EnableMsgOut_Abort(struct dc390_acb*, struct dc390_srb*); | ||
275 | static void dc390_dumpinfo(struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB); | ||
276 | static void dc390_ResetDevParam(struct dc390_acb* pACB); | ||
277 | |||
278 | static u32 dc390_laststatus = 0; | ||
279 | static u8 dc390_adapterCnt = 0; | ||
280 | |||
281 | static int disable_clustering; | ||
282 | module_param(disable_clustering, int, S_IRUGO); | ||
283 | MODULE_PARM_DESC(disable_clustering, "If you experience problems with your devices, try setting to 1"); | ||
284 | |||
285 | /* Startup values, to be overriden on the commandline */ | ||
286 | static int tmscsim[] = {-2, -2, -2, -2, -2, -2}; | ||
287 | |||
288 | module_param_array(tmscsim, int, NULL, 0); | ||
289 | MODULE_PARM_DESC(tmscsim, "Host SCSI ID, Speed (0=10MHz), Device Flags, Adapter Flags, Max Tags (log2(tags)-1), DelayReset (s)"); | ||
290 | MODULE_AUTHOR("C.L. Huang / Kurt Garloff"); | ||
291 | MODULE_DESCRIPTION("SCSI host adapter driver for Tekram DC390 and other AMD53C974A based PCI SCSI adapters"); | ||
292 | MODULE_LICENSE("GPL"); | ||
293 | MODULE_SUPPORTED_DEVICE("sd,sr,sg,st"); | ||
294 | |||
295 | static void *dc390_phase0[]={ | ||
296 | dc390_DataOut_0, | ||
297 | dc390_DataIn_0, | ||
298 | dc390_Command_0, | ||
299 | dc390_Status_0, | ||
300 | dc390_Nop_0, | ||
301 | dc390_Nop_0, | ||
302 | dc390_MsgOut_0, | ||
303 | dc390_MsgIn_0, | ||
304 | dc390_Nop_1 | ||
305 | }; | ||
306 | |||
307 | static void *dc390_phase1[]={ | ||
308 | dc390_DataOutPhase, | ||
309 | dc390_DataInPhase, | ||
310 | dc390_CommandPhase, | ||
311 | dc390_StatusPhase, | ||
312 | dc390_Nop_0, | ||
313 | dc390_Nop_0, | ||
314 | dc390_MsgOutPhase, | ||
315 | dc390_MsgInPhase, | ||
316 | dc390_Nop_1 | ||
317 | }; | ||
318 | |||
319 | #ifdef DC390_DEBUG1 | ||
320 | static char* dc390_p0_str[] = { | ||
321 | "dc390_DataOut_0", | ||
322 | "dc390_DataIn_0", | ||
323 | "dc390_Command_0", | ||
324 | "dc390_Status_0", | ||
325 | "dc390_Nop_0", | ||
326 | "dc390_Nop_0", | ||
327 | "dc390_MsgOut_0", | ||
328 | "dc390_MsgIn_0", | ||
329 | "dc390_Nop_1" | ||
330 | }; | ||
331 | |||
332 | static char* dc390_p1_str[] = { | ||
333 | "dc390_DataOutPhase", | ||
334 | "dc390_DataInPhase", | ||
335 | "dc390_CommandPhase", | ||
336 | "dc390_StatusPhase", | ||
337 | "dc390_Nop_0", | ||
338 | "dc390_Nop_0", | ||
339 | "dc390_MsgOutPhase", | ||
340 | "dc390_MsgInPhase", | ||
341 | "dc390_Nop_1" | ||
342 | }; | ||
343 | #endif | ||
344 | |||
345 | static u8 dc390_eepromBuf[MAX_ADAPTER_NUM][EE_LEN]; | ||
346 | static u8 dc390_clock_period1[] = {4, 5, 6, 7, 8, 10, 13, 20}; | ||
347 | static u8 dc390_clock_speed[] = {100,80,67,57,50, 40, 31, 20}; | ||
348 | |||
349 | /*********************************************************************** | ||
350 | * Functions for the management of the internal structures | ||
351 | * (DCBs, SRBs, Queueing) | ||
352 | * | ||
353 | **********************************************************************/ | ||
354 | static void inline dc390_start_segment(struct dc390_srb* pSRB) | ||
355 | { | ||
356 | struct scatterlist *psgl = pSRB->pSegmentList; | ||
357 | |||
358 | /* start new sg segment */ | ||
359 | pSRB->SGBusAddr = sg_dma_address(psgl); | ||
360 | pSRB->SGToBeXferLen = sg_dma_len(psgl); | ||
361 | } | ||
362 | |||
363 | static unsigned long inline dc390_advance_segment(struct dc390_srb* pSRB, u32 residue) | ||
364 | { | ||
365 | unsigned long xfer = pSRB->SGToBeXferLen - residue; | ||
366 | |||
367 | /* xfer more bytes transferred */ | ||
368 | pSRB->SGBusAddr += xfer; | ||
369 | pSRB->TotalXferredLen += xfer; | ||
370 | pSRB->SGToBeXferLen = residue; | ||
371 | |||
372 | return xfer; | ||
373 | } | ||
374 | |||
375 | static struct dc390_dcb __inline__ *dc390_findDCB ( struct dc390_acb* pACB, u8 id, u8 lun) | ||
376 | { | ||
377 | struct dc390_dcb* pDCB = pACB->pLinkDCB; if (!pDCB) return NULL; | ||
378 | while (pDCB->TargetID != id || pDCB->TargetLUN != lun) | ||
379 | { | ||
380 | pDCB = pDCB->pNextDCB; | ||
381 | if (pDCB == pACB->pLinkDCB) | ||
382 | return NULL; | ||
383 | } | ||
384 | DCBDEBUG1( printk (KERN_DEBUG "DCB %p (%02x,%02x) found.\n", \ | ||
385 | pDCB, pDCB->TargetID, pDCB->TargetLUN)); | ||
386 | return pDCB; | ||
387 | } | ||
388 | |||
389 | /* Insert SRB oin top of free list */ | ||
390 | static __inline__ void dc390_Free_insert (struct dc390_acb* pACB, struct dc390_srb* pSRB) | ||
391 | { | ||
392 | DEBUG0(printk ("DC390: Free SRB %p\n", pSRB)); | ||
393 | pSRB->pNextSRB = pACB->pFreeSRB; | ||
394 | pACB->pFreeSRB = pSRB; | ||
395 | } | ||
396 | |||
397 | static __inline__ void dc390_Going_append (struct dc390_dcb* pDCB, struct dc390_srb* pSRB) | ||
398 | { | ||
399 | pDCB->GoingSRBCnt++; | ||
400 | DEBUG0(printk("DC390: Append SRB %p to Going\n", pSRB)); | ||
401 | /* Append to the list of Going commands */ | ||
402 | if( pDCB->pGoingSRB ) | ||
403 | pDCB->pGoingLast->pNextSRB = pSRB; | ||
404 | else | ||
405 | pDCB->pGoingSRB = pSRB; | ||
406 | |||
407 | pDCB->pGoingLast = pSRB; | ||
408 | /* No next one in sent list */ | ||
409 | pSRB->pNextSRB = NULL; | ||
410 | } | ||
411 | |||
412 | static __inline__ void dc390_Going_remove (struct dc390_dcb* pDCB, struct dc390_srb* pSRB) | ||
413 | { | ||
414 | DEBUG0(printk("DC390: Remove SRB %p from Going\n", pSRB)); | ||
415 | if (pSRB == pDCB->pGoingSRB) | ||
416 | pDCB->pGoingSRB = pSRB->pNextSRB; | ||
417 | else | ||
418 | { | ||
419 | struct dc390_srb* psrb = pDCB->pGoingSRB; | ||
420 | while (psrb && psrb->pNextSRB != pSRB) | ||
421 | psrb = psrb->pNextSRB; | ||
422 | if (!psrb) | ||
423 | { printk (KERN_ERR "DC390: Remove non-ex. SRB %p from Going!\n", pSRB); return; } | ||
424 | psrb->pNextSRB = pSRB->pNextSRB; | ||
425 | if (pSRB == pDCB->pGoingLast) | ||
426 | pDCB->pGoingLast = psrb; | ||
427 | } | ||
428 | pDCB->GoingSRBCnt--; | ||
429 | } | ||
430 | |||
431 | static struct scatterlist* dc390_sg_build_single(struct scatterlist *sg, void *addr, unsigned int length) | ||
432 | { | ||
433 | sg_init_one(sg, addr, length); | ||
434 | return sg; | ||
435 | } | ||
436 | |||
437 | /* Create pci mapping */ | ||
438 | static int dc390_pci_map (struct dc390_srb* pSRB) | ||
439 | { | ||
440 | int error = 0; | ||
441 | struct scsi_cmnd *pcmd = pSRB->pcmd; | ||
442 | struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev; | ||
443 | dc390_cmd_scp_t* cmdp = ((dc390_cmd_scp_t*)(&pcmd->SCp)); | ||
444 | |||
445 | /* Map sense buffer */ | ||
446 | if (pSRB->SRBFlag & AUTO_REQSENSE) { | ||
447 | pSRB->pSegmentList = dc390_sg_build_single(&pSRB->Segmentx, pcmd->sense_buffer, SCSI_SENSE_BUFFERSIZE); | ||
448 | pSRB->SGcount = pci_map_sg(pdev, pSRB->pSegmentList, 1, | ||
449 | DMA_FROM_DEVICE); | ||
450 | cmdp->saved_dma_handle = sg_dma_address(pSRB->pSegmentList); | ||
451 | |||
452 | /* TODO: error handling */ | ||
453 | if (pSRB->SGcount != 1) | ||
454 | error = 1; | ||
455 | DEBUG1(printk("%s(): Mapped sense buffer %p at %x\n", __func__, pcmd->sense_buffer, cmdp->saved_dma_handle)); | ||
456 | /* Map SG list */ | ||
457 | } else if (scsi_sg_count(pcmd)) { | ||
458 | int nseg; | ||
459 | |||
460 | nseg = scsi_dma_map(pcmd); | ||
461 | |||
462 | pSRB->pSegmentList = scsi_sglist(pcmd); | ||
463 | pSRB->SGcount = nseg; | ||
464 | |||
465 | /* TODO: error handling */ | ||
466 | if (nseg < 0) | ||
467 | error = 1; | ||
468 | DEBUG1(printk("%s(): Mapped SG %p with %d (%d) elements\n",\ | ||
469 | __func__, scsi_sglist(pcmd), nseg, scsi_sg_count(pcmd))); | ||
470 | /* Map single segment */ | ||
471 | } else | ||
472 | pSRB->SGcount = 0; | ||
473 | |||
474 | return error; | ||
475 | } | ||
476 | |||
477 | /* Remove pci mapping */ | ||
478 | static void dc390_pci_unmap (struct dc390_srb* pSRB) | ||
479 | { | ||
480 | struct scsi_cmnd *pcmd = pSRB->pcmd; | ||
481 | struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev; | ||
482 | DEBUG1(dc390_cmd_scp_t* cmdp = ((dc390_cmd_scp_t*)(&pcmd->SCp))); | ||
483 | |||
484 | if (pSRB->SRBFlag) { | ||
485 | pci_unmap_sg(pdev, &pSRB->Segmentx, 1, DMA_FROM_DEVICE); | ||
486 | DEBUG1(printk("%s(): Unmapped sense buffer at %x\n", __func__, cmdp->saved_dma_handle)); | ||
487 | } else { | ||
488 | scsi_dma_unmap(pcmd); | ||
489 | DEBUG1(printk("%s(): Unmapped SG at %p with %d elements\n", | ||
490 | __func__, scsi_sglist(pcmd), scsi_sg_count(pcmd))); | ||
491 | } | ||
492 | } | ||
493 | |||
494 | static void __inline__ | ||
495 | dc390_freetag (struct dc390_dcb* pDCB, struct dc390_srb* pSRB) | ||
496 | { | ||
497 | if (pSRB->TagNumber != SCSI_NO_TAG) { | ||
498 | pDCB->TagMask &= ~(1 << pSRB->TagNumber); /* free tag mask */ | ||
499 | pSRB->TagNumber = SCSI_NO_TAG; | ||
500 | } | ||
501 | } | ||
502 | |||
503 | |||
504 | static int | ||
505 | dc390_StartSCSI( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB ) | ||
506 | { | ||
507 | struct scsi_cmnd *scmd = pSRB->pcmd; | ||
508 | struct scsi_device *sdev = scmd->device; | ||
509 | u8 cmd, disc_allowed, try_sync_nego; | ||
510 | |||
511 | pSRB->ScsiPhase = SCSI_NOP0; | ||
512 | |||
513 | if (pACB->Connected) | ||
514 | { | ||
515 | // Should not happen normally | ||
516 | printk (KERN_WARNING "DC390: Can't select when connected! (%08x,%02x)\n", | ||
517 | pSRB->SRBState, pSRB->SRBFlag); | ||
518 | pSRB->SRBState = SRB_READY; | ||
519 | pACB->SelConn++; | ||
520 | return 1; | ||
521 | } | ||
522 | if (time_before (jiffies, pACB->last_reset)) | ||
523 | { | ||
524 | DEBUG0(printk ("DC390: We were just reset and don't accept commands yet!\n")); | ||
525 | return 1; | ||
526 | } | ||
527 | /* KG: Moved pci mapping here */ | ||
528 | dc390_pci_map(pSRB); | ||
529 | /* TODO: error handling */ | ||
530 | DC390_write8 (Scsi_Dest_ID, pDCB->TargetID); | ||
531 | DC390_write8 (Sync_Period, pDCB->SyncPeriod); | ||
532 | DC390_write8 (Sync_Offset, pDCB->SyncOffset); | ||
533 | DC390_write8 (CtrlReg1, pDCB->CtrlR1); | ||
534 | DC390_write8 (CtrlReg3, pDCB->CtrlR3); | ||
535 | DC390_write8 (CtrlReg4, pDCB->CtrlR4); | ||
536 | DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); /* Flush FIFO */ | ||
537 | DEBUG1(printk (KERN_INFO "DC390: Start SCSI command: %02x (Sync:%02x)\n",\ | ||
538 | scmd->cmnd[0], pDCB->SyncMode)); | ||
539 | |||
540 | /* Don't disconnect on AUTO_REQSENSE, cause it might be an | ||
541 | * Contingent Allegiance Condition (6.6), where no tags should be used. | ||
542 | * All other have to be allowed to disconnect to prevent Incorrect | ||
543 | * Initiator Connection (6.8.2/6.5.2) */ | ||
544 | /* Changed KG, 99/06/06 */ | ||
545 | if (! (pSRB->SRBFlag & AUTO_REQSENSE)) | ||
546 | disc_allowed = pDCB->DevMode & EN_DISCONNECT_; | ||
547 | else | ||
548 | disc_allowed = 0; | ||
549 | |||
550 | if ((pDCB->SyncMode & SYNC_ENABLE) && pDCB->TargetLUN == 0 && sdev->sdtr && | ||
551 | (((scmd->cmnd[0] == REQUEST_SENSE || (pSRB->SRBFlag & AUTO_REQSENSE)) && | ||
552 | !(pDCB->SyncMode & SYNC_NEGO_DONE)) || scmd->cmnd[0] == INQUIRY)) | ||
553 | try_sync_nego = 1; | ||
554 | else | ||
555 | try_sync_nego = 0; | ||
556 | |||
557 | pSRB->MsgCnt = 0; | ||
558 | cmd = SEL_W_ATN; | ||
559 | DC390_write8 (ScsiFifo, IDENTIFY(disc_allowed, pDCB->TargetLUN)); | ||
560 | /* Change 99/05/31: Don't use tags when not disconnecting (BUSY) */ | ||
561 | if ((pDCB->SyncMode & EN_TAG_QUEUEING) && disc_allowed && (scmd->flags & SCMD_TAGGED)) { | ||
562 | DC390_write8(ScsiFifo, MSG_SIMPLE_TAG); | ||
563 | pDCB->TagMask |= 1 << scmd->request->tag; | ||
564 | pSRB->TagNumber = scmd->request->tag; | ||
565 | DC390_write8(ScsiFifo, scmd->request->tag); | ||
566 | DEBUG1(printk(KERN_INFO "DC390: Select w/DisCn for SRB %p, block tag %02x\n", pSRB, tag[1])); | ||
567 | cmd = SEL_W_ATN3; | ||
568 | } else { | ||
569 | /* No TagQ */ | ||
570 | //no_tag: | ||
571 | DEBUG1(printk(KERN_INFO "DC390: Select w%s/DisCn for SRB %p, No TagQ\n", disc_allowed ? "" : "o", pSRB)); | ||
572 | } | ||
573 | |||
574 | pSRB->SRBState = SRB_START_; | ||
575 | |||
576 | if (try_sync_nego) | ||
577 | { | ||
578 | u8 Sync_Off = pDCB->SyncOffset; | ||
579 | DEBUG0(printk (KERN_INFO "DC390: NEW Sync Nego code triggered (%i %i)\n", pDCB->TargetID, pDCB->TargetLUN)); | ||
580 | pSRB->MsgOutBuf[0] = EXTENDED_MESSAGE; | ||
581 | pSRB->MsgOutBuf[1] = 3; | ||
582 | pSRB->MsgOutBuf[2] = EXTENDED_SDTR; | ||
583 | pSRB->MsgOutBuf[3] = pDCB->NegoPeriod; | ||
584 | if (!(Sync_Off & 0x0f)) Sync_Off = SYNC_NEGO_OFFSET; | ||
585 | pSRB->MsgOutBuf[4] = Sync_Off; | ||
586 | pSRB->MsgCnt = 5; | ||
587 | //pSRB->SRBState = SRB_MSGOUT_; | ||
588 | pSRB->SRBState |= DO_SYNC_NEGO; | ||
589 | cmd = SEL_W_ATN_STOP; | ||
590 | } | ||
591 | |||
592 | /* Command is written in CommandPhase, if SEL_W_ATN_STOP ... */ | ||
593 | if (cmd != SEL_W_ATN_STOP) | ||
594 | { | ||
595 | if( pSRB->SRBFlag & AUTO_REQSENSE ) | ||
596 | { | ||
597 | DC390_write8 (ScsiFifo, REQUEST_SENSE); | ||
598 | DC390_write8 (ScsiFifo, pDCB->TargetLUN << 5); | ||
599 | DC390_write8 (ScsiFifo, 0); | ||
600 | DC390_write8 (ScsiFifo, 0); | ||
601 | DC390_write8 (ScsiFifo, SCSI_SENSE_BUFFERSIZE); | ||
602 | DC390_write8 (ScsiFifo, 0); | ||
603 | DEBUG1(printk (KERN_DEBUG "DC390: AutoReqSense !\n")); | ||
604 | } | ||
605 | else /* write cmnd to bus */ | ||
606 | { | ||
607 | u8 *ptr; u8 i; | ||
608 | ptr = (u8 *)scmd->cmnd; | ||
609 | for (i = 0; i < scmd->cmd_len; i++) | ||
610 | DC390_write8 (ScsiFifo, *(ptr++)); | ||
611 | } | ||
612 | } | ||
613 | DEBUG0(if (pACB->pActiveDCB) \ | ||
614 | printk (KERN_WARNING "DC390: ActiveDCB != 0\n")); | ||
615 | DEBUG0(if (pDCB->pActiveSRB) \ | ||
616 | printk (KERN_WARNING "DC390: ActiveSRB != 0\n")); | ||
617 | //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD); | ||
618 | if (DC390_read8 (Scsi_Status) & INTERRUPT) | ||
619 | { | ||
620 | dc390_freetag (pDCB, pSRB); | ||
621 | DEBUG0(printk ("DC390: Interrupt during Start SCSI (target %02i-%02i)\n", | ||
622 | scmd->device->id, (u8)scmd->device->lun)); | ||
623 | pSRB->SRBState = SRB_READY; | ||
624 | //DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); | ||
625 | pACB->SelLost++; | ||
626 | return 1; | ||
627 | } | ||
628 | DC390_write8 (ScsiCmd, cmd); | ||
629 | pACB->pActiveDCB = pDCB; | ||
630 | pDCB->pActiveSRB = pSRB; | ||
631 | pACB->Connected = 1; | ||
632 | pSRB->ScsiPhase = SCSI_NOP1; | ||
633 | return 0; | ||
634 | } | ||
635 | |||
636 | |||
637 | static void __inline__ | ||
638 | dc390_InvalidCmd(struct dc390_acb* pACB) | ||
639 | { | ||
640 | if (pACB->pActiveDCB->pActiveSRB->SRBState & (SRB_START_ | SRB_MSGOUT)) | ||
641 | DC390_write8(ScsiCmd, CLEAR_FIFO_CMD); | ||
642 | } | ||
643 | |||
644 | |||
645 | static irqreturn_t __inline__ | ||
646 | DC390_Interrupt(void *dev_id) | ||
647 | { | ||
648 | struct dc390_acb *pACB = dev_id; | ||
649 | struct dc390_dcb *pDCB; | ||
650 | struct dc390_srb *pSRB; | ||
651 | u8 sstatus=0; | ||
652 | u8 phase; | ||
653 | void (*stateV)( struct dc390_acb*, struct dc390_srb*, u8 *); | ||
654 | u8 istate, istatus; | ||
655 | |||
656 | sstatus = DC390_read8 (Scsi_Status); | ||
657 | if( !(sstatus & INTERRUPT) ) | ||
658 | return IRQ_NONE; | ||
659 | |||
660 | DEBUG1(printk (KERN_DEBUG "sstatus=%02x,", sstatus)); | ||
661 | |||
662 | //DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT); | ||
663 | //dstatus = DC390_read8 (DMA_Status); | ||
664 | //DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT); | ||
665 | |||
666 | spin_lock_irq(pACB->pScsiHost->host_lock); | ||
667 | |||
668 | istate = DC390_read8 (Intern_State); | ||
669 | istatus = DC390_read8 (INT_Status); /* This clears Scsi_Status, Intern_State and INT_Status ! */ | ||
670 | |||
671 | DEBUG1(printk (KERN_INFO "Istatus(Res,Inv,Dis,Serv,Succ,ReS,SelA,Sel)=%02x,",istatus)); | ||
672 | dc390_laststatus &= ~0x00ffffff; | ||
673 | dc390_laststatus |= /* dstatus<<24 | */ sstatus<<16 | istate<<8 | istatus; | ||
674 | |||
675 | if (sstatus & ILLEGAL_OP_ERR) | ||
676 | { | ||
677 | printk ("DC390: Illegal Operation detected (%08x)!\n", dc390_laststatus); | ||
678 | dc390_dumpinfo (pACB, pACB->pActiveDCB, pACB->pActiveDCB->pActiveSRB); | ||
679 | } | ||
680 | |||
681 | else if (istatus & INVALID_CMD) | ||
682 | { | ||
683 | printk ("DC390: Invalid Command detected (%08x)!\n", dc390_laststatus); | ||
684 | dc390_InvalidCmd( pACB ); | ||
685 | goto unlock; | ||
686 | } | ||
687 | |||
688 | if (istatus & SCSI_RESET) | ||
689 | { | ||
690 | dc390_ScsiRstDetect( pACB ); | ||
691 | goto unlock; | ||
692 | } | ||
693 | |||
694 | if (istatus & DISCONNECTED) | ||
695 | { | ||
696 | dc390_Disconnect( pACB ); | ||
697 | goto unlock; | ||
698 | } | ||
699 | |||
700 | if (istatus & RESELECTED) | ||
701 | { | ||
702 | dc390_Reselect( pACB ); | ||
703 | goto unlock; | ||
704 | } | ||
705 | |||
706 | else if (istatus & (SELECTED | SEL_ATTENTION)) | ||
707 | { | ||
708 | printk (KERN_ERR "DC390: Target mode not supported!\n"); | ||
709 | goto unlock; | ||
710 | } | ||
711 | |||
712 | if (istatus & (SUCCESSFUL_OP|SERVICE_REQUEST) ) | ||
713 | { | ||
714 | pDCB = pACB->pActiveDCB; | ||
715 | if (!pDCB) | ||
716 | { | ||
717 | printk (KERN_ERR "DC390: Suc. op/ Serv. req: pActiveDCB = 0!\n"); | ||
718 | goto unlock; | ||
719 | } | ||
720 | pSRB = pDCB->pActiveSRB; | ||
721 | if( pDCB->DCBFlag & ABORT_DEV_ ) | ||
722 | dc390_EnableMsgOut_Abort (pACB, pSRB); | ||
723 | |||
724 | phase = pSRB->ScsiPhase; | ||
725 | DEBUG1(printk (KERN_INFO "DC390: [%i]%s(0) (%02x)\n", phase, dc390_p0_str[phase], sstatus)); | ||
726 | stateV = (void *) dc390_phase0[phase]; | ||
727 | ( *stateV )( pACB, pSRB, &sstatus ); | ||
728 | |||
729 | pSRB->ScsiPhase = sstatus & 7; | ||
730 | phase = (u8) sstatus & 7; | ||
731 | DEBUG1(printk (KERN_INFO "DC390: [%i]%s(1) (%02x)\n", phase, dc390_p1_str[phase], sstatus)); | ||
732 | stateV = (void *) dc390_phase1[phase]; | ||
733 | ( *stateV )( pACB, pSRB, &sstatus ); | ||
734 | } | ||
735 | |||
736 | unlock: | ||
737 | spin_unlock_irq(pACB->pScsiHost->host_lock); | ||
738 | return IRQ_HANDLED; | ||
739 | } | ||
740 | |||
741 | static irqreturn_t do_DC390_Interrupt(int irq, void *dev_id) | ||
742 | { | ||
743 | irqreturn_t ret; | ||
744 | DEBUG1(printk (KERN_INFO "DC390: Irq (%i) caught: ", irq)); | ||
745 | /* Locking is done in DC390_Interrupt */ | ||
746 | ret = DC390_Interrupt(dev_id); | ||
747 | DEBUG1(printk (".. IRQ returned\n")); | ||
748 | return ret; | ||
749 | } | ||
750 | |||
751 | static void | ||
752 | dc390_DataOut_0(struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
753 | { | ||
754 | u8 sstatus; | ||
755 | u32 ResidCnt; | ||
756 | u8 dstate = 0; | ||
757 | |||
758 | sstatus = *psstatus; | ||
759 | |||
760 | if( !(pSRB->SRBState & SRB_XFERPAD) ) | ||
761 | { | ||
762 | if( sstatus & (PARITY_ERR | ILLEGAL_OP_ERR) ) | ||
763 | pSRB->SRBStatus |= PARITY_ERROR; | ||
764 | |||
765 | if( sstatus & COUNT_2_ZERO ) | ||
766 | { | ||
767 | unsigned long timeout = jiffies + HZ; | ||
768 | |||
769 | /* Function called from the ISR with the host_lock held and interrupts disabled */ | ||
770 | if (pSRB->SGToBeXferLen) | ||
771 | while (time_before(jiffies, timeout) && !((dstate = DC390_read8 (DMA_Status)) & DMA_XFER_DONE)) { | ||
772 | spin_unlock_irq(pACB->pScsiHost->host_lock); | ||
773 | udelay(50); | ||
774 | spin_lock_irq(pACB->pScsiHost->host_lock); | ||
775 | } | ||
776 | if (!time_before(jiffies, timeout)) | ||
777 | printk (KERN_CRIT "DC390: Deadlock in DataOut_0: DMA aborted unfinished: %06x bytes remain!!\n", | ||
778 | DC390_read32 (DMA_Wk_ByteCntr)); | ||
779 | dc390_laststatus &= ~0xff000000; | ||
780 | dc390_laststatus |= dstate << 24; | ||
781 | pSRB->TotalXferredLen += pSRB->SGToBeXferLen; | ||
782 | pSRB->SGIndex++; | ||
783 | if( pSRB->SGIndex < pSRB->SGcount ) | ||
784 | { | ||
785 | pSRB->pSegmentList++; | ||
786 | |||
787 | dc390_start_segment(pSRB); | ||
788 | } | ||
789 | else | ||
790 | pSRB->SGToBeXferLen = 0; | ||
791 | } | ||
792 | else | ||
793 | { | ||
794 | ResidCnt = ((u32) DC390_read8 (Current_Fifo) & 0x1f) + | ||
795 | (((u32) DC390_read8 (CtcReg_High) << 16) | | ||
796 | ((u32) DC390_read8 (CtcReg_Mid) << 8) | | ||
797 | (u32) DC390_read8 (CtcReg_Low)); | ||
798 | |||
799 | dc390_advance_segment(pSRB, ResidCnt); | ||
800 | } | ||
801 | } | ||
802 | if ((*psstatus & 7) != SCSI_DATA_OUT) | ||
803 | { | ||
804 | DC390_write8 (DMA_Cmd, WRITE_DIRECTION+DMA_IDLE_CMD); | ||
805 | DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); | ||
806 | } | ||
807 | } | ||
808 | |||
809 | static void | ||
810 | dc390_DataIn_0(struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
811 | { | ||
812 | u8 sstatus, residual, bval; | ||
813 | u32 ResidCnt, i; | ||
814 | unsigned long xferCnt; | ||
815 | |||
816 | sstatus = *psstatus; | ||
817 | |||
818 | if( !(pSRB->SRBState & SRB_XFERPAD) ) | ||
819 | { | ||
820 | if( sstatus & (PARITY_ERR | ILLEGAL_OP_ERR)) | ||
821 | pSRB->SRBStatus |= PARITY_ERROR; | ||
822 | |||
823 | if( sstatus & COUNT_2_ZERO ) | ||
824 | { | ||
825 | int dstate = 0; | ||
826 | unsigned long timeout = jiffies + HZ; | ||
827 | |||
828 | /* Function called from the ISR with the host_lock held and interrupts disabled */ | ||
829 | if (pSRB->SGToBeXferLen) | ||
830 | while (time_before(jiffies, timeout) && !((dstate = DC390_read8 (DMA_Status)) & DMA_XFER_DONE)) { | ||
831 | spin_unlock_irq(pACB->pScsiHost->host_lock); | ||
832 | udelay(50); | ||
833 | spin_lock_irq(pACB->pScsiHost->host_lock); | ||
834 | } | ||
835 | if (!time_before(jiffies, timeout)) { | ||
836 | printk (KERN_CRIT "DC390: Deadlock in DataIn_0: DMA aborted unfinished: %06x bytes remain!!\n", | ||
837 | DC390_read32 (DMA_Wk_ByteCntr)); | ||
838 | printk (KERN_CRIT "DC390: DataIn_0: DMA State: %i\n", dstate); | ||
839 | } | ||
840 | dc390_laststatus &= ~0xff000000; | ||
841 | dc390_laststatus |= dstate << 24; | ||
842 | DEBUG1(ResidCnt = ((unsigned long) DC390_read8 (CtcReg_High) << 16) \ | ||
843 | + ((unsigned long) DC390_read8 (CtcReg_Mid) << 8) \ | ||
844 | + ((unsigned long) DC390_read8 (CtcReg_Low))); | ||
845 | DEBUG1(printk (KERN_DEBUG "Count_2_Zero (ResidCnt=%u,ToBeXfer=%lu),", ResidCnt, pSRB->SGToBeXferLen)); | ||
846 | |||
847 | DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD); | ||
848 | |||
849 | pSRB->TotalXferredLen += pSRB->SGToBeXferLen; | ||
850 | pSRB->SGIndex++; | ||
851 | if( pSRB->SGIndex < pSRB->SGcount ) | ||
852 | { | ||
853 | pSRB->pSegmentList++; | ||
854 | |||
855 | dc390_start_segment(pSRB); | ||
856 | } | ||
857 | else | ||
858 | pSRB->SGToBeXferLen = 0; | ||
859 | } | ||
860 | else /* phase changed */ | ||
861 | { | ||
862 | residual = 0; | ||
863 | bval = DC390_read8 (Current_Fifo); | ||
864 | while( bval & 0x1f ) | ||
865 | { | ||
866 | DEBUG1(printk (KERN_DEBUG "Check for residuals,")); | ||
867 | if( (bval & 0x1f) == 1 ) | ||
868 | { | ||
869 | for(i=0; i < 0x100; i++) | ||
870 | { | ||
871 | bval = DC390_read8 (Current_Fifo); | ||
872 | if( !(bval & 0x1f) ) | ||
873 | goto din_1; | ||
874 | else if( i == 0x0ff ) | ||
875 | { | ||
876 | residual = 1; /* ;1 residual byte */ | ||
877 | goto din_1; | ||
878 | } | ||
879 | } | ||
880 | } | ||
881 | else | ||
882 | bval = DC390_read8 (Current_Fifo); | ||
883 | } | ||
884 | din_1: | ||
885 | DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_BLAST_CMD); | ||
886 | for (i = 0xa000; i; i--) | ||
887 | { | ||
888 | bval = DC390_read8 (DMA_Status); | ||
889 | if (bval & BLAST_COMPLETE) | ||
890 | break; | ||
891 | } | ||
892 | /* It seems a DMA Blast abort isn't that bad ... */ | ||
893 | if (!i) printk (KERN_ERR "DC390: DMA Blast aborted unfinished!\n"); | ||
894 | //DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD); | ||
895 | dc390_laststatus &= ~0xff000000; | ||
896 | dc390_laststatus |= bval << 24; | ||
897 | |||
898 | DEBUG1(printk (KERN_DEBUG "Blast: Read %i times DMA_Status %02x", 0xa000-i, bval)); | ||
899 | ResidCnt = (((u32) DC390_read8 (CtcReg_High) << 16) | | ||
900 | ((u32) DC390_read8 (CtcReg_Mid) << 8)) | | ||
901 | (u32) DC390_read8 (CtcReg_Low); | ||
902 | |||
903 | xferCnt = dc390_advance_segment(pSRB, ResidCnt); | ||
904 | |||
905 | if (residual) { | ||
906 | size_t count = 1; | ||
907 | size_t offset = pSRB->SGBusAddr - sg_dma_address(pSRB->pSegmentList); | ||
908 | unsigned long flags; | ||
909 | u8 *ptr; | ||
910 | |||
911 | bval = DC390_read8 (ScsiFifo); /* get one residual byte */ | ||
912 | |||
913 | local_irq_save(flags); | ||
914 | ptr = scsi_kmap_atomic_sg(pSRB->pSegmentList, pSRB->SGcount, &offset, &count); | ||
915 | if (likely(ptr)) { | ||
916 | *(ptr + offset) = bval; | ||
917 | scsi_kunmap_atomic_sg(ptr); | ||
918 | } | ||
919 | local_irq_restore(flags); | ||
920 | WARN_ON(!ptr); | ||
921 | |||
922 | /* 1 more byte read */ | ||
923 | xferCnt += dc390_advance_segment(pSRB, pSRB->SGToBeXferLen - 1); | ||
924 | } | ||
925 | DEBUG1(printk (KERN_DEBUG "Xfered: %lu, Total: %lu, Remaining: %lu\n", xferCnt,\ | ||
926 | pSRB->TotalXferredLen, pSRB->SGToBeXferLen)); | ||
927 | } | ||
928 | } | ||
929 | if ((*psstatus & 7) != SCSI_DATA_IN) | ||
930 | { | ||
931 | DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); | ||
932 | DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD); | ||
933 | } | ||
934 | } | ||
935 | |||
936 | static void | ||
937 | dc390_Command_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
938 | { | ||
939 | } | ||
940 | |||
941 | static void | ||
942 | dc390_Status_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
943 | { | ||
944 | |||
945 | pSRB->TargetStatus = DC390_read8 (ScsiFifo); | ||
946 | //udelay (1); | ||
947 | pSRB->EndMessage = DC390_read8 (ScsiFifo); /* get message */ | ||
948 | |||
949 | *psstatus = SCSI_NOP0; | ||
950 | pSRB->SRBState = SRB_COMPLETED; | ||
951 | DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD); | ||
952 | } | ||
953 | |||
954 | static void | ||
955 | dc390_MsgOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
956 | { | ||
957 | if( pSRB->SRBState & (SRB_UNEXPECT_RESEL+SRB_ABORT_SENT) ) | ||
958 | *psstatus = SCSI_NOP0; | ||
959 | //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD); | ||
960 | } | ||
961 | |||
962 | |||
963 | static void __inline__ | ||
964 | dc390_reprog (struct dc390_acb* pACB, struct dc390_dcb* pDCB) | ||
965 | { | ||
966 | DC390_write8 (Sync_Period, pDCB->SyncPeriod); | ||
967 | DC390_write8 (Sync_Offset, pDCB->SyncOffset); | ||
968 | DC390_write8 (CtrlReg3, pDCB->CtrlR3); | ||
969 | DC390_write8 (CtrlReg4, pDCB->CtrlR4); | ||
970 | dc390_SetXferRate (pACB, pDCB); | ||
971 | } | ||
972 | |||
973 | |||
974 | #ifdef DC390_DEBUG0 | ||
975 | static void | ||
976 | dc390_printMsg (u8 *MsgBuf, u8 len) | ||
977 | { | ||
978 | int i; | ||
979 | printk (" %02x", MsgBuf[0]); | ||
980 | for (i = 1; i < len; i++) | ||
981 | printk (" %02x", MsgBuf[i]); | ||
982 | printk ("\n"); | ||
983 | } | ||
984 | #endif | ||
985 | |||
986 | #define DC390_ENABLE_MSGOUT DC390_write8 (ScsiCmd, SET_ATN_CMD) | ||
987 | |||
988 | /* reject_msg */ | ||
989 | static void __inline__ | ||
990 | dc390_MsgIn_reject (struct dc390_acb* pACB, struct dc390_srb* pSRB) | ||
991 | { | ||
992 | pSRB->MsgOutBuf[0] = MESSAGE_REJECT; | ||
993 | pSRB->MsgCnt = 1; | ||
994 | DC390_ENABLE_MSGOUT; | ||
995 | DEBUG0 (printk (KERN_INFO "DC390: Reject message\n")); | ||
996 | } | ||
997 | |||
998 | /* abort command */ | ||
999 | static void | ||
1000 | dc390_EnableMsgOut_Abort ( struct dc390_acb* pACB, struct dc390_srb* pSRB ) | ||
1001 | { | ||
1002 | pSRB->MsgOutBuf[0] = ABORT; | ||
1003 | pSRB->MsgCnt = 1; DC390_ENABLE_MSGOUT; | ||
1004 | pSRB->pSRBDCB->DCBFlag &= ~ABORT_DEV_; | ||
1005 | } | ||
1006 | |||
1007 | static struct dc390_srb* | ||
1008 | dc390_MsgIn_QTag (struct dc390_acb* pACB, struct dc390_dcb* pDCB, s8 tag) | ||
1009 | { | ||
1010 | struct dc390_srb* pSRB = pDCB->pGoingSRB; | ||
1011 | |||
1012 | if (pSRB) | ||
1013 | { | ||
1014 | struct scsi_cmnd *scmd = scsi_find_tag(pSRB->pcmd->device, tag); | ||
1015 | pSRB = (struct dc390_srb *)scmd->host_scribble; | ||
1016 | |||
1017 | if (pDCB->DCBFlag & ABORT_DEV_) | ||
1018 | { | ||
1019 | pSRB->SRBState = SRB_ABORT_SENT; | ||
1020 | dc390_EnableMsgOut_Abort( pACB, pSRB ); | ||
1021 | } | ||
1022 | |||
1023 | if (!(pSRB->SRBState & SRB_DISCONNECT)) | ||
1024 | goto mingx0; | ||
1025 | |||
1026 | pDCB->pActiveSRB = pSRB; | ||
1027 | pSRB->SRBState = SRB_DATA_XFER; | ||
1028 | } | ||
1029 | else | ||
1030 | { | ||
1031 | mingx0: | ||
1032 | pSRB = pACB->pTmpSRB; | ||
1033 | pSRB->SRBState = SRB_UNEXPECT_RESEL; | ||
1034 | pDCB->pActiveSRB = pSRB; | ||
1035 | pSRB->MsgOutBuf[0] = ABORT_TAG; | ||
1036 | pSRB->MsgCnt = 1; DC390_ENABLE_MSGOUT; | ||
1037 | } | ||
1038 | return pSRB; | ||
1039 | } | ||
1040 | |||
1041 | |||
1042 | /* set async transfer mode */ | ||
1043 | static void | ||
1044 | dc390_MsgIn_set_async (struct dc390_acb* pACB, struct dc390_srb* pSRB) | ||
1045 | { | ||
1046 | struct dc390_dcb* pDCB = pSRB->pSRBDCB; | ||
1047 | if (!(pSRB->SRBState & DO_SYNC_NEGO)) | ||
1048 | printk (KERN_INFO "DC390: Target %i initiates Non-Sync?\n", pDCB->TargetID); | ||
1049 | pSRB->SRBState &= ~DO_SYNC_NEGO; | ||
1050 | pDCB->SyncMode &= ~(SYNC_ENABLE+SYNC_NEGO_DONE); | ||
1051 | pDCB->SyncPeriod = 0; | ||
1052 | pDCB->SyncOffset = 0; | ||
1053 | //pDCB->NegoPeriod = 50; /* 200ns <=> 5 MHz */ | ||
1054 | pDCB->CtrlR3 = FAST_CLK; /* fast clock / normal scsi */ | ||
1055 | pDCB->CtrlR4 &= 0x3f; | ||
1056 | pDCB->CtrlR4 |= pACB->glitch_cfg; /* glitch eater */ | ||
1057 | dc390_reprog (pACB, pDCB); | ||
1058 | } | ||
1059 | |||
1060 | /* set sync transfer mode */ | ||
1061 | static void | ||
1062 | dc390_MsgIn_set_sync (struct dc390_acb* pACB, struct dc390_srb* pSRB) | ||
1063 | { | ||
1064 | u8 bval; | ||
1065 | u16 wval, wval1; | ||
1066 | struct dc390_dcb* pDCB = pSRB->pSRBDCB; | ||
1067 | u8 oldsyncperiod = pDCB->SyncPeriod; | ||
1068 | u8 oldsyncoffset = pDCB->SyncOffset; | ||
1069 | |||
1070 | if (!(pSRB->SRBState & DO_SYNC_NEGO)) | ||
1071 | { | ||
1072 | printk (KERN_INFO "DC390: Target %i initiates Sync: %ins %i ... answer ...\n", | ||
1073 | pDCB->TargetID, pSRB->MsgInBuf[3]<<2, pSRB->MsgInBuf[4]); | ||
1074 | |||
1075 | /* reject */ | ||
1076 | //dc390_MsgIn_reject (pACB, pSRB); | ||
1077 | //return dc390_MsgIn_set_async (pACB, pSRB); | ||
1078 | |||
1079 | /* Reply with corrected SDTR Message */ | ||
1080 | if (pSRB->MsgInBuf[4] > 15) | ||
1081 | { | ||
1082 | printk (KERN_INFO "DC390: Lower Sync Offset to 15\n"); | ||
1083 | pSRB->MsgInBuf[4] = 15; | ||
1084 | } | ||
1085 | if (pSRB->MsgInBuf[3] < pDCB->NegoPeriod) | ||
1086 | { | ||
1087 | printk (KERN_INFO "DC390: Set sync nego period to %ins\n", pDCB->NegoPeriod << 2); | ||
1088 | pSRB->MsgInBuf[3] = pDCB->NegoPeriod; | ||
1089 | } | ||
1090 | memcpy (pSRB->MsgOutBuf, pSRB->MsgInBuf, 5); | ||
1091 | pSRB->MsgCnt = 5; | ||
1092 | DC390_ENABLE_MSGOUT; | ||
1093 | } | ||
1094 | |||
1095 | pSRB->SRBState &= ~DO_SYNC_NEGO; | ||
1096 | pDCB->SyncMode |= SYNC_ENABLE+SYNC_NEGO_DONE; | ||
1097 | pDCB->SyncOffset &= 0x0f0; | ||
1098 | pDCB->SyncOffset |= pSRB->MsgInBuf[4]; | ||
1099 | pDCB->NegoPeriod = pSRB->MsgInBuf[3]; | ||
1100 | |||
1101 | wval = (u16) pSRB->MsgInBuf[3]; | ||
1102 | wval = wval << 2; wval -= 3; wval1 = wval / 25; /* compute speed */ | ||
1103 | if( (wval1 * 25) != wval) wval1++; | ||
1104 | bval = FAST_CLK+FAST_SCSI; /* fast clock / fast scsi */ | ||
1105 | |||
1106 | pDCB->CtrlR4 &= 0x3f; /* Glitch eater: 12ns less than normal */ | ||
1107 | if (pACB->glitch_cfg != NS_TO_GLITCH(0)) | ||
1108 | pDCB->CtrlR4 |= NS_TO_GLITCH(((GLITCH_TO_NS(pACB->glitch_cfg)) - 1)); | ||
1109 | else | ||
1110 | pDCB->CtrlR4 |= NS_TO_GLITCH(0); | ||
1111 | if (wval1 < 4) pDCB->CtrlR4 |= NS_TO_GLITCH(0); /* Ultra */ | ||
1112 | |||
1113 | if (wval1 >= 8) | ||
1114 | { | ||
1115 | wval1--; /* Timing computation differs by 1 from FAST_SCSI */ | ||
1116 | bval = FAST_CLK; /* fast clock / normal scsi */ | ||
1117 | pDCB->CtrlR4 |= pACB->glitch_cfg; /* glitch eater */ | ||
1118 | } | ||
1119 | |||
1120 | pDCB->CtrlR3 = bval; | ||
1121 | pDCB->SyncPeriod = (u8)wval1; | ||
1122 | |||
1123 | if ((oldsyncperiod != wval1 || oldsyncoffset != pDCB->SyncOffset) && pDCB->TargetLUN == 0) | ||
1124 | { | ||
1125 | if (! (bval & FAST_SCSI)) wval1++; | ||
1126 | printk (KERN_INFO "DC390: Target %i: Sync transfer %i.%1i MHz, Offset %i\n", pDCB->TargetID, | ||
1127 | 40/wval1, ((40%wval1)*10+wval1/2)/wval1, pDCB->SyncOffset & 0x0f); | ||
1128 | } | ||
1129 | |||
1130 | dc390_reprog (pACB, pDCB); | ||
1131 | } | ||
1132 | |||
1133 | |||
1134 | /* handle RESTORE_PTR */ | ||
1135 | /* This doesn't look very healthy... to-be-fixed */ | ||
1136 | static void | ||
1137 | dc390_restore_ptr (struct dc390_acb* pACB, struct dc390_srb* pSRB) | ||
1138 | { | ||
1139 | struct scsi_cmnd *pcmd = pSRB->pcmd; | ||
1140 | struct scatterlist *psgl; | ||
1141 | pSRB->TotalXferredLen = 0; | ||
1142 | pSRB->SGIndex = 0; | ||
1143 | if (scsi_sg_count(pcmd)) { | ||
1144 | size_t saved; | ||
1145 | pSRB->pSegmentList = scsi_sglist(pcmd); | ||
1146 | psgl = pSRB->pSegmentList; | ||
1147 | //dc390_pci_sync(pSRB); | ||
1148 | |||
1149 | while (pSRB->TotalXferredLen + (unsigned long) sg_dma_len(psgl) < pSRB->Saved_Ptr) | ||
1150 | { | ||
1151 | pSRB->TotalXferredLen += (unsigned long) sg_dma_len(psgl); | ||
1152 | pSRB->SGIndex++; | ||
1153 | if( pSRB->SGIndex < pSRB->SGcount ) | ||
1154 | { | ||
1155 | pSRB->pSegmentList++; | ||
1156 | |||
1157 | dc390_start_segment(pSRB); | ||
1158 | } | ||
1159 | else | ||
1160 | pSRB->SGToBeXferLen = 0; | ||
1161 | } | ||
1162 | |||
1163 | saved = pSRB->Saved_Ptr - pSRB->TotalXferredLen; | ||
1164 | pSRB->SGToBeXferLen -= saved; | ||
1165 | pSRB->SGBusAddr += saved; | ||
1166 | printk (KERN_INFO "DC390: Pointer restored. Segment %i, Total %li, Bus %08lx\n", | ||
1167 | pSRB->SGIndex, pSRB->Saved_Ptr, pSRB->SGBusAddr); | ||
1168 | |||
1169 | } else { | ||
1170 | pSRB->SGcount = 0; | ||
1171 | printk (KERN_INFO "DC390: RESTORE_PTR message for Transfer without Scatter-Gather ??\n"); | ||
1172 | } | ||
1173 | |||
1174 | pSRB->TotalXferredLen = pSRB->Saved_Ptr; | ||
1175 | } | ||
1176 | |||
1177 | |||
1178 | /* According to the docs, the AM53C974 reads the message and | ||
1179 | * generates a Successful Operation IRQ before asserting ACK for | ||
1180 | * the last byte (how does it know whether it's the last ?) */ | ||
1181 | /* The old code handled it in another way, indicating, that on | ||
1182 | * every message byte an IRQ is generated and every byte has to | ||
1183 | * be manually ACKed. Hmmm ? (KG, 98/11/28) */ | ||
1184 | /* The old implementation was correct. Sigh! */ | ||
1185 | |||
1186 | /* Check if the message is complete */ | ||
1187 | static u8 __inline__ | ||
1188 | dc390_MsgIn_complete (u8 *msgbuf, u32 len) | ||
1189 | { | ||
1190 | if (*msgbuf == EXTENDED_MESSAGE) | ||
1191 | { | ||
1192 | if (len < 2) return 0; | ||
1193 | if (len < msgbuf[1] + 2) return 0; | ||
1194 | } | ||
1195 | else if (*msgbuf >= 0x20 && *msgbuf <= 0x2f) // two byte messages | ||
1196 | if (len < 2) return 0; | ||
1197 | return 1; | ||
1198 | } | ||
1199 | |||
1200 | |||
1201 | |||
1202 | /* read and eval received messages */ | ||
1203 | static void | ||
1204 | dc390_MsgIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
1205 | { | ||
1206 | struct dc390_dcb* pDCB = pACB->pActiveDCB; | ||
1207 | |||
1208 | /* Read the msg */ | ||
1209 | |||
1210 | pSRB->MsgInBuf[pACB->MsgLen++] = DC390_read8 (ScsiFifo); | ||
1211 | //pSRB->SRBState = 0; | ||
1212 | |||
1213 | /* Msg complete ? */ | ||
1214 | if (dc390_MsgIn_complete (pSRB->MsgInBuf, pACB->MsgLen)) | ||
1215 | { | ||
1216 | DEBUG0 (printk (KERN_INFO "DC390: MsgIn:"); dc390_printMsg (pSRB->MsgInBuf, pACB->MsgLen)); | ||
1217 | /* Now eval the msg */ | ||
1218 | switch (pSRB->MsgInBuf[0]) | ||
1219 | { | ||
1220 | case DISCONNECT: | ||
1221 | pSRB->SRBState = SRB_DISCONNECT; break; | ||
1222 | |||
1223 | case SIMPLE_QUEUE_TAG: | ||
1224 | case HEAD_OF_QUEUE_TAG: | ||
1225 | case ORDERED_QUEUE_TAG: | ||
1226 | pSRB = dc390_MsgIn_QTag (pACB, pDCB, pSRB->MsgInBuf[1]); | ||
1227 | break; | ||
1228 | |||
1229 | case MESSAGE_REJECT: | ||
1230 | DC390_write8 (ScsiCmd, RESET_ATN_CMD); | ||
1231 | pDCB->NegoPeriod = 50; /* 200ns <=> 5 MHz */ | ||
1232 | if( pSRB->SRBState & DO_SYNC_NEGO) | ||
1233 | dc390_MsgIn_set_async (pACB, pSRB); | ||
1234 | break; | ||
1235 | |||
1236 | case EXTENDED_MESSAGE: | ||
1237 | /* reject every extended msg but SDTR */ | ||
1238 | if (pSRB->MsgInBuf[1] != 3 || pSRB->MsgInBuf[2] != EXTENDED_SDTR) | ||
1239 | dc390_MsgIn_reject (pACB, pSRB); | ||
1240 | else | ||
1241 | { | ||
1242 | if (pSRB->MsgInBuf[3] == 0 || pSRB->MsgInBuf[4] == 0) | ||
1243 | dc390_MsgIn_set_async (pACB, pSRB); | ||
1244 | else | ||
1245 | dc390_MsgIn_set_sync (pACB, pSRB); | ||
1246 | } | ||
1247 | |||
1248 | // nothing has to be done | ||
1249 | case COMMAND_COMPLETE: break; | ||
1250 | |||
1251 | // SAVE POINTER may be ignored as we have the struct dc390_srb* associated with the | ||
1252 | // scsi command. Thanks, Gerard, for pointing it out. | ||
1253 | case SAVE_POINTERS: | ||
1254 | pSRB->Saved_Ptr = pSRB->TotalXferredLen; | ||
1255 | break; | ||
1256 | // The device might want to restart transfer with a RESTORE | ||
1257 | case RESTORE_POINTERS: | ||
1258 | DEBUG0(printk ("DC390: RESTORE POINTER message received ... try to handle\n")); | ||
1259 | dc390_restore_ptr (pACB, pSRB); | ||
1260 | break; | ||
1261 | |||
1262 | // reject unknown messages | ||
1263 | default: dc390_MsgIn_reject (pACB, pSRB); | ||
1264 | } | ||
1265 | |||
1266 | /* Clear counter and MsgIn state */ | ||
1267 | pSRB->SRBState &= ~SRB_MSGIN; | ||
1268 | pACB->MsgLen = 0; | ||
1269 | } | ||
1270 | |||
1271 | *psstatus = SCSI_NOP0; | ||
1272 | DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD); | ||
1273 | //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD); | ||
1274 | } | ||
1275 | |||
1276 | |||
1277 | static void | ||
1278 | dc390_DataIO_Comm( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 ioDir) | ||
1279 | { | ||
1280 | unsigned long lval; | ||
1281 | struct dc390_dcb* pDCB = pACB->pActiveDCB; | ||
1282 | |||
1283 | if (pSRB == pACB->pTmpSRB) | ||
1284 | { | ||
1285 | if (pDCB) | ||
1286 | printk(KERN_ERR "DC390: pSRB == pTmpSRB! (TagQ Error?) (%02i-%i)\n", pDCB->TargetID, pDCB->TargetLUN); | ||
1287 | else | ||
1288 | printk(KERN_ERR "DC390: pSRB == pTmpSRB! (TagQ Error?) (DCB 0!)\n"); | ||
1289 | |||
1290 | /* Try to recover - some broken disks react badly to tagged INQUIRY */ | ||
1291 | if (pDCB && pACB->scan_devices && pDCB->GoingSRBCnt == 1) { | ||
1292 | pSRB = pDCB->pGoingSRB; | ||
1293 | pDCB->pActiveSRB = pSRB; | ||
1294 | } else { | ||
1295 | pSRB->pSRBDCB = pDCB; | ||
1296 | dc390_EnableMsgOut_Abort(pACB, pSRB); | ||
1297 | if (pDCB) | ||
1298 | pDCB->DCBFlag |= ABORT_DEV; | ||
1299 | return; | ||
1300 | } | ||
1301 | } | ||
1302 | |||
1303 | if( pSRB->SGIndex < pSRB->SGcount ) | ||
1304 | { | ||
1305 | DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir); | ||
1306 | if( !pSRB->SGToBeXferLen ) | ||
1307 | { | ||
1308 | dc390_start_segment(pSRB); | ||
1309 | |||
1310 | DEBUG1(printk (KERN_DEBUG " DC390: Next SG segment.")); | ||
1311 | } | ||
1312 | lval = pSRB->SGToBeXferLen; | ||
1313 | DEBUG1(printk (KERN_DEBUG " DC390: Start transfer: %li bytes (address %08lx)\n", lval, pSRB->SGBusAddr)); | ||
1314 | DC390_write8 (CtcReg_Low, (u8) lval); | ||
1315 | lval >>= 8; | ||
1316 | DC390_write8 (CtcReg_Mid, (u8) lval); | ||
1317 | lval >>= 8; | ||
1318 | DC390_write8 (CtcReg_High, (u8) lval); | ||
1319 | |||
1320 | DC390_write32 (DMA_XferCnt, pSRB->SGToBeXferLen); | ||
1321 | DC390_write32 (DMA_XferAddr, pSRB->SGBusAddr); | ||
1322 | |||
1323 | //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir); | ||
1324 | pSRB->SRBState = SRB_DATA_XFER; | ||
1325 | |||
1326 | DC390_write8 (ScsiCmd, DMA_COMMAND+INFO_XFER_CMD); | ||
1327 | |||
1328 | DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir); | ||
1329 | //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT)); | ||
1330 | //DEBUG1(printk (KERN_DEBUG "DC390: DMA_Status: %02x\n", DC390_read8 (DMA_Status))); | ||
1331 | //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT)); | ||
1332 | } | ||
1333 | else /* xfer pad */ | ||
1334 | { | ||
1335 | if( pSRB->SGcount ) | ||
1336 | { | ||
1337 | pSRB->AdaptStatus = H_OVER_UNDER_RUN; | ||
1338 | pSRB->SRBStatus |= OVER_RUN; | ||
1339 | DEBUG0(printk (KERN_WARNING " DC390: Overrun -")); | ||
1340 | } | ||
1341 | DEBUG0(printk (KERN_WARNING " Clear transfer pad \n")); | ||
1342 | DC390_write8 (CtcReg_Low, 0); | ||
1343 | DC390_write8 (CtcReg_Mid, 0); | ||
1344 | DC390_write8 (CtcReg_High, 0); | ||
1345 | |||
1346 | pSRB->SRBState |= SRB_XFERPAD; | ||
1347 | DC390_write8 (ScsiCmd, DMA_COMMAND+XFER_PAD_BYTE); | ||
1348 | /* | ||
1349 | DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir); | ||
1350 | DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir); | ||
1351 | */ | ||
1352 | } | ||
1353 | } | ||
1354 | |||
1355 | |||
1356 | static void | ||
1357 | dc390_DataOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
1358 | { | ||
1359 | dc390_DataIO_Comm (pACB, pSRB, WRITE_DIRECTION); | ||
1360 | } | ||
1361 | |||
1362 | static void | ||
1363 | dc390_DataInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
1364 | { | ||
1365 | dc390_DataIO_Comm (pACB, pSRB, READ_DIRECTION); | ||
1366 | } | ||
1367 | |||
1368 | static void | ||
1369 | dc390_CommandPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
1370 | { | ||
1371 | struct dc390_dcb* pDCB; | ||
1372 | u8 i, cnt; | ||
1373 | u8 *ptr; | ||
1374 | |||
1375 | DC390_write8 (ScsiCmd, RESET_ATN_CMD); | ||
1376 | DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); | ||
1377 | if( !(pSRB->SRBFlag & AUTO_REQSENSE) ) | ||
1378 | { | ||
1379 | cnt = (u8) pSRB->pcmd->cmd_len; | ||
1380 | ptr = (u8 *) pSRB->pcmd->cmnd; | ||
1381 | for(i=0; i < cnt; i++) | ||
1382 | DC390_write8 (ScsiFifo, *(ptr++)); | ||
1383 | } | ||
1384 | else | ||
1385 | { | ||
1386 | DC390_write8 (ScsiFifo, REQUEST_SENSE); | ||
1387 | pDCB = pACB->pActiveDCB; | ||
1388 | DC390_write8 (ScsiFifo, pDCB->TargetLUN << 5); | ||
1389 | DC390_write8 (ScsiFifo, 0); | ||
1390 | DC390_write8 (ScsiFifo, 0); | ||
1391 | DC390_write8 (ScsiFifo, SCSI_SENSE_BUFFERSIZE); | ||
1392 | DC390_write8 (ScsiFifo, 0); | ||
1393 | DEBUG0(printk(KERN_DEBUG "DC390: AutoReqSense (CmndPhase)!\n")); | ||
1394 | } | ||
1395 | pSRB->SRBState = SRB_COMMAND; | ||
1396 | DC390_write8 (ScsiCmd, INFO_XFER_CMD); | ||
1397 | } | ||
1398 | |||
1399 | static void | ||
1400 | dc390_StatusPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
1401 | { | ||
1402 | DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); | ||
1403 | pSRB->SRBState = SRB_STATUS; | ||
1404 | DC390_write8 (ScsiCmd, INITIATOR_CMD_CMPLTE); | ||
1405 | //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD); | ||
1406 | } | ||
1407 | |||
1408 | static void | ||
1409 | dc390_MsgOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
1410 | { | ||
1411 | u8 bval, i, cnt; | ||
1412 | u8 *ptr; | ||
1413 | struct dc390_dcb* pDCB; | ||
1414 | |||
1415 | DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); | ||
1416 | pDCB = pACB->pActiveDCB; | ||
1417 | if( !(pSRB->SRBState & SRB_MSGOUT) ) | ||
1418 | { | ||
1419 | cnt = pSRB->MsgCnt; | ||
1420 | if( cnt ) | ||
1421 | { | ||
1422 | ptr = (u8 *) pSRB->MsgOutBuf; | ||
1423 | for(i=0; i < cnt; i++) | ||
1424 | DC390_write8 (ScsiFifo, *(ptr++)); | ||
1425 | pSRB->MsgCnt = 0; | ||
1426 | if( (pDCB->DCBFlag & ABORT_DEV_) && | ||
1427 | (pSRB->MsgOutBuf[0] == ABORT) ) | ||
1428 | pSRB->SRBState = SRB_ABORT_SENT; | ||
1429 | } | ||
1430 | else | ||
1431 | { | ||
1432 | bval = ABORT; /* ??? MSG_NOP */ | ||
1433 | if( (pSRB->pcmd->cmnd[0] == INQUIRY ) || | ||
1434 | (pSRB->pcmd->cmnd[0] == REQUEST_SENSE) || | ||
1435 | (pSRB->SRBFlag & AUTO_REQSENSE) ) | ||
1436 | { | ||
1437 | if( pDCB->SyncMode & SYNC_ENABLE ) | ||
1438 | goto mop1; | ||
1439 | } | ||
1440 | DC390_write8 (ScsiFifo, bval); | ||
1441 | } | ||
1442 | DC390_write8 (ScsiCmd, INFO_XFER_CMD); | ||
1443 | } | ||
1444 | else | ||
1445 | { | ||
1446 | mop1: | ||
1447 | printk (KERN_ERR "DC390: OLD Sync Nego code triggered! (%i %i)\n", pDCB->TargetID, pDCB->TargetLUN); | ||
1448 | DC390_write8 (ScsiFifo, EXTENDED_MESSAGE); | ||
1449 | DC390_write8 (ScsiFifo, 3); /* ;length of extended msg */ | ||
1450 | DC390_write8 (ScsiFifo, EXTENDED_SDTR); /* ; sync nego */ | ||
1451 | DC390_write8 (ScsiFifo, pDCB->NegoPeriod); | ||
1452 | if (pDCB->SyncOffset & 0x0f) | ||
1453 | DC390_write8 (ScsiFifo, pDCB->SyncOffset); | ||
1454 | else | ||
1455 | DC390_write8 (ScsiFifo, SYNC_NEGO_OFFSET); | ||
1456 | pSRB->SRBState |= DO_SYNC_NEGO; | ||
1457 | DC390_write8 (ScsiCmd, INFO_XFER_CMD); | ||
1458 | } | ||
1459 | } | ||
1460 | |||
1461 | static void | ||
1462 | dc390_MsgInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
1463 | { | ||
1464 | DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); | ||
1465 | if( !(pSRB->SRBState & SRB_MSGIN) ) | ||
1466 | { | ||
1467 | pSRB->SRBState &= ~SRB_DISCONNECT; | ||
1468 | pSRB->SRBState |= SRB_MSGIN; | ||
1469 | } | ||
1470 | DC390_write8 (ScsiCmd, INFO_XFER_CMD); | ||
1471 | //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD); | ||
1472 | } | ||
1473 | |||
1474 | static void | ||
1475 | dc390_Nop_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
1476 | { | ||
1477 | } | ||
1478 | |||
1479 | static void | ||
1480 | dc390_Nop_1( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) | ||
1481 | { | ||
1482 | } | ||
1483 | |||
1484 | |||
1485 | static void | ||
1486 | dc390_SetXferRate( struct dc390_acb* pACB, struct dc390_dcb* pDCB ) | ||
1487 | { | ||
1488 | u8 bval, i, cnt; | ||
1489 | struct dc390_dcb* ptr; | ||
1490 | |||
1491 | if( !(pDCB->TargetLUN) ) | ||
1492 | { | ||
1493 | if( !pACB->scan_devices ) | ||
1494 | { | ||
1495 | ptr = pACB->pLinkDCB; | ||
1496 | cnt = pACB->DCBCnt; | ||
1497 | bval = pDCB->TargetID; | ||
1498 | for(i=0; i<cnt; i++) | ||
1499 | { | ||
1500 | if( ptr->TargetID == bval ) | ||
1501 | { | ||
1502 | ptr->SyncPeriod = pDCB->SyncPeriod; | ||
1503 | ptr->SyncOffset = pDCB->SyncOffset; | ||
1504 | ptr->CtrlR3 = pDCB->CtrlR3; | ||
1505 | ptr->CtrlR4 = pDCB->CtrlR4; | ||
1506 | ptr->SyncMode = pDCB->SyncMode; | ||
1507 | } | ||
1508 | ptr = ptr->pNextDCB; | ||
1509 | } | ||
1510 | } | ||
1511 | } | ||
1512 | return; | ||
1513 | } | ||
1514 | |||
1515 | |||
1516 | static void | ||
1517 | dc390_Disconnect( struct dc390_acb* pACB ) | ||
1518 | { | ||
1519 | struct dc390_dcb *pDCB; | ||
1520 | struct dc390_srb *pSRB, *psrb; | ||
1521 | u8 i, cnt; | ||
1522 | |||
1523 | DEBUG0(printk(KERN_INFO "DISC,")); | ||
1524 | |||
1525 | if (!pACB->Connected) printk(KERN_ERR "DC390: Disconnect not-connected bus?\n"); | ||
1526 | pACB->Connected = 0; | ||
1527 | pDCB = pACB->pActiveDCB; | ||
1528 | if (!pDCB) | ||
1529 | { | ||
1530 | DEBUG0(printk(KERN_ERR "ACB:%p->ActiveDCB:%p IOPort:%04x IRQ:%02x !\n",\ | ||
1531 | pACB, pDCB, pACB->IOPortBase, pACB->IRQLevel)); | ||
1532 | mdelay(400); | ||
1533 | DC390_read8 (INT_Status); /* Reset Pending INT */ | ||
1534 | DC390_write8 (ScsiCmd, EN_SEL_RESEL); | ||
1535 | return; | ||
1536 | } | ||
1537 | DC390_write8 (ScsiCmd, EN_SEL_RESEL); | ||
1538 | pSRB = pDCB->pActiveSRB; | ||
1539 | pACB->pActiveDCB = NULL; | ||
1540 | pSRB->ScsiPhase = SCSI_NOP0; | ||
1541 | if( pSRB->SRBState & SRB_UNEXPECT_RESEL ) | ||
1542 | pSRB->SRBState = 0; | ||
1543 | else if( pSRB->SRBState & SRB_ABORT_SENT ) | ||
1544 | { | ||
1545 | pDCB->TagMask = 0; | ||
1546 | pDCB->DCBFlag = 0; | ||
1547 | cnt = pDCB->GoingSRBCnt; | ||
1548 | pDCB->GoingSRBCnt = 0; | ||
1549 | pSRB = pDCB->pGoingSRB; | ||
1550 | for( i=0; i < cnt; i++) | ||
1551 | { | ||
1552 | psrb = pSRB->pNextSRB; | ||
1553 | dc390_Free_insert (pACB, pSRB); | ||
1554 | pSRB = psrb; | ||
1555 | } | ||
1556 | pDCB->pGoingSRB = NULL; | ||
1557 | } | ||
1558 | else | ||
1559 | { | ||
1560 | if( (pSRB->SRBState & (SRB_START_+SRB_MSGOUT)) || | ||
1561 | !(pSRB->SRBState & (SRB_DISCONNECT+SRB_COMPLETED)) ) | ||
1562 | { /* Selection time out */ | ||
1563 | pSRB->AdaptStatus = H_SEL_TIMEOUT; | ||
1564 | pSRB->TargetStatus = 0; | ||
1565 | goto disc1; | ||
1566 | } | ||
1567 | else if (!(pSRB->SRBState & SRB_DISCONNECT) && (pSRB->SRBState & SRB_COMPLETED)) | ||
1568 | { | ||
1569 | disc1: | ||
1570 | dc390_freetag (pDCB, pSRB); | ||
1571 | pDCB->pActiveSRB = NULL; | ||
1572 | pSRB->SRBState = SRB_FREE; | ||
1573 | dc390_SRBdone( pACB, pDCB, pSRB); | ||
1574 | } | ||
1575 | } | ||
1576 | pACB->MsgLen = 0; | ||
1577 | } | ||
1578 | |||
1579 | |||
1580 | static void | ||
1581 | dc390_Reselect( struct dc390_acb* pACB ) | ||
1582 | { | ||
1583 | struct dc390_dcb* pDCB; | ||
1584 | struct dc390_srb* pSRB; | ||
1585 | u8 id, lun; | ||
1586 | |||
1587 | DEBUG0(printk(KERN_INFO "RSEL,")); | ||
1588 | pACB->Connected = 1; | ||
1589 | pDCB = pACB->pActiveDCB; | ||
1590 | if( pDCB ) | ||
1591 | { /* Arbitration lost but Reselection won */ | ||
1592 | DEBUG0(printk ("DC390: (ActiveDCB != 0: Arb. lost but resel. won)!\n")); | ||
1593 | pSRB = pDCB->pActiveSRB; | ||
1594 | if( !( pACB->scan_devices ) ) | ||
1595 | { | ||
1596 | struct scsi_cmnd *pcmd = pSRB->pcmd; | ||
1597 | scsi_set_resid(pcmd, scsi_bufflen(pcmd)); | ||
1598 | SET_RES_DID(pcmd->result, DID_SOFT_ERROR); | ||
1599 | dc390_Going_remove(pDCB, pSRB); | ||
1600 | dc390_Free_insert(pACB, pSRB); | ||
1601 | pcmd->scsi_done (pcmd); | ||
1602 | DEBUG0(printk(KERN_DEBUG"DC390: Return SRB %p to free\n", pSRB)); | ||
1603 | } | ||
1604 | } | ||
1605 | /* Get ID */ | ||
1606 | lun = DC390_read8 (ScsiFifo); | ||
1607 | DEBUG0(printk ("Dev %02x,", lun)); | ||
1608 | if (!(lun & (1 << pACB->pScsiHost->this_id))) | ||
1609 | printk (KERN_ERR "DC390: Reselection must select host adapter: %02x!\n", lun); | ||
1610 | else | ||
1611 | lun ^= 1 << pACB->pScsiHost->this_id; /* Mask AdapterID */ | ||
1612 | id = 0; while (lun >>= 1) id++; | ||
1613 | /* Get LUN */ | ||
1614 | lun = DC390_read8 (ScsiFifo); | ||
1615 | if (!(lun & IDENTIFY_BASE)) printk (KERN_ERR "DC390: Resel: Expect identify message!\n"); | ||
1616 | lun &= 7; | ||
1617 | DEBUG0(printk ("(%02i-%i),", id, lun)); | ||
1618 | pDCB = dc390_findDCB (pACB, id, lun); | ||
1619 | if (!pDCB) | ||
1620 | { | ||
1621 | printk (KERN_ERR "DC390: Reselect from non existing device (%02i-%i)\n", | ||
1622 | id, lun); | ||
1623 | return; | ||
1624 | } | ||
1625 | pACB->pActiveDCB = pDCB; | ||
1626 | /* TagQ: We expect a message soon, so never mind the exact SRB */ | ||
1627 | if( pDCB->SyncMode & EN_TAG_QUEUEING ) | ||
1628 | { | ||
1629 | pSRB = pACB->pTmpSRB; | ||
1630 | pDCB->pActiveSRB = pSRB; | ||
1631 | } | ||
1632 | else | ||
1633 | { | ||
1634 | pSRB = pDCB->pActiveSRB; | ||
1635 | if( !pSRB || !(pSRB->SRBState & SRB_DISCONNECT) ) | ||
1636 | { | ||
1637 | pSRB= pACB->pTmpSRB; | ||
1638 | pSRB->SRBState = SRB_UNEXPECT_RESEL; | ||
1639 | printk (KERN_ERR "DC390: Reselect without outstanding cmnd (%02i-%i)\n", | ||
1640 | id, lun); | ||
1641 | pDCB->pActiveSRB = pSRB; | ||
1642 | dc390_EnableMsgOut_Abort ( pACB, pSRB ); | ||
1643 | } | ||
1644 | else | ||
1645 | { | ||
1646 | if( pDCB->DCBFlag & ABORT_DEV_ ) | ||
1647 | { | ||
1648 | pSRB->SRBState = SRB_ABORT_SENT; | ||
1649 | printk (KERN_INFO "DC390: Reselect: Abort (%02i-%i)\n", | ||
1650 | id, lun); | ||
1651 | dc390_EnableMsgOut_Abort( pACB, pSRB ); | ||
1652 | } | ||
1653 | else | ||
1654 | pSRB->SRBState = SRB_DATA_XFER; | ||
1655 | } | ||
1656 | } | ||
1657 | |||
1658 | DEBUG1(printk (KERN_DEBUG "Resel SRB(%p): TagNum (%02x)\n", pSRB, pSRB->TagNumber)); | ||
1659 | pSRB->ScsiPhase = SCSI_NOP0; | ||
1660 | DC390_write8 (Scsi_Dest_ID, pDCB->TargetID); | ||
1661 | DC390_write8 (Sync_Period, pDCB->SyncPeriod); | ||
1662 | DC390_write8 (Sync_Offset, pDCB->SyncOffset); | ||
1663 | DC390_write8 (CtrlReg1, pDCB->CtrlR1); | ||
1664 | DC390_write8 (CtrlReg3, pDCB->CtrlR3); | ||
1665 | DC390_write8 (CtrlReg4, pDCB->CtrlR4); /* ; Glitch eater */ | ||
1666 | DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD); /* ;to release the /ACK signal */ | ||
1667 | } | ||
1668 | |||
1669 | static int __inline__ | ||
1670 | dc390_RequestSense(struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB) | ||
1671 | { | ||
1672 | struct scsi_cmnd *pcmd; | ||
1673 | |||
1674 | pcmd = pSRB->pcmd; | ||
1675 | |||
1676 | REMOVABLEDEBUG(printk(KERN_INFO "DC390: RequestSense(Cmd %02x, Id %02x, LUN %02x)\n",\ | ||
1677 | pcmd->cmnd[0], pDCB->TargetID, pDCB->TargetLUN)); | ||
1678 | |||
1679 | pSRB->SRBFlag |= AUTO_REQSENSE; | ||
1680 | pSRB->SavedTotXLen = pSRB->TotalXferredLen; | ||
1681 | pSRB->AdaptStatus = 0; | ||
1682 | pSRB->TargetStatus = 0; /* CHECK_CONDITION<<1; */ | ||
1683 | |||
1684 | /* We are called from SRBdone, original PCI mapping has been removed | ||
1685 | * already, new one is set up from StartSCSI */ | ||
1686 | pSRB->SGIndex = 0; | ||
1687 | |||
1688 | pSRB->TotalXferredLen = 0; | ||
1689 | pSRB->SGToBeXferLen = 0; | ||
1690 | return dc390_StartSCSI(pACB, pDCB, pSRB); | ||
1691 | } | ||
1692 | |||
1693 | |||
1694 | static void | ||
1695 | dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB ) | ||
1696 | { | ||
1697 | u8 status; | ||
1698 | struct scsi_cmnd *pcmd; | ||
1699 | |||
1700 | pcmd = pSRB->pcmd; | ||
1701 | /* KG: Moved pci_unmap here */ | ||
1702 | dc390_pci_unmap(pSRB); | ||
1703 | |||
1704 | status = pSRB->TargetStatus; | ||
1705 | |||
1706 | DEBUG0(printk (" SRBdone (%02x,%08x), SRB %p\n", status, pcmd->result, pSRB)); | ||
1707 | if(pSRB->SRBFlag & AUTO_REQSENSE) | ||
1708 | { /* Last command was a Request Sense */ | ||
1709 | pSRB->SRBFlag &= ~AUTO_REQSENSE; | ||
1710 | pSRB->AdaptStatus = 0; | ||
1711 | pSRB->TargetStatus = SAM_STAT_CHECK_CONDITION; | ||
1712 | |||
1713 | //pcmd->result = MK_RES(DRIVER_SENSE,DID_OK,0,status); | ||
1714 | if (status == SAM_STAT_CHECK_CONDITION) | ||
1715 | pcmd->result = MK_RES_LNX(0, DID_BAD_TARGET, 0, /*CHECK_CONDITION*/0); | ||
1716 | else /* Retry */ | ||
1717 | { | ||
1718 | if( pSRB->pcmd->cmnd[0] == TEST_UNIT_READY /* || pSRB->pcmd->cmnd[0] == START_STOP */) | ||
1719 | { | ||
1720 | /* Don't retry on TEST_UNIT_READY */ | ||
1721 | pcmd->result = MK_RES_LNX(DRIVER_SENSE, DID_OK, 0, SAM_STAT_CHECK_CONDITION); | ||
1722 | REMOVABLEDEBUG(printk(KERN_INFO "Cmd=%02x, Result=%08x, XferL=%08x\n",pSRB->pcmd->cmnd[0],\ | ||
1723 | (u32) pcmd->result, (u32) pSRB->TotalXferredLen)); | ||
1724 | } else { | ||
1725 | SET_RES_DRV(pcmd->result, DRIVER_SENSE); | ||
1726 | //pSRB->ScsiCmdLen = (u8) (pSRB->Segment1[0] >> 8); | ||
1727 | DEBUG0 (printk ("DC390: RETRY (%02x), target %02i-%02i\n", pcmd->cmnd[0], pcmd->device->id, (u8)pcmd->device->lun)); | ||
1728 | pSRB->TotalXferredLen = 0; | ||
1729 | SET_RES_DID(pcmd->result, DID_SOFT_ERROR); | ||
1730 | } | ||
1731 | } | ||
1732 | goto cmd_done; | ||
1733 | } | ||
1734 | if( status ) | ||
1735 | { | ||
1736 | if (status == SAM_STAT_CHECK_CONDITION) | ||
1737 | { | ||
1738 | if (dc390_RequestSense(pACB, pDCB, pSRB)) { | ||
1739 | SET_RES_DID(pcmd->result, DID_ERROR); | ||
1740 | goto cmd_done; | ||
1741 | } | ||
1742 | return; | ||
1743 | } | ||
1744 | else if (status == SAM_STAT_TASK_SET_FULL) | ||
1745 | { | ||
1746 | scsi_track_queue_full(pcmd->device, pDCB->GoingSRBCnt - 1); | ||
1747 | DEBUG0 (printk ("DC390: RETRY (%02x), target %02i-%02i\n", pcmd->cmnd[0], pcmd->device->id, (u8)pcmd->device->lun)); | ||
1748 | pSRB->TotalXferredLen = 0; | ||
1749 | SET_RES_DID(pcmd->result, DID_SOFT_ERROR); | ||
1750 | } | ||
1751 | else if (status == SAM_STAT_BUSY && | ||
1752 | (pcmd->cmnd[0] == TEST_UNIT_READY || pcmd->cmnd[0] == INQUIRY) && | ||
1753 | pACB->scan_devices) | ||
1754 | { | ||
1755 | pSRB->AdaptStatus = 0; | ||
1756 | pSRB->TargetStatus = status; | ||
1757 | pcmd->result = MK_RES(0,0,pSRB->EndMessage,/*status*/0); | ||
1758 | } | ||
1759 | else | ||
1760 | { /* Another error */ | ||
1761 | pSRB->TotalXferredLen = 0; | ||
1762 | SET_RES_DID(pcmd->result, DID_SOFT_ERROR); | ||
1763 | goto cmd_done; | ||
1764 | } | ||
1765 | } | ||
1766 | else | ||
1767 | { /* Target status == 0 */ | ||
1768 | status = pSRB->AdaptStatus; | ||
1769 | if (status == H_OVER_UNDER_RUN) | ||
1770 | { | ||
1771 | pSRB->TargetStatus = 0; | ||
1772 | SET_RES_DID(pcmd->result,DID_OK); | ||
1773 | SET_RES_MSG(pcmd->result,pSRB->EndMessage); | ||
1774 | } | ||
1775 | else if (status == H_SEL_TIMEOUT) | ||
1776 | { | ||
1777 | pcmd->result = MK_RES(0, DID_NO_CONNECT, 0, 0); | ||
1778 | /* Devices are removed below ... */ | ||
1779 | } | ||
1780 | else if( pSRB->SRBStatus & PARITY_ERROR) | ||
1781 | { | ||
1782 | //pcmd->result = MK_RES(0,DID_PARITY,pSRB->EndMessage,0); | ||
1783 | SET_RES_DID(pcmd->result,DID_PARITY); | ||
1784 | SET_RES_MSG(pcmd->result,pSRB->EndMessage); | ||
1785 | } | ||
1786 | else /* No error */ | ||
1787 | { | ||
1788 | pSRB->AdaptStatus = 0; | ||
1789 | pSRB->TargetStatus = 0; | ||
1790 | SET_RES_DID(pcmd->result,DID_OK); | ||
1791 | } | ||
1792 | } | ||
1793 | |||
1794 | cmd_done: | ||
1795 | scsi_set_resid(pcmd, scsi_bufflen(pcmd) - pSRB->TotalXferredLen); | ||
1796 | |||
1797 | dc390_Going_remove (pDCB, pSRB); | ||
1798 | /* Add to free list */ | ||
1799 | dc390_Free_insert (pACB, pSRB); | ||
1800 | |||
1801 | DEBUG0(printk (KERN_DEBUG "DC390: SRBdone: done\n")); | ||
1802 | pcmd->scsi_done (pcmd); | ||
1803 | |||
1804 | return; | ||
1805 | } | ||
1806 | |||
1807 | |||
1808 | /* Remove all SRBs from Going list and inform midlevel */ | ||
1809 | static void | ||
1810 | dc390_DoingSRB_Done(struct dc390_acb* pACB, struct scsi_cmnd *cmd) | ||
1811 | { | ||
1812 | struct dc390_dcb *pDCB, *pdcb; | ||
1813 | struct dc390_srb *psrb, *psrb2; | ||
1814 | int i; | ||
1815 | struct scsi_cmnd *pcmd; | ||
1816 | |||
1817 | pDCB = pACB->pLinkDCB; | ||
1818 | pdcb = pDCB; | ||
1819 | if (! pdcb) return; | ||
1820 | do | ||
1821 | { | ||
1822 | psrb = pdcb->pGoingSRB; | ||
1823 | for (i = 0; i < pdcb->GoingSRBCnt; i++) | ||
1824 | { | ||
1825 | psrb2 = psrb->pNextSRB; | ||
1826 | pcmd = psrb->pcmd; | ||
1827 | dc390_Free_insert (pACB, psrb); | ||
1828 | psrb = psrb2; | ||
1829 | } | ||
1830 | pdcb->GoingSRBCnt = 0; | ||
1831 | pdcb->pGoingSRB = NULL; | ||
1832 | pdcb->TagMask = 0; | ||
1833 | pdcb = pdcb->pNextDCB; | ||
1834 | } while( pdcb != pDCB ); | ||
1835 | } | ||
1836 | |||
1837 | |||
1838 | static void | ||
1839 | dc390_ResetSCSIBus( struct dc390_acb* pACB ) | ||
1840 | { | ||
1841 | //DC390_write8 (ScsiCmd, RST_DEVICE_CMD); | ||
1842 | //udelay (250); | ||
1843 | //DC390_write8 (ScsiCmd, NOP_CMD); | ||
1844 | |||
1845 | DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); | ||
1846 | DC390_write8 (DMA_Cmd, DMA_IDLE_CMD); | ||
1847 | DC390_write8 (ScsiCmd, RST_SCSI_BUS_CMD); | ||
1848 | pACB->Connected = 0; | ||
1849 | |||
1850 | return; | ||
1851 | } | ||
1852 | |||
1853 | static void | ||
1854 | dc390_ScsiRstDetect( struct dc390_acb* pACB ) | ||
1855 | { | ||
1856 | printk ("DC390: Rst_Detect: laststat = %08x\n", dc390_laststatus); | ||
1857 | //DEBUG0(printk(KERN_INFO "RST_DETECT,")); | ||
1858 | |||
1859 | DC390_write8 (DMA_Cmd, DMA_IDLE_CMD); | ||
1860 | /* Unlock before ? */ | ||
1861 | /* delay half a second */ | ||
1862 | udelay (1000); | ||
1863 | DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); | ||
1864 | pACB->last_reset = jiffies + 5*HZ/2 | ||
1865 | + HZ * dc390_eepromBuf[pACB->AdapterIndex][EE_DELAY]; | ||
1866 | pACB->Connected = 0; | ||
1867 | |||
1868 | if( pACB->ACBFlag & RESET_DEV ) | ||
1869 | pACB->ACBFlag |= RESET_DONE; | ||
1870 | else | ||
1871 | { /* Reset was issued by sb else */ | ||
1872 | pACB->ACBFlag |= RESET_DETECT; | ||
1873 | |||
1874 | dc390_ResetDevParam( pACB ); | ||
1875 | dc390_DoingSRB_Done( pACB, NULL); | ||
1876 | //dc390_RecoverSRB( pACB ); | ||
1877 | pACB->pActiveDCB = NULL; | ||
1878 | pACB->ACBFlag = 0; | ||
1879 | } | ||
1880 | return; | ||
1881 | } | ||
1882 | |||
1883 | static int DC390_queuecommand_lck(struct scsi_cmnd *cmd, | ||
1884 | void (*done)(struct scsi_cmnd *)) | ||
1885 | { | ||
1886 | struct scsi_device *sdev = cmd->device; | ||
1887 | struct dc390_acb *acb = (struct dc390_acb *)sdev->host->hostdata; | ||
1888 | struct dc390_dcb *dcb = sdev->hostdata; | ||
1889 | struct dc390_srb *srb; | ||
1890 | |||
1891 | if (sdev->queue_depth <= dcb->GoingSRBCnt) | ||
1892 | goto device_busy; | ||
1893 | if (acb->pActiveDCB) | ||
1894 | goto host_busy; | ||
1895 | if (acb->ACBFlag & (RESET_DETECT|RESET_DONE|RESET_DEV)) | ||
1896 | goto host_busy; | ||
1897 | |||
1898 | srb = acb->pFreeSRB; | ||
1899 | if (unlikely(srb == NULL)) | ||
1900 | goto host_busy; | ||
1901 | |||
1902 | cmd->scsi_done = done; | ||
1903 | cmd->result = 0; | ||
1904 | acb->Cmds++; | ||
1905 | |||
1906 | acb->pFreeSRB = srb->pNextSRB; | ||
1907 | srb->pNextSRB = NULL; | ||
1908 | |||
1909 | srb->pSRBDCB = dcb; | ||
1910 | srb->pcmd = cmd; | ||
1911 | cmd->host_scribble = (char *)srb; | ||
1912 | |||
1913 | srb->SGIndex = 0; | ||
1914 | srb->AdaptStatus = 0; | ||
1915 | srb->TargetStatus = 0; | ||
1916 | srb->MsgCnt = 0; | ||
1917 | |||
1918 | srb->SRBStatus = 0; | ||
1919 | srb->SRBFlag = 0; | ||
1920 | srb->SRBState = 0; | ||
1921 | srb->TotalXferredLen = 0; | ||
1922 | srb->SGBusAddr = 0; | ||
1923 | srb->SGToBeXferLen = 0; | ||
1924 | srb->ScsiPhase = 0; | ||
1925 | srb->EndMessage = 0; | ||
1926 | srb->TagNumber = SCSI_NO_TAG; | ||
1927 | |||
1928 | if (dc390_StartSCSI(acb, dcb, srb)) { | ||
1929 | dc390_Free_insert(acb, srb); | ||
1930 | goto host_busy; | ||
1931 | } | ||
1932 | |||
1933 | dc390_Going_append(dcb, srb); | ||
1934 | |||
1935 | return 0; | ||
1936 | |||
1937 | host_busy: | ||
1938 | return SCSI_MLQUEUE_HOST_BUSY; | ||
1939 | |||
1940 | device_busy: | ||
1941 | return SCSI_MLQUEUE_DEVICE_BUSY; | ||
1942 | } | ||
1943 | |||
1944 | static DEF_SCSI_QCMD(DC390_queuecommand) | ||
1945 | |||
1946 | static void dc390_dumpinfo (struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB) | ||
1947 | { | ||
1948 | struct pci_dev *pdev; | ||
1949 | u16 pstat; | ||
1950 | |||
1951 | if (!pDCB) pDCB = pACB->pActiveDCB; | ||
1952 | if (!pSRB && pDCB) pSRB = pDCB->pActiveSRB; | ||
1953 | |||
1954 | if (pSRB) | ||
1955 | { | ||
1956 | printk ("DC390: SRB: Xferred %08lx, Remain %08lx, State %08x, Phase %02x\n", | ||
1957 | pSRB->TotalXferredLen, pSRB->SGToBeXferLen, pSRB->SRBState, | ||
1958 | pSRB->ScsiPhase); | ||
1959 | printk ("DC390: AdpaterStatus: %02x, SRB Status %02x\n", pSRB->AdaptStatus, pSRB->SRBStatus); | ||
1960 | } | ||
1961 | printk ("DC390: Status of last IRQ (DMA/SC/Int/IRQ): %08x\n", dc390_laststatus); | ||
1962 | printk ("DC390: Register dump: SCSI block:\n"); | ||
1963 | printk ("DC390: XferCnt Cmd Stat IntS IRQS FFIS Ctl1 Ctl2 Ctl3 Ctl4\n"); | ||
1964 | printk ("DC390: %06x %02x %02x %02x", | ||
1965 | DC390_read8(CtcReg_Low) + (DC390_read8(CtcReg_Mid) << 8) + (DC390_read8(CtcReg_High) << 16), | ||
1966 | DC390_read8(ScsiCmd), DC390_read8(Scsi_Status), DC390_read8(Intern_State)); | ||
1967 | printk (" %02x %02x %02x %02x %02x %02x\n", | ||
1968 | DC390_read8(INT_Status), DC390_read8(Current_Fifo), DC390_read8(CtrlReg1), | ||
1969 | DC390_read8(CtrlReg2), DC390_read8(CtrlReg3), DC390_read8(CtrlReg4)); | ||
1970 | DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT); | ||
1971 | if (DC390_read8(Current_Fifo) & 0x1f) | ||
1972 | { | ||
1973 | printk ("DC390: FIFO:"); | ||
1974 | while (DC390_read8(Current_Fifo) & 0x1f) printk (" %02x", DC390_read8(ScsiFifo)); | ||
1975 | printk ("\n"); | ||
1976 | } | ||
1977 | printk ("DC390: Register dump: DMA engine:\n"); | ||
1978 | printk ("DC390: Cmd STrCnt SBusA WrkBC WrkAC Stat SBusCtrl\n"); | ||
1979 | printk ("DC390: %02x %08x %08x %08x %08x %02x %08x\n", | ||
1980 | DC390_read8(DMA_Cmd), DC390_read32(DMA_XferCnt), DC390_read32(DMA_XferAddr), | ||
1981 | DC390_read32(DMA_Wk_ByteCntr), DC390_read32(DMA_Wk_AddrCntr), | ||
1982 | DC390_read8(DMA_Status), DC390_read32(DMA_ScsiBusCtrl)); | ||
1983 | DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT); | ||
1984 | |||
1985 | pdev = pACB->pdev; | ||
1986 | pci_read_config_word(pdev, PCI_STATUS, &pstat); | ||
1987 | printk ("DC390: Register dump: PCI Status: %04x\n", pstat); | ||
1988 | printk ("DC390: In case of driver trouble read Documentation/scsi/tmscsim.txt\n"); | ||
1989 | } | ||
1990 | |||
1991 | |||
1992 | static int DC390_abort(struct scsi_cmnd *cmd) | ||
1993 | { | ||
1994 | struct dc390_acb *pACB = (struct dc390_acb*) cmd->device->host->hostdata; | ||
1995 | struct dc390_dcb *pDCB = (struct dc390_dcb*) cmd->device->hostdata; | ||
1996 | |||
1997 | scmd_printk(KERN_WARNING, cmd, "DC390: Abort command\n"); | ||
1998 | |||
1999 | /* abort() is too stupid for already sent commands at the moment. | ||
2000 | * If it's called we are in trouble anyway, so let's dump some info | ||
2001 | * into the syslog at least. (KG, 98/08/20,99/06/20) */ | ||
2002 | dc390_dumpinfo(pACB, pDCB, NULL); | ||
2003 | |||
2004 | pDCB->DCBFlag |= ABORT_DEV_; | ||
2005 | printk(KERN_INFO "DC390: Aborted.\n"); | ||
2006 | |||
2007 | return FAILED; | ||
2008 | } | ||
2009 | |||
2010 | |||
2011 | static void dc390_ResetDevParam( struct dc390_acb* pACB ) | ||
2012 | { | ||
2013 | struct dc390_dcb *pDCB, *pdcb; | ||
2014 | |||
2015 | pDCB = pACB->pLinkDCB; | ||
2016 | if (! pDCB) return; | ||
2017 | pdcb = pDCB; | ||
2018 | do | ||
2019 | { | ||
2020 | pDCB->SyncMode &= ~SYNC_NEGO_DONE; | ||
2021 | pDCB->SyncPeriod = 0; | ||
2022 | pDCB->SyncOffset = 0; | ||
2023 | pDCB->TagMask = 0; | ||
2024 | pDCB->CtrlR3 = FAST_CLK; | ||
2025 | pDCB->CtrlR4 &= NEGATE_REQACKDATA | CTRL4_RESERVED | NEGATE_REQACK; | ||
2026 | pDCB->CtrlR4 |= pACB->glitch_cfg; | ||
2027 | pDCB = pDCB->pNextDCB; | ||
2028 | } | ||
2029 | while( pdcb != pDCB ); | ||
2030 | pACB->ACBFlag &= ~(RESET_DEV | RESET_DONE | RESET_DETECT); | ||
2031 | |||
2032 | } | ||
2033 | |||
2034 | static int DC390_bus_reset (struct scsi_cmnd *cmd) | ||
2035 | { | ||
2036 | struct dc390_acb* pACB = (struct dc390_acb*) cmd->device->host->hostdata; | ||
2037 | u8 bval; | ||
2038 | |||
2039 | spin_lock_irq(cmd->device->host->host_lock); | ||
2040 | |||
2041 | bval = DC390_read8(CtrlReg1) | DIS_INT_ON_SCSI_RST; | ||
2042 | DC390_write8(CtrlReg1, bval); /* disable IRQ on bus reset */ | ||
2043 | |||
2044 | pACB->ACBFlag |= RESET_DEV; | ||
2045 | dc390_ResetSCSIBus(pACB); | ||
2046 | |||
2047 | dc390_ResetDevParam(pACB); | ||
2048 | mdelay(1); | ||
2049 | pACB->last_reset = jiffies + 3*HZ/2 | ||
2050 | + HZ * dc390_eepromBuf[pACB->AdapterIndex][EE_DELAY]; | ||
2051 | |||
2052 | DC390_write8(ScsiCmd, CLEAR_FIFO_CMD); | ||
2053 | DC390_read8(INT_Status); /* Reset Pending INT */ | ||
2054 | |||
2055 | dc390_DoingSRB_Done(pACB, cmd); | ||
2056 | |||
2057 | pACB->pActiveDCB = NULL; | ||
2058 | pACB->ACBFlag = 0; | ||
2059 | |||
2060 | bval = DC390_read8(CtrlReg1) & ~DIS_INT_ON_SCSI_RST; | ||
2061 | DC390_write8(CtrlReg1, bval); /* re-enable interrupt */ | ||
2062 | |||
2063 | spin_unlock_irq(cmd->device->host->host_lock); | ||
2064 | |||
2065 | return SUCCESS; | ||
2066 | } | ||
2067 | |||
2068 | /** | ||
2069 | * dc390_slave_alloc - Called by the scsi mid layer to tell us about a new | ||
2070 | * scsi device that we need to deal with. | ||
2071 | * | ||
2072 | * @scsi_device: The new scsi device that we need to handle. | ||
2073 | */ | ||
2074 | static int dc390_slave_alloc(struct scsi_device *scsi_device) | ||
2075 | { | ||
2076 | struct dc390_acb *pACB = (struct dc390_acb*) scsi_device->host->hostdata; | ||
2077 | struct dc390_dcb *pDCB, *pDCB2 = NULL; | ||
2078 | uint id = scsi_device->id; | ||
2079 | uint lun = scsi_device->lun; | ||
2080 | |||
2081 | pDCB = kzalloc(sizeof(struct dc390_dcb), GFP_KERNEL); | ||
2082 | if (!pDCB) | ||
2083 | return -ENOMEM; | ||
2084 | |||
2085 | if (!pACB->DCBCnt++) { | ||
2086 | pACB->pLinkDCB = pDCB; | ||
2087 | pACB->pDCBRunRobin = pDCB; | ||
2088 | } else { | ||
2089 | pACB->pLastDCB->pNextDCB = pDCB; | ||
2090 | } | ||
2091 | |||
2092 | pDCB->pNextDCB = pACB->pLinkDCB; | ||
2093 | pACB->pLastDCB = pDCB; | ||
2094 | |||
2095 | pDCB->pDCBACB = pACB; | ||
2096 | pDCB->TargetID = id; | ||
2097 | pDCB->TargetLUN = lun; | ||
2098 | |||
2099 | /* | ||
2100 | * Some values are for all LUNs: Copy them | ||
2101 | * In a clean way: We would have an own structure for a SCSI-ID | ||
2102 | */ | ||
2103 | if (lun && (pDCB2 = dc390_findDCB(pACB, id, 0))) { | ||
2104 | pDCB->DevMode = pDCB2->DevMode; | ||
2105 | pDCB->SyncMode = pDCB2->SyncMode & SYNC_NEGO_DONE; | ||
2106 | pDCB->SyncPeriod = pDCB2->SyncPeriod; | ||
2107 | pDCB->SyncOffset = pDCB2->SyncOffset; | ||
2108 | pDCB->NegoPeriod = pDCB2->NegoPeriod; | ||
2109 | |||
2110 | pDCB->CtrlR3 = pDCB2->CtrlR3; | ||
2111 | pDCB->CtrlR4 = pDCB2->CtrlR4; | ||
2112 | } else { | ||
2113 | u8 index = pACB->AdapterIndex; | ||
2114 | PEEprom prom = (PEEprom) &dc390_eepromBuf[index][id << 2]; | ||
2115 | |||
2116 | pDCB->DevMode = prom->EE_MODE1; | ||
2117 | pDCB->NegoPeriod = | ||
2118 | (dc390_clock_period1[prom->EE_SPEED] * 25) >> 2; | ||
2119 | pDCB->CtrlR3 = FAST_CLK; | ||
2120 | pDCB->CtrlR4 = pACB->glitch_cfg | CTRL4_RESERVED; | ||
2121 | if (dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION) | ||
2122 | pDCB->CtrlR4 |= NEGATE_REQACKDATA | NEGATE_REQACK; | ||
2123 | } | ||
2124 | |||
2125 | if (pDCB->DevMode & SYNC_NEGO_) | ||
2126 | pDCB->SyncMode |= SYNC_ENABLE; | ||
2127 | else { | ||
2128 | pDCB->SyncMode = 0; | ||
2129 | pDCB->SyncOffset &= ~0x0f; | ||
2130 | } | ||
2131 | |||
2132 | pDCB->CtrlR1 = pACB->pScsiHost->this_id; | ||
2133 | if (pDCB->DevMode & PARITY_CHK_) | ||
2134 | pDCB->CtrlR1 |= PARITY_ERR_REPO; | ||
2135 | |||
2136 | pACB->scan_devices = 1; | ||
2137 | scsi_device->hostdata = pDCB; | ||
2138 | return 0; | ||
2139 | } | ||
2140 | |||
2141 | /** | ||
2142 | * dc390_slave_destroy - Called by the scsi mid layer to tell us about a | ||
2143 | * device that is going away. | ||
2144 | * | ||
2145 | * @scsi_device: The scsi device that we need to remove. | ||
2146 | */ | ||
2147 | static void dc390_slave_destroy(struct scsi_device *scsi_device) | ||
2148 | { | ||
2149 | struct dc390_acb* pACB = (struct dc390_acb*) scsi_device->host->hostdata; | ||
2150 | struct dc390_dcb* pDCB = (struct dc390_dcb*) scsi_device->hostdata; | ||
2151 | struct dc390_dcb* pPrevDCB = pACB->pLinkDCB; | ||
2152 | |||
2153 | pACB->scan_devices = 0; | ||
2154 | |||
2155 | BUG_ON(pDCB->GoingSRBCnt > 1); | ||
2156 | |||
2157 | if (pDCB == pACB->pLinkDCB) { | ||
2158 | if (pACB->pLastDCB == pDCB) { | ||
2159 | pDCB->pNextDCB = NULL; | ||
2160 | pACB->pLastDCB = NULL; | ||
2161 | } | ||
2162 | pACB->pLinkDCB = pDCB->pNextDCB; | ||
2163 | } else { | ||
2164 | while (pPrevDCB->pNextDCB != pDCB) | ||
2165 | pPrevDCB = pPrevDCB->pNextDCB; | ||
2166 | pPrevDCB->pNextDCB = pDCB->pNextDCB; | ||
2167 | if (pDCB == pACB->pLastDCB) | ||
2168 | pACB->pLastDCB = pPrevDCB; | ||
2169 | } | ||
2170 | |||
2171 | if (pDCB == pACB->pActiveDCB) | ||
2172 | pACB->pActiveDCB = NULL; | ||
2173 | if (pDCB == pACB->pLinkDCB) | ||
2174 | pACB->pLinkDCB = pDCB->pNextDCB; | ||
2175 | if (pDCB == pACB->pDCBRunRobin) | ||
2176 | pACB->pDCBRunRobin = pDCB->pNextDCB; | ||
2177 | kfree(pDCB); | ||
2178 | |||
2179 | pACB->DCBCnt--; | ||
2180 | } | ||
2181 | |||
2182 | static int dc390_slave_configure(struct scsi_device *sdev) | ||
2183 | { | ||
2184 | struct dc390_acb *acb = (struct dc390_acb *)sdev->host->hostdata; | ||
2185 | struct dc390_dcb *dcb = (struct dc390_dcb *)sdev->hostdata; | ||
2186 | |||
2187 | acb->scan_devices = 0; | ||
2188 | |||
2189 | /* | ||
2190 | * XXX: Note that while this driver used to called scsi_activate_tcq, | ||
2191 | * it never actually set a tag type, so emulate the old behavior. | ||
2192 | */ | ||
2193 | scsi_set_tag_type(sdev, 0); | ||
2194 | |||
2195 | if (sdev->tagged_supported && (dcb->DevMode & TAG_QUEUEING_)) { | ||
2196 | dcb->SyncMode |= EN_TAG_QUEUEING; | ||
2197 | scsi_change_queue_depth(sdev, acb->TagMaxNum); | ||
2198 | } | ||
2199 | |||
2200 | return 0; | ||
2201 | } | ||
2202 | |||
2203 | static struct scsi_host_template driver_template = { | ||
2204 | .module = THIS_MODULE, | ||
2205 | .proc_name = "tmscsim", | ||
2206 | .name = DC390_BANNER " V" DC390_VERSION, | ||
2207 | .slave_alloc = dc390_slave_alloc, | ||
2208 | .slave_configure = dc390_slave_configure, | ||
2209 | .slave_destroy = dc390_slave_destroy, | ||
2210 | .queuecommand = DC390_queuecommand, | ||
2211 | .eh_abort_handler = DC390_abort, | ||
2212 | .eh_bus_reset_handler = DC390_bus_reset, | ||
2213 | .can_queue = 1, | ||
2214 | .this_id = 7, | ||
2215 | .sg_tablesize = SG_ALL, | ||
2216 | .cmd_per_lun = 1, | ||
2217 | .use_clustering = ENABLE_CLUSTERING, | ||
2218 | .max_sectors = 0x4000, /* 8MiB = 16 * 1024 * 512 */ | ||
2219 | .use_blk_tags = 1, | ||
2220 | }; | ||
2221 | |||
2222 | /*********************************************************************** | ||
2223 | * Functions for access to DC390 EEPROM | ||
2224 | * and some to emulate it | ||
2225 | * | ||
2226 | **********************************************************************/ | ||
2227 | |||
2228 | static void dc390_eeprom_prepare_read(struct pci_dev *pdev, u8 cmd) | ||
2229 | { | ||
2230 | u8 carryFlag = 1, j = 0x80, bval; | ||
2231 | int i; | ||
2232 | |||
2233 | for (i = 0; i < 9; i++) { | ||
2234 | if (carryFlag) { | ||
2235 | pci_write_config_byte(pdev, 0x80, 0x40); | ||
2236 | bval = 0xc0; | ||
2237 | } else | ||
2238 | bval = 0x80; | ||
2239 | |||
2240 | udelay(160); | ||
2241 | pci_write_config_byte(pdev, 0x80, bval); | ||
2242 | udelay(160); | ||
2243 | pci_write_config_byte(pdev, 0x80, 0); | ||
2244 | udelay(160); | ||
2245 | |||
2246 | carryFlag = (cmd & j) ? 1 : 0; | ||
2247 | j >>= 1; | ||
2248 | } | ||
2249 | } | ||
2250 | |||
2251 | static u16 dc390_eeprom_get_data(struct pci_dev *pdev) | ||
2252 | { | ||
2253 | int i; | ||
2254 | u16 wval = 0; | ||
2255 | u8 bval; | ||
2256 | |||
2257 | for (i = 0; i < 16; i++) { | ||
2258 | wval <<= 1; | ||
2259 | |||
2260 | pci_write_config_byte(pdev, 0x80, 0x80); | ||
2261 | udelay(160); | ||
2262 | pci_write_config_byte(pdev, 0x80, 0x40); | ||
2263 | udelay(160); | ||
2264 | pci_read_config_byte(pdev, 0x00, &bval); | ||
2265 | |||
2266 | if (bval == 0x22) | ||
2267 | wval |= 1; | ||
2268 | } | ||
2269 | |||
2270 | return wval; | ||
2271 | } | ||
2272 | |||
2273 | static void dc390_read_eeprom(struct pci_dev *pdev, u16 *ptr) | ||
2274 | { | ||
2275 | u8 cmd = EEPROM_READ, i; | ||
2276 | |||
2277 | for (i = 0; i < 0x40; i++) { | ||
2278 | pci_write_config_byte(pdev, 0xc0, 0); | ||
2279 | udelay(160); | ||
2280 | |||
2281 | dc390_eeprom_prepare_read(pdev, cmd++); | ||
2282 | *ptr++ = dc390_eeprom_get_data(pdev); | ||
2283 | |||
2284 | pci_write_config_byte(pdev, 0x80, 0); | ||
2285 | pci_write_config_byte(pdev, 0x80, 0); | ||
2286 | udelay(160); | ||
2287 | } | ||
2288 | } | ||
2289 | |||
2290 | /* Override EEprom values with explicitly set values */ | ||
2291 | static void dc390_eeprom_override(u8 index) | ||
2292 | { | ||
2293 | u8 *ptr = (u8 *) dc390_eepromBuf[index], id; | ||
2294 | |||
2295 | /* Adapter Settings */ | ||
2296 | if (tmscsim[0] != -2) | ||
2297 | ptr[EE_ADAPT_SCSI_ID] = (u8)tmscsim[0]; /* Adapter ID */ | ||
2298 | if (tmscsim[3] != -2) | ||
2299 | ptr[EE_MODE2] = (u8)tmscsim[3]; | ||
2300 | if (tmscsim[5] != -2) | ||
2301 | ptr[EE_DELAY] = tmscsim[5]; /* Reset delay */ | ||
2302 | if (tmscsim[4] != -2) | ||
2303 | ptr[EE_TAG_CMD_NUM] = (u8)tmscsim[4]; /* Tagged Cmds */ | ||
2304 | |||
2305 | /* Device Settings */ | ||
2306 | for (id = 0; id < MAX_SCSI_ID; id++) { | ||
2307 | if (tmscsim[2] != -2) | ||
2308 | ptr[id << 2] = (u8)tmscsim[2]; /* EE_MODE1 */ | ||
2309 | if (tmscsim[1] != -2) | ||
2310 | ptr[(id << 2) + 1] = (u8)tmscsim[1]; /* EE_Speed */ | ||
2311 | } | ||
2312 | } | ||
2313 | |||
2314 | static int tmscsim_def[] = { | ||
2315 | 7, | ||
2316 | 0 /* 10MHz */, | ||
2317 | PARITY_CHK_ | SEND_START_ | EN_DISCONNECT_ | SYNC_NEGO_ | TAG_QUEUEING_, | ||
2318 | MORE2_DRV | GREATER_1G | RST_SCSI_BUS | ACTIVE_NEGATION | LUN_CHECK, | ||
2319 | 3 /* 16 Tags per LUN */, | ||
2320 | 1 /* s delay after Reset */, | ||
2321 | }; | ||
2322 | |||
2323 | /* Copy defaults over set values where missing */ | ||
2324 | static void dc390_fill_with_defaults (void) | ||
2325 | { | ||
2326 | int i; | ||
2327 | |||
2328 | for (i = 0; i < 6; i++) { | ||
2329 | if (tmscsim[i] < 0 || tmscsim[i] > 255) | ||
2330 | tmscsim[i] = tmscsim_def[i]; | ||
2331 | } | ||
2332 | |||
2333 | /* Sanity checks */ | ||
2334 | if (tmscsim[0] > 7) | ||
2335 | tmscsim[0] = 7; | ||
2336 | if (tmscsim[1] > 7) | ||
2337 | tmscsim[1] = 4; | ||
2338 | if (tmscsim[4] > 5) | ||
2339 | tmscsim[4] = 4; | ||
2340 | if (tmscsim[5] > 180) | ||
2341 | tmscsim[5] = 180; | ||
2342 | } | ||
2343 | |||
2344 | static void dc390_check_eeprom(struct pci_dev *pdev, u8 index) | ||
2345 | { | ||
2346 | u8 interpd[] = {1, 3, 5, 10, 16, 30, 60, 120}; | ||
2347 | u8 EEbuf[128]; | ||
2348 | u16 *ptr = (u16 *)EEbuf, wval = 0; | ||
2349 | int i; | ||
2350 | |||
2351 | dc390_read_eeprom(pdev, ptr); | ||
2352 | memcpy(dc390_eepromBuf[index], EEbuf, EE_ADAPT_SCSI_ID); | ||
2353 | memcpy(&dc390_eepromBuf[index][EE_ADAPT_SCSI_ID], | ||
2354 | &EEbuf[REAL_EE_ADAPT_SCSI_ID], EE_LEN - EE_ADAPT_SCSI_ID); | ||
2355 | |||
2356 | dc390_eepromBuf[index][EE_DELAY] = interpd[dc390_eepromBuf[index][EE_DELAY]]; | ||
2357 | |||
2358 | for (i = 0; i < 0x40; i++, ptr++) | ||
2359 | wval += *ptr; | ||
2360 | |||
2361 | /* no Tekram EEprom found */ | ||
2362 | if (wval != 0x1234) { | ||
2363 | int speed; | ||
2364 | |||
2365 | printk(KERN_INFO "DC390_init: No EEPROM found! Trying default settings ...\n"); | ||
2366 | |||
2367 | /* | ||
2368 | * XXX(hch): bogus, because we might have tekram and | ||
2369 | * non-tekram hbas in a single machine. | ||
2370 | */ | ||
2371 | dc390_fill_with_defaults(); | ||
2372 | |||
2373 | speed = dc390_clock_speed[tmscsim[1]]; | ||
2374 | printk(KERN_INFO "DC390: Used defaults: AdaptID=%i, SpeedIdx=%i (%i.%i MHz), " | ||
2375 | "DevMode=0x%02x, AdaptMode=0x%02x, TaggedCmnds=%i (%i), DelayReset=%is\n", | ||
2376 | tmscsim[0], tmscsim[1], speed / 10, speed % 10, | ||
2377 | (u8)tmscsim[2], (u8)tmscsim[3], tmscsim[4], 2 << (tmscsim[4]), tmscsim[5]); | ||
2378 | } | ||
2379 | } | ||
2380 | |||
2381 | static void dc390_init_hw(struct dc390_acb *pACB, u8 index) | ||
2382 | { | ||
2383 | struct Scsi_Host *shost = pACB->pScsiHost; | ||
2384 | u8 dstate; | ||
2385 | |||
2386 | /* Disable SCSI bus reset interrupt */ | ||
2387 | DC390_write8(CtrlReg1, DIS_INT_ON_SCSI_RST | shost->this_id); | ||
2388 | |||
2389 | if (pACB->Gmode2 & RST_SCSI_BUS) { | ||
2390 | dc390_ResetSCSIBus(pACB); | ||
2391 | udelay(1000); | ||
2392 | pACB->last_reset = jiffies + HZ/2 + | ||
2393 | HZ * dc390_eepromBuf[pACB->AdapterIndex][EE_DELAY]; | ||
2394 | } | ||
2395 | |||
2396 | pACB->ACBFlag = 0; | ||
2397 | |||
2398 | /* Reset Pending INT */ | ||
2399 | DC390_read8(INT_Status); | ||
2400 | |||
2401 | /* 250ms selection timeout */ | ||
2402 | DC390_write8(Scsi_TimeOut, SEL_TIMEOUT); | ||
2403 | |||
2404 | /* Conversion factor = 0 , 40MHz clock */ | ||
2405 | DC390_write8(Clk_Factor, CLK_FREQ_40MHZ); | ||
2406 | |||
2407 | /* NOP cmd - clear command register */ | ||
2408 | DC390_write8(ScsiCmd, NOP_CMD); | ||
2409 | |||
2410 | /* Enable Feature and SCSI-2 */ | ||
2411 | DC390_write8(CtrlReg2, EN_FEATURE+EN_SCSI2_CMD); | ||
2412 | |||
2413 | /* Fast clock */ | ||
2414 | DC390_write8(CtrlReg3, FAST_CLK); | ||
2415 | |||
2416 | /* Negation */ | ||
2417 | DC390_write8(CtrlReg4, pACB->glitch_cfg | /* glitch eater */ | ||
2418 | (dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION) ? | ||
2419 | NEGATE_REQACKDATA : 0); | ||
2420 | |||
2421 | /* Clear Transfer Count High: ID */ | ||
2422 | DC390_write8(CtcReg_High, 0); | ||
2423 | DC390_write8(DMA_Cmd, DMA_IDLE_CMD); | ||
2424 | DC390_write8(ScsiCmd, CLEAR_FIFO_CMD); | ||
2425 | DC390_write32(DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT); | ||
2426 | |||
2427 | dstate = DC390_read8(DMA_Status); | ||
2428 | DC390_write8(DMA_Status, dstate); | ||
2429 | } | ||
2430 | |||
2431 | static int dc390_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) | ||
2432 | { | ||
2433 | struct dc390_acb *pACB; | ||
2434 | struct Scsi_Host *shost; | ||
2435 | unsigned long io_port; | ||
2436 | int error = -ENODEV, i; | ||
2437 | |||
2438 | if (pci_enable_device(pdev)) | ||
2439 | goto out; | ||
2440 | |||
2441 | pci_set_master(pdev); | ||
2442 | |||
2443 | error = -ENOMEM; | ||
2444 | if (disable_clustering) | ||
2445 | driver_template.use_clustering = DISABLE_CLUSTERING; | ||
2446 | shost = scsi_host_alloc(&driver_template, sizeof(struct dc390_acb)); | ||
2447 | if (!shost) | ||
2448 | goto out_disable_device; | ||
2449 | |||
2450 | pACB = (struct dc390_acb *)shost->hostdata; | ||
2451 | memset(pACB, 0, sizeof(struct dc390_acb)); | ||
2452 | |||
2453 | dc390_check_eeprom(pdev, dc390_adapterCnt); | ||
2454 | dc390_eeprom_override(dc390_adapterCnt); | ||
2455 | |||
2456 | io_port = pci_resource_start(pdev, 0); | ||
2457 | |||
2458 | shost->this_id = dc390_eepromBuf[dc390_adapterCnt][EE_ADAPT_SCSI_ID]; | ||
2459 | shost->io_port = io_port; | ||
2460 | shost->n_io_port = 0x80; | ||
2461 | shost->irq = pdev->irq; | ||
2462 | shost->base = io_port; | ||
2463 | shost->unique_id = io_port; | ||
2464 | |||
2465 | pACB->last_reset = jiffies; | ||
2466 | pACB->pScsiHost = shost; | ||
2467 | pACB->IOPortBase = (u16) io_port; | ||
2468 | pACB->IRQLevel = pdev->irq; | ||
2469 | |||
2470 | shost->max_id = 8; | ||
2471 | |||
2472 | if (shost->max_id - 1 == | ||
2473 | dc390_eepromBuf[dc390_adapterCnt][EE_ADAPT_SCSI_ID]) | ||
2474 | shost->max_id--; | ||
2475 | |||
2476 | if (dc390_eepromBuf[dc390_adapterCnt][EE_MODE2] & LUN_CHECK) | ||
2477 | shost->max_lun = 8; | ||
2478 | else | ||
2479 | shost->max_lun = 1; | ||
2480 | |||
2481 | pACB->pFreeSRB = pACB->SRB_array; | ||
2482 | pACB->SRBCount = MAX_SRB_CNT; | ||
2483 | pACB->AdapterIndex = dc390_adapterCnt; | ||
2484 | pACB->TagMaxNum = | ||
2485 | 2 << dc390_eepromBuf[dc390_adapterCnt][EE_TAG_CMD_NUM]; | ||
2486 | pACB->Gmode2 = dc390_eepromBuf[dc390_adapterCnt][EE_MODE2]; | ||
2487 | |||
2488 | for (i = 0; i < pACB->SRBCount-1; i++) | ||
2489 | pACB->SRB_array[i].pNextSRB = &pACB->SRB_array[i+1]; | ||
2490 | pACB->SRB_array[pACB->SRBCount-1].pNextSRB = NULL; | ||
2491 | pACB->pTmpSRB = &pACB->TmpSRB; | ||
2492 | |||
2493 | pACB->sel_timeout = SEL_TIMEOUT; | ||
2494 | pACB->glitch_cfg = EATER_25NS; | ||
2495 | pACB->pdev = pdev; | ||
2496 | |||
2497 | if (!request_region(io_port, shost->n_io_port, "tmscsim")) { | ||
2498 | printk(KERN_ERR "DC390: register IO ports error!\n"); | ||
2499 | goto out_host_put; | ||
2500 | } | ||
2501 | |||
2502 | /* Reset Pending INT */ | ||
2503 | DC390_read8_(INT_Status, io_port); | ||
2504 | |||
2505 | if (request_irq(pdev->irq, do_DC390_Interrupt, IRQF_SHARED, | ||
2506 | "tmscsim", pACB)) { | ||
2507 | printk(KERN_ERR "DC390: register IRQ error!\n"); | ||
2508 | goto out_release_region; | ||
2509 | } | ||
2510 | |||
2511 | dc390_init_hw(pACB, dc390_adapterCnt); | ||
2512 | |||
2513 | dc390_adapterCnt++; | ||
2514 | |||
2515 | pci_set_drvdata(pdev, shost); | ||
2516 | |||
2517 | error = scsi_add_host(shost, &pdev->dev); | ||
2518 | if (error) | ||
2519 | goto out_free_irq; | ||
2520 | scsi_scan_host(shost); | ||
2521 | return 0; | ||
2522 | |||
2523 | out_free_irq: | ||
2524 | free_irq(pdev->irq, pACB); | ||
2525 | out_release_region: | ||
2526 | release_region(io_port, shost->n_io_port); | ||
2527 | out_host_put: | ||
2528 | scsi_host_put(shost); | ||
2529 | out_disable_device: | ||
2530 | pci_disable_device(pdev); | ||
2531 | out: | ||
2532 | return error; | ||
2533 | } | ||
2534 | |||
2535 | /** | ||
2536 | * dc390_remove_one - Called to remove a single instance of the adapter. | ||
2537 | * | ||
2538 | * @dev: The PCI device to remove. | ||
2539 | */ | ||
2540 | static void dc390_remove_one(struct pci_dev *dev) | ||
2541 | { | ||
2542 | struct Scsi_Host *scsi_host = pci_get_drvdata(dev); | ||
2543 | unsigned long iflags; | ||
2544 | struct dc390_acb* pACB = (struct dc390_acb*) scsi_host->hostdata; | ||
2545 | u8 bval; | ||
2546 | |||
2547 | scsi_remove_host(scsi_host); | ||
2548 | |||
2549 | spin_lock_irqsave(scsi_host->host_lock, iflags); | ||
2550 | pACB->ACBFlag = RESET_DEV; | ||
2551 | bval = DC390_read8(CtrlReg1) | DIS_INT_ON_SCSI_RST; | ||
2552 | DC390_write8 (CtrlReg1, bval); /* disable interrupt */ | ||
2553 | if (pACB->Gmode2 & RST_SCSI_BUS) | ||
2554 | dc390_ResetSCSIBus(pACB); | ||
2555 | spin_unlock_irqrestore(scsi_host->host_lock, iflags); | ||
2556 | |||
2557 | free_irq(scsi_host->irq, pACB); | ||
2558 | release_region(scsi_host->io_port, scsi_host->n_io_port); | ||
2559 | |||
2560 | pci_disable_device(dev); | ||
2561 | scsi_host_put(scsi_host); | ||
2562 | } | ||
2563 | |||
2564 | static struct pci_device_id tmscsim_pci_tbl[] = { | ||
2565 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD53C974, | ||
2566 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, | ||
2567 | { } | ||
2568 | }; | ||
2569 | MODULE_DEVICE_TABLE(pci, tmscsim_pci_tbl); | ||
2570 | |||
2571 | static struct pci_driver dc390_driver = { | ||
2572 | .name = "tmscsim", | ||
2573 | .id_table = tmscsim_pci_tbl, | ||
2574 | .probe = dc390_probe_one, | ||
2575 | .remove = dc390_remove_one, | ||
2576 | }; | ||
2577 | |||
2578 | static int __init dc390_module_init(void) | ||
2579 | { | ||
2580 | if (!disable_clustering) { | ||
2581 | printk(KERN_INFO "DC390: clustering now enabled by default. If you get problems load\n"); | ||
2582 | printk(KERN_INFO " with \"disable_clustering=1\" and report to maintainers\n"); | ||
2583 | } | ||
2584 | |||
2585 | if (tmscsim[0] == -1 || tmscsim[0] > 15) { | ||
2586 | tmscsim[0] = 7; | ||
2587 | tmscsim[1] = 4; | ||
2588 | tmscsim[2] = PARITY_CHK_ | TAG_QUEUEING_; | ||
2589 | tmscsim[3] = MORE2_DRV | GREATER_1G | RST_SCSI_BUS | ACTIVE_NEGATION; | ||
2590 | tmscsim[4] = 2; | ||
2591 | tmscsim[5] = 10; | ||
2592 | printk (KERN_INFO "DC390: Using safe settings.\n"); | ||
2593 | } | ||
2594 | |||
2595 | return pci_register_driver(&dc390_driver); | ||
2596 | } | ||
2597 | |||
2598 | static void __exit dc390_module_exit(void) | ||
2599 | { | ||
2600 | pci_unregister_driver(&dc390_driver); | ||
2601 | } | ||
2602 | |||
2603 | module_init(dc390_module_init); | ||
2604 | module_exit(dc390_module_exit); | ||
2605 | |||
2606 | #ifndef MODULE | ||
2607 | static int __init dc390_setup (char *str) | ||
2608 | { | ||
2609 | int ints[8],i, im; | ||
2610 | |||
2611 | get_options(str, ARRAY_SIZE(ints), ints); | ||
2612 | im = ints[0]; | ||
2613 | |||
2614 | if (im > 6) { | ||
2615 | printk (KERN_NOTICE "DC390: ignore extra params!\n"); | ||
2616 | im = 6; | ||
2617 | } | ||
2618 | |||
2619 | for (i = 0; i < im; i++) | ||
2620 | tmscsim[i] = ints[i+1]; | ||
2621 | /* dc390_checkparams (); */ | ||
2622 | return 1; | ||
2623 | } | ||
2624 | |||
2625 | __setup("tmscsim=", dc390_setup); | ||
2626 | #endif | ||
diff --git a/drivers/scsi/tmscsim.h b/drivers/scsi/tmscsim.h deleted file mode 100644 index c9ad4bb77098..000000000000 --- a/drivers/scsi/tmscsim.h +++ /dev/null | |||
@@ -1,549 +0,0 @@ | |||
1 | /*********************************************************************** | ||
2 | ;* File Name : TMSCSIM.H * | ||
3 | ;* TEKRAM DC-390(T) PCI SCSI Bus Master Host Adapter * | ||
4 | ;* Device Driver * | ||
5 | ;***********************************************************************/ | ||
6 | /* $Id: tmscsim.h,v 2.15.2.3 2000/11/17 20:52:27 garloff Exp $ */ | ||
7 | |||
8 | #ifndef _TMSCSIM_H | ||
9 | #define _TMSCSIM_H | ||
10 | |||
11 | #include <linux/types.h> | ||
12 | |||
13 | #define MAX_ADAPTER_NUM 4 | ||
14 | #define MAX_SG_LIST_BUF 16 /* Not used */ | ||
15 | #define MAX_SCSI_ID 8 | ||
16 | #define MAX_SRB_CNT 50 /* Max number of started commands */ | ||
17 | |||
18 | #define SEL_TIMEOUT 153 /* 250 ms selection timeout (@ 40 MHz) */ | ||
19 | |||
20 | /* | ||
21 | ;----------------------------------------------------------------------- | ||
22 | ; SCSI Request Block | ||
23 | ;----------------------------------------------------------------------- | ||
24 | */ | ||
25 | struct dc390_srb | ||
26 | { | ||
27 | //u8 CmdBlock[12]; | ||
28 | |||
29 | struct dc390_srb *pNextSRB; | ||
30 | struct dc390_dcb *pSRBDCB; | ||
31 | struct scsi_cmnd *pcmd; | ||
32 | struct scatterlist *pSegmentList; | ||
33 | |||
34 | struct scatterlist Segmentx; /* make a one entry of S/G list table */ | ||
35 | |||
36 | unsigned long SGBusAddr; /*;a segment starting address as seen by AM53C974A | ||
37 | in CPU endianness. We're only getting 32-bit bus | ||
38 | addresses by default */ | ||
39 | unsigned long SGToBeXferLen; /*; to be xfer length */ | ||
40 | unsigned long TotalXferredLen; | ||
41 | unsigned long SavedTotXLen; | ||
42 | unsigned long Saved_Ptr; | ||
43 | u32 SRBState; | ||
44 | |||
45 | u8 SRBStatus; | ||
46 | u8 SRBFlag; /*; b0-AutoReqSense,b6-Read,b7-write */ | ||
47 | /*; b4-settimeout,b5-Residual valid */ | ||
48 | u8 AdaptStatus; | ||
49 | u8 TargetStatus; | ||
50 | |||
51 | u8 ScsiPhase; | ||
52 | s8 TagNumber; | ||
53 | u8 SGIndex; | ||
54 | u8 SGcount; | ||
55 | |||
56 | u8 MsgCnt; | ||
57 | u8 EndMessage; | ||
58 | |||
59 | u8 MsgInBuf[6]; | ||
60 | u8 MsgOutBuf[6]; | ||
61 | |||
62 | //u8 IORBFlag; /*;81h-Reset, 2-retry */ | ||
63 | }; | ||
64 | |||
65 | |||
66 | /* | ||
67 | ;----------------------------------------------------------------------- | ||
68 | ; Device Control Block | ||
69 | ;----------------------------------------------------------------------- | ||
70 | */ | ||
71 | struct dc390_dcb | ||
72 | { | ||
73 | struct dc390_dcb *pNextDCB; | ||
74 | struct dc390_acb *pDCBACB; | ||
75 | |||
76 | /* Queued SRBs */ | ||
77 | struct dc390_srb *pGoingSRB; | ||
78 | struct dc390_srb *pGoingLast; | ||
79 | struct dc390_srb *pActiveSRB; | ||
80 | u8 GoingSRBCnt; | ||
81 | |||
82 | u32 TagMask; | ||
83 | |||
84 | u8 TargetID; /*; SCSI Target ID (SCSI Only) */ | ||
85 | u8 TargetLUN; /*; SCSI Log. Unit (SCSI Only) */ | ||
86 | u8 DevMode; | ||
87 | u8 DCBFlag; | ||
88 | |||
89 | u8 CtrlR1; | ||
90 | u8 CtrlR3; | ||
91 | u8 CtrlR4; | ||
92 | |||
93 | u8 SyncMode; /*; 0:async mode */ | ||
94 | u8 NegoPeriod; /*;for nego. */ | ||
95 | u8 SyncPeriod; /*;for reg. */ | ||
96 | u8 SyncOffset; /*;for reg. and nego.(low nibble) */ | ||
97 | }; | ||
98 | |||
99 | |||
100 | /* | ||
101 | ;----------------------------------------------------------------------- | ||
102 | ; Adapter Control Block | ||
103 | ;----------------------------------------------------------------------- | ||
104 | */ | ||
105 | struct dc390_acb | ||
106 | { | ||
107 | struct Scsi_Host *pScsiHost; | ||
108 | u16 IOPortBase; | ||
109 | u8 IRQLevel; | ||
110 | u8 status; | ||
111 | |||
112 | u8 SRBCount; | ||
113 | u8 AdapterIndex; /*; nth Adapter this driver */ | ||
114 | u8 DCBCnt; | ||
115 | |||
116 | u8 TagMaxNum; | ||
117 | u8 ACBFlag; | ||
118 | u8 Gmode2; | ||
119 | u8 scan_devices; | ||
120 | |||
121 | struct dc390_dcb *pLinkDCB; | ||
122 | struct dc390_dcb *pLastDCB; | ||
123 | struct dc390_dcb *pDCBRunRobin; | ||
124 | |||
125 | struct dc390_dcb *pActiveDCB; | ||
126 | struct dc390_srb *pFreeSRB; | ||
127 | struct dc390_srb *pTmpSRB; | ||
128 | |||
129 | u8 msgin123[4]; | ||
130 | u8 Connected; | ||
131 | u8 pad; | ||
132 | |||
133 | #if defined(USE_SPINLOCKS) && USE_SPINLOCKS > 1 && (defined(CONFIG_SMP) || DEBUG_SPINLOCKS > 0) | ||
134 | spinlock_t lock; | ||
135 | #endif | ||
136 | u8 sel_timeout; | ||
137 | u8 glitch_cfg; | ||
138 | |||
139 | u8 MsgLen; | ||
140 | u8 Ignore_IRQ; /* Not used */ | ||
141 | |||
142 | struct pci_dev *pdev; | ||
143 | |||
144 | unsigned long last_reset; | ||
145 | unsigned long Cmds; | ||
146 | u32 SelLost; | ||
147 | u32 SelConn; | ||
148 | u32 CmdInQ; | ||
149 | u32 CmdOutOfSRB; | ||
150 | |||
151 | struct dc390_srb TmpSRB; | ||
152 | struct dc390_srb SRB_array[MAX_SRB_CNT]; /* 50 SRBs */ | ||
153 | }; | ||
154 | |||
155 | |||
156 | /*;-----------------------------------------------------------------------*/ | ||
157 | |||
158 | |||
159 | #define BIT31 0x80000000 | ||
160 | #define BIT30 0x40000000 | ||
161 | #define BIT29 0x20000000 | ||
162 | #define BIT28 0x10000000 | ||
163 | #define BIT27 0x08000000 | ||
164 | #define BIT26 0x04000000 | ||
165 | #define BIT25 0x02000000 | ||
166 | #define BIT24 0x01000000 | ||
167 | #define BIT23 0x00800000 | ||
168 | #define BIT22 0x00400000 | ||
169 | #define BIT21 0x00200000 | ||
170 | #define BIT20 0x00100000 | ||
171 | #define BIT19 0x00080000 | ||
172 | #define BIT18 0x00040000 | ||
173 | #define BIT17 0x00020000 | ||
174 | #define BIT16 0x00010000 | ||
175 | #define BIT15 0x00008000 | ||
176 | #define BIT14 0x00004000 | ||
177 | #define BIT13 0x00002000 | ||
178 | #define BIT12 0x00001000 | ||
179 | #define BIT11 0x00000800 | ||
180 | #define BIT10 0x00000400 | ||
181 | #define BIT9 0x00000200 | ||
182 | #define BIT8 0x00000100 | ||
183 | #define BIT7 0x00000080 | ||
184 | #define BIT6 0x00000040 | ||
185 | #define BIT5 0x00000020 | ||
186 | #define BIT4 0x00000010 | ||
187 | #define BIT3 0x00000008 | ||
188 | #define BIT2 0x00000004 | ||
189 | #define BIT1 0x00000002 | ||
190 | #define BIT0 0x00000001 | ||
191 | |||
192 | /*;---UnitCtrlFlag */ | ||
193 | #define UNIT_ALLOCATED BIT0 | ||
194 | #define UNIT_INFO_CHANGED BIT1 | ||
195 | #define FORMATING_MEDIA BIT2 | ||
196 | #define UNIT_RETRY BIT3 | ||
197 | |||
198 | /*;---UnitFlags */ | ||
199 | #define DASD_SUPPORT BIT0 | ||
200 | #define SCSI_SUPPORT BIT1 | ||
201 | #define ASPI_SUPPORT BIT2 | ||
202 | |||
203 | /*;----SRBState machine definition */ | ||
204 | #define SRB_FREE 0 | ||
205 | #define SRB_WAIT BIT0 | ||
206 | #define SRB_READY BIT1 | ||
207 | #define SRB_MSGOUT BIT2 /*;arbitration+msg_out 1st byte*/ | ||
208 | #define SRB_MSGIN BIT3 | ||
209 | #define SRB_MSGIN_MULTI BIT4 | ||
210 | #define SRB_COMMAND BIT5 | ||
211 | #define SRB_START_ BIT6 /*;arbitration+msg_out+command_out*/ | ||
212 | #define SRB_DISCONNECT BIT7 | ||
213 | #define SRB_DATA_XFER BIT8 | ||
214 | #define SRB_XFERPAD BIT9 | ||
215 | #define SRB_STATUS BIT10 | ||
216 | #define SRB_COMPLETED BIT11 | ||
217 | #define SRB_ABORT_SENT BIT12 | ||
218 | #define DO_SYNC_NEGO BIT13 | ||
219 | #define SRB_UNEXPECT_RESEL BIT14 | ||
220 | |||
221 | /*;---SRBstatus */ | ||
222 | #define SRB_OK BIT0 | ||
223 | #define ABORTION BIT1 | ||
224 | #define OVER_RUN BIT2 | ||
225 | #define UNDER_RUN BIT3 | ||
226 | #define PARITY_ERROR BIT4 | ||
227 | #define SRB_ERROR BIT5 | ||
228 | |||
229 | /*;---ACBFlag */ | ||
230 | #define RESET_DEV BIT0 | ||
231 | #define RESET_DETECT BIT1 | ||
232 | #define RESET_DONE BIT2 | ||
233 | |||
234 | /*;---DCBFlag */ | ||
235 | #define ABORT_DEV_ BIT0 | ||
236 | |||
237 | /*;---SRBFlag */ | ||
238 | #define DATAOUT BIT7 | ||
239 | #define DATAIN BIT6 | ||
240 | #define RESIDUAL_VALID BIT5 | ||
241 | #define ENABLE_TIMER BIT4 | ||
242 | #define RESET_DEV0 BIT2 | ||
243 | #define ABORT_DEV BIT1 | ||
244 | #define AUTO_REQSENSE BIT0 | ||
245 | |||
246 | /*;---Adapter status */ | ||
247 | #define H_STATUS_GOOD 0 | ||
248 | #define H_SEL_TIMEOUT 0x11 | ||
249 | #define H_OVER_UNDER_RUN 0x12 | ||
250 | #define H_UNEXP_BUS_FREE 0x13 | ||
251 | #define H_TARGET_PHASE_F 0x14 | ||
252 | #define H_INVALID_CCB_OP 0x16 | ||
253 | #define H_LINK_CCB_BAD 0x17 | ||
254 | #define H_BAD_TARGET_DIR 0x18 | ||
255 | #define H_DUPLICATE_CCB 0x19 | ||
256 | #define H_BAD_CCB_OR_SG 0x1A | ||
257 | #define H_ABORT 0x0FF | ||
258 | |||
259 | /* cmd->result */ | ||
260 | #define RES_TARGET 0x000000FF /* Target State */ | ||
261 | #define RES_TARGET_LNX STATUS_MASK /* Only official ... */ | ||
262 | #define RES_ENDMSG 0x0000FF00 /* End Message */ | ||
263 | #define RES_DID 0x00FF0000 /* DID_ codes */ | ||
264 | #define RES_DRV 0xFF000000 /* DRIVER_ codes */ | ||
265 | |||
266 | #define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)) | ||
267 | #define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)) | ||
268 | |||
269 | #define SET_RES_TARGET(who, tgt) do { who &= ~RES_TARGET; who |= (int)(tgt); } while (0) | ||
270 | #define SET_RES_TARGET_LNX(who, tgt) do { who &= ~RES_TARGET_LNX; who |= (int)(tgt) << 1; } while (0) | ||
271 | #define SET_RES_MSG(who, msg) do { who &= ~RES_ENDMSG; who |= (int)(msg) << 8; } while (0) | ||
272 | #define SET_RES_DID(who, did) do { who &= ~RES_DID; who |= (int)(did) << 16; } while (0) | ||
273 | #define SET_RES_DRV(who, drv) do { who &= ~RES_DRV; who |= (int)(drv) << 24; } while (0) | ||
274 | |||
275 | /*;---Sync_Mode */ | ||
276 | #define SYNC_DISABLE 0 | ||
277 | #define SYNC_ENABLE BIT0 | ||
278 | #define SYNC_NEGO_DONE BIT1 | ||
279 | #define WIDE_ENABLE BIT2 /* Not used ;-) */ | ||
280 | #define WIDE_NEGO_DONE BIT3 /* Not used ;-) */ | ||
281 | #define EN_TAG_QUEUEING BIT4 | ||
282 | #define EN_ATN_STOP BIT5 | ||
283 | |||
284 | #define SYNC_NEGO_OFFSET 15 | ||
285 | |||
286 | /*;---SCSI bus phase*/ | ||
287 | #define SCSI_DATA_OUT 0 | ||
288 | #define SCSI_DATA_IN 1 | ||
289 | #define SCSI_COMMAND 2 | ||
290 | #define SCSI_STATUS_ 3 | ||
291 | #define SCSI_NOP0 4 | ||
292 | #define SCSI_NOP1 5 | ||
293 | #define SCSI_MSG_OUT 6 | ||
294 | #define SCSI_MSG_IN 7 | ||
295 | |||
296 | /*;----SCSI MSG BYTE*/ /* see scsi/scsi.h */ /* One is missing ! */ | ||
297 | #define ABORT_TAG 0x0d | ||
298 | |||
299 | /* | ||
300 | * SISC query queue | ||
301 | */ | ||
302 | typedef struct { | ||
303 | dma_addr_t saved_dma_handle; | ||
304 | } dc390_cmd_scp_t; | ||
305 | |||
306 | /* | ||
307 | ;========================================================== | ||
308 | ; EEPROM byte offset | ||
309 | ;========================================================== | ||
310 | */ | ||
311 | typedef struct _EEprom | ||
312 | { | ||
313 | u8 EE_MODE1; | ||
314 | u8 EE_SPEED; | ||
315 | u8 xx1; | ||
316 | u8 xx2; | ||
317 | } EEprom, *PEEprom; | ||
318 | |||
319 | #define REAL_EE_ADAPT_SCSI_ID 64 | ||
320 | #define REAL_EE_MODE2 65 | ||
321 | #define REAL_EE_DELAY 66 | ||
322 | #define REAL_EE_TAG_CMD_NUM 67 | ||
323 | |||
324 | #define EE_ADAPT_SCSI_ID 32 | ||
325 | #define EE_MODE2 33 | ||
326 | #define EE_DELAY 34 | ||
327 | #define EE_TAG_CMD_NUM 35 | ||
328 | |||
329 | #define EE_LEN 40 | ||
330 | |||
331 | /*; EE_MODE1 bits definition*/ | ||
332 | #define PARITY_CHK_ BIT0 | ||
333 | #define SYNC_NEGO_ BIT1 | ||
334 | #define EN_DISCONNECT_ BIT2 | ||
335 | #define SEND_START_ BIT3 | ||
336 | #define TAG_QUEUEING_ BIT4 | ||
337 | |||
338 | /*; EE_MODE2 bits definition*/ | ||
339 | #define MORE2_DRV BIT0 | ||
340 | #define GREATER_1G BIT1 | ||
341 | #define RST_SCSI_BUS BIT2 | ||
342 | #define ACTIVE_NEGATION BIT3 | ||
343 | #define NO_SEEK BIT4 | ||
344 | #define LUN_CHECK BIT5 | ||
345 | |||
346 | #define ENABLE_CE 1 | ||
347 | #define DISABLE_CE 0 | ||
348 | #define EEPROM_READ 0x80 | ||
349 | |||
350 | /* | ||
351 | ;========================================================== | ||
352 | ; AMD 53C974 Registers bit Definition | ||
353 | ;========================================================== | ||
354 | */ | ||
355 | /* | ||
356 | ;==================== | ||
357 | ; SCSI Register | ||
358 | ;==================== | ||
359 | */ | ||
360 | |||
361 | /*; Command Reg.(+0CH) (rw) */ | ||
362 | #define DMA_COMMAND BIT7 | ||
363 | #define NOP_CMD 0 | ||
364 | #define CLEAR_FIFO_CMD 1 | ||
365 | #define RST_DEVICE_CMD 2 | ||
366 | #define RST_SCSI_BUS_CMD 3 | ||
367 | |||
368 | #define INFO_XFER_CMD 0x10 | ||
369 | #define INITIATOR_CMD_CMPLTE 0x11 | ||
370 | #define MSG_ACCEPTED_CMD 0x12 | ||
371 | #define XFER_PAD_BYTE 0x18 | ||
372 | #define SET_ATN_CMD 0x1A | ||
373 | #define RESET_ATN_CMD 0x1B | ||
374 | |||
375 | #define SEL_WO_ATN 0x41 /* currently not used */ | ||
376 | #define SEL_W_ATN 0x42 | ||
377 | #define SEL_W_ATN_STOP 0x43 | ||
378 | #define SEL_W_ATN3 0x46 | ||
379 | #define EN_SEL_RESEL 0x44 | ||
380 | #define DIS_SEL_RESEL 0x45 /* currently not used */ | ||
381 | #define RESEL 0x40 /* " */ | ||
382 | #define RESEL_ATN3 0x47 /* " */ | ||
383 | |||
384 | #define DATA_XFER_CMD INFO_XFER_CMD | ||
385 | |||
386 | |||
387 | /*; SCSI Status Reg.(+10H) (r) */ | ||
388 | #define INTERRUPT BIT7 | ||
389 | #define ILLEGAL_OP_ERR BIT6 | ||
390 | #define PARITY_ERR BIT5 | ||
391 | #define COUNT_2_ZERO BIT4 | ||
392 | #define GROUP_CODE_VALID BIT3 | ||
393 | #define SCSI_PHASE_MASK (BIT2+BIT1+BIT0) | ||
394 | /* BIT2: MSG phase; BIT1: C/D physe; BIT0: I/O phase */ | ||
395 | |||
396 | /*; Interrupt Status Reg.(+14H) (r) */ | ||
397 | #define SCSI_RESET BIT7 | ||
398 | #define INVALID_CMD BIT6 | ||
399 | #define DISCONNECTED BIT5 | ||
400 | #define SERVICE_REQUEST BIT4 | ||
401 | #define SUCCESSFUL_OP BIT3 | ||
402 | #define RESELECTED BIT2 | ||
403 | #define SEL_ATTENTION BIT1 | ||
404 | #define SELECTED BIT0 | ||
405 | |||
406 | /*; Internal State Reg.(+18H) (r) */ | ||
407 | #define SYNC_OFFSET_FLAG BIT3 | ||
408 | #define INTRN_STATE_MASK (BIT2+BIT1+BIT0) | ||
409 | /* 0x04: Sel. successful (w/o stop), 0x01: Sel. successful (w/ stop) */ | ||
410 | |||
411 | /*; Clock Factor Reg.(+24H) (w) */ | ||
412 | #define CLK_FREQ_40MHZ 0 | ||
413 | #define CLK_FREQ_35MHZ (BIT2+BIT1+BIT0) | ||
414 | #define CLK_FREQ_30MHZ (BIT2+BIT1) | ||
415 | #define CLK_FREQ_25MHZ (BIT2+BIT0) | ||
416 | #define CLK_FREQ_20MHZ BIT2 | ||
417 | #define CLK_FREQ_15MHZ (BIT1+BIT0) | ||
418 | #define CLK_FREQ_10MHZ BIT1 | ||
419 | |||
420 | /*; Control Reg. 1(+20H) (rw) */ | ||
421 | #define EXTENDED_TIMING BIT7 | ||
422 | #define DIS_INT_ON_SCSI_RST BIT6 | ||
423 | #define PARITY_ERR_REPO BIT4 | ||
424 | #define SCSI_ID_ON_BUS (BIT2+BIT1+BIT0) /* host adapter ID */ | ||
425 | |||
426 | /*; Control Reg. 2(+2CH) (rw) */ | ||
427 | #define EN_FEATURE BIT6 | ||
428 | #define EN_SCSI2_CMD BIT3 | ||
429 | |||
430 | /*; Control Reg. 3(+30H) (rw) */ | ||
431 | #define ID_MSG_CHECK BIT7 | ||
432 | #define EN_QTAG_MSG BIT6 | ||
433 | #define EN_GRP2_CMD BIT5 | ||
434 | #define FAST_SCSI BIT4 /* ;10MB/SEC */ | ||
435 | #define FAST_CLK BIT3 /* ;25 - 40 MHZ */ | ||
436 | |||
437 | /*; Control Reg. 4(+34H) (rw) */ | ||
438 | #define EATER_12NS 0 | ||
439 | #define EATER_25NS BIT7 | ||
440 | #define EATER_35NS BIT6 | ||
441 | #define EATER_0NS (BIT7+BIT6) | ||
442 | #define REDUCED_POWER BIT5 | ||
443 | #define CTRL4_RESERVED BIT4 /* must be 1 acc. to AM53C974.c */ | ||
444 | #define NEGATE_REQACKDATA BIT2 | ||
445 | #define NEGATE_REQACK BIT3 | ||
446 | |||
447 | #define GLITCH_TO_NS(x) (((~x>>6 & 2) >> 1) | ((x>>6 & 1) << 1 ^ (x>>6 & 2))) | ||
448 | #define NS_TO_GLITCH(y) (((~y<<7) | ~((y<<6) ^ ((y<<5 & 1<<6) | ~0x40))) & 0xc0) | ||
449 | |||
450 | /* | ||
451 | ;==================== | ||
452 | ; DMA Register | ||
453 | ;==================== | ||
454 | */ | ||
455 | /*; DMA Command Reg.(+40H) (rw) */ | ||
456 | #define READ_DIRECTION BIT7 | ||
457 | #define WRITE_DIRECTION 0 | ||
458 | #define EN_DMA_INT BIT6 | ||
459 | #define EN_PAGE_INT BIT5 /* page transfer interrupt enable */ | ||
460 | #define MAP_TO_MDL BIT4 | ||
461 | #define DIAGNOSTIC BIT2 | ||
462 | #define DMA_IDLE_CMD 0 | ||
463 | #define DMA_BLAST_CMD BIT0 | ||
464 | #define DMA_ABORT_CMD BIT1 | ||
465 | #define DMA_START_CMD (BIT1+BIT0) | ||
466 | |||
467 | /*; DMA Status Reg.(+54H) (r) */ | ||
468 | #define PCI_MS_ABORT BIT6 | ||
469 | #define BLAST_COMPLETE BIT5 | ||
470 | #define SCSI_INTERRUPT BIT4 | ||
471 | #define DMA_XFER_DONE BIT3 | ||
472 | #define DMA_XFER_ABORT BIT2 | ||
473 | #define DMA_XFER_ERROR BIT1 | ||
474 | #define POWER_DOWN BIT0 | ||
475 | |||
476 | /*; DMA SCSI Bus and Ctrl.(+70H) */ | ||
477 | #define EN_INT_ON_PCI_ABORT BIT25 | ||
478 | #define WRT_ERASE_DMA_STAT BIT24 | ||
479 | #define PW_DOWN_CTRL BIT21 | ||
480 | #define SCSI_BUSY BIT20 | ||
481 | #define SCLK BIT19 | ||
482 | #define SCAM BIT18 | ||
483 | #define SCSI_LINES 0x0003ffff | ||
484 | |||
485 | /* | ||
486 | ;========================================================== | ||
487 | ; SCSI Chip register address offset | ||
488 | ;========================================================== | ||
489 | ;Registers are rw unless declared otherwise | ||
490 | */ | ||
491 | #define CtcReg_Low 0x00 /* r curr. transfer count */ | ||
492 | #define CtcReg_Mid 0x04 /* r */ | ||
493 | #define CtcReg_High 0x38 /* r */ | ||
494 | #define ScsiFifo 0x08 | ||
495 | #define ScsiCmd 0x0C | ||
496 | #define Scsi_Status 0x10 /* r */ | ||
497 | #define INT_Status 0x14 /* r */ | ||
498 | #define Sync_Period 0x18 /* w */ | ||
499 | #define Sync_Offset 0x1C /* w */ | ||
500 | #define Clk_Factor 0x24 /* w */ | ||
501 | #define CtrlReg1 0x20 | ||
502 | #define CtrlReg2 0x2C | ||
503 | #define CtrlReg3 0x30 | ||
504 | #define CtrlReg4 0x34 | ||
505 | #define DMA_Cmd 0x40 | ||
506 | #define DMA_XferCnt 0x44 /* rw starting transfer count (32 bit) */ | ||
507 | #define DMA_XferAddr 0x48 /* rw starting physical address (32 bit) */ | ||
508 | #define DMA_Wk_ByteCntr 0x4C /* r working byte counter */ | ||
509 | #define DMA_Wk_AddrCntr 0x50 /* r working address counter */ | ||
510 | #define DMA_Status 0x54 /* r */ | ||
511 | #define DMA_MDL_Addr 0x58 /* rw starting MDL address */ | ||
512 | #define DMA_Wk_MDL_Cntr 0x5C /* r working MDL counter */ | ||
513 | #define DMA_ScsiBusCtrl 0x70 /* rw SCSI Bus, PCI/DMA Ctrl */ | ||
514 | |||
515 | #define StcReg_Low CtcReg_Low /* w start transfer count */ | ||
516 | #define StcReg_Mid CtcReg_Mid /* w */ | ||
517 | #define StcReg_High CtcReg_High /* w */ | ||
518 | #define Scsi_Dest_ID Scsi_Status /* w */ | ||
519 | #define Scsi_TimeOut INT_Status /* w */ | ||
520 | #define Intern_State Sync_Period /* r */ | ||
521 | #define Current_Fifo Sync_Offset /* r Curr. FIFO / int. state */ | ||
522 | |||
523 | |||
524 | #define DC390_read8(address) \ | ||
525 | (inb (pACB->IOPortBase + (address))) | ||
526 | |||
527 | #define DC390_read8_(address, base) \ | ||
528 | (inb ((u16)(base) + (address))) | ||
529 | |||
530 | #define DC390_read16(address) \ | ||
531 | (inw (pACB->IOPortBase + (address))) | ||
532 | |||
533 | #define DC390_read32(address) \ | ||
534 | (inl (pACB->IOPortBase + (address))) | ||
535 | |||
536 | #define DC390_write8(address,value) \ | ||
537 | outb ((value), pACB->IOPortBase + (address)) | ||
538 | |||
539 | #define DC390_write8_(address,value,base) \ | ||
540 | outb ((value), (u16)(base) + (address)) | ||
541 | |||
542 | #define DC390_write16(address,value) \ | ||
543 | outw ((value), pACB->IOPortBase + (address)) | ||
544 | |||
545 | #define DC390_write32(address,value) \ | ||
546 | outl ((value), pACB->IOPortBase + (address)) | ||
547 | |||
548 | |||
549 | #endif /* _TMSCSIM_H */ | ||