Import 2.3.18pre1
[davej-history.git] / drivers / scsi / ini9100u.c
blobf37f2ae4d36012b8d543a3e0858958beec4ff7b1
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>
6 * All rights reserved.
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)
11 * any later version.
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
26 * are met:
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
53 * SUCH DAMAGE.
55 *************************************************************************
57 * DESCRIPTION:
59 * This is the Linux low-level SCSI driver for Initio INI-9X00U/UW SCSI host
60 * adapters
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
78 * - Support 0002134A
79 * 08/07/98 hc - v1.01o
80 * - Change the tul_abort_srb routine to use scsi_done. <01>
81 * 09/07/98 hl - v1.02
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.
88 * 09/21/98 hl - v1.03
89 * - remove comments.
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.
104 * Now fixed.
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>
113 #endif
115 #ifdef MODULE
116 #include <linux/module.h>
117 #endif
119 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
120 #include <stdarg.h>
121 #include <asm/irq.h>
122 #include <linux/errno.h>
123 #if LINUX_VERSION_CODE <= CVT_LINUX_VERSION(2,1,92)
124 #include <linux/bios32.h>
125 #endif
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>
130 #endif
131 #include <linux/blk.h>
132 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
133 #include <linux/spinlock.h>
134 #endif
135 #include <linux/stat.h>
136 #include <linux/config.h>
138 #else
140 #include <linux/head.h>
141 #include <linux/types.h>
142 #include <asm/system.h>
143 #include "../block/blk.h"
144 #endif
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>
151 #include <asm/io.h>
152 #include "scsi.h"
153 #include "sd.h"
154 #include "hosts.h"
155 #include <linux/malloc.h>
156 #include "ini9100u.h"
158 #ifdef DEBUG_i91u
159 unsigned int i91u_debug = DEBUG_DEFAULT;
160 #endif
162 #ifdef MODULE
163 Scsi_Host_Template driver_template = INI9100U;
164 #include "scsi_module.c"
165 #endif
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
179 #endif
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;
190 static SCB *tul_scb;
192 #ifdef DEBUG_i91u
193 static int setup_debug = 0;
194 #endif
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 *);
207 #else
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 *);
216 #endif
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 },
251 * queue services:
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
258 Output : None.
259 Return : None.
260 *****************************************************************************/
261 static void i91uAppendSRBToQueue(HCS * pHCB, Scsi_Cmnd * pSRB)
263 ULONG flags;
264 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
265 spin_lock_irqsave(&(pHCB->pSRB_lock), flags);
266 #else
267 save_flags(flags);
268 cli();
269 #endif
271 pSRB->next = NULL; /* Pointer to next */
273 if (pHCB->pSRB_head == NULL)
274 pHCB->pSRB_head = pSRB;
275 else
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);
281 #else
282 restore_flags(flags);
283 #endif
284 return;
287 /*****************************************************************************
288 Function name : i91uPopSRBFromQueue
289 Description : This function will pop current request from save list
290 Input : pHCB - Pointer to host adapter structure
291 Output : None.
292 Return : pSRB - Pointer to SCSI request block.
293 *****************************************************************************/
294 static Scsi_Cmnd *i91uPopSRBFromQueue(HCS * pHCB)
296 Scsi_Cmnd *pSRB;
297 ULONG flags;
299 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
300 spin_lock_irqsave(&(pHCB->pSRB_lock), flags);
301 #else
302 save_flags(flags);
303 cli();
304 #endif
306 if ((pSRB = pHCB->pSRB_head) != NULL) {
307 pHCB->pSRB_head = pHCB->pSRB_head->next;
308 pSRB->next = NULL;
310 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
311 spin_unlock_irqrestore(&(pHCB->pSRB_lock), flags);
312 #else
313 restore_flags(flags);
314 #endif
316 return (pSRB);
319 /* called from init/main.c */
321 void i91u_setup(char *str, int *ints)
323 if (setup_called)
324 i91u_panic("i91u: i91u_setup called twice.\n");
326 setup_called = ints[0];
327 setup_str = str;
329 #ifdef DEBUG_i91u
330 setup_debug = ints[0] >= 1 ? ints[1] : DEBUG_DEFAULT;
331 #endif
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 */
338 int iAdapters = 0;
339 long dRegValue;
340 WORD wBIOS;
341 int i = 0;
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)
351 dRegValue = 0;
352 wBIOS = (wBIOS << 8) + ((UWORD) ((dRegValue & 0xFF00) >> 8));
353 if (Addi91u_into_Adapter_table(wBIOS,
354 (pDev->resource[0].start),
355 pDev->irq,
356 pDev->bus->number,
357 (pDev->devfn >> 3)
358 ) == 0)
359 iAdapters++;
363 return (iAdapters);
366 #else /* <01> */
368 /*****************************************************************************
369 Function name : tul_ReturnNumberOfAdapters
370 Description : This function will scan PCI bus to get all Orchid card
371 Input : None.
372 Output : None.
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;
381 WORD wBIOS, wBASE;
382 BYTE bPCIBusNum, bInterrupt, bPCIDeviceNum;
384 iAdapters = 0;
386 * PCI-bus probe.
388 if (pcibios_present()) {
389 #ifdef MMAPIO
390 unsigned long page_offset, base;
391 #endif
393 int index;
394 unsigned char pci_bus, pci_devfn;
396 bPCIBusNum = 0;
397 bPCIDeviceNum = 0;
398 init_i91uAdapter_table();
399 for (i = 0; i < TULSZ(i91u_pci_devices); i++) {
400 index = 0;
401 while (!(pcibios_find_device(i91u_pci_devices[i].vendor_id,
402 i91u_pci_devices[i].device_id,
403 index++, &pci_bus, &pci_devfn)))
405 if (i == 2) {
406 printk("i91u: The RAID controller is not supported by\n");
407 printk("i91u: this driver, we are ignoring it.\n");
408 } else {
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,
415 &dRegValue);
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,
425 &dRegValue);
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);
433 #ifdef MMAPIO
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);
443 #else
444 wBASE = (WORD) vremap(base, page_offset + 256);
445 #endif
446 if (wBASE) {
447 wBASE += page_offset;
449 #endif
451 if (Addi91u_into_Adapter_table(wBIOS, wBASE, bInterrupt, bPCIBusNum,
452 bPCIDeviceNum) == 0x0)
453 iAdapters++;
455 } /* while(pdev=....) */
456 } /* for PCI_DEVICES */
457 } /* PCI BIOS present */
458 return (iAdapters);
460 #endif
462 int i91u_detect(Scsi_Host_Template * tpnt)
464 SCB *pSCB;
465 HCS *pHCB;
466 struct Scsi_Host *hreg;
467 unsigned long i; /* 01/14/98 */
468 int ok = 0, iAdapters;
469 ULONG dBiosAdr;
470 BYTE *pbBiosAdr;
472 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
473 tpnt->proc_dir = &proc_scsi_ini9100u;
474 #endif
476 if (setup_called) { /* Setup by i91u_setup */
477 printk("i91u: processing commandline: ");
479 #ifdef DEBUG_i91u
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;
486 #endif
488 /* Get total number of adapters in the motherboard */
489 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,93)
490 #ifdef CONFIG_PCI
491 iAdapters = tul_NewReturnNumberOfAdapters();
492 #else
493 iAdapters = tul_ReturnNumberOfAdapters();
494 #endif
495 #else
496 iAdapters = tul_ReturnNumberOfAdapters();
497 #endif
499 if (iAdapters == 0) /* If no tulip founded, return */
500 return (0);
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;
506 } else {
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)
519 break;
521 #else
522 i = tul_num_ch * tul_num_scb * sizeof(SCB);
523 tul_scb = (SCB *) scsi_init_malloc(i, GFP_ATOMIC | GFP_DMA);
524 #endif
525 if (tul_scb == NULL) {
526 printk("i91u: SCB memory allocation error\n");
527 return (0);
529 memset((unsigned char *) tul_scb, 0, i);
531 pSCB = tul_scb;
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]);
535 #else
536 pSCB->SCB_SGPAddr = (U32) (&pSCB->SCB_SGList[0]);
537 #endif
540 for (i = 0, pHCB = &tul_hcs[0]; /* Get pointer for control block */
541 i < tul_num_ch;
542 i++, pHCB++) {
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 */
547 #endif
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);
557 #endif
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;
568 #endif
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 */
576 switch (i) {
577 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(1,3,0)
578 case 0:
579 ok = request_irq(pHCB->HCS_Intr, i91u_intr0, SA_INTERRUPT | SA_SHIRQ, "i91u", NULL);
580 break;
581 case 1:
582 ok = request_irq(pHCB->HCS_Intr, i91u_intr1, SA_INTERRUPT | SA_SHIRQ, "i91u", NULL);
583 break;
584 case 2:
585 ok = request_irq(pHCB->HCS_Intr, i91u_intr2, SA_INTERRUPT | SA_SHIRQ, "i91u", NULL);
586 break;
587 case 3:
588 ok = request_irq(pHCB->HCS_Intr, i91u_intr3, SA_INTERRUPT | SA_SHIRQ, "i91u", NULL);
589 break;
590 case 4:
591 ok = request_irq(pHCB->HCS_Intr, i91u_intr4, SA_INTERRUPT | SA_SHIRQ, "i91u", NULL);
592 break;
593 case 5:
594 ok = request_irq(pHCB->HCS_Intr, i91u_intr5, SA_INTERRUPT | SA_SHIRQ, "i91u", NULL);
595 break;
596 case 6:
597 ok = request_irq(pHCB->HCS_Intr, i91u_intr6, SA_INTERRUPT | SA_SHIRQ, "i91u", NULL);
598 break;
599 case 7:
600 ok = request_irq(pHCB->HCS_Intr, i91u_intr7, SA_INTERRUPT | SA_SHIRQ, "i91u", NULL);
601 break;
602 default:
603 i91u_panic("i91u: Too many host adapters\n");
604 break;
606 if (ok < 0) {
607 if (ok == -EINVAL) {
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",
612 pHCB->HCS_Intr);
613 else {
614 printk("\ni91u: Unexpected error code on requesting IRQ %d.\n",
615 pHCB->HCS_Intr);
616 printk(" Contact author.\n");
618 i91u_panic("i91u: driver needs an IRQ.\n");
620 #endif
623 tpnt->this_id = -1;
624 tpnt->can_queue = 1;
626 return 1;
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 */
633 int i;
634 long TotalLen;
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);
647 #else
648 pSCB->SCB_SensePtr = (U32) (SCpnt->sense_buffer);
649 #endif
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 */
660 } else {
661 pSCB->SCB_TagMsg = 0; /* No tag support */
664 if (SCpnt->use_sg) {
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);
669 #else
670 pSCB->SCB_BufPtr = (U32) (pSrbSG->address);
671 #endif
672 TotalLen = pSrbSG->length;
673 pSCB->SCB_SGLen = 0;
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 */
678 i < SCpnt->use_sg;
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);
682 #else
683 pSG->SG_Ptr = (U32) (pSrbSG->address);
684 #endif
685 TotalLen += pSG->SG_Len = pSrbSG->length;
687 pSCB->SCB_SGLen = i;
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);
694 #else
695 pSCB->SCB_BufPtr = (U32) (SCpnt->request_buffer);
696 #endif
697 pSCB->SCB_BufLen = SCpnt->request_bufflen;
698 pSCB->SCB_SGLen = 0;
701 return;
705 * Queue a command and setup interrupts for a free bus.
707 int i91u_queue(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
709 register SCB *pSCB;
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 */
716 return (0);
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 */
724 return (0);
726 i91uBuildSCB(pHCB, pSCB, SCpnt);
727 tul_exec_scb(pHCB, pSCB); /* Start execute SCB */
728 return (0);
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");
737 return -1;
741 * Abort a queued command
742 * (commands that are on the bus can't be aborted easily)
744 int i91u_abort(Scsi_Cmnd * SCpnt)
746 HCS *pHCB;
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 */
758 HCS *pHCB;
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);
764 else
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)
773 #else
774 int i91u_biosparam(Scsi_Disk * disk, int dev, int *info_array)
775 #endif
777 HCS *pHcb; /* Point to Host adapter control block */
778 TCS *pTcb;
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;
787 } else {
788 if (pTcb->TCS_DrvFlags & TCF_DRV_255_63) {
789 info_array[0] = 255;
790 info_array[1] = 63;
791 info_array[2] = disk->capacity / 255 / 63;
792 } else {
793 info_array[0] = 64;
794 info_array[1] = 32;
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");
805 #endif
807 return 0;
810 /*****************************************************************************
811 Function name : i91uSCBPost
812 Description : This is callback routine be called when tulip finish one
813 SCSI command.
814 Input : pHCB - Pointer to host adapter control block.
815 pSCB - Pointer to SCSI control block.
816 Output : None.
817 Return : None.
818 *****************************************************************************/
819 static void i91uSCBPost(BYTE * pHcb, BYTE * pScb)
821 Scsi_Cmnd *pSRB; /* Pointer to SCSI request block */
822 HCS *pHCB;
823 SCB *pSCB;
825 pHCB = (HCS *) pHcb;
826 pSCB = (SCB *) pScb;
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 */
831 return;
833 switch (pSCB->SCB_HaStat) {
834 case 0x0:
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;
838 break;
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;
843 break;
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
848 a SCRD interrupt */
849 pSCB->SCB_HaStat = DID_RESET;
850 break;
852 case 0x1a: /* SCB Aborted. 07/21/98 */
853 pSCB->SCB_HaStat = DID_ABORT;
854 break;
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. */
862 default:
863 printk("ini9100u: %x %x\n", pSCB->SCB_HaStat, pSCB->SCB_TaStat);
864 pSCB->SCB_HaStat = DID_ERROR; /* Couldn't find any better */
865 break;
868 pSRB->result = pSCB->SCB_TaStat | (pSCB->SCB_HaStat << 16);
870 if (pSRB == NULL) {
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 */
877 /* Reuse old SCB */
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 */
884 return;
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)
892 #else
893 static void i91u_intr0(int irqno, struct pt_regs *regs)
894 #endif
896 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
897 unsigned long flags;
898 #endif
900 if (tul_hcs[0].HCS_Intr != irqno)
901 return;
903 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
904 spin_lock_irqsave(&io_request_lock, flags);
905 #endif
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);
911 #endif
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)
916 #else
917 static void i91u_intr1(int irqno, struct pt_regs *regs)
918 #endif
920 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
921 unsigned long flags;
922 #endif
924 if (tul_hcs[1].HCS_Intr != irqno)
925 return;
927 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
928 spin_lock_irqsave(&io_request_lock, flags);
929 #endif
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);
935 #endif
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)
940 #else
941 static void i91u_intr2(int irqno, struct pt_regs *regs)
942 #endif
944 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
945 unsigned long flags;
946 #endif
948 if (tul_hcs[2].HCS_Intr != irqno)
949 return;
951 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
952 spin_lock_irqsave(&io_request_lock, flags);
953 #endif
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);
959 #endif
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)
964 #else
965 static void i91u_intr3(int irqno, struct pt_regs *regs)
966 #endif
968 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
969 unsigned long flags;
970 #endif
972 if (tul_hcs[3].HCS_Intr != irqno)
973 return;
975 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
976 spin_lock_irqsave(&io_request_lock, flags);
977 #endif
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);
983 #endif
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)
988 #else
989 static void i91u_intr4(int irqno, struct pt_regs *regs)
990 #endif
992 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
993 unsigned long flags;
994 #endif
996 if (tul_hcs[4].HCS_Intr != irqno)
997 return;
999 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1000 spin_lock_irqsave(&io_request_lock, flags);
1001 #endif
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);
1007 #endif
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)
1012 #else
1013 static void i91u_intr5(int irqno, struct pt_regs *regs)
1014 #endif
1016 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1017 unsigned long flags;
1018 #endif
1020 if (tul_hcs[5].HCS_Intr != irqno)
1021 return;
1023 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1024 spin_lock_irqsave(&io_request_lock, flags);
1025 #endif
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);
1031 #endif
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)
1036 #else
1037 static void i91u_intr6(int irqno, struct pt_regs *regs)
1038 #endif
1040 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1041 unsigned long flags;
1042 #endif
1044 if (tul_hcs[6].HCS_Intr != irqno)
1045 return;
1047 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1048 spin_lock_irqsave(&io_request_lock, flags);
1049 #endif
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);
1055 #endif
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)
1060 #else
1061 static void i91u_intr7(int irqno, struct pt_regs *regs)
1062 #endif
1064 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1065 unsigned long flags;
1066 #endif
1068 if (tul_hcs[7].HCS_Intr != irqno)
1069 return;
1071 #if LINUX_VERSION_CODE >= CVT_LINUX_VERSION(2,1,95)
1072 spin_lock_irqsave(&io_request_lock, flags);
1073 #endif
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);
1079 #endif
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");