OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [scsi/] [inia100.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.