1 /**************************************************************************
2 * Initio 9100 device driver for Linux.
4 * Copyright (c) 1994-1998 Initio Corporation
5 * Copyright (c) 1998 Bas Vermeulen <bvermeul@blackstar.xs4all.nl>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 * --------------------------------------------------------------------------
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions, and the following disclaimer,
29 * without modification, immediately at the beginning of the file.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. The name of the author may not be used to endorse or promote products
34 * derived from this software without specific prior written permission.
36 * Where this Software is combined with software released under the terms of
37 * the GNU Public License ("GPL") and the terms of the GPL would require the
38 * combined work to also be released under the terms of the GPL, the terms
39 * and conditions of this License will apply in addition to those of the
40 * GPL with the exception of any terms or conditions of this License that
41 * conflict with, or are expressly prohibited by, the GPL.
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
47 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 *************************************************************************
59 * This is the Linux low-level SCSI driver for Initio INI-9X00U/UW SCSI host
62 * 08/06/97 hc - v1.01h
63 * - Support inic-940 and inic-935
64 * 09/26/97 hc - v1.01i
65 * - Make correction from J.W. Schultz suggestion
66 * 10/13/97 hc - Support reset function
67 * 10/21/97 hc - v1.01j
68 * - Support 32 LUN (SCSI 3)
69 * 01/14/98 hc - v1.01k
70 * - Fix memory allocation problem
71 * 03/04/98 hc - v1.01l
72 * - Fix tape rewind which will hang the system problem
73 * - Set can_queue to tul_num_scb
74 * 06/25/98 hc - v1.01m
75 * - Get it work for kernel version >= 2.1.75
76 * - Dynamic assign SCSI bus reset holding time in init_tulip()
77 * 07/02/98 hc - v1.01n
79 * 08/07/98 hc - v1.01o
80 * - Change the tul_abort_srb routine to use scsi_done. <01>
82 * - Change the INI9100U define and proc_dir_entry to
83 * reflect the newer Kernel 2.1.118, but the v1.o1o
84 * should work with Kernel 2.1.118.
85 * 09/20/98 wh - v1.02a
86 * - Support Abort command.
87 * - Handle reset routine.
90 * 12/09/98 bv - v1.03a
91 * - Removed unused code
92 * 12/13/98 bv - v1.03b
93 * - Remove cli() locking for kernels >= 2.1.95. This uses
94 * spinlocks to serialize access to the pSRB_head and
95 * pSRB_tail members of the HCS structure.
96 * 09/01/99 bv - v1.03d
97 * - Fixed a deadlock problem in SMP.
98 * 21/01/99 bv - v1.03e
99 * - Add support for the Domex 3192U PCI SCSI
100 * This is a slightly modified patch by
101 * Brian Macy <bmacy@sunshinecomputing.com>
102 * 22/02/99 bv - v1.03f
103 * - Didn't detect the INIC-950 in 2.0.x correctly.
105 * 05/07/99 bv - v1.03g
106 * - Changed the assumption that HZ = 100
107 **************************************************************************/
109 #define CVT_LINUX_VERSION(V,P,S) (V * 65536 + P * 256 + S)
111 #ifndef LINUX_VERSION_CODE
112 #include <linux/version.h>
116 #include <linux/module.h>
119 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
122 #include <linux/errno.h>
123 #if LINUX_VERSION_CODE <= CVT_LINUX_VERSION(2,1,92)
124 #include <linux/bios32.h>
126 #include <linux/delay.h>
127 #include <linux/pci.h>
128 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,23)
129 #include <linux/init.h>
131 #include <linux/blk.h>
132 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
133 #include <linux/spinlock.h>
135 #include <linux/stat.h>
136 #include <linux/config.h>
140 #include <linux/head.h>
141 #include <linux/types.h>
142 #include <asm/system.h>
143 #include "../block/blk.h"
146 #include <linux/kernel.h>
147 #include <linux/string.h>
148 #include <linux/ioport.h>
149 #include <linux/sched.h>
150 #include <linux/proc_fs.h>
155 #include <linux/malloc.h>
156 #include "ini9100u.h"
159 unsigned int i91u_debug
= DEBUG_DEFAULT
;
163 Scsi_Host_Template driver_template
= INI9100U
;
164 #include "scsi_module.c"
167 char *i91uCopyright
= "Copyright (C) 1996-98";
168 char *i91uInitioName
= "by Initio Corporation";
169 char *i91uProductName
= "INI-9X00U/UW";
170 char *i91uVersion
= "v1.03g";
172 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
173 struct proc_dir_entry proc_scsi_ini9100u
=
175 PROC_SCSI_INI9100U
, 7, "INI9100U",
176 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2,
177 0, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
181 #define TULSZ(sz) (sizeof(sz) / sizeof(sz[0]))
182 #define TUL_RDWORD(x,y) (short)(inl((int)((ULONG)((ULONG)x+(UCHAR)y)) ))
184 /* set by i91_setup according to the command line */
185 static int setup_called
= 0;
187 static int tul_num_ch
= 4; /* Maximum 4 adapters */
188 static int tul_num_scb
;
189 static int tul_tag_enable
= 1;
193 static int setup_debug
= 0;
196 static char *setup_str
= (char *) NULL
;
198 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
199 static void i91u_intr0(int irq
, void *dev_id
, struct pt_regs
*);
200 static void i91u_intr1(int irq
, void *dev_id
, struct pt_regs
*);
201 static void i91u_intr2(int irq
, void *dev_id
, struct pt_regs
*);
202 static void i91u_intr3(int irq
, void *dev_id
, struct pt_regs
*);
203 static void i91u_intr4(int irq
, void *dev_id
, struct pt_regs
*);
204 static void i91u_intr5(int irq
, void *dev_id
, struct pt_regs
*);
205 static void i91u_intr6(int irq
, void *dev_id
, struct pt_regs
*);
206 static void i91u_intr7(int irq
, void *dev_id
, struct pt_regs
*);
208 static void i91u_intr0(int irq
, struct pt_regs
*);
209 static void i91u_intr1(int irq
, struct pt_regs
*);
210 static void i91u_intr2(int irq
, struct pt_regs
*);
211 static void i91u_intr3(int irq
, struct pt_regs
*);
212 static void i91u_intr4(int irq
, struct pt_regs
*);
213 static void i91u_intr5(int irq
, struct pt_regs
*);
214 static void i91u_intr6(int irq
, struct pt_regs
*);
215 static void i91u_intr7(int irq
, struct pt_regs
*);
218 static void i91u_panic(char *msg
);
220 static void i91uSCBPost(BYTE
* pHcb
, BYTE
* pScb
);
222 /* ---- EXTERNAL FUNCTIONS ---- */
223 /* Get total number of adapters */
224 extern void init_i91uAdapter_table(void);
225 extern int Addi91u_into_Adapter_table(WORD
, WORD
, BYTE
, BYTE
, BYTE
);
226 extern int tul_ReturnNumberOfAdapters(void);
227 extern void get_tulipPCIConfig(HCS
* pHCB
, int iChannel_index
);
228 extern int init_tulip(HCS
* pHCB
, SCB
* pSCB
, int tul_num_scb
, BYTE
* pbBiosAdr
, int reset_time
);
229 extern SCB
*tul_alloc_scb(HCS
* pHCB
);
230 extern int tul_abort_srb(HCS
* pHCB
, Scsi_Cmnd
* pSRB
);
231 extern void tul_exec_scb(HCS
* pHCB
, SCB
* pSCB
);
232 extern void tul_release_scb(HCS
* pHCB
, SCB
* pSCB
);
233 extern void tul_stop_bm(HCS
* pHCB
);
234 extern int tul_reset_scsi(HCS
* pCurHcb
, int seconds
);
235 extern int tul_isr(HCS
* pHCB
);
236 extern int tul_reset(HCS
* pHCB
, Scsi_Cmnd
* pSRB
, unsigned char target
);
237 extern int tul_reset_scsi_bus(HCS
* pCurHcb
);
238 extern int tul_device_reset(HCS
* pCurHcb
, ULONG pSrb
, unsigned int target
, unsigned int ResetFlags
);
239 /* ---- EXTERNAL VARIABLES ---- */
240 extern HCS tul_hcs
[];
242 const PCI_ID i91u_pci_devices
[] = {
243 { INI_VENDOR_ID
, I950_DEVICE_ID
},
244 { INI_VENDOR_ID
, I940_DEVICE_ID
},
245 { INI_VENDOR_ID
, I935_DEVICE_ID
},
246 { INI_VENDOR_ID
, I920_DEVICE_ID
},
247 { DMX_VENDOR_ID
, I920_DEVICE_ID
},
253 /*****************************************************************************
254 Function name : i91uAppendSRBToQueue
255 Description : This function will push current request into save list
256 Input : pSRB - Pointer to SCSI request block.
257 pHCB - Pointer to host adapter structure
260 *****************************************************************************/
261 static void i91uAppendSRBToQueue(HCS
* pHCB
, Scsi_Cmnd
* pSRB
)
264 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
265 spin_lock_irqsave(&(pHCB
->pSRB_lock
), flags
);
271 pSRB
->next
= NULL
; /* Pointer to next */
273 if (pHCB
->pSRB_head
== NULL
)
274 pHCB
->pSRB_head
= pSRB
;
276 pHCB
->pSRB_tail
->next
= pSRB
; /* Pointer to next */
277 pHCB
->pSRB_tail
= pSRB
;
279 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
280 spin_unlock_irqrestore(&(pHCB
->pSRB_lock
), flags
);
282 restore_flags(flags
);
287 /*****************************************************************************
288 Function name : i91uPopSRBFromQueue
289 Description : This function will pop current request from save list
290 Input : pHCB - Pointer to host adapter structure
292 Return : pSRB - Pointer to SCSI request block.
293 *****************************************************************************/
294 static Scsi_Cmnd
*i91uPopSRBFromQueue(HCS
* pHCB
)
299 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
300 spin_lock_irqsave(&(pHCB
->pSRB_lock
), flags
);
306 if ((pSRB
= pHCB
->pSRB_head
) != NULL
) {
307 pHCB
->pSRB_head
= pHCB
->pSRB_head
->next
;
310 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
311 spin_unlock_irqrestore(&(pHCB
->pSRB_lock
), flags
);
313 restore_flags(flags
);
319 /* called from init/main.c */
321 void i91u_setup(char *str
, int *ints
)
324 i91u_panic("i91u: i91u_setup called twice.\n");
326 setup_called
= ints
[0];
330 setup_debug
= ints
[0] >= 1 ? ints
[1] : DEBUG_DEFAULT
;
334 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,93)
335 int tul_NewReturnNumberOfAdapters(void)
337 struct pci_dev
*pDev
= NULL
; /* Start from none */
343 init_i91uAdapter_table();
345 for (i
= 0; i
< TULSZ(i91u_pci_devices
); i
++)
347 while ((pDev
= pci_find_device(i91u_pci_devices
[i
].vendor_id
, i91u_pci_devices
[i
].device_id
, pDev
)) != NULL
) {
348 pci_read_config_dword(pDev
, 0x44, (u32
*) & dRegValue
);
349 wBIOS
= (UWORD
) (dRegValue
& 0xFF);
350 if (((dRegValue
& 0xFF00) >> 8) == 0xFF)
352 wBIOS
= (wBIOS
<< 8) + ((UWORD
) ((dRegValue
& 0xFF00) >> 8));
353 if (Addi91u_into_Adapter_table(wBIOS
,
354 (pDev
->resource
[0].start
),
368 /*****************************************************************************
369 Function name : tul_ReturnNumberOfAdapters
370 Description : This function will scan PCI bus to get all Orchid card
373 Return : SUCCESSFUL - Successful scan
374 ohterwise - No drives founded
375 *****************************************************************************/
376 int tul_ReturnNumberOfAdapters(void)
378 unsigned int i
, iAdapters
;
379 unsigned int dRegValue
;
380 unsigned short command
;
382 BYTE bPCIBusNum
, bInterrupt
, bPCIDeviceNum
;
388 if (pcibios_present()) {
390 unsigned long page_offset
, base
;
394 unsigned char pci_bus
, pci_devfn
;
398 init_i91uAdapter_table();
399 for (i
= 0; i
< TULSZ(i91u_pci_devices
); i
++) {
401 while (!(pcibios_find_device(i91u_pci_devices
[i
].vendor_id
,
402 i91u_pci_devices
[i
].device_id
,
403 index
++, &pci_bus
, &pci_devfn
)))
406 printk("i91u: The RAID controller is not supported by\n");
407 printk("i91u: this driver, we are ignoring it.\n");
410 * Read sundry information from PCI BIOS.
412 bPCIBusNum
= pci_bus
;
413 bPCIDeviceNum
= pci_devfn
;
414 pcibios_read_config_dword(pci_bus
, pci_devfn
, PCI_BASE_ADDRESS_0
,
416 if (dRegValue
== -1) { /* Check return code */
417 printk("\n\ri91u: tulip read configuration error.\n");
418 return (0); /* Read configuration space error */
420 /* <02> read from base address + 0x50 offset to get the wBIOS balue. */
421 wBASE
= (WORD
) dRegValue
;
423 /* Now read the interrupt line */
424 pcibios_read_config_dword(pci_bus
, pci_devfn
, PCI_INTERRUPT_LINE
,
426 bInterrupt
= dRegValue
& 0xFF; /* Assign interrupt line */
427 pcibios_read_config_word(pci_bus
, pci_devfn
, PCI_COMMAND
, &command
);
428 pcibios_write_config_word(pci_bus
, pci_devfn
, PCI_COMMAND
,
429 command
| PCI_COMMAND_MASTER
| PCI_COMMAND_IO
);
430 wBASE
&= PCI_BASE_ADDRESS_IO_MASK
;
431 wBIOS
= TUL_RDWORD(wBASE
, 0x50);
434 base
= wBASE
& PAGE_MASK
;
435 page_offset
= wBASE
- base
;
438 * replace the next line with this one if you are using 2.1.x:
439 * temp_p->maddr = ioremap(base, page_offset + 256);
441 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,0)
442 wBASE
= ioremap(base
, page_offset
+ 256);
444 wBASE
= (WORD
) vremap(base
, page_offset
+ 256);
447 wBASE
+= page_offset
;
451 if (Addi91u_into_Adapter_table(wBIOS
, wBASE
, bInterrupt
, bPCIBusNum
,
452 bPCIDeviceNum
) == 0x0)
455 } /* while(pdev=....) */
456 } /* for PCI_DEVICES */
457 } /* PCI BIOS present */
462 int i91u_detect(Scsi_Host_Template
* tpnt
)
466 struct Scsi_Host
*hreg
;
467 unsigned long i
; /* 01/14/98 */
468 int ok
= 0, iAdapters
;
472 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
473 tpnt
->proc_dir
= &proc_scsi_ini9100u
;
476 if (setup_called
) { /* Setup by i91u_setup */
477 printk("i91u: processing commandline: ");
480 if (setup_called
> 1) {
481 printk("\ni91u: %s\n", setup_str
);
482 printk("i91u: usage: i91u[=<DEBUG>]\n");
483 i91u_panic("i91u panics in line %d", __LINE__
);
485 i91u_debug
= setup_debug
;
488 /* Get total number of adapters in the motherboard */
489 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,93)
491 iAdapters
= tul_NewReturnNumberOfAdapters();
493 iAdapters
= tul_ReturnNumberOfAdapters();
496 iAdapters
= tul_ReturnNumberOfAdapters();
499 if (iAdapters
== 0) /* If no tulip founded, return */
502 tul_num_ch
= (iAdapters
> tul_num_ch
) ? tul_num_ch
: iAdapters
;
503 /* Update actually channel number */
504 if (tul_tag_enable
) { /* 1.01i */
505 tul_num_scb
= MAX_TARGETS
* i91u_MAXQUEUE
;
507 tul_num_scb
= MAX_TARGETS
+ 3; /* 1-tape, 1-CD_ROM, 1- extra */
508 } /* Update actually SCBs per adapter */
510 /* Get total memory needed for HCS */
511 i
= tul_num_ch
* sizeof(HCS
);
512 memset((unsigned char *) &tul_hcs
[0], 0, i
); /* Initialize tul_hcs 0 */
513 /* Get total memory needed for SCB */
515 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
516 for (; tul_num_scb
>= MAX_TARGETS
+ 3; tul_num_scb
--) {
517 i
= tul_num_ch
* tul_num_scb
* sizeof(SCB
);
518 if ((tul_scb
= (SCB
*) kmalloc(i
, GFP_ATOMIC
| GFP_DMA
)) != NULL
)
522 i
= tul_num_ch
* tul_num_scb
* sizeof(SCB
);
523 tul_scb
= (SCB
*) scsi_init_malloc(i
, GFP_ATOMIC
| GFP_DMA
);
525 if (tul_scb
== NULL
) {
526 printk("i91u: SCB memory allocation error\n");
529 memset((unsigned char *) tul_scb
, 0, i
);
532 for (i
= 0; i
< tul_num_ch
* tul_num_scb
; i
++, pSCB
++) {
533 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
534 pSCB
->SCB_SGPAddr
= (U32
) VIRT_TO_BUS(&pSCB
->SCB_SGList
[0]);
536 pSCB
->SCB_SGPAddr
= (U32
) (&pSCB
->SCB_SGList
[0]);
540 for (i
= 0, pHCB
= &tul_hcs
[0]; /* Get pointer for control block */
543 pHCB
->pSRB_head
= NULL
; /* Initial SRB save queue */
544 pHCB
->pSRB_tail
= NULL
; /* Initial SRB save queue */
545 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
546 pHCB
->pSRB_lock
= SPIN_LOCK_UNLOCKED
; /* SRB save queue lock */
548 request_region(pHCB
->HCS_Base
, 0x100, "i91u"); /* Register */
550 get_tulipPCIConfig(pHCB
, i
);
552 dBiosAdr
= pHCB
->HCS_BIOS
;
553 dBiosAdr
= (dBiosAdr
<< 4);
555 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
556 pbBiosAdr
= phys_to_virt(dBiosAdr
);
559 init_tulip(pHCB
, tul_scb
+ (i
* tul_num_scb
), tul_num_scb
, pbBiosAdr
, 10);
560 pHCB
->HCS_Index
= i
; /* 7/29/98 */
561 hreg
= scsi_register(tpnt
, sizeof(HCS
));
562 hreg
->io_port
= pHCB
->HCS_Base
;
563 hreg
->n_io_port
= 0xff;
564 hreg
->can_queue
= tul_num_scb
; /* 03/05/98 */
565 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
566 hreg
->unique_id
= pHCB
->HCS_Base
;
567 hreg
->max_id
= pHCB
->HCS_MaxTar
;
569 hreg
->max_lun
= 32; /* 10/21/97 */
570 hreg
->irq
= pHCB
->HCS_Intr
;
571 hreg
->this_id
= pHCB
->HCS_SCSI_ID
; /* Assign HCS index */
572 hreg
->base
= (UCHAR
*) pHCB
;
573 hreg
->sg_tablesize
= TOTAL_SG_ENTRY
; /* Maximun support is 32 */
575 /* Initial tulip chip */
577 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
579 ok
= request_irq(pHCB
->HCS_Intr
, i91u_intr0
, SA_INTERRUPT
| SA_SHIRQ
, "i91u", NULL
);
582 ok
= request_irq(pHCB
->HCS_Intr
, i91u_intr1
, SA_INTERRUPT
| SA_SHIRQ
, "i91u", NULL
);
585 ok
= request_irq(pHCB
->HCS_Intr
, i91u_intr2
, SA_INTERRUPT
| SA_SHIRQ
, "i91u", NULL
);
588 ok
= request_irq(pHCB
->HCS_Intr
, i91u_intr3
, SA_INTERRUPT
| SA_SHIRQ
, "i91u", NULL
);
591 ok
= request_irq(pHCB
->HCS_Intr
, i91u_intr4
, SA_INTERRUPT
| SA_SHIRQ
, "i91u", NULL
);
594 ok
= request_irq(pHCB
->HCS_Intr
, i91u_intr5
, SA_INTERRUPT
| SA_SHIRQ
, "i91u", NULL
);
597 ok
= request_irq(pHCB
->HCS_Intr
, i91u_intr6
, SA_INTERRUPT
| SA_SHIRQ
, "i91u", NULL
);
600 ok
= request_irq(pHCB
->HCS_Intr
, i91u_intr7
, SA_INTERRUPT
| SA_SHIRQ
, "i91u", NULL
);
603 i91u_panic("i91u: Too many host adapters\n");
608 printk("i91u: bad IRQ %d.\n", pHCB
->HCS_Intr
);
609 printk(" Contact author.\n");
610 } else if (ok
== -EBUSY
)
611 printk("i91u: IRQ %d already in use. Configure another.\n",
614 printk("\ni91u: Unexpected error code on requesting IRQ %d.\n",
616 printk(" Contact author.\n");
618 i91u_panic("i91u: driver needs an IRQ.\n");
629 static void i91uBuildSCB(HCS
* pHCB
, SCB
* pSCB
, Scsi_Cmnd
* SCpnt
)
630 { /* Create corresponding SCB */
631 struct scatterlist
*pSrbSG
;
632 SG
*pSG
; /* Pointer to SG list */
636 pSCB
->SCB_Post
= i91uSCBPost
; /* i91u's callback routine */
637 pSCB
->SCB_Srb
= SCpnt
;
638 pSCB
->SCB_Opcode
= ExecSCSI
;
639 pSCB
->SCB_Flags
= SCF_POST
; /* After SCSI done, call post routine */
640 pSCB
->SCB_Target
= SCpnt
->target
;
641 pSCB
->SCB_Lun
= SCpnt
->lun
;
642 pSCB
->SCB_Ident
= SCpnt
->lun
| DISC_ALLOW
;
643 pSCB
->SCB_Flags
|= SCF_SENSE
; /* Turn on auto request sense */
645 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
646 pSCB
->SCB_SensePtr
= (U32
) VIRT_TO_BUS(SCpnt
->sense_buffer
);
648 pSCB
->SCB_SensePtr
= (U32
) (SCpnt
->sense_buffer
);
651 pSCB
->SCB_SenseLen
= SENSE_SIZE
;
653 pSCB
->SCB_CDBLen
= SCpnt
->cmd_len
;
654 pSCB
->SCB_HaStat
= 0;
655 pSCB
->SCB_TaStat
= 0;
656 memcpy(&pSCB
->SCB_CDB
[0], &SCpnt
->cmnd
, SCpnt
->cmd_len
);
658 if (SCpnt
->device
->tagged_supported
) { /* Tag Support */
659 pSCB
->SCB_TagMsg
= SIMPLE_QUEUE_TAG
; /* Do simple tag only */
661 pSCB
->SCB_TagMsg
= 0; /* No tag support */
665 pSrbSG
= (struct scatterlist
*) SCpnt
->request_buffer
;
666 if (SCpnt
->use_sg
== 1) { /* If only one entry in the list *//* treat it as regular I/O */
667 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
668 pSCB
->SCB_BufPtr
= (U32
) VIRT_TO_BUS(pSrbSG
->address
);
670 pSCB
->SCB_BufPtr
= (U32
) (pSrbSG
->address
);
672 TotalLen
= pSrbSG
->length
;
674 } else { /* Assign SG physical address */
675 pSCB
->SCB_BufPtr
= pSCB
->SCB_SGPAddr
;
676 pSCB
->SCB_Flags
|= SCF_SG
; /* Turn on SG list flag */
677 for (i
= 0, TotalLen
= 0, pSG
= &pSCB
->SCB_SGList
[0]; /* 1.01g */
679 i
++, pSG
++, pSrbSG
++) {
680 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
681 pSG
->SG_Ptr
= (U32
) VIRT_TO_BUS(pSrbSG
->address
);
683 pSG
->SG_Ptr
= (U32
) (pSrbSG
->address
);
685 TotalLen
+= pSG
->SG_Len
= pSrbSG
->length
;
689 pSCB
->SCB_BufLen
= (SCpnt
->request_bufflen
> TotalLen
) ?
690 TotalLen
: SCpnt
->request_bufflen
;
691 } else { /* Non SG */
692 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
693 pSCB
->SCB_BufPtr
= (U32
) VIRT_TO_BUS(SCpnt
->request_buffer
);
695 pSCB
->SCB_BufPtr
= (U32
) (SCpnt
->request_buffer
);
697 pSCB
->SCB_BufLen
= SCpnt
->request_bufflen
;
705 * Queue a command and setup interrupts for a free bus.
707 int i91u_queue(Scsi_Cmnd
* SCpnt
, void (*done
) (Scsi_Cmnd
*))
710 HCS
*pHCB
; /* Point to Host adapter control block */
712 if (SCpnt
->lun
> 16) { /* 07/22/98 */
714 SCpnt
->result
= (DID_TIME_OUT
<< 16);
715 done(SCpnt
); /* Notify system DONE */
718 pHCB
= (HCS
*) SCpnt
->host
->base
;
720 SCpnt
->scsi_done
= done
;
721 /* Get free SCSI control block */
722 if ((pSCB
= tul_alloc_scb(pHCB
)) == NULL
) {
723 i91uAppendSRBToQueue(pHCB
, SCpnt
); /* Buffer this request */
726 i91uBuildSCB(pHCB
, pSCB
, SCpnt
);
727 tul_exec_scb(pHCB
, pSCB
); /* Start execute SCB */
732 * We only support command in interrupt-driven fashion
734 int i91u_command(Scsi_Cmnd
* SCpnt
)
736 printk("i91u: interrupt driven driver; use i91u_queue()\n");
741 * Abort a queued command
742 * (commands that are on the bus can't be aborted easily)
744 int i91u_abort(Scsi_Cmnd
* SCpnt
)
748 pHCB
= (HCS
*) SCpnt
->host
->base
;
749 return tul_abort_srb(pHCB
, SCpnt
);
753 * Reset registers, reset a hanging bus and
754 * kill active and disconnected commands for target w/o soft reset
756 int i91u_reset(Scsi_Cmnd
* SCpnt
, unsigned int reset_flags
)
757 { /* I need Host Control Block Information */
760 pHCB
= (HCS
*) SCpnt
->host
->base
;
762 if (reset_flags
& (SCSI_RESET_SUGGEST_BUS_RESET
| SCSI_RESET_SUGGEST_HOST_RESET
))
763 return tul_reset_scsi_bus(pHCB
);
765 return tul_device_reset(pHCB
, (ULONG
) SCpnt
, SCpnt
->target
, reset_flags
);
769 * Return the "logical geometry"
771 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
772 int i91u_biosparam(Scsi_Disk
* disk
, kdev_t dev
, int *info_array
)
774 int i91u_biosparam(Scsi_Disk
* disk
, int dev
, int *info_array
)
777 HCS
*pHcb
; /* Point to Host adapter control block */
780 pHcb
= (HCS
*) disk
->device
->host
->base
;
781 pTcb
= &pHcb
->HCS_Tcs
[disk
->device
->id
];
783 if (pTcb
->TCS_DrvHead
) {
784 info_array
[0] = pTcb
->TCS_DrvHead
;
785 info_array
[1] = pTcb
->TCS_DrvSector
;
786 info_array
[2] = disk
->capacity
/ pTcb
->TCS_DrvHead
/ pTcb
->TCS_DrvSector
;
788 if (pTcb
->TCS_DrvFlags
& TCF_DRV_255_63
) {
791 info_array
[2] = disk
->capacity
/ 255 / 63;
795 info_array
[2] = disk
->capacity
>> 11;
799 #if defined(DEBUG_BIOSPARAM)
800 if (i91u_debug
& debug_biosparam
) {
801 printk("bios geometry: head=%d, sec=%d, cyl=%d\n",
802 info_array
[0], info_array
[1], info_array
[2]);
803 printk("WARNING: check, if the bios geometry is correct.\n");
810 /*****************************************************************************
811 Function name : i91uSCBPost
812 Description : This is callback routine be called when tulip finish one
814 Input : pHCB - Pointer to host adapter control block.
815 pSCB - Pointer to SCSI control block.
818 *****************************************************************************/
819 static void i91uSCBPost(BYTE
* pHcb
, BYTE
* pScb
)
821 Scsi_Cmnd
*pSRB
; /* Pointer to SCSI request block */
827 if ((pSRB
= pSCB
->SCB_Srb
) == 0) {
828 printk("i91uSCBPost: SRB pointer is empty\n");
830 tul_release_scb(pHCB
, pSCB
); /* Release SCB for current channel */
833 switch (pSCB
->SCB_HaStat
) {
835 case 0xa: /* Linked command complete without error and linked normally */
836 case 0xb: /* Linked command complete without error interrupt generated */
837 pSCB
->SCB_HaStat
= 0;
840 case 0x11: /* Selection time out-The initiator selection or target
841 reselection was not complete within the SCSI Time out period */
842 pSCB
->SCB_HaStat
= DID_TIME_OUT
;
845 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
846 phase sequence was requested by the target. The host adapter
847 will generate a SCSI Reset Condition, notifying the host with
849 pSCB
->SCB_HaStat
= DID_RESET
;
852 case 0x1a: /* SCB Aborted. 07/21/98 */
853 pSCB
->SCB_HaStat
= DID_ABORT
;
856 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
857 than was allocated by the Data Length field or the sum of the
858 Scatter / Gather Data Length fields. */
859 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
860 case 0x16: /* Invalid SCB Operation Code. */
863 printk("ini9100u: %x %x\n", pSCB
->SCB_HaStat
, pSCB
->SCB_TaStat
);
864 pSCB
->SCB_HaStat
= DID_ERROR
; /* Couldn't find any better */
868 pSRB
->result
= pSCB
->SCB_TaStat
| (pSCB
->SCB_HaStat
<< 16);
871 printk("pSRB is NULL\n");
873 pSRB
->scsi_done(pSRB
); /* Notify system DONE */
874 if ((pSRB
= i91uPopSRBFromQueue(pHCB
)) != NULL
)
875 /* Find the next pending SRB */
876 { /* Assume resend will success */
878 i91uBuildSCB(pHCB
, pSCB
, pSRB
); /* Create corresponding SCB */
880 tul_exec_scb(pHCB
, pSCB
); /* Start execute SCB */
881 } else { /* No Pending SRB */
882 tul_release_scb(pHCB
, pSCB
); /* Release SCB for current channel */
888 * Interrupts handler (main routine of the driver)
890 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
891 static void i91u_intr0(int irqno
, void *dev_id
, struct pt_regs
*regs
)
893 static void i91u_intr0(int irqno
, struct pt_regs
*regs
)
896 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
900 if (tul_hcs
[0].HCS_Intr
!= irqno
)
903 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
904 spin_lock_irqsave(&io_request_lock
, flags
);
907 tul_isr(&tul_hcs
[0]);
909 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
910 spin_unlock_irqrestore(&io_request_lock
, flags
);
914 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
915 static void i91u_intr1(int irqno
, void *dev_id
, struct pt_regs
*regs
)
917 static void i91u_intr1(int irqno
, struct pt_regs
*regs
)
920 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
924 if (tul_hcs
[1].HCS_Intr
!= irqno
)
927 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
928 spin_lock_irqsave(&io_request_lock
, flags
);
931 tul_isr(&tul_hcs
[1]);
933 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
934 spin_unlock_irqrestore(&io_request_lock
, flags
);
938 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
939 static void i91u_intr2(int irqno
, void *dev_id
, struct pt_regs
*regs
)
941 static void i91u_intr2(int irqno
, struct pt_regs
*regs
)
944 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
948 if (tul_hcs
[2].HCS_Intr
!= irqno
)
951 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
952 spin_lock_irqsave(&io_request_lock
, flags
);
955 tul_isr(&tul_hcs
[2]);
957 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
958 spin_unlock_irqrestore(&io_request_lock
, flags
);
962 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
963 static void i91u_intr3(int irqno
, void *dev_id
, struct pt_regs
*regs
)
965 static void i91u_intr3(int irqno
, struct pt_regs
*regs
)
968 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
972 if (tul_hcs
[3].HCS_Intr
!= irqno
)
975 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
976 spin_lock_irqsave(&io_request_lock
, flags
);
979 tul_isr(&tul_hcs
[3]);
981 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
982 spin_unlock_irqrestore(&io_request_lock
, flags
);
986 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
987 static void i91u_intr4(int irqno
, void *dev_id
, struct pt_regs
*regs
)
989 static void i91u_intr4(int irqno
, struct pt_regs
*regs
)
992 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
996 if (tul_hcs
[4].HCS_Intr
!= irqno
)
999 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1000 spin_lock_irqsave(&io_request_lock
, flags
);
1003 tul_isr(&tul_hcs
[4]);
1005 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1006 spin_unlock_irqrestore(&io_request_lock
, flags
);
1010 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
1011 static void i91u_intr5(int irqno
, void *dev_id
, struct pt_regs
*regs
)
1013 static void i91u_intr5(int irqno
, struct pt_regs
*regs
)
1016 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1017 unsigned long flags
;
1020 if (tul_hcs
[5].HCS_Intr
!= irqno
)
1023 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1024 spin_lock_irqsave(&io_request_lock
, flags
);
1027 tul_isr(&tul_hcs
[5]);
1029 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1030 spin_unlock_irqrestore(&io_request_lock
, flags
);
1034 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
1035 static void i91u_intr6(int irqno
, void *dev_id
, struct pt_regs
*regs
)
1037 static void i91u_intr6(int irqno
, struct pt_regs
*regs
)
1040 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1041 unsigned long flags
;
1044 if (tul_hcs
[6].HCS_Intr
!= irqno
)
1047 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1048 spin_lock_irqsave(&io_request_lock
, flags
);
1051 tul_isr(&tul_hcs
[6]);
1053 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1054 spin_unlock_irqrestore(&io_request_lock
, flags
);
1058 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
1059 static void i91u_intr7(int irqno
, void *dev_id
, struct pt_regs
*regs
)
1061 static void i91u_intr7(int irqno
, struct pt_regs
*regs
)
1064 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1065 unsigned long flags
;
1068 if (tul_hcs
[7].HCS_Intr
!= irqno
)
1071 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1072 spin_lock_irqsave(&io_request_lock
, flags
);
1075 tul_isr(&tul_hcs
[7]);
1077 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1078 spin_unlock_irqrestore(&io_request_lock
, flags
);
1083 * Dump the current driver status and panic...
1085 static void i91u_panic(char *msg
)
1087 printk("\ni91u_panic: %s\n", msg
);
1088 panic("i91u panic");