File: /usr/src/linux/drivers/scsi/inia100.c

1     /**************************************************************************
2      * Initio A100 device driver for Linux.
3      *
4      * Copyright (c) 1994-1998 Initio Corporation
5      * All rights reserved.
6      *
7      * This program is free software; you can redistribute it and/or modify
8      * it under the terms of the GNU General Public License as published by
9      * the Free Software Foundation; either version 2, or (at your option)
10      * any later version.
11      *
12      * This program is distributed in the hope that it will be useful,
13      * but WITHOUT ANY WARRANTY; without even the implied warranty of
14      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15      * GNU General Public License for more details.
16      *
17      * You should have received a copy of the GNU General Public License
18      * along with this program; see the file COPYING.  If not, write to
19      * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20      *
21      * --------------------------------------------------------------------------
22      *
23      * Redistribution and use in source and binary forms, with or without
24      * modification, are permitted provided that the following conditions
25      * are met:
26      * 1. Redistributions of source code must retain the above copyright
27      *    notice, this list of conditions, and the following disclaimer,
28      *    without modification, immediately at the beginning of the file.
29      * 2. Redistributions in binary form must reproduce the above copyright
30      *    notice, this list of conditions and the following disclaimer in the
31      *    documentation and/or other materials provided with the distribution.
32      * 3. The name of the author may not be used to endorse or promote products
33      *    derived from this software without specific prior written permission.
34      *
35      * Where this Software is combined with software released under the terms of 
36      * the GNU General Public License ("GPL") and the terms of the GPL would require the 
37      * combined work to also be released under the terms of the GPL, the terms
38      * and conditions of this License will apply in addition to those of the
39      * GPL with the exception of any terms or conditions of this License that
40      * conflict with, or are expressly prohibited by, the GPL.
41      *
42      * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
43      * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44      * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45      * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
46      * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47      * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48      * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49      * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50      * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51      * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52      * SUCH DAMAGE.
53      *
54      **************************************************************************
55      * 
56      * module: inia100.c
57      * DESCRIPTION:
58      * 	This is the Linux low-level SCSI driver for Initio INIA100 SCSI host
59      * 	adapters
60      * 09/24/98 hl - v1.02 initial production release.
61      * 12/19/98 bv - v1.02a Use spinlocks for 2.1.95 and up.
62      **************************************************************************/
63     
64     #define CVT_LINUX_VERSION(V,P,S)        (V * 65536 + P * 256 + S)
65     
66     #ifndef LINUX_VERSION_CODE
67     #include <linux/version.h>
68     #endif
69     
70     #ifdef MODULE
71     #include <linux/module.h>
72     #endif
73     
74     #include <stdarg.h>
75     #include <asm/irq.h>
76     #include <linux/errno.h>
77     #include <linux/delay.h>
78     #include <linux/pci.h>
79     #include <linux/init.h>
80     #include <linux/blk.h>
81     #include <linux/spinlock.h>
82     #include <linux/stat.h>
83     #include <linux/kernel.h>
84     #include <linux/string.h>
85     #include <linux/ioport.h>
86     #include <linux/sched.h>
87     #include <linux/proc_fs.h>
88     #include <asm/io.h>
89     #include "scsi.h"
90     #include "sd.h"
91     #include "hosts.h"
92     #include <linux/slab.h>
93     #include "inia100.h"
94     
95     static Scsi_Host_Template driver_template = INIA100;
96     #include "scsi_module.c"
97     
98     #define ORC_RDWORD(x,y)         (short)(inl((int)((ULONG)((ULONG)x+(UCHAR)y)) ))
99     
100     char *inia100_Copyright = "Copyright (C) 1998-99";
101     char *inia100_InitioName = "by Initio Corporation";
102     char *inia100_ProductName = "INI-A100U2W";
103     char *inia100_Version = "v1.02c";
104     
105     /* set by inia100_setup according to the command line */
106     static int setup_called = 0;
107     static int orc_num_ch = MAX_SUPPORTED_ADAPTERS;		/* Maximum 4 adapters           */
108     
109     /* ---- INTERNAL VARIABLES ---- */
110     #define NUMBER(arr)     (sizeof(arr) / sizeof(arr[0]))
111     static char *setup_str = (char *) NULL;
112     
113     static void inia100_intr0(int irq, void *dev_id, struct pt_regs *);
114     static void inia100_intr1(int irq, void *dev_id, struct pt_regs *);
115     static void inia100_intr2(int irq, void *dev_id, struct pt_regs *);
116     static void inia100_intr3(int irq, void *dev_id, struct pt_regs *);
117     static void inia100_intr4(int irq, void *dev_id, struct pt_regs *);
118     static void inia100_intr5(int irq, void *dev_id, struct pt_regs *);
119     static void inia100_intr6(int irq, void *dev_id, struct pt_regs *);
120     static void inia100_intr7(int irq, void *dev_id, struct pt_regs *);
121     
122     static void inia100_panic(char *msg);
123     void inia100SCBPost(BYTE * pHcb, BYTE * pScb);
124     
125     /* ---- EXTERNAL VARIABLES ---- */
126     extern int Addinia100_into_Adapter_table(WORD, WORD, BYTE, BYTE, BYTE);
127     extern void init_inia100Adapter_table(void);
128     extern ORC_SCB *orc_alloc_scb(ORC_HCS * hcsp);
129     extern void orc_exec_scb(ORC_HCS * hcsp, ORC_SCB * scbp);
130     extern void orc_release_scb(ORC_HCS * hcsp, ORC_SCB * scbp);
131     extern void orc_interrupt(ORC_HCS * hcsp);
132     extern int orc_device_reset(ORC_HCS * pHCB, ULONG SCpnt, unsigned int target, unsigned int ResetFlags);
133     extern int orc_reset_scsi_bus(ORC_HCS * pHCB);
134     extern int abort_SCB(ORC_HCS * hcsp, ORC_SCB * pScb);
135     extern int orc_abort_srb(ORC_HCS * hcsp, ULONG SCpnt);
136     extern void get_orcPCIConfig(ORC_HCS * pCurHcb, int ch_idx);
137     extern int init_orchid(ORC_HCS * hcsp);
138     
139     extern int orc_num_scb;
140     extern ORC_HCS orc_hcs[];
141     
142     /*****************************************************************************
143      Function name  : inia100AppendSRBToQueue
144      Description    : This function will push current request into save list
145      Input          : pSRB  -       Pointer to SCSI request block.
146     		  pHCB  -       Pointer to host adapter structure
147      Output         : None.
148      Return         : None.
149     *****************************************************************************/
150     static void inia100AppendSRBToQueue(ORC_HCS * pHCB, Scsi_Cmnd * pSRB)
151     {
152     	ULONG flags;
153     
154     	spin_lock_irqsave(&(pHCB->pSRB_lock), flags);
155     
156     	pSRB->next = NULL;	/* Pointer to next */
157     	if (pHCB->pSRB_head == NULL)
158     		pHCB->pSRB_head = pSRB;
159     	else
160     		pHCB->pSRB_tail->next = pSRB;	/* Pointer to next */
161     	pHCB->pSRB_tail = pSRB;
162     	spin_unlock_irqrestore(&(pHCB->pSRB_lock), flags);
163     	return;
164     }
165     
166     /*****************************************************************************
167      Function name  : inia100PopSRBFromQueue
168      Description    : This function will pop current request from save list
169      Input          : pHCB  -       Pointer to host adapter structure
170      Output         : None.
171      Return         : pSRB  -       Pointer to SCSI request block.
172     *****************************************************************************/
173     static Scsi_Cmnd *inia100PopSRBFromQueue(ORC_HCS * pHCB)
174     {
175     	Scsi_Cmnd *pSRB;
176     	ULONG flags;
177     	spin_lock_irqsave(&(pHCB->pSRB_lock), flags);
178     	if ((pSRB = (Scsi_Cmnd *) pHCB->pSRB_head) != NULL) {
179     		pHCB->pSRB_head = pHCB->pSRB_head->next;
180     		pSRB->next = NULL;
181     	}
182     	spin_unlock_irqrestore(&(pHCB->pSRB_lock), flags);
183     	return (pSRB);
184     }
185     
186     /*****************************************************************************
187      Function name  : inia100_setup
188      Description    : 
189      Input          : pHCB  -       Pointer to host adapter structure
190      Output         : None.
191      Return         : pSRB  -       Pointer to SCSI request block.
192     *****************************************************************************/
193     void inia100_setup(char *str, int *ints)
194     {
195     	if (setup_called)
196     		inia100_panic("inia100: inia100_setup called twice.\n");
197     
198     	setup_called = ints[0];
199     	setup_str = str;
200     }
201     
202     /*****************************************************************************
203      Function name	: orc_ReturnNumberOfAdapters
204      Description	: This function will scan PCI bus to get all Orchid card
205      Input		: None.
206      Output		: None.
207      Return		: SUCCESSFUL	- Successful scan
208     		  ohterwise	- No drives founded
209     *****************************************************************************/
210     int orc_ReturnNumberOfAdapters(void)
211     {
212     	unsigned int i, iAdapters;
213     
214     	iAdapters = 0;
215     	/*
216     	 * PCI-bus probe.
217     	 */
218     	if (pcibios_present()) {
219     		struct {
220     			unsigned short vendor_id;
221     			unsigned short device_id;
222     		} const inia100_pci_devices[] =
223     		{
224     			{ORC_VENDOR_ID, I920_DEVICE_ID},
225     			{ORC_VENDOR_ID, ORC_DEVICE_ID}
226     		};
227     
228     		unsigned int dRegValue;
229     		WORD wBIOS, wBASE;
230     		BYTE bPCIBusNum, bInterrupt, bPCIDeviceNum;
231     
232     #ifdef MMAPIO
233     		unsigned long page_offset, base;
234     #endif
235     
236     		struct pci_dev *pdev = NULL;
237     
238     		bPCIBusNum = 0;
239     		bPCIDeviceNum = 0;
240     		init_inia100Adapter_table();
241     		for (i = 0; i < NUMBER(inia100_pci_devices); i++) {
242     			pdev = NULL;
243     			while ((pdev = pci_find_device(inia100_pci_devices[i].vendor_id,
244     					inia100_pci_devices[i].device_id,
245     						       pdev)))
246     			{
247     				if (pci_enable_device(pdev))
248     					continue;
249     				if (iAdapters >= MAX_SUPPORTED_ADAPTERS)
250     					break;	/* Never greater than maximum   */
251     
252     				if (i == 0) {
253     					/*
254     					   printk("inia100: The RAID controller is not supported by\n");
255     					   printk("inia100:         this driver, we are ignoring it.\n");
256     					 */
257     				} else {
258     					/*
259     					 * Read sundry information from PCI BIOS.
260     					 */
261     					bPCIBusNum = pdev->bus->number;
262     					bPCIDeviceNum = pdev->devfn;
263     					dRegValue = pci_resource_start(pdev, 0);
264     					if (dRegValue == -1) {	/* Check return code            */
265     						printk("\n\rinia100: orchid read configuration error.\n");
266     						return (0);	/* Read configuration space error  */
267     					}
268     
269     					/* <02> read from base address + 0x50 offset to get the wBIOS balue. */
270     					wBASE = (WORD) dRegValue;
271     
272     					/* Now read the interrupt line value */
273     					dRegValue = pdev->irq;
274     					bInterrupt = dRegValue;		/* Assign interrupt line      */
275     
276     					wBIOS = ORC_RDWORD(wBASE, 0x50);
277     
278     					pci_set_master(pdev);
279     
280     #ifdef MMAPIO
281     					base = wBASE & PAGE_MASK;
282     					page_offset = wBASE - base;
283     
284     					/*
285     					 * replace the next line with this one if you are using 2.1.x:
286     					 * temp_p->maddr = ioremap(base, page_offset + 256);
287     					 */
288     					wBASE = ioremap(base, page_offset + 256);
289     					if (wBASE) {
290     						wBASE += page_offset;
291     					}
292     #endif
293     
294     					if (Addinia100_into_Adapter_table(wBIOS, wBASE, bInterrupt, bPCIBusNum,
295     					    bPCIDeviceNum) == SUCCESSFUL)
296     						iAdapters++;
297     				}
298     			}	/* while(pdev=....) */
299     		}		/* for PCI_DEVICES */
300     	}			/* PCI BIOS present */
301     	return (iAdapters);
302     }
303     
304     /*****************************************************************************
305      Function name  : inia100_detect
306      Description    : 
307      Input          : pHCB  -       Pointer to host adapter structure
308      Output         : None.
309      Return         : pSRB  -       Pointer to SCSI request block.
310     *****************************************************************************/
311     int inia100_detect(Scsi_Host_Template * tpnt)
312     {
313     	ORC_HCS *pHCB;
314     	struct Scsi_Host *hreg;
315     	U32 sz;
316     	U32 i;			/* 01/14/98                     */
317     	int ok = 0, iAdapters;
318     	ULONG dBiosAdr;
319     	BYTE *pbBiosAdr;
320     
321     	tpnt->proc_name = "INIA100";
322     	if (setup_called) {
323     		/* Setup by inia100_setup          */
324     		printk("inia100: processing commandline: ");
325     	}
326     	/* Get total number of adapters in the motherboard */
327     	iAdapters = orc_ReturnNumberOfAdapters();
328     
329     	/* printk("inia100: Total Initio Adapters = %d\n", iAdapters); */
330     	if (iAdapters == 0)	/* If no orc founded, return */
331     		return (0);
332     
333     	orc_num_ch = (iAdapters > orc_num_ch) ? orc_num_ch : iAdapters;
334     	orc_num_scb = ORC_MAXQUEUE;
335     
336     	/* clear the memory needed for HCS */
337     	i = orc_num_ch * sizeof(ORC_HCS);
338     	memset((unsigned char *) &orc_hcs[0], 0, i);	/* Initialize orc_hcs 0   */
339     
340     #if 0
341     	printk("orc_num_scb= %x orc_num_ch= %x hcsize= %x scbsize= %x escbsize= %x\n",
342     	       orc_num_scb, orc_num_ch, sizeof(ORC_HCS), sizeof(ORC_SCB), sizeof(ESCB));
343     #endif
344     
345     	for (i = 0, pHCB = &orc_hcs[0];		/* Get pointer for control block */
346     	     i < orc_num_ch;
347     	     i++, pHCB++) {
348     
349     		pHCB->pSRB_head = NULL;		/* Initial SRB save queue       */
350     		pHCB->pSRB_tail = NULL;		/* Initial SRB save queue       */
351     		pHCB->pSRB_lock = SPIN_LOCK_UNLOCKED; /* SRB save queue lock */
352     		pHCB->BitAllocFlagLock = SPIN_LOCK_UNLOCKED;
353     		/* Get total memory needed for SCB */
354     		sz = orc_num_scb * sizeof(ORC_SCB);
355     		if ((pHCB->HCS_virScbArray = (PVOID) kmalloc(sz, GFP_ATOMIC | GFP_DMA)) == NULL) {
356     			printk("inia100: SCB memory allocation error\n");
357     			return (0);
358     		}
359     		memset((unsigned char *) pHCB->HCS_virScbArray, 0, sz);
360     		pHCB->HCS_physScbArray = (U32) VIRT_TO_BUS(pHCB->HCS_virScbArray);
361     
362     		/* Get total memory needed for ESCB */
363     		sz = orc_num_scb * sizeof(ESCB);
364     		if ((pHCB->HCS_virEscbArray = (PVOID) kmalloc(sz, GFP_ATOMIC | GFP_DMA)) == NULL) {
365     			printk("inia100: ESCB memory allocation error\n");
366     			/* ?? does pHCB->HCS_virtScbArray leak ??*/
367     			return (0);
368     		}
369     		memset((unsigned char *) pHCB->HCS_virEscbArray, 0, sz);
370     		pHCB->HCS_physEscbArray = (U32) VIRT_TO_BUS(pHCB->HCS_virEscbArray);
371     
372     		get_orcPCIConfig(pHCB, i);
373     
374     		dBiosAdr = pHCB->HCS_BIOS;
375     		dBiosAdr = (dBiosAdr << 4);
376     
377     		pbBiosAdr = phys_to_virt(dBiosAdr);
378     
379     		if (init_orchid(pHCB)) {	/* Initial orchid chip    */
380     			printk("inia100: initial orchid fail!!\n");
381     			return (0);
382     		}
383     		request_region(pHCB->HCS_Base, 256, "inia100");	/* Register */
384     
385     		hreg = scsi_register(tpnt, sizeof(ORC_HCS));
386     		if (hreg == NULL) {
387     			release_region(pHCB->HCS_Base, 256);	/* Register */
388     			return 0;
389     		}
390     		hreg->io_port = pHCB->HCS_Base;
391     		hreg->n_io_port = 0xff;
392     		hreg->can_queue = orc_num_scb;	/* 03/05/98                   */
393     
394     		hreg->unique_id = pHCB->HCS_Base;
395     		hreg->max_id = pHCB->HCS_MaxTar;
396     
397     		hreg->max_lun = 32;	/* 10/21/97                     */
398     /*
399        hreg->max_lun = 8;
400        hreg->max_channel = 1;
401      */
402     		hreg->irq = pHCB->HCS_Intr;
403     		hreg->this_id = pHCB->HCS_SCSI_ID;	/* Assign HCS index           */
404     		hreg->base = (unsigned long)pHCB;
405     
406     #if 1
407     		hreg->sg_tablesize = TOTAL_SG_ENTRY;	/* Maximun support is 32 */
408     #else
409     		hreg->sg_tablesize = SG_NONE;	/* No SG                        */
410     #endif
411     
412     		/* Initial orc chip           */
413     		switch (i) {
414     		case 0:
415     			ok = request_irq(pHCB->HCS_Intr, inia100_intr0, SA_INTERRUPT | SA_SHIRQ, "inia100", hreg);
416     			break;
417     		case 1:
418     			ok = request_irq(pHCB->HCS_Intr, inia100_intr1, SA_INTERRUPT | SA_SHIRQ, "inia100", hreg);
419     			break;
420     		case 2:
421     			ok = request_irq(pHCB->HCS_Intr, inia100_intr2, SA_INTERRUPT | SA_SHIRQ, "inia100", hreg);
422     			break;
423     		case 3:
424     			ok = request_irq(pHCB->HCS_Intr, inia100_intr3, SA_INTERRUPT | SA_SHIRQ, "inia100", hreg);
425     			break;
426     		case 4:
427     			ok = request_irq(pHCB->HCS_Intr, inia100_intr4, SA_INTERRUPT | SA_SHIRQ, "inia100", hreg);
428     			break;
429     		case 5:
430     			ok = request_irq(pHCB->HCS_Intr, inia100_intr5, SA_INTERRUPT | SA_SHIRQ, "inia100", hreg);
431     			break;
432     		case 6:
433     			ok = request_irq(pHCB->HCS_Intr, inia100_intr6, SA_INTERRUPT | SA_SHIRQ, "inia100", hreg);
434     			break;
435     		case 7:
436     			ok = request_irq(pHCB->HCS_Intr, inia100_intr7, SA_INTERRUPT | SA_SHIRQ, "inia100", hreg);
437     			break;
438     		default:
439     			inia100_panic("inia100: Too many host adapters\n");
440     			break;
441     		}
442     
443     		if (ok < 0) {
444     			if (ok == -EINVAL) {
445     				printk("inia100: bad IRQ %d.\n", pHCB->HCS_Intr);
446     				printk("         Contact author.\n");
447     			} else {
448     				if (ok == -EBUSY)
449     					printk("inia100: IRQ %d already in use. Configure another.\n", pHCB->HCS_Intr);
450     				else {
451     					printk("\ninia100: Unexpected error code on requesting IRQ %d.\n",
452     					       pHCB->HCS_Intr);
453     					printk("         Contact author.\n");
454     				}
455     			}
456     			inia100_panic("inia100: driver needs an IRQ.\n");
457     		}
458     	}
459     
460     	tpnt->this_id = -1;
461     	tpnt->can_queue = 1;
462     	return 1;
463     }
464     
465     /*****************************************************************************
466      Function name  : inia100BuildSCB
467      Description    : 
468      Input          : pHCB  -       Pointer to host adapter structure
469      Output         : None.
470      Return         : pSRB  -       Pointer to SCSI request block.
471     *****************************************************************************/
472     static void inia100BuildSCB(ORC_HCS * pHCB, ORC_SCB * pSCB, Scsi_Cmnd * SCpnt)
473     {				/* Create corresponding SCB     */
474     	struct scatterlist *pSrbSG;
475     	ORC_SG *pSG;		/* Pointer to SG list           */
476     	int i;
477     	U32 TotalLen;
478     	ESCB *pEScb;
479     
480     	pEScb = pSCB->SCB_EScb;
481     	pEScb->SCB_Srb = SCpnt;
482     	pSG = NULL;
483     
484     	pSCB->SCB_Opcode = ORC_EXECSCSI;
485     	pSCB->SCB_Flags = SCF_NO_DCHK;	/* Clear done bit               */
486     	pSCB->SCB_Target = SCpnt->target;
487     	pSCB->SCB_Lun = SCpnt->lun;
488     	pSCB->SCB_Reserved0 = 0;
489     	pSCB->SCB_Reserved1 = 0;
490     	pSCB->SCB_SGLen = 0;
491     
492     	if ((pSCB->SCB_XferLen = (U32) SCpnt->request_bufflen)) {
493     		pSG = (ORC_SG *) & pEScb->ESCB_SGList[0];
494     		if (SCpnt->use_sg) {
495     			TotalLen = 0;
496     			pSCB->SCB_SGLen = (U32) (SCpnt->use_sg * 8);
497     			pSrbSG = (struct scatterlist *) SCpnt->request_buffer;
498     			for (i = 0; i < SCpnt->use_sg; i++, pSG++, pSrbSG++) {
499     				pSG->SG_Ptr = (U32) (VIRT_TO_BUS(pSrbSG->address));
500     				pSG->SG_Len = (U32) pSrbSG->length;
501     				TotalLen += (U32) pSrbSG->length;
502     			}
503     		} else {	/* Non SG                       */
504     			pSCB->SCB_SGLen = 0x8;
505     			pSG->SG_Ptr = (U32) (VIRT_TO_BUS(SCpnt->request_buffer));
506     			pSG->SG_Len = (U32) SCpnt->request_bufflen;
507     		}
508     	}
509     	pSCB->SCB_SGPAddr = (U32) pSCB->SCB_SensePAddr;
510     	pSCB->SCB_HaStat = 0;
511     	pSCB->SCB_TaStat = 0;
512     	pSCB->SCB_Link = 0xFF;
513     	pSCB->SCB_SenseLen = SENSE_SIZE;
514     	pSCB->SCB_CDBLen = SCpnt->cmd_len;
515     	if (pSCB->SCB_CDBLen >= IMAX_CDB) {
516     		printk("max cdb length= %x\b", SCpnt->cmd_len);
517     		pSCB->SCB_CDBLen = IMAX_CDB;
518     	}
519     	pSCB->SCB_Ident = SCpnt->lun | DISC_ALLOW;
520     	if (SCpnt->device->tagged_supported) {	/* Tag Support                  */
521     		pSCB->SCB_TagMsg = SIMPLE_QUEUE_TAG;	/* Do simple tag only   */
522     	} else {
523     		pSCB->SCB_TagMsg = 0;	/* No tag support               */
524     	}
525     	memcpy(&pSCB->SCB_CDB[0], &SCpnt->cmnd, pSCB->SCB_CDBLen);
526     	return;
527     }
528     
529     /*****************************************************************************
530      Function name  : inia100_queue
531      Description    : Queue a command and setup interrupts for a free bus.
532      Input          : pHCB  -       Pointer to host adapter structure
533      Output         : None.
534      Return         : pSRB  -       Pointer to SCSI request block.
535     *****************************************************************************/
536     int inia100_queue(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
537     {
538     	register ORC_SCB *pSCB;
539     	ORC_HCS *pHCB;		/* Point to Host adapter control block */
540     
541     	if (SCpnt->lun > 16) {
542     		SCpnt->result = (DID_TIME_OUT << 16);
543     		done(SCpnt);	/* Notify system DONE           */
544     		return (0);
545     	}
546     	pHCB = (ORC_HCS *) SCpnt->host->base;
547     	SCpnt->scsi_done = done;
548     	/* Get free SCSI control block  */
549     	if ((pSCB = orc_alloc_scb(pHCB)) == NULL) {
550     		inia100AppendSRBToQueue(pHCB, SCpnt);	/* Buffer this request  */
551     		/* printk("inia100_entry: can't allocate SCB\n"); */
552     		return (0);
553     	}
554     	inia100BuildSCB(pHCB, pSCB, SCpnt);
555     	orc_exec_scb(pHCB, pSCB);	/* Start execute SCB            */
556     
557     	return (0);
558     }
559     
560     /*****************************************************************************
561      Function name  : inia100_command
562      Description    : We only support command in interrupt-driven fashion
563      Input          : pHCB  -       Pointer to host adapter structure
564      Output         : None.
565      Return         : pSRB  -       Pointer to SCSI request block.
566     *****************************************************************************/
567     int inia100_command(Scsi_Cmnd * SCpnt)
568     {
569     	printk("inia100: interrupt driven driver; use inia100_queue()\n");
570     	return -1;
571     }
572     
573     /*****************************************************************************
574      Function name  : inia100_abort
575      Description    : Abort a queued command.
576     	                 (commands that are on the bus can't be aborted easily)
577      Input          : pHCB  -       Pointer to host adapter structure
578      Output         : None.
579      Return         : pSRB  -       Pointer to SCSI request block.
580     *****************************************************************************/
581     int inia100_abort(Scsi_Cmnd * SCpnt)
582     {
583     	ORC_HCS *hcsp;
584     
585     	hcsp = (ORC_HCS *) SCpnt->host->base;
586     	return orc_abort_srb(hcsp, (ULONG) SCpnt);
587     }
588     
589     /*****************************************************************************
590      Function name  : inia100_reset
591      Description    : Reset registers, reset a hanging bus and
592                       kill active and disconnected commands for target w/o soft reset
593      Input          : pHCB  -       Pointer to host adapter structure
594      Output         : None.
595      Return         : pSRB  -       Pointer to SCSI request block.
596     *****************************************************************************/
597     int inia100_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
598     {				/* I need Host Control Block Information */
599     	ORC_HCS *pHCB;
600     	pHCB = (ORC_HCS *) SCpnt->host->base;
601     
602     	if (reset_flags & (SCSI_RESET_SUGGEST_BUS_RESET | SCSI_RESET_SUGGEST_HOST_RESET))
603     		return orc_reset_scsi_bus(pHCB);
604     	else
605     		return orc_device_reset(pHCB, (ULONG) SCpnt, SCpnt->target, reset_flags);
606     
607     }
608     
609     /*****************************************************************************
610      Function name  : inia100SCBPost
611      Description    : This is callback routine be called when orc finish one
612     			SCSI command.
613      Input          : pHCB  -       Pointer to host adapter control block.
614     		  pSCB  -       Pointer to SCSI control block.
615      Output         : None.
616      Return         : None.
617     *****************************************************************************/
618     void inia100SCBPost(BYTE * pHcb, BYTE * pScb)
619     {
620     	Scsi_Cmnd *pSRB;	/* Pointer to SCSI request block */
621     	ORC_HCS *pHCB;
622     	ORC_SCB *pSCB;
623     	ESCB *pEScb;
624     
625     	pHCB = (ORC_HCS *) pHcb;
626     	pSCB = (ORC_SCB *) pScb;
627     	pEScb = pSCB->SCB_EScb;
628     	if ((pSRB = (Scsi_Cmnd *) pEScb->SCB_Srb) == 0) {
629     		printk("inia100SCBPost: SRB pointer is empty\n");
630     		orc_release_scb(pHCB, pSCB);	/* Release SCB for current channel */
631     		return;
632     	}
633     	pEScb->SCB_Srb = NULL;
634     
635     	switch (pSCB->SCB_HaStat) {
636     	case 0x0:
637     	case 0xa:		/* Linked command complete without error and linked normally */
638     	case 0xb:		/* Linked command complete without error interrupt generated */
639     		pSCB->SCB_HaStat = 0;
640     		break;
641     
642     	case 0x11:		/* Selection time out-The initiator selection or target
643     				   reselection was not complete within the SCSI Time out period */
644     		pSCB->SCB_HaStat = DID_TIME_OUT;
645     		break;
646     
647     	case 0x14:		/* Target bus phase sequence failure-An invalid bus phase or bus
648     				   phase sequence was requested by the target. The host adapter
649     				   will generate a SCSI Reset Condition, notifying the host with
650     				   a SCRD interrupt */
651     		pSCB->SCB_HaStat = DID_RESET;
652     		break;
653     
654     	case 0x1a:		/* SCB Aborted. 07/21/98 */
655     		pSCB->SCB_HaStat = DID_ABORT;
656     		break;
657     
658     	case 0x12:		/* Data overrun/underrun-The target attempted to transfer more data
659     				   than was allocated by the Data Length field or the sum of the
660     				   Scatter / Gather Data Length fields. */
661     	case 0x13:		/* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
662     	case 0x16:		/* Invalid CCB Operation Code-The first byte of the CCB was invalid. */
663     
664     	default:
665     		printk("inia100: %x %x\n", pSCB->SCB_HaStat, pSCB->SCB_TaStat);
666     		pSCB->SCB_HaStat = DID_ERROR;	/* Couldn't find any better */
667     		break;
668     	}
669     
670     	if (pSCB->SCB_TaStat == 2) {	/* Check condition              */
671     		memcpy((unsigned char *) &pSRB->sense_buffer[0],
672     		   (unsigned char *) &pEScb->ESCB_SGList[0], SENSE_SIZE);
673     	}
674     	pSRB->result = pSCB->SCB_TaStat | (pSCB->SCB_HaStat << 16);
675     	pSRB->scsi_done(pSRB);	/* Notify system DONE           */
676     
677     	/* Find the next pending SRB    */
678     	if ((pSRB = inia100PopSRBFromQueue(pHCB)) != NULL) {	/* Assume resend will success   */
679     		/* Reuse old SCB                */
680     		inia100BuildSCB(pHCB, pSCB, pSRB);	/* Create corresponding SCB     */
681     		orc_exec_scb(pHCB, pSCB);	/* Start execute SCB            */
682     	} else {		/* No Pending SRB               */
683     		orc_release_scb(pHCB, pSCB);	/* Release SCB for current channel */
684     	}
685     	return;
686     }
687     
688     /*****************************************************************************
689      Function name  : inia100_biosparam
690      Description    : Return the "logical geometry"
691      Input          : pHCB  -       Pointer to host adapter structure
692      Output         : None.
693      Return         : pSRB  -       Pointer to SCSI request block.
694     *****************************************************************************/
695     int inia100_biosparam(Scsi_Disk * disk, kdev_t dev, int *info_array)
696     {
697     	ORC_HCS *pHcb;		/* Point to Host adapter control block */
698     	ORC_TCS *pTcb;
699     
700     	pHcb = (ORC_HCS *) disk->device->host->base;
701     	pTcb = &pHcb->HCS_Tcs[disk->device->id];
702     
703     	if (pTcb->TCS_DrvHead) {
704     		info_array[0] = pTcb->TCS_DrvHead;
705     		info_array[1] = pTcb->TCS_DrvSector;
706     		info_array[2] = disk->capacity / pTcb->TCS_DrvHead / pTcb->TCS_DrvSector;
707     	} else {
708     		if (pTcb->TCS_DrvFlags & TCF_DRV_255_63) {
709     			info_array[0] = 255;
710     			info_array[1] = 63;
711     			info_array[2] = disk->capacity / 255 / 63;
712     		} else {
713     			info_array[0] = 64;
714     			info_array[1] = 32;
715     			info_array[2] = disk->capacity >> 11;
716     		}
717     	}
718     	return 0;
719     }
720     
721     
722     static void subIntr(ORC_HCS * pHCB, int irqno)
723     {
724     	unsigned long flags;
725     
726     	spin_lock_irqsave(&io_request_lock, flags);
727     
728     	if (pHCB->HCS_Intr != irqno) {
729     		spin_unlock_irqrestore(&io_request_lock, flags);
730     		return;
731     	}
732     	orc_interrupt(pHCB);
733     
734     	spin_unlock_irqrestore(&io_request_lock, flags);
735     }
736     
737     /*
738      * Interrupts handler (main routine of the driver)
739      */
740     static void inia100_intr0(int irqno, void *dev_id, struct pt_regs *regs)
741     {
742     	subIntr(&orc_hcs[0], irqno);
743     }
744     
745     static void inia100_intr1(int irqno, void *dev_id, struct pt_regs *regs)
746     {
747     	subIntr(&orc_hcs[1], irqno);
748     }
749     
750     static void inia100_intr2(int irqno, void *dev_id, struct pt_regs *regs)
751     {
752     	subIntr(&orc_hcs[2], irqno);
753     }
754     
755     static void inia100_intr3(int irqno, void *dev_id, struct pt_regs *regs)
756     {
757     	subIntr(&orc_hcs[3], irqno);
758     }
759     
760     static void inia100_intr4(int irqno, void *dev_id, struct pt_regs *regs)
761     {
762     	subIntr(&orc_hcs[4], irqno);
763     }
764     
765     static void inia100_intr5(int irqno, void *dev_id, struct pt_regs *regs)
766     {
767     	subIntr(&orc_hcs[5], irqno);
768     }
769     
770     static void inia100_intr6(int irqno, void *dev_id, struct pt_regs *regs)
771     {
772     	subIntr(&orc_hcs[6], irqno);
773     }
774     
775     static void inia100_intr7(int irqno, void *dev_id, struct pt_regs *regs)
776     {
777     	subIntr(&orc_hcs[7], irqno);
778     }
779     
780     /* 
781      * Dump the current driver status and panic...
782      */
783     static void inia100_panic(char *msg)
784     {
785     	printk("\ninia100_panic: %s\n", msg);
786     	panic("inia100 panic");
787     }
788     
789     /*
790      * Release ressources
791      */
792     int inia100_release(struct Scsi_Host *hreg)
793     {
794             free_irq(hreg->irq, hreg);
795             release_region(hreg->io_port, 256);
796             return 0;
797     } 
798     
799     /*#include "inia100scsi.c" */
800