]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/tmscsim.c
[SCSI] tmscsim: convert to use the data buffer accessors
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / tmscsim.c
CommitLineData
1da177e4
LT
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
1da177e4
LT
221#include <linux/module.h>
222#include <linux/delay.h>
223#include <linux/signal.h>
1da177e4
LT
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 <asm/io.h>
237
238#include <scsi/scsi.h>
239#include <scsi/scsi_cmnd.h>
240#include <scsi/scsi_device.h>
241#include <scsi/scsi_host.h>
242#include <scsi/scsicam.h>
243#include <scsi/scsi_tcq.h>
244
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
254static void dc390_DataOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
255static void dc390_DataIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
256static void dc390_Command_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
257static void dc390_Status_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
258static void dc390_MsgOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
259static void dc390_MsgIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
260static void dc390_DataOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
261static void dc390_DataInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
262static void dc390_CommandPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
263static void dc390_StatusPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
264static void dc390_MsgOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
265static void dc390_MsgInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
266static void dc390_Nop_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
267static void dc390_Nop_1( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
268
269static void dc390_SetXferRate( struct dc390_acb* pACB, struct dc390_dcb* pDCB );
270static void dc390_Disconnect( struct dc390_acb* pACB );
271static void dc390_Reselect( struct dc390_acb* pACB );
272static void dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB );
273static void dc390_ScsiRstDetect( struct dc390_acb* pACB );
274static void dc390_EnableMsgOut_Abort(struct dc390_acb*, struct dc390_srb*);
275static void dc390_dumpinfo(struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB);
276static void dc390_ResetDevParam(struct dc390_acb* pACB);
277
278static u32 dc390_laststatus = 0;
279static u8 dc390_adapterCnt = 0;
280
8f6fd19f
GL
281static int disable_clustering;
282module_param(disable_clustering, int, S_IRUGO);
283MODULE_PARM_DESC(disable_clustering, "If you experience problems with your devices, try setting to 1");
284
1da177e4
LT
285/* Startup values, to be overriden on the commandline */
286static int tmscsim[] = {-2, -2, -2, -2, -2, -2};
287
288module_param_array(tmscsim, int, NULL, 0);
289MODULE_PARM_DESC(tmscsim, "Host SCSI ID, Speed (0=10MHz), Device Flags, Adapter Flags, Max Tags (log2(tags)-1), DelayReset (s)");
290MODULE_AUTHOR("C.L. Huang / Kurt Garloff");
291MODULE_DESCRIPTION("SCSI host adapter driver for Tekram DC390 and other AMD53C974A based PCI SCSI adapters");
292MODULE_LICENSE("GPL");
293MODULE_SUPPORTED_DEVICE("sd,sr,sg,st");
294
295static 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
307static 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
320static 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
332static 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
345static u8 dc390_eepromBuf[MAX_ADAPTER_NUM][EE_LEN];
346static u8 dc390_clock_period1[] = {4, 5, 6, 7, 8, 10, 13, 20};
347static 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 **********************************************************************/
85923211
GL
354static 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
363static 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
1da177e4
LT
375static 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 */
390static __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
397static __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
412static __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
431static struct scatterlist* dc390_sg_build_single(struct scatterlist *sg, void *addr, unsigned int length)
432{
433 memset(sg, 0, sizeof(struct scatterlist));
434 sg->page = virt_to_page(addr);
435 sg->length = length;
436 sg->offset = (unsigned long)addr & ~PAGE_MASK;
437 return sg;
438}
439
440/* Create pci mapping */
441static int dc390_pci_map (struct dc390_srb* pSRB)
442{
443 int error = 0;
444 struct scsi_cmnd *pcmd = pSRB->pcmd;
445 struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev;
446 dc390_cmd_scp_t* cmdp = ((dc390_cmd_scp_t*)(&pcmd->SCp));
447
448 /* Map sense buffer */
449 if (pSRB->SRBFlag & AUTO_REQSENSE) {
450 pSRB->pSegmentList = dc390_sg_build_single(&pSRB->Segmentx, pcmd->sense_buffer, sizeof(pcmd->sense_buffer));
451 pSRB->SGcount = pci_map_sg(pdev, pSRB->pSegmentList, 1,
452 DMA_FROM_DEVICE);
453 cmdp->saved_dma_handle = sg_dma_address(pSRB->pSegmentList);
454
455 /* TODO: error handling */
456 if (pSRB->SGcount != 1)
457 error = 1;
458 DEBUG1(printk("%s(): Mapped sense buffer %p at %x\n", __FUNCTION__, pcmd->sense_buffer, cmdp->saved_dma_handle));
459 /* Map SG list */
85289f2e
FT
460 } else if (scsi_sg_count(pcmd)) {
461 int nseg;
462
463 nseg = scsi_dma_map(pcmd);
464
465 pSRB->pSegmentList = scsi_sglist(pcmd);
466 pSRB->SGcount = nseg;
467
1da177e4 468 /* TODO: error handling */
85289f2e 469 if (nseg < 0)
1da177e4
LT
470 error = 1;
471 DEBUG1(printk("%s(): Mapped SG %p with %d (%d) elements\n",\
85289f2e 472 __FUNCTION__, scsi_sglist(pcmd), nseg, scsi_sg_count(pcmd)));
1da177e4 473 /* Map single segment */
85289f2e 474 } else
1da177e4
LT
475 pSRB->SGcount = 0;
476
477 return error;
478}
479
480/* Remove pci mapping */
481static void dc390_pci_unmap (struct dc390_srb* pSRB)
482{
483 struct scsi_cmnd *pcmd = pSRB->pcmd;
484 struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev;
485 DEBUG1(dc390_cmd_scp_t* cmdp = ((dc390_cmd_scp_t*)(&pcmd->SCp)));
486
487 if (pSRB->SRBFlag) {
488 pci_unmap_sg(pdev, &pSRB->Segmentx, 1, DMA_FROM_DEVICE);
489 DEBUG1(printk("%s(): Unmapped sense buffer at %x\n", __FUNCTION__, cmdp->saved_dma_handle));
85289f2e
FT
490 } else {
491 scsi_dma_unmap(pcmd);
492 DEBUG1(printk("%s(): Unmapped SG at %p with %d elements\n",
493 __FUNCTION__, scsi_sglist(pcmd), scsi_sg_count(pcmd)));
1da177e4
LT
494 }
495}
496
497static void __inline__
498dc390_freetag (struct dc390_dcb* pDCB, struct dc390_srb* pSRB)
499{
500 if (pSRB->TagNumber != SCSI_NO_TAG) {
501 pDCB->TagMask &= ~(1 << pSRB->TagNumber); /* free tag mask */
502 pSRB->TagNumber = SCSI_NO_TAG;
503 }
504}
505
506
507static int
508dc390_StartSCSI( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB )
509{
510 struct scsi_cmnd *scmd = pSRB->pcmd;
511 struct scsi_device *sdev = scmd->device;
512 u8 cmd, disc_allowed, try_sync_nego;
513 char tag[2];
514
515 pSRB->ScsiPhase = SCSI_NOP0;
516
517 if (pACB->Connected)
518 {
519 // Should not happen normally
520 printk (KERN_WARNING "DC390: Can't select when connected! (%08x,%02x)\n",
521 pSRB->SRBState, pSRB->SRBFlag);
522 pSRB->SRBState = SRB_READY;
523 pACB->SelConn++;
524 return 1;
525 }
526 if (time_before (jiffies, pACB->pScsiHost->last_reset))
527 {
528 DEBUG0(printk ("DC390: We were just reset and don't accept commands yet!\n"));
529 return 1;
530 }
531 /* KG: Moved pci mapping here */
532 dc390_pci_map(pSRB);
533 /* TODO: error handling */
534 DC390_write8 (Scsi_Dest_ID, pDCB->TargetID);
535 DC390_write8 (Sync_Period, pDCB->SyncPeriod);
536 DC390_write8 (Sync_Offset, pDCB->SyncOffset);
537 DC390_write8 (CtrlReg1, pDCB->CtrlR1);
538 DC390_write8 (CtrlReg3, pDCB->CtrlR3);
539 DC390_write8 (CtrlReg4, pDCB->CtrlR4);
540 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); /* Flush FIFO */
541 DEBUG1(printk (KERN_INFO "DC390: Start SCSI command: %02x (Sync:%02x)\n",\
542 scmd->cmnd[0], pDCB->SyncMode));
543
544 /* Don't disconnect on AUTO_REQSENSE, cause it might be an
545 * Contingent Allegiance Condition (6.6), where no tags should be used.
546 * All other have to be allowed to disconnect to prevent Incorrect
547 * Initiator Connection (6.8.2/6.5.2) */
548 /* Changed KG, 99/06/06 */
549 if (! (pSRB->SRBFlag & AUTO_REQSENSE))
550 disc_allowed = pDCB->DevMode & EN_DISCONNECT_;
551 else
552 disc_allowed = 0;
553
554 if ((pDCB->SyncMode & SYNC_ENABLE) && pDCB->TargetLUN == 0 && sdev->sdtr &&
555 (((scmd->cmnd[0] == REQUEST_SENSE || (pSRB->SRBFlag & AUTO_REQSENSE)) &&
556 !(pDCB->SyncMode & SYNC_NEGO_DONE)) || scmd->cmnd[0] == INQUIRY))
557 try_sync_nego = 1;
558 else
559 try_sync_nego = 0;
560
561 pSRB->MsgCnt = 0;
562 cmd = SEL_W_ATN;
563 DC390_write8 (ScsiFifo, IDENTIFY(disc_allowed, pDCB->TargetLUN));
564 /* Change 99/05/31: Don't use tags when not disconnecting (BUSY) */
565 if ((pDCB->SyncMode & EN_TAG_QUEUEING) && disc_allowed && scsi_populate_tag_msg(scmd, tag)) {
566 DC390_write8(ScsiFifo, tag[0]);
567 pDCB->TagMask |= 1 << tag[1];
568 pSRB->TagNumber = tag[1];
569 DC390_write8(ScsiFifo, tag[1]);
570 DEBUG1(printk(KERN_INFO "DC390: Select w/DisCn for Cmd %li (SRB %p), block tag %02x\n", scmd->pid, pSRB, tag[1]));
571 cmd = SEL_W_ATN3;
572 } else {
573 /* No TagQ */
574//no_tag:
575 DEBUG1(printk(KERN_INFO "DC390: Select w%s/DisCn for Cmd %li (SRB %p), No TagQ\n", disc_allowed ? "" : "o", scmd->pid, pSRB));
576 }
577
578 pSRB->SRBState = SRB_START_;
579
580 if (try_sync_nego)
581 {
582 u8 Sync_Off = pDCB->SyncOffset;
583 DEBUG0(printk (KERN_INFO "DC390: NEW Sync Nego code triggered (%i %i)\n", pDCB->TargetID, pDCB->TargetLUN));
584 pSRB->MsgOutBuf[0] = EXTENDED_MESSAGE;
585 pSRB->MsgOutBuf[1] = 3;
586 pSRB->MsgOutBuf[2] = EXTENDED_SDTR;
587 pSRB->MsgOutBuf[3] = pDCB->NegoPeriod;
588 if (!(Sync_Off & 0x0f)) Sync_Off = SYNC_NEGO_OFFSET;
589 pSRB->MsgOutBuf[4] = Sync_Off;
590 pSRB->MsgCnt = 5;
591 //pSRB->SRBState = SRB_MSGOUT_;
592 pSRB->SRBState |= DO_SYNC_NEGO;
593 cmd = SEL_W_ATN_STOP;
594 }
595
596 /* Command is written in CommandPhase, if SEL_W_ATN_STOP ... */
597 if (cmd != SEL_W_ATN_STOP)
598 {
599 if( pSRB->SRBFlag & AUTO_REQSENSE )
600 {
601 DC390_write8 (ScsiFifo, REQUEST_SENSE);
602 DC390_write8 (ScsiFifo, pDCB->TargetLUN << 5);
603 DC390_write8 (ScsiFifo, 0);
604 DC390_write8 (ScsiFifo, 0);
605 DC390_write8 (ScsiFifo, sizeof(scmd->sense_buffer));
606 DC390_write8 (ScsiFifo, 0);
607 DEBUG1(printk (KERN_DEBUG "DC390: AutoReqSense !\n"));
608 }
609 else /* write cmnd to bus */
610 {
611 u8 *ptr; u8 i;
612 ptr = (u8 *)scmd->cmnd;
613 for (i = 0; i < scmd->cmd_len; i++)
614 DC390_write8 (ScsiFifo, *(ptr++));
615 }
616 }
617 DEBUG0(if (pACB->pActiveDCB) \
618 printk (KERN_WARNING "DC390: ActiveDCB != 0\n"));
619 DEBUG0(if (pDCB->pActiveSRB) \
620 printk (KERN_WARNING "DC390: ActiveSRB != 0\n"));
621 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
622 if (DC390_read8 (Scsi_Status) & INTERRUPT)
623 {
624 dc390_freetag (pDCB, pSRB);
625 DEBUG0(printk ("DC390: Interrupt during Start SCSI (pid %li, target %02i-%02i)\n",
626 scmd->pid, scmd->device->id, scmd->device->lun));
627 pSRB->SRBState = SRB_READY;
628 //DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
629 pACB->SelLost++;
630 return 1;
631 }
632 DC390_write8 (ScsiCmd, cmd);
633 pACB->pActiveDCB = pDCB;
634 pDCB->pActiveSRB = pSRB;
635 pACB->Connected = 1;
636 pSRB->ScsiPhase = SCSI_NOP1;
637 return 0;
638}
639
1da177e4
LT
640
641static void __inline__
642dc390_InvalidCmd(struct dc390_acb* pACB)
643{
644 if (pACB->pActiveDCB->pActiveSRB->SRBState & (SRB_START_ | SRB_MSGOUT))
645 DC390_write8(ScsiCmd, CLEAR_FIFO_CMD);
646}
647
648
649static irqreturn_t __inline__
c7bec5ab 650DC390_Interrupt(void *dev_id)
1da177e4 651{
c7bec5ab 652 struct dc390_acb *pACB = dev_id;
1da177e4
LT
653 struct dc390_dcb *pDCB;
654 struct dc390_srb *pSRB;
655 u8 sstatus=0;
656 u8 phase;
657 void (*stateV)( struct dc390_acb*, struct dc390_srb*, u8 *);
658 u8 istate, istatus;
1da177e4
LT
659
660 sstatus = DC390_read8 (Scsi_Status);
661 if( !(sstatus & INTERRUPT) )
662 return IRQ_NONE;
663
664 DEBUG1(printk (KERN_DEBUG "sstatus=%02x,", sstatus));
665
1da177e4
LT
666 //DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT);
667 //dstatus = DC390_read8 (DMA_Status);
668 //DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT);
1da177e4
LT
669
670 spin_lock_irq(pACB->pScsiHost->host_lock);
671
672 istate = DC390_read8 (Intern_State);
673 istatus = DC390_read8 (INT_Status); /* This clears Scsi_Status, Intern_State and INT_Status ! */
674
675 DEBUG1(printk (KERN_INFO "Istatus(Res,Inv,Dis,Serv,Succ,ReS,SelA,Sel)=%02x,",istatus));
676 dc390_laststatus &= ~0x00ffffff;
677 dc390_laststatus |= /* dstatus<<24 | */ sstatus<<16 | istate<<8 | istatus;
678
679 if (sstatus & ILLEGAL_OP_ERR)
680 {
681 printk ("DC390: Illegal Operation detected (%08x)!\n", dc390_laststatus);
682 dc390_dumpinfo (pACB, pACB->pActiveDCB, pACB->pActiveDCB->pActiveSRB);
683 }
684
685 else if (istatus & INVALID_CMD)
686 {
687 printk ("DC390: Invalid Command detected (%08x)!\n", dc390_laststatus);
688 dc390_InvalidCmd( pACB );
689 goto unlock;
690 }
691
692 if (istatus & SCSI_RESET)
693 {
694 dc390_ScsiRstDetect( pACB );
695 goto unlock;
696 }
697
698 if (istatus & DISCONNECTED)
699 {
700 dc390_Disconnect( pACB );
701 goto unlock;
702 }
703
704 if (istatus & RESELECTED)
705 {
706 dc390_Reselect( pACB );
707 goto unlock;
708 }
709
710 else if (istatus & (SELECTED | SEL_ATTENTION))
711 {
712 printk (KERN_ERR "DC390: Target mode not supported!\n");
713 goto unlock;
714 }
715
716 if (istatus & (SUCCESSFUL_OP|SERVICE_REQUEST) )
717 {
718 pDCB = pACB->pActiveDCB;
719 if (!pDCB)
720 {
721 printk (KERN_ERR "DC390: Suc. op/ Serv. req: pActiveDCB = 0!\n");
722 goto unlock;
723 }
724 pSRB = pDCB->pActiveSRB;
725 if( pDCB->DCBFlag & ABORT_DEV_ )
726 dc390_EnableMsgOut_Abort (pACB, pSRB);
727
728 phase = pSRB->ScsiPhase;
729 DEBUG1(printk (KERN_INFO "DC390: [%i]%s(0) (%02x)\n", phase, dc390_p0_str[phase], sstatus));
730 stateV = (void *) dc390_phase0[phase];
731 ( *stateV )( pACB, pSRB, &sstatus );
732
733 pSRB->ScsiPhase = sstatus & 7;
734 phase = (u8) sstatus & 7;
735 DEBUG1(printk (KERN_INFO "DC390: [%i]%s(1) (%02x)\n", phase, dc390_p1_str[phase], sstatus));
736 stateV = (void *) dc390_phase1[phase];
737 ( *stateV )( pACB, pSRB, &sstatus );
738 }
739
740 unlock:
741 spin_unlock_irq(pACB->pScsiHost->host_lock);
742 return IRQ_HANDLED;
743}
744
c7bec5ab 745static irqreturn_t do_DC390_Interrupt(int irq, void *dev_id)
1da177e4
LT
746{
747 irqreturn_t ret;
748 DEBUG1(printk (KERN_INFO "DC390: Irq (%i) caught: ", irq));
749 /* Locking is done in DC390_Interrupt */
c7bec5ab 750 ret = DC390_Interrupt(dev_id);
1da177e4
LT
751 DEBUG1(printk (".. IRQ returned\n"));
752 return ret;
753}
754
755static void
85923211 756dc390_DataOut_0(struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1da177e4
LT
757{
758 u8 sstatus;
85923211 759 u32 ResidCnt;
1da177e4
LT
760 u8 dstate = 0;
761
762 sstatus = *psstatus;
763
764 if( !(pSRB->SRBState & SRB_XFERPAD) )
765 {
766 if( sstatus & (PARITY_ERR | ILLEGAL_OP_ERR) )
767 pSRB->SRBStatus |= PARITY_ERROR;
768
769 if( sstatus & COUNT_2_ZERO )
770 {
771 unsigned long timeout = jiffies + HZ;
772
773 /* Function called from the ISR with the host_lock held and interrupts disabled */
774 if (pSRB->SGToBeXferLen)
775 while (time_before(jiffies, timeout) && !((dstate = DC390_read8 (DMA_Status)) & DMA_XFER_DONE)) {
776 spin_unlock_irq(pACB->pScsiHost->host_lock);
777 udelay(50);
778 spin_lock_irq(pACB->pScsiHost->host_lock);
779 }
780 if (!time_before(jiffies, timeout))
781 printk (KERN_CRIT "DC390: Deadlock in DataOut_0: DMA aborted unfinished: %06x bytes remain!!\n",
782 DC390_read32 (DMA_Wk_ByteCntr));
783 dc390_laststatus &= ~0xff000000;
784 dc390_laststatus |= dstate << 24;
785 pSRB->TotalXferredLen += pSRB->SGToBeXferLen;
786 pSRB->SGIndex++;
787 if( pSRB->SGIndex < pSRB->SGcount )
788 {
789 pSRB->pSegmentList++;
1da177e4 790
85923211 791 dc390_start_segment(pSRB);
1da177e4
LT
792 }
793 else
794 pSRB->SGToBeXferLen = 0;
795 }
796 else
797 {
85923211
GL
798 ResidCnt = ((u32) DC390_read8 (Current_Fifo) & 0x1f) +
799 (((u32) DC390_read8 (CtcReg_High) << 16) |
800 ((u32) DC390_read8 (CtcReg_Mid) << 8) |
801 (u32) DC390_read8 (CtcReg_Low));
802
803 dc390_advance_segment(pSRB, ResidCnt);
1da177e4
LT
804 }
805 }
806 if ((*psstatus & 7) != SCSI_DATA_OUT)
807 {
860bfecf 808 DC390_write8 (DMA_Cmd, WRITE_DIRECTION+DMA_IDLE_CMD);
1da177e4
LT
809 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
810 }
811}
812
813static void
85923211 814dc390_DataIn_0(struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1da177e4
LT
815{
816 u8 sstatus, residual, bval;
85923211 817 u32 ResidCnt, i;
1da177e4 818 unsigned long xferCnt;
1da177e4
LT
819
820 sstatus = *psstatus;
821
822 if( !(pSRB->SRBState & SRB_XFERPAD) )
823 {
824 if( sstatus & (PARITY_ERR | ILLEGAL_OP_ERR))
825 pSRB->SRBStatus |= PARITY_ERROR;
826
827 if( sstatus & COUNT_2_ZERO )
828 {
829 int dstate = 0;
830 unsigned long timeout = jiffies + HZ;
831
832 /* Function called from the ISR with the host_lock held and interrupts disabled */
833 if (pSRB->SGToBeXferLen)
834 while (time_before(jiffies, timeout) && !((dstate = DC390_read8 (DMA_Status)) & DMA_XFER_DONE)) {
835 spin_unlock_irq(pACB->pScsiHost->host_lock);
836 udelay(50);
837 spin_lock_irq(pACB->pScsiHost->host_lock);
838 }
839 if (!time_before(jiffies, timeout)) {
840 printk (KERN_CRIT "DC390: Deadlock in DataIn_0: DMA aborted unfinished: %06x bytes remain!!\n",
841 DC390_read32 (DMA_Wk_ByteCntr));
842 printk (KERN_CRIT "DC390: DataIn_0: DMA State: %i\n", dstate);
843 }
844 dc390_laststatus &= ~0xff000000;
845 dc390_laststatus |= dstate << 24;
846 DEBUG1(ResidCnt = ((unsigned long) DC390_read8 (CtcReg_High) << 16) \
847 + ((unsigned long) DC390_read8 (CtcReg_Mid) << 8) \
848 + ((unsigned long) DC390_read8 (CtcReg_Low)));
46e5ba2b 849 DEBUG1(printk (KERN_DEBUG "Count_2_Zero (ResidCnt=%u,ToBeXfer=%lu),", ResidCnt, pSRB->SGToBeXferLen));
1da177e4 850
860bfecf 851 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD);
1da177e4
LT
852
853 pSRB->TotalXferredLen += pSRB->SGToBeXferLen;
854 pSRB->SGIndex++;
855 if( pSRB->SGIndex < pSRB->SGcount )
856 {
857 pSRB->pSegmentList++;
1da177e4 858
85923211 859 dc390_start_segment(pSRB);
1da177e4
LT
860 }
861 else
862 pSRB->SGToBeXferLen = 0;
863 }
864 else /* phase changed */
865 {
866 residual = 0;
867 bval = DC390_read8 (Current_Fifo);
868 while( bval & 0x1f )
869 {
870 DEBUG1(printk (KERN_DEBUG "Check for residuals,"));
871 if( (bval & 0x1f) == 1 )
872 {
873 for(i=0; i < 0x100; i++)
874 {
875 bval = DC390_read8 (Current_Fifo);
876 if( !(bval & 0x1f) )
877 goto din_1;
878 else if( i == 0x0ff )
879 {
880 residual = 1; /* ;1 residual byte */
881 goto din_1;
882 }
883 }
884 }
885 else
886 bval = DC390_read8 (Current_Fifo);
887 }
888din_1:
889 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_BLAST_CMD);
890 for (i = 0xa000; i; i--)
891 {
892 bval = DC390_read8 (DMA_Status);
893 if (bval & BLAST_COMPLETE)
894 break;
895 }
896 /* It seems a DMA Blast abort isn't that bad ... */
897 if (!i) printk (KERN_ERR "DC390: DMA Blast aborted unfinished!\n");
860bfecf 898 //DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD);
85923211
GL
899 dc390_laststatus &= ~0xff000000;
900 dc390_laststatus |= bval << 24;
1da177e4
LT
901
902 DEBUG1(printk (KERN_DEBUG "Blast: Read %i times DMA_Status %02x", 0xa000-i, bval));
85923211
GL
903 ResidCnt = (((u32) DC390_read8 (CtcReg_High) << 16) |
904 ((u32) DC390_read8 (CtcReg_Mid) << 8)) |
905 (u32) DC390_read8 (CtcReg_Low);
906
907 xferCnt = dc390_advance_segment(pSRB, ResidCnt);
908
909 if (residual) {
910 size_t count = 1;
911 size_t offset = pSRB->SGBusAddr - sg_dma_address(pSRB->pSegmentList);
912 unsigned long flags;
913 u8 *ptr;
914
1da177e4 915 bval = DC390_read8 (ScsiFifo); /* get one residual byte */
fe607aa9 916
85923211
GL
917 local_irq_save(flags);
918 ptr = scsi_kmap_atomic_sg(pSRB->pSegmentList, pSRB->SGcount, &offset, &count);
919 if (likely(ptr)) {
920 *(ptr + offset) = bval;
921 scsi_kunmap_atomic_sg(ptr);
fe607aa9 922 }
85923211
GL
923 local_irq_restore(flags);
924 WARN_ON(!ptr);
fe607aa9 925
85923211
GL
926 /* 1 more byte read */
927 xferCnt += dc390_advance_segment(pSRB, pSRB->SGToBeXferLen - 1);
1da177e4 928 }
46e5ba2b 929 DEBUG1(printk (KERN_DEBUG "Xfered: %lu, Total: %lu, Remaining: %lu\n", xferCnt,\
1da177e4 930 pSRB->TotalXferredLen, pSRB->SGToBeXferLen));
1da177e4
LT
931 }
932 }
933 if ((*psstatus & 7) != SCSI_DATA_IN)
934 {
935 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
860bfecf 936 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD);
1da177e4
LT
937 }
938}
939
940static void
941dc390_Command_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
942{
943}
944
945static void
946dc390_Status_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
947{
948
949 pSRB->TargetStatus = DC390_read8 (ScsiFifo);
950 //udelay (1);
951 pSRB->EndMessage = DC390_read8 (ScsiFifo); /* get message */
952
953 *psstatus = SCSI_NOP0;
954 pSRB->SRBState = SRB_COMPLETED;
955 DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD);
956}
957
958static void
959dc390_MsgOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
960{
961 if( pSRB->SRBState & (SRB_UNEXPECT_RESEL+SRB_ABORT_SENT) )
962 *psstatus = SCSI_NOP0;
963 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
964}
965
966
967static void __inline__
968dc390_reprog (struct dc390_acb* pACB, struct dc390_dcb* pDCB)
969{
970 DC390_write8 (Sync_Period, pDCB->SyncPeriod);
971 DC390_write8 (Sync_Offset, pDCB->SyncOffset);
972 DC390_write8 (CtrlReg3, pDCB->CtrlR3);
973 DC390_write8 (CtrlReg4, pDCB->CtrlR4);
974 dc390_SetXferRate (pACB, pDCB);
975}
976
977
978#ifdef DC390_DEBUG0
979static void
980dc390_printMsg (u8 *MsgBuf, u8 len)
981{
982 int i;
983 printk (" %02x", MsgBuf[0]);
984 for (i = 1; i < len; i++)
985 printk (" %02x", MsgBuf[i]);
986 printk ("\n");
987}
988#endif
989
990#define DC390_ENABLE_MSGOUT DC390_write8 (ScsiCmd, SET_ATN_CMD)
991
992/* reject_msg */
993static void __inline__
994dc390_MsgIn_reject (struct dc390_acb* pACB, struct dc390_srb* pSRB)
995{
996 pSRB->MsgOutBuf[0] = MESSAGE_REJECT;
997 pSRB->MsgCnt = 1;
998 DC390_ENABLE_MSGOUT;
999 DEBUG0 (printk (KERN_INFO "DC390: Reject message\n"));
1000}
1001
1002/* abort command */
1003static void
1004dc390_EnableMsgOut_Abort ( struct dc390_acb* pACB, struct dc390_srb* pSRB )
1005{
1006 pSRB->MsgOutBuf[0] = ABORT;
1007 pSRB->MsgCnt = 1; DC390_ENABLE_MSGOUT;
1008 pSRB->pSRBDCB->DCBFlag &= ~ABORT_DEV_;
1009}
1010
1011static struct dc390_srb*
1012dc390_MsgIn_QTag (struct dc390_acb* pACB, struct dc390_dcb* pDCB, s8 tag)
1013{
1014 struct dc390_srb* pSRB = pDCB->pGoingSRB;
1015
1016 if (pSRB)
1017 {
1018 struct scsi_cmnd *scmd = scsi_find_tag(pSRB->pcmd->device, tag);
1019 pSRB = (struct dc390_srb *)scmd->host_scribble;
1020
1021 if (pDCB->DCBFlag & ABORT_DEV_)
1022 {
1023 pSRB->SRBState = SRB_ABORT_SENT;
1024 dc390_EnableMsgOut_Abort( pACB, pSRB );
1025 }
1026
1027 if (!(pSRB->SRBState & SRB_DISCONNECT))
1028 goto mingx0;
1029
1030 pDCB->pActiveSRB = pSRB;
1031 pSRB->SRBState = SRB_DATA_XFER;
1032 }
1033 else
1034 {
1035 mingx0:
1036 pSRB = pACB->pTmpSRB;
1037 pSRB->SRBState = SRB_UNEXPECT_RESEL;
1038 pDCB->pActiveSRB = pSRB;
1039 pSRB->MsgOutBuf[0] = ABORT_TAG;
1040 pSRB->MsgCnt = 1; DC390_ENABLE_MSGOUT;
1041 }
1042 return pSRB;
1043}
1044
1045
1046/* set async transfer mode */
1047static void
1048dc390_MsgIn_set_async (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1049{
1050 struct dc390_dcb* pDCB = pSRB->pSRBDCB;
1051 if (!(pSRB->SRBState & DO_SYNC_NEGO))
1052 printk (KERN_INFO "DC390: Target %i initiates Non-Sync?\n", pDCB->TargetID);
1053 pSRB->SRBState &= ~DO_SYNC_NEGO;
1054 pDCB->SyncMode &= ~(SYNC_ENABLE+SYNC_NEGO_DONE);
1055 pDCB->SyncPeriod = 0;
1056 pDCB->SyncOffset = 0;
1057 //pDCB->NegoPeriod = 50; /* 200ns <=> 5 MHz */
1058 pDCB->CtrlR3 = FAST_CLK; /* fast clock / normal scsi */
1059 pDCB->CtrlR4 &= 0x3f;
1060 pDCB->CtrlR4 |= pACB->glitch_cfg; /* glitch eater */
1061 dc390_reprog (pACB, pDCB);
1062}
1063
1064/* set sync transfer mode */
1065static void
1066dc390_MsgIn_set_sync (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1067{
1068 u8 bval;
1069 u16 wval, wval1;
1070 struct dc390_dcb* pDCB = pSRB->pSRBDCB;
1071 u8 oldsyncperiod = pDCB->SyncPeriod;
1072 u8 oldsyncoffset = pDCB->SyncOffset;
1073
1074 if (!(pSRB->SRBState & DO_SYNC_NEGO))
1075 {
1076 printk (KERN_INFO "DC390: Target %i initiates Sync: %ins %i ... answer ...\n",
1077 pDCB->TargetID, pSRB->MsgInBuf[3]<<2, pSRB->MsgInBuf[4]);
1078
1079 /* reject */
1080 //dc390_MsgIn_reject (pACB, pSRB);
1081 //return dc390_MsgIn_set_async (pACB, pSRB);
1082
1083 /* Reply with corrected SDTR Message */
1084 if (pSRB->MsgInBuf[4] > 15)
1085 {
1086 printk (KERN_INFO "DC390: Lower Sync Offset to 15\n");
1087 pSRB->MsgInBuf[4] = 15;
1088 }
1089 if (pSRB->MsgInBuf[3] < pDCB->NegoPeriod)
1090 {
1091 printk (KERN_INFO "DC390: Set sync nego period to %ins\n", pDCB->NegoPeriod << 2);
1092 pSRB->MsgInBuf[3] = pDCB->NegoPeriod;
1093 }
1094 memcpy (pSRB->MsgOutBuf, pSRB->MsgInBuf, 5);
1095 pSRB->MsgCnt = 5;
1096 DC390_ENABLE_MSGOUT;
1097 }
1098
1099 pSRB->SRBState &= ~DO_SYNC_NEGO;
1100 pDCB->SyncMode |= SYNC_ENABLE+SYNC_NEGO_DONE;
1101 pDCB->SyncOffset &= 0x0f0;
1102 pDCB->SyncOffset |= pSRB->MsgInBuf[4];
1103 pDCB->NegoPeriod = pSRB->MsgInBuf[3];
1104
1105 wval = (u16) pSRB->MsgInBuf[3];
1106 wval = wval << 2; wval -= 3; wval1 = wval / 25; /* compute speed */
1107 if( (wval1 * 25) != wval) wval1++;
1108 bval = FAST_CLK+FAST_SCSI; /* fast clock / fast scsi */
1109
1110 pDCB->CtrlR4 &= 0x3f; /* Glitch eater: 12ns less than normal */
1111 if (pACB->glitch_cfg != NS_TO_GLITCH(0))
1112 pDCB->CtrlR4 |= NS_TO_GLITCH(((GLITCH_TO_NS(pACB->glitch_cfg)) - 1));
1113 else
1114 pDCB->CtrlR4 |= NS_TO_GLITCH(0);
1115 if (wval1 < 4) pDCB->CtrlR4 |= NS_TO_GLITCH(0); /* Ultra */
1116
1117 if (wval1 >= 8)
1118 {
1119 wval1--; /* Timing computation differs by 1 from FAST_SCSI */
1120 bval = FAST_CLK; /* fast clock / normal scsi */
1121 pDCB->CtrlR4 |= pACB->glitch_cfg; /* glitch eater */
1122 }
1123
1124 pDCB->CtrlR3 = bval;
1125 pDCB->SyncPeriod = (u8)wval1;
1126
1127 if ((oldsyncperiod != wval1 || oldsyncoffset != pDCB->SyncOffset) && pDCB->TargetLUN == 0)
1128 {
1129 if (! (bval & FAST_SCSI)) wval1++;
1130 printk (KERN_INFO "DC390: Target %i: Sync transfer %i.%1i MHz, Offset %i\n", pDCB->TargetID,
1131 40/wval1, ((40%wval1)*10+wval1/2)/wval1, pDCB->SyncOffset & 0x0f);
1132 }
1133
1134 dc390_reprog (pACB, pDCB);
1135}
1136
1137
1138/* handle RESTORE_PTR */
85923211 1139/* This doesn't look very healthy... to-be-fixed */
1da177e4
LT
1140static void
1141dc390_restore_ptr (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1142{
1143 struct scsi_cmnd *pcmd = pSRB->pcmd;
1144 struct scatterlist *psgl;
1145 pSRB->TotalXferredLen = 0;
1146 pSRB->SGIndex = 0;
85289f2e 1147 if (scsi_sg_count(pcmd)) {
85923211 1148 size_t saved;
85289f2e 1149 pSRB->pSegmentList = scsi_sglist(pcmd);
1da177e4
LT
1150 psgl = pSRB->pSegmentList;
1151 //dc390_pci_sync(pSRB);
1152
1153 while (pSRB->TotalXferredLen + (unsigned long) sg_dma_len(psgl) < pSRB->Saved_Ptr)
1154 {
1155 pSRB->TotalXferredLen += (unsigned long) sg_dma_len(psgl);
1156 pSRB->SGIndex++;
1157 if( pSRB->SGIndex < pSRB->SGcount )
1158 {
1159 pSRB->pSegmentList++;
85923211
GL
1160
1161 dc390_start_segment(pSRB);
1da177e4
LT
1162 }
1163 else
1164 pSRB->SGToBeXferLen = 0;
1165 }
85923211
GL
1166
1167 saved = pSRB->Saved_Ptr - pSRB->TotalXferredLen;
1168 pSRB->SGToBeXferLen -= saved;
1169 pSRB->SGBusAddr += saved;
1da177e4
LT
1170 printk (KERN_INFO "DC390: Pointer restored. Segment %i, Total %li, Bus %08lx\n",
1171 pSRB->SGIndex, pSRB->Saved_Ptr, pSRB->SGBusAddr);
1172
1da177e4
LT
1173 } else {
1174 pSRB->SGcount = 0;
1175 printk (KERN_INFO "DC390: RESTORE_PTR message for Transfer without Scatter-Gather ??\n");
1176 }
1177
1178 pSRB->TotalXferredLen = pSRB->Saved_Ptr;
1179}
1180
1181
1182/* According to the docs, the AM53C974 reads the message and
1183 * generates a Successful Operation IRQ before asserting ACK for
1184 * the last byte (how does it know whether it's the last ?) */
1185/* The old code handled it in another way, indicating, that on
1186 * every message byte an IRQ is generated and every byte has to
1187 * be manually ACKed. Hmmm ? (KG, 98/11/28) */
1188/* The old implementation was correct. Sigh! */
1189
1190/* Check if the message is complete */
1191static u8 __inline__
1192dc390_MsgIn_complete (u8 *msgbuf, u32 len)
1193{
1194 if (*msgbuf == EXTENDED_MESSAGE)
1195 {
1196 if (len < 2) return 0;
1197 if (len < msgbuf[1] + 2) return 0;
1198 }
1199 else if (*msgbuf >= 0x20 && *msgbuf <= 0x2f) // two byte messages
1200 if (len < 2) return 0;
1201 return 1;
1202}
1203
1204
1205
1206/* read and eval received messages */
1207static void
1208dc390_MsgIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1209{
1210 struct dc390_dcb* pDCB = pACB->pActiveDCB;
1211
1212 /* Read the msg */
1213
1214 pSRB->MsgInBuf[pACB->MsgLen++] = DC390_read8 (ScsiFifo);
1215 //pSRB->SRBState = 0;
1216
1217 /* Msg complete ? */
1218 if (dc390_MsgIn_complete (pSRB->MsgInBuf, pACB->MsgLen))
1219 {
1220 DEBUG0 (printk (KERN_INFO "DC390: MsgIn:"); dc390_printMsg (pSRB->MsgInBuf, pACB->MsgLen));
1221 /* Now eval the msg */
1222 switch (pSRB->MsgInBuf[0])
1223 {
1224 case DISCONNECT:
1225 pSRB->SRBState = SRB_DISCONNECT; break;
1226
1227 case SIMPLE_QUEUE_TAG:
1228 case HEAD_OF_QUEUE_TAG:
1229 case ORDERED_QUEUE_TAG:
1230 pSRB = dc390_MsgIn_QTag (pACB, pDCB, pSRB->MsgInBuf[1]);
1231 break;
1232
1233 case MESSAGE_REJECT:
1234 DC390_write8 (ScsiCmd, RESET_ATN_CMD);
1235 pDCB->NegoPeriod = 50; /* 200ns <=> 5 MHz */
1236 if( pSRB->SRBState & DO_SYNC_NEGO)
1237 dc390_MsgIn_set_async (pACB, pSRB);
1238 break;
1239
1240 case EXTENDED_MESSAGE:
1241 /* reject every extended msg but SDTR */
1242 if (pSRB->MsgInBuf[1] != 3 || pSRB->MsgInBuf[2] != EXTENDED_SDTR)
1243 dc390_MsgIn_reject (pACB, pSRB);
1244 else
1245 {
1246 if (pSRB->MsgInBuf[3] == 0 || pSRB->MsgInBuf[4] == 0)
1247 dc390_MsgIn_set_async (pACB, pSRB);
1248 else
1249 dc390_MsgIn_set_sync (pACB, pSRB);
1250 }
1251
1252 // nothing has to be done
1253 case COMMAND_COMPLETE: break;
1254
1255 // SAVE POINTER may be ignored as we have the struct dc390_srb* associated with the
1256 // scsi command. Thanks, Gerard, for pointing it out.
1257 case SAVE_POINTERS:
1258 pSRB->Saved_Ptr = pSRB->TotalXferredLen;
1259 break;
1260 // The device might want to restart transfer with a RESTORE
1261 case RESTORE_POINTERS:
1262 DEBUG0(printk ("DC390: RESTORE POINTER message received ... try to handle\n"));
1263 dc390_restore_ptr (pACB, pSRB);
1264 break;
1265
1266 // reject unknown messages
1267 default: dc390_MsgIn_reject (pACB, pSRB);
1268 }
1269
1270 /* Clear counter and MsgIn state */
1271 pSRB->SRBState &= ~SRB_MSGIN;
1272 pACB->MsgLen = 0;
1273 }
1274
1275 *psstatus = SCSI_NOP0;
1276 DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD);
1277 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1278}
1279
1280
1281static void
1282dc390_DataIO_Comm( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 ioDir)
1283{
1da177e4
LT
1284 unsigned long lval;
1285 struct dc390_dcb* pDCB = pACB->pActiveDCB;
1286
1287 if (pSRB == pACB->pTmpSRB)
1288 {
1289 if (pDCB)
1290 printk(KERN_ERR "DC390: pSRB == pTmpSRB! (TagQ Error?) (%02i-%i)\n", pDCB->TargetID, pDCB->TargetLUN);
1291 else
1292 printk(KERN_ERR "DC390: pSRB == pTmpSRB! (TagQ Error?) (DCB 0!)\n");
1293
1294 /* Try to recover - some broken disks react badly to tagged INQUIRY */
1295 if (pDCB && pACB->scan_devices && pDCB->GoingSRBCnt == 1) {
1296 pSRB = pDCB->pGoingSRB;
1297 pDCB->pActiveSRB = pSRB;
1298 } else {
1299 pSRB->pSRBDCB = pDCB;
1300 dc390_EnableMsgOut_Abort(pACB, pSRB);
1301 if (pDCB)
1302 pDCB->DCBFlag |= ABORT_DEV;
1303 return;
1304 }
1305 }
1306
1307 if( pSRB->SGIndex < pSRB->SGcount )
1308 {
860bfecf 1309 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir);
1da177e4
LT
1310 if( !pSRB->SGToBeXferLen )
1311 {
85923211
GL
1312 dc390_start_segment(pSRB);
1313
1da177e4
LT
1314 DEBUG1(printk (KERN_DEBUG " DC390: Next SG segment."));
1315 }
1316 lval = pSRB->SGToBeXferLen;
1317 DEBUG1(printk (KERN_DEBUG " DC390: Start transfer: %li bytes (address %08lx)\n", lval, pSRB->SGBusAddr));
1318 DC390_write8 (CtcReg_Low, (u8) lval);
1319 lval >>= 8;
1320 DC390_write8 (CtcReg_Mid, (u8) lval);
1321 lval >>= 8;
1322 DC390_write8 (CtcReg_High, (u8) lval);
1323
1324 DC390_write32 (DMA_XferCnt, pSRB->SGToBeXferLen);
1325 DC390_write32 (DMA_XferAddr, pSRB->SGBusAddr);
1326
860bfecf 1327 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir);
1da177e4
LT
1328 pSRB->SRBState = SRB_DATA_XFER;
1329
1330 DC390_write8 (ScsiCmd, DMA_COMMAND+INFO_XFER_CMD);
1331
860bfecf 1332 DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir);
1da177e4
LT
1333 //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT));
1334 //DEBUG1(printk (KERN_DEBUG "DC390: DMA_Status: %02x\n", DC390_read8 (DMA_Status)));
1335 //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT));
1336 }
1337 else /* xfer pad */
1338 {
1339 if( pSRB->SGcount )
1340 {
1341 pSRB->AdaptStatus = H_OVER_UNDER_RUN;
1342 pSRB->SRBStatus |= OVER_RUN;
1343 DEBUG0(printk (KERN_WARNING " DC390: Overrun -"));
1344 }
1345 DEBUG0(printk (KERN_WARNING " Clear transfer pad \n"));
1346 DC390_write8 (CtcReg_Low, 0);
1347 DC390_write8 (CtcReg_Mid, 0);
1348 DC390_write8 (CtcReg_High, 0);
1349
1350 pSRB->SRBState |= SRB_XFERPAD;
1351 DC390_write8 (ScsiCmd, DMA_COMMAND+XFER_PAD_BYTE);
1352/*
860bfecf
GL
1353 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir);
1354 DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir);
1da177e4
LT
1355*/
1356 }
1357}
1358
1359
1360static void
1361dc390_DataOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1362{
1363 dc390_DataIO_Comm (pACB, pSRB, WRITE_DIRECTION);
1364}
1365
1366static void
1367dc390_DataInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1368{
1369 dc390_DataIO_Comm (pACB, pSRB, READ_DIRECTION);
1370}
1371
1372static void
1373dc390_CommandPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1374{
1375 struct dc390_dcb* pDCB;
1376 u8 i, cnt;
1377 u8 *ptr;
1378
1379 DC390_write8 (ScsiCmd, RESET_ATN_CMD);
1380 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1381 if( !(pSRB->SRBFlag & AUTO_REQSENSE) )
1382 {
1383 cnt = (u8) pSRB->pcmd->cmd_len;
1384 ptr = (u8 *) pSRB->pcmd->cmnd;
1385 for(i=0; i < cnt; i++)
1386 DC390_write8 (ScsiFifo, *(ptr++));
1387 }
1388 else
1389 {
1390 DC390_write8 (ScsiFifo, REQUEST_SENSE);
1391 pDCB = pACB->pActiveDCB;
1392 DC390_write8 (ScsiFifo, pDCB->TargetLUN << 5);
1393 DC390_write8 (ScsiFifo, 0);
1394 DC390_write8 (ScsiFifo, 0);
1395 DC390_write8 (ScsiFifo, sizeof(pSRB->pcmd->sense_buffer));
1396 DC390_write8 (ScsiFifo, 0);
1397 DEBUG0(printk(KERN_DEBUG "DC390: AutoReqSense (CmndPhase)!\n"));
1398 }
1399 pSRB->SRBState = SRB_COMMAND;
1400 DC390_write8 (ScsiCmd, INFO_XFER_CMD);
1401}
1402
1403static void
1404dc390_StatusPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1405{
1406 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1407 pSRB->SRBState = SRB_STATUS;
1408 DC390_write8 (ScsiCmd, INITIATOR_CMD_CMPLTE);
1409 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1410}
1411
1412static void
1413dc390_MsgOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1414{
1415 u8 bval, i, cnt;
1416 u8 *ptr;
1417 struct dc390_dcb* pDCB;
1418
1419 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1420 pDCB = pACB->pActiveDCB;
1421 if( !(pSRB->SRBState & SRB_MSGOUT) )
1422 {
1423 cnt = pSRB->MsgCnt;
1424 if( cnt )
1425 {
1426 ptr = (u8 *) pSRB->MsgOutBuf;
1427 for(i=0; i < cnt; i++)
1428 DC390_write8 (ScsiFifo, *(ptr++));
1429 pSRB->MsgCnt = 0;
1430 if( (pDCB->DCBFlag & ABORT_DEV_) &&
1431 (pSRB->MsgOutBuf[0] == ABORT) )
1432 pSRB->SRBState = SRB_ABORT_SENT;
1433 }
1434 else
1435 {
1436 bval = ABORT; /* ??? MSG_NOP */
1437 if( (pSRB->pcmd->cmnd[0] == INQUIRY ) ||
1438 (pSRB->pcmd->cmnd[0] == REQUEST_SENSE) ||
1439 (pSRB->SRBFlag & AUTO_REQSENSE) )
1440 {
1441 if( pDCB->SyncMode & SYNC_ENABLE )
1442 goto mop1;
1443 }
1444 DC390_write8 (ScsiFifo, bval);
1445 }
1446 DC390_write8 (ScsiCmd, INFO_XFER_CMD);
1447 }
1448 else
1449 {
1450mop1:
1451 printk (KERN_ERR "DC390: OLD Sync Nego code triggered! (%i %i)\n", pDCB->TargetID, pDCB->TargetLUN);
1452 DC390_write8 (ScsiFifo, EXTENDED_MESSAGE);
1453 DC390_write8 (ScsiFifo, 3); /* ;length of extended msg */
1454 DC390_write8 (ScsiFifo, EXTENDED_SDTR); /* ; sync nego */
1455 DC390_write8 (ScsiFifo, pDCB->NegoPeriod);
1456 if (pDCB->SyncOffset & 0x0f)
1457 DC390_write8 (ScsiFifo, pDCB->SyncOffset);
1458 else
1459 DC390_write8 (ScsiFifo, SYNC_NEGO_OFFSET);
1460 pSRB->SRBState |= DO_SYNC_NEGO;
1461 DC390_write8 (ScsiCmd, INFO_XFER_CMD);
1462 }
1463}
1464
1465static void
1466dc390_MsgInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1467{
1468 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1469 if( !(pSRB->SRBState & SRB_MSGIN) )
1470 {
1471 pSRB->SRBState &= ~SRB_DISCONNECT;
1472 pSRB->SRBState |= SRB_MSGIN;
1473 }
1474 DC390_write8 (ScsiCmd, INFO_XFER_CMD);
1475 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1476}
1477
1478static void
1479dc390_Nop_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1480{
1481}
1482
1483static void
1484dc390_Nop_1( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1485{
1486}
1487
1488
1489static void
1490dc390_SetXferRate( struct dc390_acb* pACB, struct dc390_dcb* pDCB )
1491{
1492 u8 bval, i, cnt;
1493 struct dc390_dcb* ptr;
1494
1495 if( !(pDCB->TargetLUN) )
1496 {
1497 if( !pACB->scan_devices )
1498 {
1499 ptr = pACB->pLinkDCB;
1500 cnt = pACB->DCBCnt;
1501 bval = pDCB->TargetID;
1502 for(i=0; i<cnt; i++)
1503 {
1504 if( ptr->TargetID == bval )
1505 {
1506 ptr->SyncPeriod = pDCB->SyncPeriod;
1507 ptr->SyncOffset = pDCB->SyncOffset;
1508 ptr->CtrlR3 = pDCB->CtrlR3;
1509 ptr->CtrlR4 = pDCB->CtrlR4;
1510 ptr->SyncMode = pDCB->SyncMode;
1511 }
1512 ptr = ptr->pNextDCB;
1513 }
1514 }
1515 }
1516 return;
1517}
1518
1519
1520static void
1521dc390_Disconnect( struct dc390_acb* pACB )
1522{
1523 struct dc390_dcb *pDCB;
1524 struct dc390_srb *pSRB, *psrb;
1525 u8 i, cnt;
1526
1527 DEBUG0(printk(KERN_INFO "DISC,"));
1528
1529 if (!pACB->Connected) printk(KERN_ERR "DC390: Disconnect not-connected bus?\n");
1530 pACB->Connected = 0;
1531 pDCB = pACB->pActiveDCB;
1532 if (!pDCB)
1533 {
1534 DEBUG0(printk(KERN_ERR "ACB:%p->ActiveDCB:%p IOPort:%04x IRQ:%02x !\n",\
1535 pACB, pDCB, pACB->IOPortBase, pACB->IRQLevel));
1536 mdelay(400);
1537 DC390_read8 (INT_Status); /* Reset Pending INT */
1538 DC390_write8 (ScsiCmd, EN_SEL_RESEL);
1539 return;
1540 }
1541 DC390_write8 (ScsiCmd, EN_SEL_RESEL);
1542 pSRB = pDCB->pActiveSRB;
1543 pACB->pActiveDCB = NULL;
1544 pSRB->ScsiPhase = SCSI_NOP0;
1545 if( pSRB->SRBState & SRB_UNEXPECT_RESEL )
1546 pSRB->SRBState = 0;
1547 else if( pSRB->SRBState & SRB_ABORT_SENT )
1548 {
1549 pDCB->TagMask = 0;
1550 pDCB->DCBFlag = 0;
1551 cnt = pDCB->GoingSRBCnt;
1552 pDCB->GoingSRBCnt = 0;
1553 pSRB = pDCB->pGoingSRB;
1554 for( i=0; i < cnt; i++)
1555 {
1556 psrb = pSRB->pNextSRB;
1557 dc390_Free_insert (pACB, pSRB);
1558 pSRB = psrb;
1559 }
1560 pDCB->pGoingSRB = NULL;
1561 }
1562 else
1563 {
1564 if( (pSRB->SRBState & (SRB_START_+SRB_MSGOUT)) ||
1565 !(pSRB->SRBState & (SRB_DISCONNECT+SRB_COMPLETED)) )
1566 { /* Selection time out */
1567 pSRB->TargetStatus = SCSI_STAT_SEL_TIMEOUT;
1568 goto disc1;
1569 }
1570 else if (!(pSRB->SRBState & SRB_DISCONNECT) && (pSRB->SRBState & SRB_COMPLETED))
1571 {
1572disc1:
1573 dc390_freetag (pDCB, pSRB);
1574 pDCB->pActiveSRB = NULL;
1575 pSRB->SRBState = SRB_FREE;
1576 dc390_SRBdone( pACB, pDCB, pSRB);
1577 }
1578 }
1579 pACB->MsgLen = 0;
1580}
1581
1582
1583static void
1584dc390_Reselect( struct dc390_acb* pACB )
1585{
1586 struct dc390_dcb* pDCB;
1587 struct dc390_srb* pSRB;
1588 u8 id, lun;
1589
1590 DEBUG0(printk(KERN_INFO "RSEL,"));
1591 pACB->Connected = 1;
1592 pDCB = pACB->pActiveDCB;
1593 if( pDCB )
1594 { /* Arbitration lost but Reselection won */
1595 DEBUG0(printk ("DC390: (ActiveDCB != 0: Arb. lost but resel. won)!\n"));
1596 pSRB = pDCB->pActiveSRB;
1597 if( !( pACB->scan_devices ) )
1598 {
1599 struct scsi_cmnd *pcmd = pSRB->pcmd;
85289f2e 1600 scsi_set_resid(pcmd, scsi_bufflen(pcmd));
1da177e4
LT
1601 SET_RES_DID(pcmd->result, DID_SOFT_ERROR);
1602 dc390_Going_remove(pDCB, pSRB);
1603 dc390_Free_insert(pACB, pSRB);
1604 pcmd->scsi_done (pcmd);
1605 DEBUG0(printk(KERN_DEBUG"DC390: Return SRB %p to free\n", pSRB));
1606 }
1607 }
1608 /* Get ID */
1609 lun = DC390_read8 (ScsiFifo);
1610 DEBUG0(printk ("Dev %02x,", lun));
1611 if (!(lun & (1 << pACB->pScsiHost->this_id)))
1612 printk (KERN_ERR "DC390: Reselection must select host adapter: %02x!\n", lun);
1613 else
1614 lun ^= 1 << pACB->pScsiHost->this_id; /* Mask AdapterID */
1615 id = 0; while (lun >>= 1) id++;
1616 /* Get LUN */
1617 lun = DC390_read8 (ScsiFifo);
1618 if (!(lun & IDENTIFY_BASE)) printk (KERN_ERR "DC390: Resel: Expect identify message!\n");
1619 lun &= 7;
1620 DEBUG0(printk ("(%02i-%i),", id, lun));
1621 pDCB = dc390_findDCB (pACB, id, lun);
1622 if (!pDCB)
1623 {
1624 printk (KERN_ERR "DC390: Reselect from non existing device (%02i-%i)\n",
1625 id, lun);
1626 return;
1627 }
1628 pACB->pActiveDCB = pDCB;
1629 /* TagQ: We expect a message soon, so never mind the exact SRB */
1630 if( pDCB->SyncMode & EN_TAG_QUEUEING )
1631 {
1632 pSRB = pACB->pTmpSRB;
1633 pDCB->pActiveSRB = pSRB;
1634 }
1635 else
1636 {
1637 pSRB = pDCB->pActiveSRB;
1638 if( !pSRB || !(pSRB->SRBState & SRB_DISCONNECT) )
1639 {
1640 pSRB= pACB->pTmpSRB;
1641 pSRB->SRBState = SRB_UNEXPECT_RESEL;
1642 printk (KERN_ERR "DC390: Reselect without outstanding cmnd (%02i-%i)\n",
1643 id, lun);
1644 pDCB->pActiveSRB = pSRB;
1645 dc390_EnableMsgOut_Abort ( pACB, pSRB );
1646 }
1647 else
1648 {
1649 if( pDCB->DCBFlag & ABORT_DEV_ )
1650 {
1651 pSRB->SRBState = SRB_ABORT_SENT;
1652 printk (KERN_INFO "DC390: Reselect: Abort (%02i-%i)\n",
1653 id, lun);
1654 dc390_EnableMsgOut_Abort( pACB, pSRB );
1655 }
1656 else
1657 pSRB->SRBState = SRB_DATA_XFER;
1658 }
1659 }
1660
1661 DEBUG1(printk (KERN_DEBUG "Resel SRB(%p): TagNum (%02x)\n", pSRB, pSRB->TagNumber));
1662 pSRB->ScsiPhase = SCSI_NOP0;
1663 DC390_write8 (Scsi_Dest_ID, pDCB->TargetID);
1664 DC390_write8 (Sync_Period, pDCB->SyncPeriod);
1665 DC390_write8 (Sync_Offset, pDCB->SyncOffset);
1666 DC390_write8 (CtrlReg1, pDCB->CtrlR1);
1667 DC390_write8 (CtrlReg3, pDCB->CtrlR3);
1668 DC390_write8 (CtrlReg4, pDCB->CtrlR4); /* ; Glitch eater */
1669 DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD); /* ;to release the /ACK signal */
1670}
1671
1672static int __inline__
1673dc390_RequestSense(struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB)
1674{
1675 struct scsi_cmnd *pcmd;
1676
1677 pcmd = pSRB->pcmd;
1678
1679 REMOVABLEDEBUG(printk(KERN_INFO "DC390: RequestSense(Cmd %02x, Id %02x, LUN %02x)\n",\
1680 pcmd->cmnd[0], pDCB->TargetID, pDCB->TargetLUN));
1681
1682 pSRB->SRBFlag |= AUTO_REQSENSE;
85289f2e 1683 pSRB->SavedSGCount = scsi_sg_count(pcmd);
1da177e4
LT
1684 pSRB->SavedTotXLen = pSRB->TotalXferredLen;
1685 pSRB->AdaptStatus = 0;
1686 pSRB->TargetStatus = 0; /* CHECK_CONDITION<<1; */
1687
1688 /* We are called from SRBdone, original PCI mapping has been removed
1689 * already, new one is set up from StartSCSI */
1690 pSRB->SGIndex = 0;
1691
1692 pSRB->TotalXferredLen = 0;
1693 pSRB->SGToBeXferLen = 0;
1694 return dc390_StartSCSI(pACB, pDCB, pSRB);
1695}
1696
1697
1698static void
1699dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB )
1700{
1701 u8 status;
1702 struct scsi_cmnd *pcmd;
1703
1704 pcmd = pSRB->pcmd;
1705 /* KG: Moved pci_unmap here */
1706 dc390_pci_unmap(pSRB);
1707
1708 status = pSRB->TargetStatus;
1709
1710 DEBUG0(printk (" SRBdone (%02x,%08x), SRB %p, pid %li\n", status, pcmd->result,\
1711 pSRB, pcmd->pid));
1712 if(pSRB->SRBFlag & AUTO_REQSENSE)
1713 { /* Last command was a Request Sense */
1714 pSRB->SRBFlag &= ~AUTO_REQSENSE;
1715 pSRB->AdaptStatus = 0;
1716 pSRB->TargetStatus = CHECK_CONDITION << 1;
1717
1718 //pcmd->result = MK_RES(DRIVER_SENSE,DID_OK,0,status);
1719 if (status == (CHECK_CONDITION << 1))
1720 pcmd->result = MK_RES_LNX(0, DID_BAD_TARGET, 0, /*CHECK_CONDITION*/0);
1721 else /* Retry */
1722 {
1723 if( pSRB->pcmd->cmnd[0] == TEST_UNIT_READY /* || pSRB->pcmd->cmnd[0] == START_STOP */)
1724 {
1725 /* Don't retry on TEST_UNIT_READY */
1726 pcmd->result = MK_RES_LNX(DRIVER_SENSE,DID_OK,0,CHECK_CONDITION);
1727 REMOVABLEDEBUG(printk(KERN_INFO "Cmd=%02x, Result=%08x, XferL=%08x\n",pSRB->pcmd->cmnd[0],\
1728 (u32) pcmd->result, (u32) pSRB->TotalXferredLen));
1729 } else {
1730 SET_RES_DRV(pcmd->result, DRIVER_SENSE);
85289f2e 1731 scsi_sg_count(pcmd) = pSRB->SavedSGCount;
1da177e4
LT
1732 //pSRB->ScsiCmdLen = (u8) (pSRB->Segment1[0] >> 8);
1733 DEBUG0 (printk ("DC390: RETRY pid %li (%02x), target %02i-%02i\n", pcmd->pid, pcmd->cmnd[0], pcmd->device->id, pcmd->device->lun));
1734 pSRB->TotalXferredLen = 0;
1735 SET_RES_DID(pcmd->result, DID_SOFT_ERROR);
1736 }
1737 }
1738 goto cmd_done;
1739 }
1740 if( status )
1741 {
1742 if( status_byte(status) == CHECK_CONDITION )
1743 {
1744 if (dc390_RequestSense(pACB, pDCB, pSRB)) {
1745 SET_RES_DID(pcmd->result, DID_ERROR);
1746 goto cmd_done;
1747 }
1748 return;
1749 }
1750 else if( status_byte(status) == QUEUE_FULL )
1751 {
1752 scsi_track_queue_full(pcmd->device, pDCB->GoingSRBCnt - 1);
85289f2e 1753 scsi_sg_count(pcmd) = pSRB->SavedSGCount;
1da177e4
LT
1754 DEBUG0 (printk ("DC390: RETRY pid %li (%02x), target %02i-%02i\n", pcmd->pid, pcmd->cmnd[0], pcmd->device->id, pcmd->device->lun));
1755 pSRB->TotalXferredLen = 0;
1756 SET_RES_DID(pcmd->result, DID_SOFT_ERROR);
1757 }
1758 else if(status == SCSI_STAT_SEL_TIMEOUT)
1759 {
1760 pSRB->AdaptStatus = H_SEL_TIMEOUT;
1761 pSRB->TargetStatus = 0;
1762 pcmd->result = MK_RES(0,DID_NO_CONNECT,0,0);
1763 /* Devices are removed below ... */
1764 }
1765 else if (status_byte(status) == BUSY &&
1766 (pcmd->cmnd[0] == TEST_UNIT_READY || pcmd->cmnd[0] == INQUIRY) &&
1767 pACB->scan_devices)
1768 {
1769 pSRB->AdaptStatus = 0;
1770 pSRB->TargetStatus = status;
1771 pcmd->result = MK_RES(0,0,pSRB->EndMessage,/*status*/0);
1772 }
1773 else
1774 { /* Another error */
1775 pSRB->TotalXferredLen = 0;
1776 SET_RES_DID(pcmd->result, DID_SOFT_ERROR);
1777 goto cmd_done;
1778 }
1779 }
1780 else
1781 { /* Target status == 0 */
1782 status = pSRB->AdaptStatus;
1783 if(status & H_OVER_UNDER_RUN)
1784 {
1785 pSRB->TargetStatus = 0;
1786 SET_RES_DID(pcmd->result,DID_OK);
1787 SET_RES_MSG(pcmd->result,pSRB->EndMessage);
1788 }
1789 else if( pSRB->SRBStatus & PARITY_ERROR)
1790 {
1791 //pcmd->result = MK_RES(0,DID_PARITY,pSRB->EndMessage,0);
1792 SET_RES_DID(pcmd->result,DID_PARITY);
1793 SET_RES_MSG(pcmd->result,pSRB->EndMessage);
1794 }
1795 else /* No error */
1796 {
1797 pSRB->AdaptStatus = 0;
1798 pSRB->TargetStatus = 0;
1799 SET_RES_DID(pcmd->result,DID_OK);
1800 }
1801 }
1802
1803cmd_done:
85289f2e 1804 scsi_set_resid(pcmd, scsi_bufflen(pcmd) - pSRB->TotalXferredLen);
1da177e4
LT
1805
1806 dc390_Going_remove (pDCB, pSRB);
1807 /* Add to free list */
1808 dc390_Free_insert (pACB, pSRB);
1809
1810 DEBUG0(printk (KERN_DEBUG "DC390: SRBdone: done pid %li\n", pcmd->pid));
1811 pcmd->scsi_done (pcmd);
1812
1813 return;
1814}
1815
1816
1817/* Remove all SRBs from Going list and inform midlevel */
1818static void
1819dc390_DoingSRB_Done(struct dc390_acb* pACB, struct scsi_cmnd *cmd)
1820{
1821 struct dc390_dcb *pDCB, *pdcb;
1822 struct dc390_srb *psrb, *psrb2;
1823 int i;
1824 struct scsi_cmnd *pcmd;
1825
1826 pDCB = pACB->pLinkDCB;
1827 pdcb = pDCB;
1828 if (! pdcb) return;
1829 do
1830 {
1831 psrb = pdcb->pGoingSRB;
1832 for (i = 0; i < pdcb->GoingSRBCnt; i++)
1833 {
1834 psrb2 = psrb->pNextSRB;
1835 pcmd = psrb->pcmd;
1836 dc390_Free_insert (pACB, psrb);
1837 psrb = psrb2;
1838 }
1839 pdcb->GoingSRBCnt = 0;
1840 pdcb->pGoingSRB = NULL;
1841 pdcb->TagMask = 0;
1842 pdcb = pdcb->pNextDCB;
1843 } while( pdcb != pDCB );
1844}
1845
1846
1847static void
1848dc390_ResetSCSIBus( struct dc390_acb* pACB )
1849{
1850 //DC390_write8 (ScsiCmd, RST_DEVICE_CMD);
1851 //udelay (250);
1852 //DC390_write8 (ScsiCmd, NOP_CMD);
1853
1854 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1855 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1856 DC390_write8 (ScsiCmd, RST_SCSI_BUS_CMD);
1857 pACB->Connected = 0;
1858
1859 return;
1860}
1861
1862static void
1863dc390_ScsiRstDetect( struct dc390_acb* pACB )
1864{
1865 printk ("DC390: Rst_Detect: laststat = %08x\n", dc390_laststatus);
1866 //DEBUG0(printk(KERN_INFO "RST_DETECT,"));
1867
1868 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1869 /* Unlock before ? */
1870 /* delay half a second */
1871 udelay (1000);
1872 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1873 pACB->pScsiHost->last_reset = jiffies + 5*HZ/2
1874 + HZ * dc390_eepromBuf[pACB->AdapterIndex][EE_DELAY];
1875 pACB->Connected = 0;
1876
1877 if( pACB->ACBFlag & RESET_DEV )
1878 pACB->ACBFlag |= RESET_DONE;
1879 else
1880 { /* Reset was issued by sb else */
1881 pACB->ACBFlag |= RESET_DETECT;
1882
1883 dc390_ResetDevParam( pACB );
1884 dc390_DoingSRB_Done( pACB, NULL);
1885 //dc390_RecoverSRB( pACB );
1886 pACB->pActiveDCB = NULL;
1887 pACB->ACBFlag = 0;
1888 }
1889 return;
1890}
1891
1892static int DC390_queuecommand(struct scsi_cmnd *cmd,
1893 void (*done)(struct scsi_cmnd *))
1894{
1895 struct scsi_device *sdev = cmd->device;
1896 struct dc390_acb *acb = (struct dc390_acb *)sdev->host->hostdata;
1897 struct dc390_dcb *dcb = sdev->hostdata;
1898 struct dc390_srb *srb;
1899
1900 if (sdev->queue_depth <= dcb->GoingSRBCnt)
1901 goto device_busy;
1902 if (acb->pActiveDCB)
1903 goto host_busy;
1904 if (acb->ACBFlag & (RESET_DETECT|RESET_DONE|RESET_DEV))
1905 goto host_busy;
1906
1907 srb = acb->pFreeSRB;
1908 if (unlikely(srb == NULL))
1909 goto host_busy;
1910
1911 cmd->scsi_done = done;
1912 cmd->result = 0;
1913 acb->Cmds++;
1914
1915 acb->pFreeSRB = srb->pNextSRB;
1916 srb->pNextSRB = NULL;
1917
1918 srb->pSRBDCB = dcb;
1919 srb->pcmd = cmd;
1920 cmd->host_scribble = (char *)srb;
1921
1922 srb->SGIndex = 0;
1923 srb->AdaptStatus = 0;
1924 srb->TargetStatus = 0;
1925 srb->MsgCnt = 0;
1926
1927 srb->SRBStatus = 0;
1928 srb->SRBFlag = 0;
1929 srb->SRBState = 0;
1930 srb->TotalXferredLen = 0;
1931 srb->SGBusAddr = 0;
1932 srb->SGToBeXferLen = 0;
1933 srb->ScsiPhase = 0;
1934 srb->EndMessage = 0;
1935 srb->TagNumber = SCSI_NO_TAG;
1936
1937 if (dc390_StartSCSI(acb, dcb, srb)) {
1938 dc390_Free_insert(acb, srb);
1939 goto host_busy;
1940 }
1941
1942 dc390_Going_append(dcb, srb);
1943
1944 return 0;
1945
1946 host_busy:
1947 return SCSI_MLQUEUE_HOST_BUSY;
1948
1949 device_busy:
1950 return SCSI_MLQUEUE_DEVICE_BUSY;
1951}
1952
1953static void dc390_dumpinfo (struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB)
1954{
1955 struct pci_dev *pdev;
1956 u16 pstat;
1957
1958 if (!pDCB) pDCB = pACB->pActiveDCB;
1959 if (!pSRB && pDCB) pSRB = pDCB->pActiveSRB;
1960
1961 if (pSRB)
1962 {
1963 printk ("DC390: SRB: Xferred %08lx, Remain %08lx, State %08x, Phase %02x\n",
1964 pSRB->TotalXferredLen, pSRB->SGToBeXferLen, pSRB->SRBState,
1965 pSRB->ScsiPhase);
1966 printk ("DC390: AdpaterStatus: %02x, SRB Status %02x\n", pSRB->AdaptStatus, pSRB->SRBStatus);
1967 }
1968 printk ("DC390: Status of last IRQ (DMA/SC/Int/IRQ): %08x\n", dc390_laststatus);
1969 printk ("DC390: Register dump: SCSI block:\n");
1970 printk ("DC390: XferCnt Cmd Stat IntS IRQS FFIS Ctl1 Ctl2 Ctl3 Ctl4\n");
1971 printk ("DC390: %06x %02x %02x %02x",
1972 DC390_read8(CtcReg_Low) + (DC390_read8(CtcReg_Mid) << 8) + (DC390_read8(CtcReg_High) << 16),
1973 DC390_read8(ScsiCmd), DC390_read8(Scsi_Status), DC390_read8(Intern_State));
1974 printk (" %02x %02x %02x %02x %02x %02x\n",
1975 DC390_read8(INT_Status), DC390_read8(Current_Fifo), DC390_read8(CtrlReg1),
1976 DC390_read8(CtrlReg2), DC390_read8(CtrlReg3), DC390_read8(CtrlReg4));
1977 DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT);
1978 if (DC390_read8(Current_Fifo) & 0x1f)
1979 {
1980 printk ("DC390: FIFO:");
1981 while (DC390_read8(Current_Fifo) & 0x1f) printk (" %02x", DC390_read8(ScsiFifo));
1982 printk ("\n");
1983 }
1984 printk ("DC390: Register dump: DMA engine:\n");
1985 printk ("DC390: Cmd STrCnt SBusA WrkBC WrkAC Stat SBusCtrl\n");
1986 printk ("DC390: %02x %08x %08x %08x %08x %02x %08x\n",
1987 DC390_read8(DMA_Cmd), DC390_read32(DMA_XferCnt), DC390_read32(DMA_XferAddr),
1988 DC390_read32(DMA_Wk_ByteCntr), DC390_read32(DMA_Wk_AddrCntr),
1989 DC390_read8(DMA_Status), DC390_read32(DMA_ScsiBusCtrl));
1990 DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT);
1991
1992 pdev = pACB->pdev;
1993 pci_read_config_word(pdev, PCI_STATUS, &pstat);
1994 printk ("DC390: Register dump: PCI Status: %04x\n", pstat);
1995 printk ("DC390: In case of driver trouble read Documentation/scsi/tmscsim.txt\n");
1996}
1997
1998
1999static int DC390_abort(struct scsi_cmnd *cmd)
2000{
2001 struct dc390_acb *pACB = (struct dc390_acb*) cmd->device->host->hostdata;
2002 struct dc390_dcb *pDCB = (struct dc390_dcb*) cmd->device->hostdata;
2003
017560fc
JG
2004 scmd_printk(KERN_WARNING, cmd,
2005 "DC390: Abort command (pid %li)\n", cmd->pid);
1da177e4
LT
2006
2007 /* abort() is too stupid for already sent commands at the moment.
2008 * If it's called we are in trouble anyway, so let's dump some info
2009 * into the syslog at least. (KG, 98/08/20,99/06/20) */
2010 dc390_dumpinfo(pACB, pDCB, NULL);
2011
2012 pDCB->DCBFlag |= ABORT_DEV_;
2013 printk(KERN_INFO "DC390: Aborted pid %li\n", cmd->pid);
2014
2015 return FAILED;
2016}
2017
2018
2019static void dc390_ResetDevParam( struct dc390_acb* pACB )
2020{
2021 struct dc390_dcb *pDCB, *pdcb;
2022
2023 pDCB = pACB->pLinkDCB;
2024 if (! pDCB) return;
2025 pdcb = pDCB;
2026 do
2027 {
2028 pDCB->SyncMode &= ~SYNC_NEGO_DONE;
2029 pDCB->SyncPeriod = 0;
2030 pDCB->SyncOffset = 0;
2031 pDCB->TagMask = 0;
2032 pDCB->CtrlR3 = FAST_CLK;
2033 pDCB->CtrlR4 &= NEGATE_REQACKDATA | CTRL4_RESERVED | NEGATE_REQACK;
2034 pDCB->CtrlR4 |= pACB->glitch_cfg;
2035 pDCB = pDCB->pNextDCB;
2036 }
2037 while( pdcb != pDCB );
2038 pACB->ACBFlag &= ~(RESET_DEV | RESET_DONE | RESET_DETECT);
2039
2040}
2041
2042static int DC390_bus_reset (struct scsi_cmnd *cmd)
2043{
2044 struct dc390_acb* pACB = (struct dc390_acb*) cmd->device->host->hostdata;
2045 u8 bval;
2046
68b3aa7c
JG
2047 spin_lock_irq(cmd->device->host->host_lock);
2048
1da177e4
LT
2049 bval = DC390_read8(CtrlReg1) | DIS_INT_ON_SCSI_RST;
2050 DC390_write8(CtrlReg1, bval); /* disable IRQ on bus reset */
2051
2052 pACB->ACBFlag |= RESET_DEV;
2053 dc390_ResetSCSIBus(pACB);
2054
2055 dc390_ResetDevParam(pACB);
68b3aa7c 2056 mdelay(1);
1da177e4
LT
2057 pACB->pScsiHost->last_reset = jiffies + 3*HZ/2
2058 + HZ * dc390_eepromBuf[pACB->AdapterIndex][EE_DELAY];
2059
2060 DC390_write8(ScsiCmd, CLEAR_FIFO_CMD);
2061 DC390_read8(INT_Status); /* Reset Pending INT */
2062
2063 dc390_DoingSRB_Done(pACB, cmd);
2064
2065 pACB->pActiveDCB = NULL;
2066 pACB->ACBFlag = 0;
2067
2068 bval = DC390_read8(CtrlReg1) & ~DIS_INT_ON_SCSI_RST;
2069 DC390_write8(CtrlReg1, bval); /* re-enable interrupt */
2070
68b3aa7c
JG
2071 spin_unlock_irq(cmd->device->host->host_lock);
2072
1da177e4
LT
2073 return SUCCESS;
2074}
2075
2076/**
2077 * dc390_slave_alloc - Called by the scsi mid layer to tell us about a new
2078 * scsi device that we need to deal with.
2079 *
2080 * @scsi_device: The new scsi device that we need to handle.
2081 */
2082static int dc390_slave_alloc(struct scsi_device *scsi_device)
2083{
2084 struct dc390_acb *pACB = (struct dc390_acb*) scsi_device->host->hostdata;
2085 struct dc390_dcb *pDCB, *pDCB2 = NULL;
2086 uint id = scsi_device->id;
2087 uint lun = scsi_device->lun;
2088
2089 pDCB = kmalloc(sizeof(struct dc390_dcb), GFP_KERNEL);
2090 if (!pDCB)
2091 return -ENOMEM;
2092 memset(pDCB, 0, sizeof(struct dc390_dcb));
2093
2094 if (!pACB->DCBCnt++) {
2095 pACB->pLinkDCB = pDCB;
2096 pACB->pDCBRunRobin = pDCB;
2097 } else {
2098 pACB->pLastDCB->pNextDCB = pDCB;
2099 }
2100
2101 pDCB->pNextDCB = pACB->pLinkDCB;
2102 pACB->pLastDCB = pDCB;
2103
2104 pDCB->pDCBACB = pACB;
2105 pDCB->TargetID = id;
2106 pDCB->TargetLUN = lun;
2107
2108 /*
2109 * Some values are for all LUNs: Copy them
2110 * In a clean way: We would have an own structure for a SCSI-ID
2111 */
2112 if (lun && (pDCB2 = dc390_findDCB(pACB, id, 0))) {
2113 pDCB->DevMode = pDCB2->DevMode;
2114 pDCB->SyncMode = pDCB2->SyncMode & SYNC_NEGO_DONE;
2115 pDCB->SyncPeriod = pDCB2->SyncPeriod;
2116 pDCB->SyncOffset = pDCB2->SyncOffset;
2117 pDCB->NegoPeriod = pDCB2->NegoPeriod;
2118
2119 pDCB->CtrlR3 = pDCB2->CtrlR3;
2120 pDCB->CtrlR4 = pDCB2->CtrlR4;
2121 } else {
2122 u8 index = pACB->AdapterIndex;
2123 PEEprom prom = (PEEprom) &dc390_eepromBuf[index][id << 2];
2124
2125 pDCB->DevMode = prom->EE_MODE1;
2126 pDCB->NegoPeriod =
2127 (dc390_clock_period1[prom->EE_SPEED] * 25) >> 2;
2128 pDCB->CtrlR3 = FAST_CLK;
2129 pDCB->CtrlR4 = pACB->glitch_cfg | CTRL4_RESERVED;
2130 if (dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION)
2131 pDCB->CtrlR4 |= NEGATE_REQACKDATA | NEGATE_REQACK;
2132 }
2133
2134 if (pDCB->DevMode & SYNC_NEGO_)
2135 pDCB->SyncMode |= SYNC_ENABLE;
2136 else {
2137 pDCB->SyncMode = 0;
2138 pDCB->SyncOffset &= ~0x0f;
2139 }
2140
2141 pDCB->CtrlR1 = pACB->pScsiHost->this_id;
2142 if (pDCB->DevMode & PARITY_CHK_)
2143 pDCB->CtrlR1 |= PARITY_ERR_REPO;
2144
2145 pACB->scan_devices = 1;
2146 scsi_device->hostdata = pDCB;
2147 return 0;
2148}
2149
2150/**
2151 * dc390_slave_destroy - Called by the scsi mid layer to tell us about a
2152 * device that is going away.
2153 *
2154 * @scsi_device: The scsi device that we need to remove.
2155 */
2156static void dc390_slave_destroy(struct scsi_device *scsi_device)
2157{
2158 struct dc390_acb* pACB = (struct dc390_acb*) scsi_device->host->hostdata;
2159 struct dc390_dcb* pDCB = (struct dc390_dcb*) scsi_device->hostdata;
2160 struct dc390_dcb* pPrevDCB = pACB->pLinkDCB;
2161
2162 pACB->scan_devices = 0;
2163
2164 BUG_ON(pDCB->GoingSRBCnt > 1);
2165
2166 if (pDCB == pACB->pLinkDCB) {
2167 if (pACB->pLastDCB == pDCB) {
2168 pDCB->pNextDCB = NULL;
2169 pACB->pLastDCB = NULL;
2170 }
2171 pACB->pLinkDCB = pDCB->pNextDCB;
2172 } else {
2173 while (pPrevDCB->pNextDCB != pDCB)
2174 pPrevDCB = pPrevDCB->pNextDCB;
2175 pPrevDCB->pNextDCB = pDCB->pNextDCB;
2176 if (pDCB == pACB->pLastDCB)
2177 pACB->pLastDCB = pPrevDCB;
2178 }
2179
2180 if (pDCB == pACB->pActiveDCB)
2181 pACB->pActiveDCB = NULL;
2182 if (pDCB == pACB->pLinkDCB)
2183 pACB->pLinkDCB = pDCB->pNextDCB;
2184 if (pDCB == pACB->pDCBRunRobin)
2185 pACB->pDCBRunRobin = pDCB->pNextDCB;
2186 kfree(pDCB);
2187
2188 pACB->DCBCnt--;
2189}
2190
2191static int dc390_slave_configure(struct scsi_device *sdev)
2192{
2193 struct dc390_acb *acb = (struct dc390_acb *)sdev->host->hostdata;
2194 struct dc390_dcb *dcb = (struct dc390_dcb *)sdev->hostdata;
2195
2196 acb->scan_devices = 0;
2197 if (sdev->tagged_supported && (dcb->DevMode & TAG_QUEUEING_)) {
2198 dcb->SyncMode |= EN_TAG_QUEUEING;
2199 scsi_activate_tcq(sdev, acb->TagMaxNum);
2200 }
2201
2202 return 0;
2203}
2204
2205static struct scsi_host_template driver_template = {
2206 .module = THIS_MODULE,
2207 .proc_name = "tmscsim",
2208 .name = DC390_BANNER " V" DC390_VERSION,
2209 .slave_alloc = dc390_slave_alloc,
2210 .slave_configure = dc390_slave_configure,
2211 .slave_destroy = dc390_slave_destroy,
2212 .queuecommand = DC390_queuecommand,
2213 .eh_abort_handler = DC390_abort,
2214 .eh_bus_reset_handler = DC390_bus_reset,
2215 .can_queue = 1,
2216 .this_id = 7,
2217 .sg_tablesize = SG_ALL,
2218 .cmd_per_lun = 1,
8f6fd19f 2219 .use_clustering = ENABLE_CLUSTERING,
75c28851 2220 .max_sectors = 0x4000, /* 8MiB = 16 * 1024 * 512 */
1da177e4
LT
2221};
2222
2223/***********************************************************************
2224 * Functions for access to DC390 EEPROM
2225 * and some to emulate it
2226 *
2227 **********************************************************************/
2228
2229static void __devinit dc390_eeprom_prepare_read(struct pci_dev *pdev, u8 cmd)
2230{
2231 u8 carryFlag = 1, j = 0x80, bval;
2232 int i;
2233
2234 for (i = 0; i < 9; i++) {
2235 if (carryFlag) {
2236 pci_write_config_byte(pdev, 0x80, 0x40);
2237 bval = 0xc0;
2238 } else
2239 bval = 0x80;
2240
2241 udelay(160);
2242 pci_write_config_byte(pdev, 0x80, bval);
2243 udelay(160);
2244 pci_write_config_byte(pdev, 0x80, 0);
2245 udelay(160);
2246
2247 carryFlag = (cmd & j) ? 1 : 0;
2248 j >>= 1;
2249 }
2250}
2251
2252static u16 __devinit dc390_eeprom_get_data(struct pci_dev *pdev)
2253{
2254 int i;
2255 u16 wval = 0;
2256 u8 bval;
2257
2258 for (i = 0; i < 16; i++) {
2259 wval <<= 1;
2260
2261 pci_write_config_byte(pdev, 0x80, 0x80);
2262 udelay(160);
2263 pci_write_config_byte(pdev, 0x80, 0x40);
2264 udelay(160);
2265 pci_read_config_byte(pdev, 0x00, &bval);
2266
2267 if (bval == 0x22)
2268 wval |= 1;
2269 }
2270
2271 return wval;
2272}
2273
2274static void __devinit dc390_read_eeprom(struct pci_dev *pdev, u16 *ptr)
2275{
2276 u8 cmd = EEPROM_READ, i;
2277
2278 for (i = 0; i < 0x40; i++) {
2279 pci_write_config_byte(pdev, 0xc0, 0);
2280 udelay(160);
2281
2282 dc390_eeprom_prepare_read(pdev, cmd++);
2283 *ptr++ = dc390_eeprom_get_data(pdev);
2284
2285 pci_write_config_byte(pdev, 0x80, 0);
2286 pci_write_config_byte(pdev, 0x80, 0);
2287 udelay(160);
2288 }
2289}
2290
2291/* Override EEprom values with explicitly set values */
2292static void __devinit dc390_eeprom_override(u8 index)
2293{
2294 u8 *ptr = (u8 *) dc390_eepromBuf[index], id;
2295
2296 /* Adapter Settings */
2297 if (tmscsim[0] != -2)
2298 ptr[EE_ADAPT_SCSI_ID] = (u8)tmscsim[0]; /* Adapter ID */
2299 if (tmscsim[3] != -2)
2300 ptr[EE_MODE2] = (u8)tmscsim[3];
2301 if (tmscsim[5] != -2)
2302 ptr[EE_DELAY] = tmscsim[5]; /* Reset delay */
2303 if (tmscsim[4] != -2)
2304 ptr[EE_TAG_CMD_NUM] = (u8)tmscsim[4]; /* Tagged Cmds */
2305
2306 /* Device Settings */
2307 for (id = 0; id < MAX_SCSI_ID; id++) {
2308 if (tmscsim[2] != -2)
2309 ptr[id << 2] = (u8)tmscsim[2]; /* EE_MODE1 */
2310 if (tmscsim[1] != -2)
2311 ptr[(id << 2) + 1] = (u8)tmscsim[1]; /* EE_Speed */
2312 }
2313}
2314
2315static int __devinitdata tmscsim_def[] = {
2316 7,
2317 0 /* 10MHz */,
2318 PARITY_CHK_ | SEND_START_ | EN_DISCONNECT_ | SYNC_NEGO_ | TAG_QUEUEING_,
2319 MORE2_DRV | GREATER_1G | RST_SCSI_BUS | ACTIVE_NEGATION | LUN_CHECK,
2320 3 /* 16 Tags per LUN */,
2321 1 /* s delay after Reset */,
2322};
2323
2324/* Copy defaults over set values where missing */
2325static void __devinit dc390_fill_with_defaults (void)
2326{
2327 int i;
2328
2329 for (i = 0; i < 6; i++) {
2330 if (tmscsim[i] < 0 || tmscsim[i] > 255)
2331 tmscsim[i] = tmscsim_def[i];
2332 }
2333
2334 /* Sanity checks */
2335 if (tmscsim[0] > 7)
2336 tmscsim[0] = 7;
2337 if (tmscsim[1] > 7)
2338 tmscsim[1] = 4;
2339 if (tmscsim[4] > 5)
2340 tmscsim[4] = 4;
2341 if (tmscsim[5] > 180)
2342 tmscsim[5] = 180;
2343}
2344
2345static void __devinit dc390_check_eeprom(struct pci_dev *pdev, u8 index)
2346{
2347 u8 interpd[] = {1, 3, 5, 10, 16, 30, 60, 120};
2348 u8 EEbuf[128];
2349 u16 *ptr = (u16 *)EEbuf, wval = 0;
2350 int i;
2351
2352 dc390_read_eeprom(pdev, ptr);
2353 memcpy(dc390_eepromBuf[index], EEbuf, EE_ADAPT_SCSI_ID);
2354 memcpy(&dc390_eepromBuf[index][EE_ADAPT_SCSI_ID],
2355 &EEbuf[REAL_EE_ADAPT_SCSI_ID], EE_LEN - EE_ADAPT_SCSI_ID);
2356
2357 dc390_eepromBuf[index][EE_DELAY] = interpd[dc390_eepromBuf[index][EE_DELAY]];
2358
2359 for (i = 0; i < 0x40; i++, ptr++)
2360 wval += *ptr;
2361
2362 /* no Tekram EEprom found */
2363 if (wval != 0x1234) {
2364 int speed;
2365
2366 printk(KERN_INFO "DC390_init: No EEPROM found! Trying default settings ...\n");
2367
2368 /*
2369 * XXX(hch): bogus, because we might have tekram and
2370 * non-tekram hbas in a single machine.
2371 */
2372 dc390_fill_with_defaults();
2373
2374 speed = dc390_clock_speed[tmscsim[1]];
2375 printk(KERN_INFO "DC390: Used defaults: AdaptID=%i, SpeedIdx=%i (%i.%i MHz), "
2376 "DevMode=0x%02x, AdaptMode=0x%02x, TaggedCmnds=%i (%i), DelayReset=%is\n",
2377 tmscsim[0], tmscsim[1], speed / 10, speed % 10,
2378 (u8)tmscsim[2], (u8)tmscsim[3], tmscsim[4], 2 << (tmscsim[4]), tmscsim[5]);
2379 }
2380}
2381
2382static void __devinit dc390_init_hw(struct dc390_acb *pACB, u8 index)
2383{
2384 struct Scsi_Host *shost = pACB->pScsiHost;
2385 u8 dstate;
2386
2387 /* Disable SCSI bus reset interrupt */
2388 DC390_write8(CtrlReg1, DIS_INT_ON_SCSI_RST | shost->this_id);
2389
2390 if (pACB->Gmode2 & RST_SCSI_BUS) {
2391 dc390_ResetSCSIBus(pACB);
2392 udelay(1000);
2393 shost->last_reset = jiffies + HZ/2 +
2394 HZ * dc390_eepromBuf[pACB->AdapterIndex][EE_DELAY];
2395 }
2396
2397 pACB->ACBFlag = 0;
2398
2399 /* Reset Pending INT */
2400 DC390_read8(INT_Status);
2401
2402 /* 250ms selection timeout */
2403 DC390_write8(Scsi_TimeOut, SEL_TIMEOUT);
2404
2405 /* Conversion factor = 0 , 40MHz clock */
2406 DC390_write8(Clk_Factor, CLK_FREQ_40MHZ);
2407
2408 /* NOP cmd - clear command register */
2409 DC390_write8(ScsiCmd, NOP_CMD);
2410
2411 /* Enable Feature and SCSI-2 */
2412 DC390_write8(CtrlReg2, EN_FEATURE+EN_SCSI2_CMD);
2413
2414 /* Fast clock */
2415 DC390_write8(CtrlReg3, FAST_CLK);
2416
2417 /* Negation */
2418 DC390_write8(CtrlReg4, pACB->glitch_cfg | /* glitch eater */
2419 (dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION) ?
2420 NEGATE_REQACKDATA : 0);
2421
2422 /* Clear Transfer Count High: ID */
2423 DC390_write8(CtcReg_High, 0);
2424 DC390_write8(DMA_Cmd, DMA_IDLE_CMD);
2425 DC390_write8(ScsiCmd, CLEAR_FIFO_CMD);
2426 DC390_write32(DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT);
2427
2428 dstate = DC390_read8(DMA_Status);
2429 DC390_write8(DMA_Status, dstate);
2430}
2431
2432static int __devinit dc390_probe_one(struct pci_dev *pdev,
2433 const struct pci_device_id *id)
2434{
2435 struct dc390_acb *pACB;
2436 struct Scsi_Host *shost;
2437 unsigned long io_port;
2438 int error = -ENODEV, i;
2439
2440 if (pci_enable_device(pdev))
2441 goto out;
2442
2443 pci_set_master(pdev);
2444
2445 error = -ENOMEM;
8f6fd19f
GL
2446 if (disable_clustering)
2447 driver_template.use_clustering = DISABLE_CLUSTERING;
1da177e4
LT
2448 shost = scsi_host_alloc(&driver_template, sizeof(struct dc390_acb));
2449 if (!shost)
2450 goto out_disable_device;
2451
2452 pACB = (struct dc390_acb *)shost->hostdata;
2453 memset(pACB, 0, sizeof(struct dc390_acb));
2454
2455 dc390_check_eeprom(pdev, dc390_adapterCnt);
2456 dc390_eeprom_override(dc390_adapterCnt);
2457
2458 io_port = pci_resource_start(pdev, 0);
2459
2460 shost->this_id = dc390_eepromBuf[dc390_adapterCnt][EE_ADAPT_SCSI_ID];
2461 shost->io_port = io_port;
2462 shost->n_io_port = 0x80;
2463 shost->irq = pdev->irq;
2464 shost->base = io_port;
2465 shost->unique_id = io_port;
2466 shost->last_reset = jiffies;
2467
2468 pACB->pScsiHost = shost;
2469 pACB->IOPortBase = (u16) io_port;
2470 pACB->IRQLevel = pdev->irq;
2471
2472 shost->max_id = 8;
2473
2474 if (shost->max_id - 1 ==
2475 dc390_eepromBuf[dc390_adapterCnt][EE_ADAPT_SCSI_ID])
2476 shost->max_id--;
2477
2478 if (dc390_eepromBuf[dc390_adapterCnt][EE_MODE2] & LUN_CHECK)
2479 shost->max_lun = 8;
2480 else
2481 shost->max_lun = 1;
2482
2483 pACB->pFreeSRB = pACB->SRB_array;
2484 pACB->SRBCount = MAX_SRB_CNT;
2485 pACB->AdapterIndex = dc390_adapterCnt;
2486 pACB->TagMaxNum =
2487 2 << dc390_eepromBuf[dc390_adapterCnt][EE_TAG_CMD_NUM];
2488 pACB->Gmode2 = dc390_eepromBuf[dc390_adapterCnt][EE_MODE2];
2489
2490 for (i = 0; i < pACB->SRBCount-1; i++)
2491 pACB->SRB_array[i].pNextSRB = &pACB->SRB_array[i+1];
2492 pACB->SRB_array[pACB->SRBCount-1].pNextSRB = NULL;
2493 pACB->pTmpSRB = &pACB->TmpSRB;
2494
2495 pACB->sel_timeout = SEL_TIMEOUT;
2496 pACB->glitch_cfg = EATER_25NS;
2497 pACB->pdev = pdev;
2498
2499 if (!request_region(io_port, shost->n_io_port, "tmscsim")) {
2500 printk(KERN_ERR "DC390: register IO ports error!\n");
2501 goto out_host_put;
2502 }
2503
2504 /* Reset Pending INT */
2505 DC390_read8_(INT_Status, io_port);
2506
1d6f359a 2507 if (request_irq(pdev->irq, do_DC390_Interrupt, IRQF_SHARED,
1da177e4
LT
2508 "tmscsim", pACB)) {
2509 printk(KERN_ERR "DC390: register IRQ error!\n");
2510 goto out_release_region;
2511 }
2512
2513 dc390_init_hw(pACB, dc390_adapterCnt);
2514
2515 dc390_adapterCnt++;
2516
2517 pci_set_drvdata(pdev, shost);
2518
2519 error = scsi_add_host(shost, &pdev->dev);
2520 if (error)
2521 goto out_free_irq;
2522 scsi_scan_host(shost);
2523 return 0;
2524
2525 out_free_irq:
2526 free_irq(pdev->irq, pACB);
2527 out_release_region:
2528 release_region(io_port, shost->n_io_port);
2529 out_host_put:
2530 scsi_host_put(shost);
2531 out_disable_device:
2532 pci_disable_device(pdev);
2533 out:
2534 return error;
2535}
2536
2537/**
2538 * dc390_remove_one - Called to remove a single instance of the adapter.
2539 *
2540 * @dev: The PCI device to remove.
2541 */
2542static void __devexit dc390_remove_one(struct pci_dev *dev)
2543{
2544 struct Scsi_Host *scsi_host = pci_get_drvdata(dev);
2545 unsigned long iflags;
2546 struct dc390_acb* pACB = (struct dc390_acb*) scsi_host->hostdata;
2547 u8 bval;
2548
2549 scsi_remove_host(scsi_host);
2550
2551 spin_lock_irqsave(scsi_host->host_lock, iflags);
2552 pACB->ACBFlag = RESET_DEV;
2553 bval = DC390_read8(CtrlReg1) | DIS_INT_ON_SCSI_RST;
2554 DC390_write8 (CtrlReg1, bval); /* disable interrupt */
2555 if (pACB->Gmode2 & RST_SCSI_BUS)
2556 dc390_ResetSCSIBus(pACB);
2557 spin_unlock_irqrestore(scsi_host->host_lock, iflags);
2558
2559 free_irq(scsi_host->irq, pACB);
2560 release_region(scsi_host->io_port, scsi_host->n_io_port);
2561
2562 pci_disable_device(dev);
2563 scsi_host_put(scsi_host);
2564 pci_set_drvdata(dev, NULL);
2565}
2566
2567static struct pci_device_id tmscsim_pci_tbl[] = {
2568 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD53C974,
2569 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
2570 { }
2571};
2572MODULE_DEVICE_TABLE(pci, tmscsim_pci_tbl);
2573
2574static struct pci_driver dc390_driver = {
2575 .name = "tmscsim",
2576 .id_table = tmscsim_pci_tbl,
2577 .probe = dc390_probe_one,
2578 .remove = __devexit_p(dc390_remove_one),
2579};
2580
2581static int __init dc390_module_init(void)
2582{
8f6fd19f
GL
2583 if (!disable_clustering)
2584 printk(KERN_INFO "DC390: clustering now enabled by default. If you get problems load\n"
2585 "\twith \"disable_clustering=1\" and report to maintainers\n");
2586
1da177e4
LT
2587 if (tmscsim[0] == -1 || tmscsim[0] > 15) {
2588 tmscsim[0] = 7;
2589 tmscsim[1] = 4;
2590 tmscsim[2] = PARITY_CHK_ | TAG_QUEUEING_;
2591 tmscsim[3] = MORE2_DRV | GREATER_1G | RST_SCSI_BUS | ACTIVE_NEGATION;
2592 tmscsim[4] = 2;
2593 tmscsim[5] = 10;
2594 printk (KERN_INFO "DC390: Using safe settings.\n");
2595 }
2596
886a0768 2597 return pci_register_driver(&dc390_driver);
1da177e4
LT
2598}
2599
2600static void __exit dc390_module_exit(void)
2601{
2602 pci_unregister_driver(&dc390_driver);
2603}
2604
2605module_init(dc390_module_init);
2606module_exit(dc390_module_exit);
2607
2608#ifndef MODULE
2609static int __init dc390_setup (char *str)
2610{
2611 int ints[8],i, im;
2612
2613 get_options(str, ARRAY_SIZE(ints), ints);
2614 im = ints[0];
2615
2616 if (im > 6) {
2617 printk (KERN_NOTICE "DC390: ignore extra params!\n");
2618 im = 6;
2619 }
2620
2621 for (i = 0; i < im; i++)
2622 tmscsim[i] = ints[i+1];
2623 /* dc390_checkparams (); */
2624 return 1;
2625}
2626
2627__setup("tmscsim=", dc390_setup);
2628#endif