MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / scsi / ini9100u.c
blob96fa264b84edd75a1bf3e3746e81e55cfd9fbc73
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 General 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 * 10/17/03 mc - v1.04
108 * - added new DMA API support
109 * 06/01/04 jmd - v1.04a
110 * - Re-add reset_bus support
111 **************************************************************************/
113 #define CVT_LINUX_VERSION(V,P,S) (V * 65536 + P * 256 + S)
115 #ifndef LINUX_VERSION_CODE
116 #include <linux/version.h>
117 #endif
119 #include <linux/module.h>
120 #include <linux/errno.h>
121 #include <linux/delay.h>
122 #include <linux/pci.h>
123 #include <linux/init.h>
124 #include <linux/blkdev.h>
125 #include <linux/spinlock.h>
126 #include <linux/stat.h>
127 #include <linux/config.h>
128 #include <linux/kernel.h>
129 #include <linux/proc_fs.h>
130 #include <linux/string.h>
131 #include <linux/interrupt.h>
132 #include <linux/ioport.h>
133 #include <linux/sched.h>
134 #include <linux/slab.h>
136 #include <asm/io.h>
138 #include "scsi.h"
139 #include <scsi/scsi_host.h>
140 #include "ini9100u.h"
142 #ifdef DEBUG_i91u
143 unsigned int i91u_debug = DEBUG_DEFAULT;
144 #endif
146 static Scsi_Host_Template driver_template = {
147 .proc_name = "INI9100U",
148 .name = i91u_REVID,
149 .detect = i91u_detect,
150 .release = i91u_release,
151 .queuecommand = i91u_queue,
152 // .abort = i91u_abort,
153 // .reset = i91u_reset,
154 .eh_bus_reset_handler = i91u_bus_reset,
155 .bios_param = i91u_biosparam,
156 .can_queue = 1,
157 .this_id = 1,
158 .sg_tablesize = SG_ALL,
159 .cmd_per_lun = 1,
160 .use_clustering = ENABLE_CLUSTERING,
162 #include "scsi_module.c"
164 char *i91uCopyright = "Copyright (C) 1996-98";
165 char *i91uInitioName = "by Initio Corporation";
166 char *i91uProductName = "INI-9X00U/UW";
167 char *i91uVersion = "v1.04a";
169 #define TULSZ(sz) (sizeof(sz) / sizeof(sz[0]))
170 #define TUL_RDWORD(x,y) (short)(inl((int)((ULONG)((ULONG)x+(UCHAR)y)) ))
172 /* set by i91_setup according to the command line */
173 static int setup_called = 0;
175 static int tul_num_ch = 4; /* Maximum 4 adapters */
176 static int tul_num_scb;
177 static int tul_tag_enable = 1;
178 static SCB *tul_scb;
180 #ifdef DEBUG_i91u
181 static int setup_debug = 0;
182 #endif
184 static char *setup_str = (char *) NULL;
186 static void i91u_panic(char *msg);
188 static void i91uSCBPost(BYTE * pHcb, BYTE * pScb);
190 /* ---- EXTERNAL FUNCTIONS ---- */
191 /* Get total number of adapters */
192 extern void init_i91uAdapter_table(void);
193 extern int Addi91u_into_Adapter_table(WORD, WORD, BYTE, BYTE, BYTE);
194 extern int tul_ReturnNumberOfAdapters(void);
195 extern void get_tulipPCIConfig(HCS * pHCB, int iChannel_index);
196 extern int init_tulip(HCS * pHCB, SCB * pSCB, int tul_num_scb, BYTE * pbBiosAdr, int reset_time);
197 extern SCB *tul_alloc_scb(HCS * pHCB);
198 extern int tul_abort_srb(HCS * pHCB, Scsi_Cmnd * pSRB);
199 extern void tul_exec_scb(HCS * pHCB, SCB * pSCB);
200 extern void tul_release_scb(HCS * pHCB, SCB * pSCB);
201 extern void tul_stop_bm(HCS * pHCB);
202 extern int tul_reset_scsi(HCS * pCurHcb, int seconds);
203 extern int tul_isr(HCS * pHCB);
204 extern int tul_reset(HCS * pHCB, Scsi_Cmnd * pSRB, unsigned char target);
205 extern int tul_reset_scsi_bus(HCS * pCurHcb);
206 extern int tul_device_reset(HCS * pCurHcb, ULONG pSrb, unsigned int target, unsigned int ResetFlags);
207 /* ---- EXTERNAL VARIABLES ---- */
208 extern HCS tul_hcs[];
210 const PCI_ID i91u_pci_devices[] = {
211 { INI_VENDOR_ID, I950_DEVICE_ID },
212 { INI_VENDOR_ID, I940_DEVICE_ID },
213 { INI_VENDOR_ID, I935_DEVICE_ID },
214 { INI_VENDOR_ID, I920_DEVICE_ID },
215 { DMX_VENDOR_ID, I920_DEVICE_ID },
219 * queue services:
221 /*****************************************************************************
222 Function name : i91uAppendSRBToQueue
223 Description : This function will push current request into save list
224 Input : pSRB - Pointer to SCSI request block.
225 pHCB - Pointer to host adapter structure
226 Output : None.
227 Return : None.
228 *****************************************************************************/
229 static void i91uAppendSRBToQueue(HCS * pHCB, Scsi_Cmnd * pSRB)
231 ULONG flags;
232 spin_lock_irqsave(&(pHCB->pSRB_lock), flags);
234 pSRB->host_scribble = NULL; /* Pointer to next */
236 if (pHCB->pSRB_head == NULL)
237 pHCB->pSRB_head = pSRB;
238 else
239 pHCB->pSRB_tail->host_scribble = (char *)pSRB; /* Pointer to next */
240 pHCB->pSRB_tail = pSRB;
242 spin_unlock_irqrestore(&(pHCB->pSRB_lock), flags);
243 return;
246 /*****************************************************************************
247 Function name : i91uPopSRBFromQueue
248 Description : This function will pop current request from save list
249 Input : pHCB - Pointer to host adapter structure
250 Output : None.
251 Return : pSRB - Pointer to SCSI request block.
252 *****************************************************************************/
253 static Scsi_Cmnd *i91uPopSRBFromQueue(HCS * pHCB)
255 Scsi_Cmnd *pSRB;
256 ULONG flags;
258 spin_lock_irqsave(&(pHCB->pSRB_lock), flags);
260 if ((pSRB = pHCB->pSRB_head) != NULL) {
261 pHCB->pSRB_head = (struct scsi_cmnd *)pHCB->pSRB_head->host_scribble;
262 pSRB->host_scribble = NULL;
264 spin_unlock_irqrestore(&(pHCB->pSRB_lock), flags);
266 return (pSRB);
269 static irqreturn_t i91u_intr(int irqno, void *dev_id, struct pt_regs *regs)
271 struct Scsi_Host *dev = dev_id;
272 unsigned long flags;
274 spin_lock_irqsave(dev->host_lock, flags);
275 tul_isr((HCS *)dev->base);
276 spin_unlock_irqrestore(dev->host_lock, flags);
277 return IRQ_HANDLED;
280 /* called from init/main.c */
282 void i91u_setup(char *str, int *ints)
284 if (setup_called)
285 i91u_panic("i91u: i91u_setup called twice.\n");
287 setup_called = ints[0];
288 setup_str = str;
290 #ifdef DEBUG_i91u
291 setup_debug = ints[0] >= 1 ? ints[1] : DEBUG_DEFAULT;
292 #endif
295 int tul_NewReturnNumberOfAdapters(void)
297 struct pci_dev *pDev = NULL; /* Start from none */
298 int iAdapters = 0;
299 long dRegValue;
300 WORD wBIOS;
301 int i = 0;
303 init_i91uAdapter_table();
305 for (i = 0; i < TULSZ(i91u_pci_devices); i++)
307 while ((pDev = pci_find_device(i91u_pci_devices[i].vendor_id, i91u_pci_devices[i].device_id, pDev)) != NULL) {
308 if (pci_enable_device(pDev))
309 continue;
310 pci_read_config_dword(pDev, 0x44, (u32 *) & dRegValue);
311 wBIOS = (UWORD) (dRegValue & 0xFF);
312 if (((dRegValue & 0xFF00) >> 8) == 0xFF)
313 dRegValue = 0;
314 wBIOS = (wBIOS << 8) + ((UWORD) ((dRegValue & 0xFF00) >> 8));
315 if (pci_set_dma_mask(pDev, 0xffffffff)) {
316 printk(KERN_WARNING
317 "i91u: Could not set 32 bit DMA mask\n");
318 continue;
321 if (Addi91u_into_Adapter_table(wBIOS,
322 (pDev->resource[0].start),
323 pDev->irq,
324 pDev->bus->number,
325 (pDev->devfn >> 3)
326 ) == 0)
327 iAdapters++;
331 return (iAdapters);
334 int i91u_detect(Scsi_Host_Template * tpnt)
336 HCS *pHCB;
337 struct Scsi_Host *hreg;
338 unsigned long i; /* 01/14/98 */
339 int ok = 0, iAdapters;
340 ULONG dBiosAdr;
341 BYTE *pbBiosAdr;
343 tpnt->proc_name = "INI9100U";
345 if (setup_called) { /* Setup by i91u_setup */
346 printk("i91u: processing commandline: ");
348 #ifdef DEBUG_i91u
349 if (setup_called > 1) {
350 printk("\ni91u: %s\n", setup_str);
351 printk("i91u: usage: i91u[=<DEBUG>]\n");
352 i91u_panic("i91u panics in line %d", __LINE__);
354 i91u_debug = setup_debug;
355 #endif
357 /* Get total number of adapters in the motherboard */
358 iAdapters = tul_NewReturnNumberOfAdapters();
359 if (iAdapters == 0) /* If no tulip founded, return */
360 return (0);
362 tul_num_ch = (iAdapters > tul_num_ch) ? tul_num_ch : iAdapters;
363 /* Update actually channel number */
364 if (tul_tag_enable) { /* 1.01i */
365 tul_num_scb = MAX_TARGETS * i91u_MAXQUEUE;
366 } else {
367 tul_num_scb = MAX_TARGETS + 3; /* 1-tape, 1-CD_ROM, 1- extra */
368 } /* Update actually SCBs per adapter */
370 /* Get total memory needed for HCS */
371 i = tul_num_ch * sizeof(HCS);
372 memset((unsigned char *) &tul_hcs[0], 0, i); /* Initialize tul_hcs 0 */
373 /* Get total memory needed for SCB */
375 for (; tul_num_scb >= MAX_TARGETS + 3; tul_num_scb--) {
376 i = tul_num_ch * tul_num_scb * sizeof(SCB);
377 if ((tul_scb = (SCB *) kmalloc(i, GFP_ATOMIC | GFP_DMA)) != NULL)
378 break;
380 if (tul_scb == NULL) {
381 printk("i91u: SCB memory allocation error\n");
382 return (0);
384 memset((unsigned char *) tul_scb, 0, i);
386 for (i = 0, pHCB = &tul_hcs[0]; /* Get pointer for control block */
387 i < tul_num_ch;
388 i++, pHCB++) {
389 pHCB->pSRB_head = NULL; /* Initial SRB save queue */
390 pHCB->pSRB_tail = NULL; /* Initial SRB save queue */
391 pHCB->pSRB_lock = SPIN_LOCK_UNLOCKED; /* SRB save queue lock */
392 get_tulipPCIConfig(pHCB, i);
394 dBiosAdr = pHCB->HCS_BIOS;
395 dBiosAdr = (dBiosAdr << 4);
397 pbBiosAdr = phys_to_virt(dBiosAdr);
399 init_tulip(pHCB, tul_scb + (i * tul_num_scb), tul_num_scb, pbBiosAdr, 10);
400 request_region(pHCB->HCS_Base, 256, "i91u"); /* Register */
402 pHCB->HCS_Index = i; /* 7/29/98 */
403 hreg = scsi_register(tpnt, sizeof(HCS));
404 if(hreg == NULL) {
405 release_region(pHCB->HCS_Base, 256);
406 return 0;
408 hreg->io_port = pHCB->HCS_Base;
409 hreg->n_io_port = 0xff;
410 hreg->can_queue = tul_num_scb; /* 03/05/98 */
411 hreg->unique_id = pHCB->HCS_Base;
412 hreg->max_id = pHCB->HCS_MaxTar;
413 hreg->max_lun = 32; /* 10/21/97 */
414 hreg->irq = pHCB->HCS_Intr;
415 hreg->this_id = pHCB->HCS_SCSI_ID; /* Assign HCS index */
416 hreg->base = (unsigned long)pHCB;
417 hreg->sg_tablesize = TOTAL_SG_ENTRY; /* Maximun support is 32 */
419 /* Initial tulip chip */
420 ok = request_irq(pHCB->HCS_Intr, i91u_intr, SA_INTERRUPT | SA_SHIRQ, "i91u", hreg);
421 if (ok < 0) {
422 printk(KERN_WARNING "i91u: unable to request IRQ %d\n\n", pHCB->HCS_Intr);
423 return 0;
427 tpnt->this_id = -1;
428 tpnt->can_queue = 1;
430 return 1;
433 static void i91uBuildSCB(HCS * pHCB, SCB * pSCB, Scsi_Cmnd * SCpnt)
434 { /* Create corresponding SCB */
435 struct scatterlist *pSrbSG;
436 SG *pSG; /* Pointer to SG list */
437 int i;
438 long TotalLen;
439 dma_addr_t dma_addr;
441 pSCB->SCB_Post = i91uSCBPost; /* i91u's callback routine */
442 pSCB->SCB_Srb = SCpnt;
443 pSCB->SCB_Opcode = ExecSCSI;
444 pSCB->SCB_Flags = SCF_POST; /* After SCSI done, call post routine */
445 pSCB->SCB_Target = SCpnt->device->id;
446 pSCB->SCB_Lun = SCpnt->device->lun;
447 pSCB->SCB_Ident = SCpnt->device->lun | DISC_ALLOW;
449 pSCB->SCB_Flags |= SCF_SENSE; /* Turn on auto request sense */
450 dma_addr = dma_map_single(&pHCB->pci_dev->dev, SCpnt->sense_buffer,
451 SENSE_SIZE, DMA_FROM_DEVICE);
452 pSCB->SCB_SensePtr = cpu_to_le32((u32)dma_addr);
453 pSCB->SCB_SenseLen = cpu_to_le32(SENSE_SIZE);
454 SCpnt->SCp.ptr = (char *)(unsigned long)dma_addr;
456 pSCB->SCB_CDBLen = SCpnt->cmd_len;
457 pSCB->SCB_HaStat = 0;
458 pSCB->SCB_TaStat = 0;
459 memcpy(&pSCB->SCB_CDB[0], &SCpnt->cmnd, SCpnt->cmd_len);
461 if (SCpnt->device->tagged_supported) { /* Tag Support */
462 pSCB->SCB_TagMsg = SIMPLE_QUEUE_TAG; /* Do simple tag only */
463 } else {
464 pSCB->SCB_TagMsg = 0; /* No tag support */
466 /* todo handle map_sg error */
467 if (SCpnt->use_sg) {
468 dma_addr = dma_map_single(&pHCB->pci_dev->dev, &pSCB->SCB_SGList[0],
469 sizeof(struct SG_Struc) * TOTAL_SG_ENTRY,
470 DMA_BIDIRECTIONAL);
471 pSCB->SCB_BufPtr = cpu_to_le32((u32)dma_addr);
472 SCpnt->SCp.dma_handle = dma_addr;
474 pSrbSG = (struct scatterlist *) SCpnt->request_buffer;
475 pSCB->SCB_SGLen = dma_map_sg(&pHCB->pci_dev->dev, pSrbSG,
476 SCpnt->use_sg, SCpnt->sc_data_direction);
478 pSCB->SCB_Flags |= SCF_SG; /* Turn on SG list flag */
479 for (i = 0, TotalLen = 0, pSG = &pSCB->SCB_SGList[0]; /* 1.01g */
480 i < pSCB->SCB_SGLen; i++, pSG++, pSrbSG++) {
481 pSG->SG_Ptr = cpu_to_le32((u32)sg_dma_address(pSrbSG));
482 TotalLen += pSG->SG_Len = cpu_to_le32((u32)sg_dma_len(pSrbSG));
485 pSCB->SCB_BufLen = (SCpnt->request_bufflen > TotalLen) ?
486 TotalLen : SCpnt->request_bufflen;
487 } else if (SCpnt->request_bufflen) { /* Non SG */
488 dma_addr = dma_map_single(&pHCB->pci_dev->dev, SCpnt->request_buffer,
489 SCpnt->request_bufflen,
490 SCpnt->sc_data_direction);
491 SCpnt->SCp.dma_handle = dma_addr;
492 pSCB->SCB_BufPtr = cpu_to_le32((u32)dma_addr);
493 pSCB->SCB_BufLen = cpu_to_le32((u32)SCpnt->request_bufflen);
494 pSCB->SCB_SGLen = 0;
495 } else {
496 pSCB->SCB_BufLen = 0;
497 pSCB->SCB_SGLen = 0;
502 * Queue a command and setup interrupts for a free bus.
504 int i91u_queue(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
506 register SCB *pSCB;
507 HCS *pHCB; /* Point to Host adapter control block */
509 if (SCpnt->device->lun > 16) { /* 07/22/98 */
511 SCpnt->result = (DID_TIME_OUT << 16);
512 done(SCpnt); /* Notify system DONE */
513 return (0);
515 pHCB = (HCS *) SCpnt->device->host->base;
517 SCpnt->scsi_done = done;
518 /* Get free SCSI control block */
519 if ((pSCB = tul_alloc_scb(pHCB)) == NULL) {
520 i91uAppendSRBToQueue(pHCB, SCpnt); /* Buffer this request */
521 return (0);
523 i91uBuildSCB(pHCB, pSCB, SCpnt);
524 tul_exec_scb(pHCB, pSCB); /* Start execute SCB */
525 return (0);
529 * Abort a queued command
530 * (commands that are on the bus can't be aborted easily)
532 int i91u_abort(Scsi_Cmnd * SCpnt)
534 HCS *pHCB;
536 pHCB = (HCS *) SCpnt->device->host->base;
537 return tul_abort_srb(pHCB, SCpnt);
541 * Reset registers, reset a hanging bus and
542 * kill active and disconnected commands for target w/o soft reset
544 int i91u_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
545 { /* I need Host Control Block Information */
546 HCS *pHCB;
548 pHCB = (HCS *) SCpnt->device->host->base;
550 if (reset_flags & (SCSI_RESET_SUGGEST_BUS_RESET | SCSI_RESET_SUGGEST_HOST_RESET))
551 return tul_reset_scsi_bus(pHCB);
552 else
553 return tul_device_reset(pHCB, (ULONG) SCpnt, SCpnt->device->id, reset_flags);
556 int i91u_bus_reset(Scsi_Cmnd * SCpnt)
558 HCS *pHCB;
560 pHCB = (HCS *) SCpnt->device->host->base;
561 tul_reset_scsi(pHCB, 0);
562 return SUCCESS;
566 * Return the "logical geometry"
568 int i91u_biosparam(struct scsi_device *sdev, struct block_device *dev,
569 sector_t capacity, int *info_array)
571 HCS *pHcb; /* Point to Host adapter control block */
572 TCS *pTcb;
574 pHcb = (HCS *) sdev->host->base;
575 pTcb = &pHcb->HCS_Tcs[sdev->id];
577 if (pTcb->TCS_DrvHead) {
578 info_array[0] = pTcb->TCS_DrvHead;
579 info_array[1] = pTcb->TCS_DrvSector;
580 info_array[2] = (unsigned long)capacity / pTcb->TCS_DrvHead / pTcb->TCS_DrvSector;
581 } else {
582 if (pTcb->TCS_DrvFlags & TCF_DRV_255_63) {
583 info_array[0] = 255;
584 info_array[1] = 63;
585 info_array[2] = (unsigned long)capacity / 255 / 63;
586 } else {
587 info_array[0] = 64;
588 info_array[1] = 32;
589 info_array[2] = (unsigned long)capacity >> 11;
593 #if defined(DEBUG_BIOSPARAM)
594 if (i91u_debug & debug_biosparam) {
595 printk("bios geometry: head=%d, sec=%d, cyl=%d\n",
596 info_array[0], info_array[1], info_array[2]);
597 printk("WARNING: check, if the bios geometry is correct.\n");
599 #endif
601 return 0;
604 static void i91u_unmap_cmnd(struct pci_dev *pci_dev, struct scsi_cmnd *cmnd)
606 /* auto sense buffer */
607 if (cmnd->SCp.ptr) {
608 dma_unmap_single(&pci_dev->dev,
609 (dma_addr_t)((unsigned long)cmnd->SCp.ptr),
610 SENSE_SIZE, SCSI_DATA_READ);
611 cmnd->SCp.ptr = NULL;
614 /* request buffer */
615 if (cmnd->use_sg) {
616 dma_unmap_single(&pci_dev->dev, cmnd->SCp.dma_handle,
617 sizeof(struct SG_Struc) * TOTAL_SG_ENTRY,
618 DMA_BIDIRECTIONAL);
620 dma_unmap_sg(&pci_dev->dev, cmnd->request_buffer,
621 cmnd->use_sg,
622 cmnd->sc_data_direction);
623 } else if (cmnd->request_bufflen) {
624 dma_unmap_single(&pci_dev->dev, cmnd->SCp.dma_handle,
625 cmnd->request_bufflen,
626 cmnd->sc_data_direction);
630 /*****************************************************************************
631 Function name : i91uSCBPost
632 Description : This is callback routine be called when tulip finish one
633 SCSI command.
634 Input : pHCB - Pointer to host adapter control block.
635 pSCB - Pointer to SCSI control block.
636 Output : None.
637 Return : None.
638 *****************************************************************************/
639 static void i91uSCBPost(BYTE * pHcb, BYTE * pScb)
641 Scsi_Cmnd *pSRB; /* Pointer to SCSI request block */
642 HCS *pHCB;
643 SCB *pSCB;
645 pHCB = (HCS *) pHcb;
646 pSCB = (SCB *) pScb;
647 if ((pSRB = pSCB->SCB_Srb) == 0) {
648 printk("i91uSCBPost: SRB pointer is empty\n");
650 tul_release_scb(pHCB, pSCB); /* Release SCB for current channel */
651 return;
653 switch (pSCB->SCB_HaStat) {
654 case 0x0:
655 case 0xa: /* Linked command complete without error and linked normally */
656 case 0xb: /* Linked command complete without error interrupt generated */
657 pSCB->SCB_HaStat = 0;
658 break;
660 case 0x11: /* Selection time out-The initiator selection or target
661 reselection was not complete within the SCSI Time out period */
662 pSCB->SCB_HaStat = DID_TIME_OUT;
663 break;
665 case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
666 phase sequence was requested by the target. The host adapter
667 will generate a SCSI Reset Condition, notifying the host with
668 a SCRD interrupt */
669 pSCB->SCB_HaStat = DID_RESET;
670 break;
672 case 0x1a: /* SCB Aborted. 07/21/98 */
673 pSCB->SCB_HaStat = DID_ABORT;
674 break;
676 case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
677 than was allocated by the Data Length field or the sum of the
678 Scatter / Gather Data Length fields. */
679 case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
680 case 0x16: /* Invalid SCB Operation Code. */
682 default:
683 printk("ini9100u: %x %x\n", pSCB->SCB_HaStat, pSCB->SCB_TaStat);
684 pSCB->SCB_HaStat = DID_ERROR; /* Couldn't find any better */
685 break;
688 pSRB->result = pSCB->SCB_TaStat | (pSCB->SCB_HaStat << 16);
690 if (pSRB == NULL) {
691 printk("pSRB is NULL\n");
694 i91u_unmap_cmnd(pHCB->pci_dev, pSRB);
695 pSRB->scsi_done(pSRB); /* Notify system DONE */
696 if ((pSRB = i91uPopSRBFromQueue(pHCB)) != NULL)
697 /* Find the next pending SRB */
698 { /* Assume resend will success */
699 /* Reuse old SCB */
700 i91uBuildSCB(pHCB, pSCB, pSRB); /* Create corresponding SCB */
702 tul_exec_scb(pHCB, pSCB); /* Start execute SCB */
703 } else { /* No Pending SRB */
704 tul_release_scb(pHCB, pSCB); /* Release SCB for current channel */
706 return;
710 * Dump the current driver status and panic...
712 static void i91u_panic(char *msg)
714 printk("\ni91u_panic: %s\n", msg);
715 panic("i91u panic");
719 * Release ressources
721 int i91u_release(struct Scsi_Host *hreg)
723 free_irq(hreg->irq, hreg);
724 release_region(hreg->io_port, 256);
725 return 0;
727 MODULE_LICENSE("Dual BSD/GPL");