Annotation of Gnu-Mach/i386/i386at/gpl/linux/scsi/eata_dma.c, revision 1.1.1.1

1.1       root        1: /************************************************************
                      2:  *                                                         *
                      3:  *                 Linux EATA SCSI driver                  *
                      4:  *                                                         *
                      5:  *  based on the CAM document CAM/89-004 rev. 2.0c,        *
                      6:  *  DPT's driver kit, some internal documents and source,   *
                      7:  *  and several other Linux scsi drivers and kernel docs.   *
                      8:  *                                                         *
                      9:  *  The driver currently:                                  *
                     10:  *     -supports all ISA based EATA-DMA boards             *
                     11:  *     -supports all EISA based EATA-DMA boards            *
                     12:  *     -supports all PCI based EATA-DMA boards             *
                     13:  *     -supports multiple HBAs with & without IRQ sharing  *
                     14:  *     -supports all SCSI channels on multi channel boards *
                     15:  *     -needs identical IDs on all channels of a HBA       * 
                     16:  *     -can be loaded as module                            *
                     17:  *     -displays statistical and hardware information      *
                     18:  *      in /proc/scsi/eata_dma                             *
                     19:  *      -provides rudimentary latency measurement           * 
                     20:  *       possibilities via /proc/scsi/eata_dma/<hostnum>    *
                     21:  *                                                         *
                     22:  *  (c)1993,94,95 Michael Neuffer                          *
                     23:  *               [email protected]            *
                     24:  *                                                         *
                     25:  *  This program is free software; you can redistribute it  *
                     26:  *  and/or modify it under the terms of the GNU General            *
                     27:  *  Public License as published by the Free Software       *
                     28:  *  Foundation; either version 2 of the License, or        *
                     29:  *  (at your option) any later version.                            *
                     30:  *                                                         *
                     31:  *  This program is distributed in the hope that it will be *
                     32:  *  useful, but WITHOUT ANY WARRANTY; without even the     *
                     33:  *  implied warranty of MERCHANTABILITY or FITNESS FOR A    *
                     34:  *  PARTICULAR PURPOSE.         See the GNU General Public License *
                     35:  *  for more details.                                      *
                     36:  *                                                         *
                     37:  *  You should have received a copy of the GNU General     *
                     38:  *  Public License along with this kernel; if not, write to *
                     39:  *  the Free Software Foundation, Inc., 675 Mass Ave,      *
                     40:  *  Cambridge, MA 02139, USA.                              *
                     41:  *                                                         *
                     42:  * I have to thank DPT for their excellent support. I took  *
                     43:  * me almost a year and a stopover at their HQ, on my first *
                     44:  * trip to the USA, to get it, but since then they've been  *
                     45:  * very helpful and tried to give me all the infos and     *
                     46:  * support I need.                                         *
                     47:  *                                                         *
                     48:  * Thanks also to Greg Hosler who did a lot of testing and  *
                     49:  * found quite a number of bugs during the development.            *
                     50:  ************************************************************
                     51:  *  last change: 95/11/29                 OS: Linux 1.3.45  *
                     52:  ************************************************************/
                     53: 
                     54: /* Look in eata_dma.h for configuration and revision information */
                     55: 
                     56: #include <linux/module.h>
                     57: #include <linux/kernel.h>
                     58: #include <linux/sched.h>
                     59: #include <linux/string.h>
                     60: #include <linux/ioport.h>
                     61: #include <linux/malloc.h>
                     62: #include <linux/in.h>
                     63: #include <linux/bios32.h>
                     64: #include <linux/pci.h>
                     65: #include <linux/proc_fs.h>
                     66: #include <asm/byteorder.h>
                     67: #include <asm/types.h>
                     68: #include <asm/io.h>
                     69: #include <asm/dma.h>
                     70: #include <linux/blk.h>
                     71: #include "scsi.h"
                     72: #include "sd.h"
                     73: #include "hosts.h"
                     74: #include <linux/scsicam.h>
                     75: #include "eata_dma.h"
                     76: #include "eata_dma_proc.h" 
                     77: 
                     78: #include <linux/stat.h>
                     79: #include <linux/config.h>      /* for CONFIG_PCI */
                     80: 
                     81: struct proc_dir_entry proc_scsi_eata_dma = {
                     82:     PROC_SCSI_EATA, 8, "eata_dma",
                     83:     S_IFDIR | S_IRUGO | S_IXUGO, 2
                     84: };
                     85: 
                     86: static u32 ISAbases[] =
                     87: {0x1F0, 0x170, 0x330, 0x230};
                     88: static unchar EISAbases[] =
                     89: {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
                     90: static uint registered_HBAs = 0;
                     91: static struct Scsi_Host *last_HBA = NULL;
                     92: static struct Scsi_Host *first_HBA = NULL;
                     93: static unchar reg_IRQ[] =
                     94: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
                     95: static unchar reg_IRQL[] =
                     96: {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
                     97: static struct eata_sp *status = 0;   /* Statuspacket array   */
                     98: static void *dma_scratch = 0;
                     99: 
                    100: static struct eata_register *fake_int_base;
                    101: static int fake_int_result;
                    102: static int fake_int_happened;
                    103: 
                    104: static ulong int_counter = 0;
                    105: static ulong queue_counter = 0;
                    106: 
                    107: void eata_scsi_done (Scsi_Cmnd * scmd)
                    108: {
                    109:     scmd->request.rq_status = RQ_SCSI_DONE;
                    110: 
                    111:     if (scmd->request.sem != NULL)
                    112:        up(scmd->request.sem);
                    113:     
                    114:     return;
                    115: }   
                    116: 
                    117: void eata_fake_int_handler(s32 irq, struct pt_regs * regs)
                    118: {
                    119:     fake_int_result = inb((ulong)fake_int_base + HA_RSTATUS);
                    120:     fake_int_happened = TRUE;
                    121:     DBG(DBG_INTR3, printk("eata_fake_int_handler called irq%d base %p"
                    122:                          " res %#x\n", irq, fake_int_base, fake_int_result));
                    123:     return;
                    124: }
                    125: 
                    126: #ifdef MACH
                    127: #include "eata_dma_proc.src"
                    128: #else
                    129: #include "eata_dma_proc.c"
                    130: #endif
                    131: 
                    132: #ifdef MODULE
                    133: int eata_release(struct Scsi_Host *sh)
                    134: {
                    135:     uint i;
                    136:     if (sh->irq && reg_IRQ[sh->irq] == 1) free_irq(sh->irq);
                    137:     else reg_IRQ[sh->irq]--;
                    138:     
                    139:     scsi_init_free((void *)status, 512);
                    140:     scsi_init_free((void *)dma_scratch, 512);
                    141:     for (i = 0; i < sh->can_queue; i++){ /* Free all SG arrays */
                    142:        if(SD(sh)->ccb[i].sg_list != NULL)
                    143:            scsi_init_free((void *) SD(sh)->ccb[i].sg_list, 
                    144:                           sh->sg_tablesize * sizeof(struct eata_sg_list));
                    145:     }
                    146:     
                    147:     if (SD(sh)->channel == 0) {
                    148:        if (sh->dma_channel != BUSMASTER) free_dma(sh->dma_channel);
                    149:        if (sh->io_port && sh->n_io_port)
                    150:            release_region(sh->io_port, sh->n_io_port);
                    151:     }
                    152:     return(TRUE);
                    153: }
                    154: #endif
                    155: 
                    156: 
                    157: void eata_int_handler(int irq, struct pt_regs * regs)
                    158: {
                    159:     uint i, result = 0;
                    160:     uint hba_stat, scsi_stat, eata_stat;
                    161:     Scsi_Cmnd *cmd;
                    162:     struct eata_ccb *cp;
                    163:     struct eata_sp *sp;
                    164:     uint base;
                    165:     ulong flags;
                    166:     uint x;
                    167:     struct Scsi_Host *sh;
                    168: 
                    169:     save_flags(flags);
                    170:     cli();
                    171: 
                    172:     for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->next) {
                    173:        if (sh->irq != irq)
                    174:            continue;
                    175:        
                    176:        while(inb((uint)sh->base + HA_RAUXSTAT) & HA_AIRQ) {
                    177:            
                    178:            int_counter++;
                    179:            
                    180:            sp = &SD(sh)->sp;
                    181:            cp = sp->ccb;
                    182:            
                    183:            if(cp == NULL) {
                    184:                eata_stat = inb((uint)sh->base + HA_RSTATUS);
                    185:                printk("eata_dma: int_handler, Spurious IRQ %d "
                    186:                       "received. CCB pointer not set.\n", irq);
                    187:                break;
                    188:            }
                    189: 
                    190:            cmd = cp->cmd;
                    191:            base = (uint) cmd->host->base;
                    192:                    hba_stat = sp->hba_stat;
                    193:            
                    194:            scsi_stat = (sp->scsi_stat >> 1) & 0x1f; 
                    195:            
                    196:            if (sp->EOC == FALSE) {
                    197:                eata_stat = inb(base + HA_RSTATUS);
                    198:                printk("eata_dma: int_handler, board: %x cmd %lx returned "
                    199:                       "unfinished.\nEATA: %x HBA: %x SCSI: %x spadr %lx "
                    200:                       "spadrirq %lx, irq%d\n", base, (long)cp, eata_stat, 
                    201:                       hba_stat, scsi_stat,(long)&status, (long)&status[irq], 
                    202:                       irq);
                    203:                DBG(DBG_DELAY, DEL2(800));
                    204:                break;
                    205:            } 
                    206:            
                    207:            if (cp->status == LOCKED) {
                    208:                cp->status = FREE;
                    209:                eata_stat = inb(base + HA_RSTATUS);
                    210:                printk("eata_dma: int_handler, freeing locked queueslot\n");
                    211:                DBG(DBG_INTR && DBG_DELAY, DEL2(800));
                    212:                break;
                    213:            }
                    214:            
                    215:            eata_stat = inb(base + HA_RSTATUS); 
                    216:            DBG(DBG_INTR, printk("IRQ %d received, base %#.4x, pid %ld, "
                    217:                                 "target: %x, lun: %x, ea_s: %#.2x, hba_s: "
                    218:                                 "%#.2x \n", irq, base, cmd->pid, cmd->target,
                    219:                                 cmd->lun, eata_stat, hba_stat));
                    220:            
                    221:            switch (hba_stat) {
                    222:            case HA_NO_ERROR:   /* NO Error */
                    223:                if (scsi_stat == CONDITION_GOOD
                    224:                    && cmd->device->type == TYPE_DISK
                    225:                    && (HD(cmd)->t_state[cp->cp_channel][cp->cp_id] == RESET))
                    226:                    result = DID_BUS_BUSY << 16;            
                    227:                else if (scsi_stat == GOOD) {
                    228:                    HD(cmd)->t_state[cp->cp_channel][cp->cp_id] = OK;
                    229:                    if(HD(cmd)->do_latency == TRUE && cp->timestamp) {
                    230:                        uint time;
                    231:                        time = jiffies - cp->timestamp;
                    232:                        if((cp->rw_latency) == TRUE) { /* was WRITE */
                    233:                            if(HD(cmd)->writes_lat[cp->sizeindex][1] > time)
                    234:                                HD(cmd)->writes_lat[cp->sizeindex][1] = time;
                    235:                            if(HD(cmd)->writes_lat[cp->sizeindex][2] < time)
                    236:                                HD(cmd)->writes_lat[cp->sizeindex][2] = time;
                    237:                            HD(cmd)->writes_lat[cp->sizeindex][3] += time;
                    238:                            HD(cmd)->writes_lat[cp->sizeindex][0]++;
                    239:                        } else {
                    240:                            if(HD(cmd)->reads_lat[cp->sizeindex][1] > time)
                    241:                                HD(cmd)->reads_lat[cp->sizeindex][1] = time;
                    242:                            if(HD(cmd)->reads_lat[cp->sizeindex][2] < time)
                    243:                                HD(cmd)->reads_lat[cp->sizeindex][2] = time;
                    244:                            HD(cmd)->reads_lat[cp->sizeindex][3] += time;
                    245:                            HD(cmd)->reads_lat[cp->sizeindex][0]++;
                    246:                        }
                    247:                    }
                    248:                }
                    249:                else if (scsi_stat == CHECK_CONDITION
                    250:                         && cmd->device->type == TYPE_DISK
                    251:                         && (cmd->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
                    252:                    result = DID_BUS_BUSY << 16;
                    253:                else
                    254:                    result = DID_OK << 16;
                    255:                HD(cmd)->t_timeout[cp->cp_channel][cp->cp_id] = OK;
                    256:                break;
                    257:            case HA_ERR_SEL_TO:         /* Selection Timeout */
                    258:                result = DID_BAD_TARGET << 16;  
                    259:                break;
                    260:            case HA_ERR_CMD_TO:         /* Command Timeout   */
                    261:                if (HD(cmd)->t_timeout[cp->cp_channel][cp->cp_id] > 1)
                    262:                    result = DID_ERROR << 16;
                    263:                else {
                    264:                    result = DID_TIME_OUT << 16;
                    265:                    HD(cmd)->t_timeout[cp->cp_channel][cp->cp_id]++;
                    266:                }
                    267:                break;
                    268:            case HA_ERR_RESET:          /* SCSI Bus Reset Received */
                    269:            case HA_INIT_POWERUP:       /* Initial Controller Power-up */
                    270:                if (cmd->device->type != TYPE_TAPE)
                    271:                    result = DID_BUS_BUSY << 16;
                    272:                else
                    273:                    result = DID_ERROR << 16;
                    274:                
                    275:                for (i = 0; i < MAXTARGET; i++)
                    276:                    HD(cmd)->t_state[cp->cp_channel][i] = RESET;
                    277:                break;
                    278:            case HA_UNX_BUSPHASE:       /* Unexpected Bus Phase */
                    279:            case HA_UNX_BUS_FREE:       /* Unexpected Bus Free */
                    280:            case HA_BUS_PARITY:         /* Bus Parity Error */
                    281:            case HA_SCSI_HUNG:          /* SCSI Hung */
                    282:            case HA_UNX_MSGRJCT:        /* Unexpected Message Reject */
                    283:            case HA_RESET_STUCK:        /* SCSI Bus Reset Stuck */
                    284:            case HA_RSENSE_FAIL:        /* Auto Request-Sense Failed */
                    285:            case HA_PARITY_ERR:         /* Controller Ram Parity */
                    286:            default:
                    287:                result = DID_ERROR << 16;
                    288:                break;
                    289:            }
                    290:            cmd->result = result | (scsi_stat << 1); 
                    291:            
                    292: #if DBG_INTR2
                    293:            if (scsi_stat || result || hba_stat || eata_stat != 0x50 
                    294:                || cmd->scsi_done == NULL || cmd->device->id == 7) 
                    295:                printk("HBA: %d, channel %d, id: %d, lun %d, pid %ld:\n" 
                    296:                       "eata_stat %#x, hba_stat %#.2x, scsi_stat %#.2x, "
                    297:                       "sense_key: %#x, result: %#.8x\n", x, 
                    298:                       cmd->device->channel, cmd->device->id, cmd->device->lun,
                    299:                       cmd->pid, eata_stat, hba_stat, scsi_stat, 
                    300:                       cmd->sense_buffer[2] & 0xf, cmd->result); 
                    301:            DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
                    302: #endif
                    303:            
                    304:            cp->status = FREE;      /* now we can release the slot  */
                    305:            cmd->scsi_done(cmd);
                    306:        }
                    307:     }
                    308:     restore_flags(flags);
                    309:     
                    310:     return;
                    311: }
                    312: 
                    313: inline int eata_send_command(u32 addr, u32 base, u8 command)
                    314: {
                    315:     long loop = R_LIMIT;
                    316:     
                    317:     while (inb(base + HA_RAUXSTAT) & HA_ABUSY)
                    318:        if (--loop == 0)
                    319:            return(FALSE);
                    320: 
                    321:     /* And now the address in nice little byte chunks */
                    322:     outb( addr & 0x000000ff,       base + HA_WDMAADDR);
                    323:     outb((addr & 0x0000ff00) >> 8,  base + HA_WDMAADDR + 1);
                    324:     outb((addr & 0x00ff0000) >> 16, base + HA_WDMAADDR + 2);
                    325:     outb((addr & 0xff000000) >> 24, base + HA_WDMAADDR + 3);
                    326:     outb(command, base + HA_WCOMMAND);
                    327:     return(TRUE);
                    328: }
                    329: 
                    330: #if 0 
                    331: inline int eata_send_immediate(u32 addr, u32 base, u8 cmnd, u8 cmnd2, u8 id, 
                    332:                               u8 lun)
                    333: {
                    334:     if(addr){
                    335:        outb( addr & 0x000000ff,        base + HA_WDMAADDR);
                    336:        outb((addr & 0x0000ff00) >> 8,  base + HA_WDMAADDR + 1);
                    337:        outb((addr & 0x00ff0000) >> 16, base + HA_WDMAADDR + 2);
                    338:        outb((addr & 0xff000000) >> 24, base + HA_WDMAADDR + 3);
                    339:     } else {
                    340:        outb(id,  base + HA_WSUBCODE);
                    341:        outb(lun, base + HA_WSUBLUN);
                    342:     }
                    343:     
                    344:     outb(cmnd2, base + HA_WCOMMAND2);
                    345:     outb(cmnd, base + HA_WCOMMAND);
                    346:     return(TRUE);
                    347: }
                    348: #endif
                    349: 
                    350: int eata_queue(Scsi_Cmnd * cmd, void (* done) (Scsi_Cmnd *))
                    351: {
                    352:     unsigned int i, x, y;
                    353:     u32 flags;
                    354:     hostdata *hd;
                    355:     struct Scsi_Host *sh;
                    356:     struct eata_ccb *cp;
                    357:     struct scatterlist *sl;
                    358:     
                    359:     save_flags(flags);
                    360:     cli();
                    361:     
                    362:     queue_counter++;
                    363: 
                    364:     hd = HD(cmd);
                    365:     sh = cmd->host;
                    366:     
                    367:     /* check for free slot */
                    368:     for (y = hd->last_ccb + 1, x = 0; x < sh->can_queue; x++, y++) { 
                    369:        if (y >= sh->can_queue)
                    370:            y = 0;
                    371:        if (hd->ccb[y].status == FREE)
                    372:            break;
                    373:     }
                    374:     
                    375:     hd->last_ccb = y;
                    376: 
                    377:     if (x >= sh->can_queue) { 
                    378:        uint z;
                    379:        
                    380:        printk(KERN_EMERG "eata_dma: run out of queue slots cmdno:%ld"
                    381:               " intrno: %ld, can_queue: %d, x: %d, y: %d\n", 
                    382:               queue_counter, int_counter, sh->can_queue, x, y);
                    383:        printk(KERN_EMERG "Status of queueslots:");
                    384:        for(z = 0; z < sh->can_queue; z +=2) {
                    385:            switch(hd->ccb[z].status) {
                    386:            case FREE:
                    387:                printk(KERN_EMERG "Slot %2d is FREE  \t", z);
                    388:                break;
                    389:            case USED:
                    390:                printk(KERN_EMERG "Slot %2d is USED  \t", z);
                    391:                break;
                    392:            case LOCKED:
                    393:                printk(KERN_EMERG "Slot %2d is LOCKED\t", z);
                    394:                break;
                    395:            default:
                    396:                printk(KERN_EMERG "Slot %2d is UNKNOWN\t", z);
                    397:            }
                    398:            panic("\nSystem halted.\n");
                    399:        }
                    400:     }
                    401:     cp = &hd->ccb[y];
                    402:     
                    403:     memset(cp, 0, sizeof(struct eata_ccb) - sizeof(struct eata_sg_list *));
                    404:     
                    405:     cp->status = USED;                 /* claim free slot */
                    406:     
                    407:     DBG(DBG_QUEUE, printk("eata_queue pid %ld, target: %x, lun: %x, y %d\n",
                    408:                          cmd->pid, cmd->target, cmd->lun, y));
                    409:     DBG(DBG_QUEUE && DBG_DELAY, DEL2(250));
                    410:     
                    411:     if(hd->do_latency == TRUE) {
                    412:        int x, z;
                    413:        short *sho;
                    414:        long *lon;
                    415:        x = 0;  /* just to keep GCC quiet */ 
                    416:        if (cmd->cmnd[0] == WRITE_6 || cmd->cmnd[0] == WRITE_10 || 
                    417:            cmd->cmnd[0] == WRITE_12 || cmd->cmnd[0] == READ_6 || 
                    418:            cmd->cmnd[0] == READ_10 || cmd->cmnd[0] == READ_12) {
                    419:            
                    420:            cp->timestamp = jiffies;    /* For latency measurements */
                    421:            switch(cmd->cmnd[0]) {
                    422:            case WRITE_6:   
                    423:            case READ_6:    
                    424:                x = cmd->cmnd[4]/2; 
                    425:                break;
                    426:            case WRITE_10:   
                    427:            case READ_10:
                    428:                sho = (short *) &cmd->cmnd[7];
                    429:                x = ntohs(*sho)/2;            
                    430:                break;
                    431:            case WRITE_12:   
                    432:            case READ_12:
                    433:                lon = (long *) &cmd->cmnd[6];
                    434:                x = ntohl(*lon)/2;            
                    435:                break;
                    436:            }
                    437: 
                    438:            for(z = 0; (x > (1 << z)) && (z <= 11); z++) 
                    439:                /* nothing */;
                    440:            cp->sizeindex = z;
                    441:            if (cmd->cmnd[0] == WRITE_6 || cmd->cmnd[0] == WRITE_10 || 
                    442:                cmd->cmnd[0] == WRITE_12){
                    443:                cp->rw_latency = TRUE;
                    444:            }
                    445:        }
                    446:     }
                    447:     cmd->scsi_done = (void *)done;
                    448:     
                    449:     switch (cmd->cmnd[0]) {
                    450:     case CHANGE_DEFINITION: case COMPARE:        case COPY:
                    451:     case COPY_VERIFY:      case LOG_SELECT:      case MODE_SELECT:
                    452:     case MODE_SELECT_10:    case SEND_DIAGNOSTIC: case WRITE_BUFFER:
                    453:     case FORMAT_UNIT:      case REASSIGN_BLOCKS: case RESERVE:
                    454:     case SEARCH_EQUAL:     case SEARCH_HIGH:     case SEARCH_LOW:
                    455:     case WRITE_6:          case WRITE_10:        case WRITE_VERIFY:
                    456:     case UPDATE_BLOCK:     case WRITE_LONG:      case WRITE_SAME:      
                    457:     case SEARCH_HIGH_12:    case SEARCH_EQUAL_12: case SEARCH_LOW_12:
                    458:     case WRITE_12:         case WRITE_VERIFY_12: case SET_WINDOW: 
                    459:     case MEDIUM_SCAN:      case SEND_VOLUME_TAG:            
                    460:     case 0xea:     /* alternate number for WRITE LONG */
                    461:        cp->DataOut = TRUE;     /* Output mode */
                    462:        break;
                    463:     case TEST_UNIT_READY:
                    464:     default:
                    465:        cp->DataIn = TRUE;      /* Input mode  */
                    466:     }
                    467: 
                    468:     /* FIXME: This will will have to be changed once the midlevel driver 
                    469:      *        allows different HBA IDs on every channel.
                    470:      */
                    471:     if (cmd->target == sh->this_id) 
                    472:        cp->Interpret = TRUE;   /* Interpret command */
                    473: 
                    474:     if (cmd->use_sg) {
                    475:        cp->scatter = TRUE;     /* SG mode     */
                    476:        if (cp->sg_list == NULL) {
                    477:            cp->sg_list = kmalloc(sh->sg_tablesize * sizeof(struct eata_sg_list),
                    478:                                  GFP_ATOMIC | GFP_DMA);
                    479:        }
                    480:        if (cp->sg_list == NULL)
                    481:            panic("eata_dma: Run out of DMA memory for SG lists !\n");
                    482:        cp->cp_dataDMA = htonl(virt_to_bus(cp->sg_list)); 
                    483:        
                    484:        cp->cp_datalen = htonl(cmd->use_sg * sizeof(struct eata_sg_list));
                    485:        sl=(struct scatterlist *)cmd->request_buffer;
                    486:        for(i = 0; i < cmd->use_sg; i++, sl++){
                    487:            cp->sg_list[i].data = htonl(virt_to_bus(sl->address));
                    488:            cp->sg_list[i].len = htonl((u32) sl->length);
                    489:        }
                    490:     } else {
                    491:        cp->scatter = FALSE;
                    492:        cp->cp_datalen = htonl(cmd->request_bufflen);
                    493:        cp->cp_dataDMA = htonl(virt_to_bus(cmd->request_buffer));
                    494:     }
                    495:     
                    496:     cp->Auto_Req_Sen = TRUE;
                    497:     cp->cp_reqDMA = htonl(virt_to_bus(cmd->sense_buffer));
                    498:     cp->reqlen = sizeof(cmd->sense_buffer);
                    499:     
                    500:     cp->cp_id = cmd->target;
                    501:     cp->cp_channel = cmd->channel;
                    502:     cp->cp_lun = cmd->lun;
                    503:     cp->cp_dispri = TRUE;
                    504:     cp->cp_identify = TRUE;
                    505:     memcpy(cp->cp_cdb, cmd->cmnd, cmd->cmd_len);
                    506:     
                    507:     cp->cp_statDMA = htonl(virt_to_bus(&(hd->sp)));
                    508:     
                    509:     cp->cp_viraddr = cp; /* This will be passed thru, so we don't need to 
                    510:                           * convert it */
                    511:     cp->cmd = cmd;
                    512:     cmd->host_scribble = (char *)&hd->ccb[y];  
                    513:     
                    514:     if(eata_send_command((u32) cp, (u32) sh->base, EATA_CMD_DMA_SEND_CP) == FALSE) {
                    515:        cmd->result = DID_BUS_BUSY << 16;
                    516:        DBG(DBG_QUEUE && DBG_ABNORM, 
                    517:            printk("eata_queue target %d, pid %ld, HBA busy, "
                    518:                   "returning DID_BUS_BUSY\n",cmd->target, cmd->pid));
                    519:        done(cmd);
                    520:        cp->status = FREE;    
                    521:        restore_flags(flags);
                    522:        return(0);
                    523:     }
                    524:     DBG(DBG_QUEUE, printk("Queued base %#.4x pid: %ld target: %x lun: %x "
                    525:                         "slot %d irq %d\n", (s32)sh->base, cmd->pid, 
                    526:                         cmd->target, cmd->lun, y, sh->irq));
                    527:     DBG(DBG_QUEUE && DBG_DELAY, DEL2(200));
                    528:     restore_flags(flags);
                    529:     return(0);
                    530: }
                    531: 
                    532: 
                    533: int eata_abort(Scsi_Cmnd * cmd)
                    534: {
                    535:     ulong loop = R_LIMIT;
                    536:     ulong flags;
                    537: 
                    538:     save_flags(flags);
                    539:     cli();
                    540: 
                    541:     DBG(DBG_ABNORM, printk("eata_abort called pid: %ld target: %x lun: %x"
                    542:                           " reason %x\n", cmd->pid, cmd->target, cmd->lun, 
                    543:                           cmd->abort_reason));
                    544:     DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    545: 
                    546:     while (inb((u32)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY) {
                    547:        if (--loop == 0) {
                    548:            printk("eata_dma: abort, timeout error.\n");
                    549:            restore_flags(flags);
                    550:            DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    551:            return (SCSI_ABORT_ERROR);
                    552:        }
                    553:     }
                    554:     if (CD(cmd)->status == RESET) {
                    555:        restore_flags(flags);
                    556:        printk("eata_dma: abort, command reset error.\n");
                    557:        DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    558:        return (SCSI_ABORT_ERROR);
                    559:     }
                    560:     if (CD(cmd)->status == LOCKED) {
                    561:        restore_flags(flags);
                    562:        DBG(DBG_ABNORM, printk("eata_dma: abort, queue slot locked.\n"));
                    563:        DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    564:        return (SCSI_ABORT_NOT_RUNNING);
                    565:     }
                    566:     if (CD(cmd)->status == USED) {
                    567:        DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_BUSY\n"));
                    568:        restore_flags(flags);
                    569:        return (SCSI_ABORT_BUSY);  /* SNOOZE */ 
                    570:     }
                    571:     if (CD(cmd)->status == FREE) {
                    572:        DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_NOT_RUNNING\n")); 
                    573:        restore_flags(flags);
                    574:        return (SCSI_ABORT_NOT_RUNNING);
                    575:     }
                    576:     restore_flags(flags);
                    577:     panic("eata_dma: abort: invalid slot status\n");
                    578: }
                    579: 
                    580: int eata_reset(Scsi_Cmnd * cmd)
                    581: {
                    582:     ushort x, z; 
                    583:     ulong time, limit = 0;
                    584:     ulong loop = R_LIMIT;
                    585:     ulong flags;
                    586:     unchar success = FALSE;
                    587:     Scsi_Cmnd *sp; 
                    588:     
                    589:     save_flags(flags);
                    590:     cli();
                    591:     
                    592:     DBG(DBG_ABNORM, printk("eata_reset called pid:%ld target: %x lun: %x"
                    593:                           " reason %x\n", cmd->pid, cmd->target, cmd->lun, 
                    594:                           cmd->abort_reason));
                    595:        
                    596:     if (HD(cmd)->state == RESET) {
                    597:        printk("eata_reset: exit, already in reset.\n");
                    598:        restore_flags(flags);
                    599:        DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    600:        return (SCSI_RESET_ERROR);
                    601:     }
                    602:     
                    603:     while (inb((u32)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
                    604:        if (--loop == 0) {
                    605:            printk("eata_reset: exit, timeout error.\n");
                    606:            restore_flags(flags);
                    607:            DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    608:            return (SCSI_RESET_ERROR);
                    609:        }
                    610:  
                    611:     for (x = 0; x < MAXCHANNEL; x++) {
                    612:        for (z = 0; z < MAXTARGET; z++) {
                    613:            HD(cmd)->t_state[x][z] = RESET;
                    614:            HD(cmd)->t_timeout[x][z] = NO_TIMEOUT;
                    615:        }
                    616:     }
                    617: 
                    618:     for (x = 0; x < cmd->host->can_queue; x++) {
                    619:        if (HD(cmd)->ccb[x].status == FREE)
                    620:            continue;
                    621:        
                    622:        if (HD(cmd)->ccb[x].status == LOCKED) {
                    623:            HD(cmd)->ccb[x].status = FREE;
                    624:            printk("eata_reset: locked slot %d forced free.\n", x);
                    625:            DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    626:            continue;
                    627:        }
                    628:        sp = HD(cmd)->ccb[x].cmd;
                    629:        HD(cmd)->ccb[x].status = RESET;
                    630:        printk("eata_reset: slot %d in reset, pid %ld.\n", x, sp->pid);
                    631:        DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    632:        
                    633:        if (sp == NULL)
                    634:            panic("eata_reset: slot %d, sp==NULL.\n", x);
                    635:        DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    636:        
                    637:        if (sp == cmd)
                    638:            success = TRUE;
                    639:     }
                    640:     
                    641:     /* hard reset the HBA  */
                    642:     inb((u32) (cmd->host->base) + HA_RSTATUS); /* This might cause trouble */
                    643:     eata_send_command(0, (u32) cmd->host->base, EATA_CMD_RESET);
                    644:     
                    645:     DBG(DBG_ABNORM, printk("eata_reset: board reset done, enabling interrupts.\n"));
                    646:     HD(cmd)->state = RESET;
                    647:     
                    648:     restore_flags(flags);
                    649:     
                    650:     time = jiffies;
                    651:     while (jiffies < (time + (3 * HZ)) || limit++ < 10000000)
                    652:        /* As time goes by... */;
                    653:     
                    654:     save_flags(flags);
                    655:     cli();
                    656:     
                    657:     DBG(DBG_ABNORM, printk("eata_reset: interrupts disabled, loops %ld.\n", 
                    658:                           limit));
                    659:     DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    660:     
                    661:     for (x = 0; x < cmd->host->can_queue; x++) {
                    662:        
                    663:        /* Skip slots already set free by interrupt */
                    664:        if (HD(cmd)->ccb[x].status != RESET)
                    665:            continue;
                    666:        
                    667:        sp = HD(cmd)->ccb[x].cmd;
                    668:        sp->result = DID_RESET << 16;
                    669:        
                    670:        /* This mailbox is still waiting for its interrupt */
                    671:        HD(cmd)->ccb[x].status = LOCKED;
                    672:        
                    673:        printk("eata_reset: slot %d locked, DID_RESET, pid %ld done.\n",
                    674:               x, sp->pid);
                    675:        DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    676:        restore_flags(flags);
                    677:        sp->scsi_done(sp);
                    678:        cli();
                    679:     }
                    680:     
                    681:     HD(cmd)->state = FALSE;
                    682:     restore_flags(flags);
                    683:     
                    684:     if (success) {
                    685:        DBG(DBG_ABNORM, printk("eata_reset: exit, success.\n"));
                    686:        DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    687:        return (SCSI_RESET_SUCCESS);
                    688:     } else {
                    689:        DBG(DBG_ABNORM, printk("eata_reset: exit, wakeup.\n"));
                    690:        DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
                    691:        return (SCSI_RESET_PUNT);
                    692:     }
                    693: }
                    694: 
                    695: char * get_board_data(u32 base, u32 irq, u32 id)
                    696: {
                    697:     struct eata_ccb *cp;
                    698:     struct eata_sp  *sp;
                    699:     static char *buff;
                    700:     ulong i;
                    701:     ulong limit = 0;
                    702: 
                    703:     cp = (struct eata_ccb *) scsi_init_malloc(sizeof(struct eata_ccb),
                    704:                                              GFP_ATOMIC | GFP_DMA);
                    705:     sp = (struct eata_sp *) scsi_init_malloc(sizeof(struct eata_sp), 
                    706:                                             GFP_ATOMIC | GFP_DMA);
                    707: 
                    708:     buff = dma_scratch;
                    709:  
                    710:     memset(cp, 0, sizeof(struct eata_ccb));
                    711:     memset(sp, 0, sizeof(struct eata_sp));
                    712:     memset(buff, 0, 256);
                    713: 
                    714:     cp->DataIn = TRUE;    
                    715:     cp->Interpret = TRUE;   /* Interpret command */
                    716:     cp->cp_dispri = TRUE;
                    717:     cp->cp_identify = TRUE;
                    718:  
                    719:     cp->cp_datalen = htonl(56);  
                    720:     cp->cp_dataDMA = htonl(virt_to_bus(buff));
                    721:     cp->cp_statDMA = htonl(virt_to_bus(sp));
                    722:     cp->cp_viraddr = cp;
                    723:     
                    724:     cp->cp_id = id;
                    725:     cp->cp_lun = 0;
                    726: 
                    727:     cp->cp_cdb[0] = INQUIRY;
                    728:     cp->cp_cdb[1] = 0;
                    729:     cp->cp_cdb[2] = 0;
                    730:     cp->cp_cdb[3] = 0;
                    731:     cp->cp_cdb[4] = 56;
                    732:     cp->cp_cdb[5] = 0;
                    733: 
                    734:     fake_int_base = (struct eata_register *) base;
                    735:     fake_int_result = FALSE;
                    736:     fake_int_happened = FALSE;
                    737: 
                    738:     eata_send_command((u32) cp, (u32) base, EATA_CMD_DMA_SEND_CP);
                    739:     
                    740:     i = jiffies + (3 * HZ);
                    741:     while (fake_int_happened == FALSE && jiffies <= i) 
                    742:        barrier();
                    743:     
                    744:     DBG(DBG_INTR3, printk("fake_int_result: %#x hbastat %#x scsistat %#x,"
                    745:                          " buff %p sp %p\n",
                    746:                          fake_int_result, (u32) (sp->hba_stat /*& 0x7f*/), 
                    747:                          (u32) sp->scsi_stat, buff, sp));
                    748: 
                    749:     scsi_init_free((void *)cp, sizeof(struct eata_ccb));
                    750:     scsi_init_free((void *)sp, sizeof(struct eata_sp));
                    751:     
                    752:     if ((fake_int_result & HA_SERROR) || jiffies > i){
                    753:        /* hard reset the HBA  */
                    754:        inb((u32) (base) + HA_RSTATUS);
                    755:        eata_send_command(0, base, EATA_CMD_RESET);
                    756:        i = jiffies;
                    757:        while (jiffies < (i + (3 * HZ)) && limit++ < 10000000) 
                    758:            barrier();
                    759:        return (NULL);
                    760:     } else
                    761:        return (buff);
                    762: }
                    763:     
                    764: int check_blink_state(long base)
                    765: {
                    766:     ushort loops = 10;
                    767:     u32 blinkindicator;
                    768:     u32 state = 0x12345678;
                    769:     u32 oldstate = 0;
                    770: 
                    771:     blinkindicator = htonl(0x54504442);
                    772:     while ((loops--) && (state != oldstate)) {
                    773:        oldstate = state;
                    774:        state = inl((uint) base + 1);
                    775:     }
                    776: 
                    777:     DBG(DBG_BLINK, printk("Did Blink check. Status: %d\n",
                    778:              (state == oldstate) && (state == blinkindicator)));
                    779: 
                    780:     if ((state == oldstate) && (state == blinkindicator))
                    781:        return(TRUE);
                    782:     else
                    783:        return (FALSE);
                    784: }
                    785: 
                    786: int get_conf_PIO(u32 base, struct get_conf *buf)
                    787: {
                    788:     ulong loop = R_LIMIT;
                    789:     u16 *p;
                    790: 
                    791:     if(check_region(base, 9)) 
                    792:        return (FALSE);
                    793:      
                    794:     memset(buf, 0, sizeof(struct get_conf));
                    795: 
                    796:     while (inb(base + HA_RSTATUS) & HA_SBUSY)
                    797:        if (--loop == 0) 
                    798:            return (FALSE);
                    799:        
                    800:     DBG(DBG_PIO && DBG_PROBE,
                    801:        printk("Issuing PIO READ CONFIG to HBA at %#x\n", base));
                    802:     eata_send_command(0, base, EATA_CMD_PIO_READ_CONFIG);
                    803: 
                    804:     loop = R_LIMIT;
                    805:     for (p = (u16 *) buf; 
                    806:         (long)p <= ((long)buf + (sizeof(struct get_conf) / 2)); p++) {
                    807:        while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
                    808:            if (--loop == 0)
                    809:                return (FALSE);
                    810: 
                    811:        loop = R_LIMIT;
                    812:        *p = inw(base + HA_RDATA);
                    813:     }
                    814: 
                    815:     if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {           /* Error ? */
                    816:        if (htonl(EATA_SIGNATURE) == buf->signature) {
                    817:            DBG(DBG_PIO&&DBG_PROBE, printk("EATA Controller found at %x "
                    818:                                           "EATA Level: %x\n", (uint) base, 
                    819:                                           (uint) (buf->version)));
                    820:            
                    821:            while (inb(base + HA_RSTATUS) & HA_SDRQ) 
                    822:                inw(base + HA_RDATA);
                    823:            return (TRUE);
                    824:        } 
                    825:     } else {
                    826:        DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during transfer "
                    827:                  "for HBA at %lx\n", (long)base));
                    828:     }
                    829:     return (FALSE);
                    830: }
                    831: 
                    832: void print_config(struct get_conf *gc)
                    833: {
                    834:     printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d DMAS:%d\n",
                    835:           (u32) ntohl(gc->len), gc->version,
                    836:           gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support,
                    837:           gc->DMA_support);
                    838:     printk("DMAV:%d HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n",
                    839:           gc->DMA_valid, gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2],
                    840:           gc->scsi_id[1], ntohs(gc->queuesiz), ntohs(gc->SGsiz), gc->SECOND);
                    841:     printk("IRQ:%d IRQT:%d DMAC:%d FORCADR:%d SG_64K:%d SG_UAE:%d MID:%d "
                    842:           "MCH:%d MLUN:%d\n",
                    843:           gc->IRQ, gc->IRQ_TR, (8 - gc->DMA_channel) & 7, gc->FORCADR, 
                    844:           gc->SG_64K, gc->SG_UAE, gc->MAX_ID, gc->MAX_CHAN, gc->MAX_LUN); 
                    845:     printk("RIDQ:%d PCI:%d EISA:%d\n",
                    846:           gc->ID_qest, gc->is_PCI, gc->is_EISA);
                    847:     DBG(DPT_DEBUG, DELAY(14));
                    848: }
                    849: 
                    850: short register_HBA(u32 base, struct get_conf *gc, Scsi_Host_Template * tpnt, 
                    851:                   u8 bustype)
                    852: {
                    853:     ulong size = 0;
                    854:     unchar dma_channel = 0;
                    855:     char *buff = 0;
                    856:     unchar bugs = 0;
                    857:     struct Scsi_Host *sh;
                    858:     hostdata *hd;
                    859:     int x;
                    860:     
                    861:     
                    862:     DBG(DBG_REGISTER, print_config(gc));
                    863: 
                    864:     if (gc->DMA_support == FALSE) {
                    865:        printk("The EATA HBA at %#.4x does not support DMA.\n" 
                    866:               "Please use the EATA-PIO driver.\n", base);
                    867:        return (FALSE);
                    868:     }
                    869:     if(gc->HAA_valid == FALSE || ntohl(gc->len) < 0x22) 
                    870:        gc->MAX_CHAN = 0;
                    871:     
                    872:     if (reg_IRQ[gc->IRQ] == FALSE) {   /* Interrupt already registered ? */
                    873:        if (!request_irq(gc->IRQ, (void *) eata_fake_int_handler, SA_INTERRUPT,
                    874:                         "eata_dma")){
                    875:            reg_IRQ[gc->IRQ]++;
                    876:            if (!gc->IRQ_TR)
                    877:                reg_IRQL[gc->IRQ] = TRUE;   /* IRQ is edge triggered */
                    878:        } else {
                    879:            printk("Couldn't allocate IRQ %d, Sorry.", gc->IRQ);
                    880:            return (FALSE);
                    881:        }
                    882:     } else {           /* More than one HBA on this IRQ */
                    883:        if (reg_IRQL[gc->IRQ] == TRUE) {
                    884:            printk("Can't support more than one HBA on this IRQ,\n"
                    885:                   "  if the IRQ is edge triggered. Sorry.\n");
                    886:            return (FALSE);
                    887:        } else
                    888:            reg_IRQ[gc->IRQ]++;
                    889:     }
                    890:     
                    891:     /* if gc->DMA_valid it must be an ISA HBA and we have to register it */
                    892:     dma_channel = BUSMASTER;
                    893:     if (gc->DMA_valid) {
                    894:        if (request_dma(dma_channel = (8 - gc->DMA_channel) & 7, "eata_dma")) {
                    895:            printk("Unable to allocate DMA channel %d for ISA HBA at %#.4x.\n",
                    896:                   dma_channel, base);
                    897:            reg_IRQ[gc->IRQ]--;
                    898:            if (reg_IRQ[gc->IRQ] == 0)
                    899:                free_irq(gc->IRQ);
                    900:            if (gc->IRQ_TR == FALSE)
                    901:                reg_IRQL[gc->IRQ] = FALSE; 
                    902:            return (FALSE);
                    903:        }
                    904:     }
                    905:  
                    906: #if !(NEWSTUFF)
                    907:     if (bustype != IS_EISA && bustype != IS_ISA)
                    908: #endif
                    909:        buff = get_board_data(base, gc->IRQ, gc->scsi_id[3]);
                    910: 
                    911:     if (buff == NULL) {
                    912: #if !(NEWSTUFF)
                    913:        if (bustype == IS_EISA || bustype == IS_ISA) {
                    914:            bugs = bugs || BROKEN_INQUIRY;
                    915:        } else {
                    916: #endif
                    917:            if (gc->DMA_support == FALSE)
                    918:                printk("HBA at %#.4x doesn't support DMA. Sorry\n", base);
                    919:            else
                    920:                printk("HBA at %#.4x does not react on INQUIRY. Sorry.\n", 
                    921:                       base);
                    922:            if (gc->DMA_valid) 
                    923:                free_dma(dma_channel);
                    924:            reg_IRQ[gc->IRQ]--;
                    925:            if (reg_IRQ[gc->IRQ] == 0)
                    926:                free_irq(gc->IRQ);
                    927:            if (gc->IRQ_TR == FALSE)
                    928:                reg_IRQL[gc->IRQ] = FALSE; 
                    929:            return (FALSE);
                    930: #if !(NEWSTUFF)
                    931:        }
                    932: #endif
                    933:     }
                    934:     
                    935:     if (gc->DMA_support == FALSE && buff != NULL)  
                    936:        printk("HBA %.12sat %#.4x doesn't set the DMA_support flag correctly.\n",
                    937:               &buff[16], base);
                    938:     
                    939:     request_region(base, 9, "eata_dma"); /* We already checked the 
                    940:                                          * availability, so this
                    941:                                          * should not fail.
                    942:                                          */
                    943:     
                    944:     if(ntohs(gc->queuesiz) == 0) {
                    945:        gc->queuesiz = ntohs(64);
                    946:        printk("Warning: Queue size has to be corrected. Assuming 64 queueslots\n"
                    947:               "         This might be a PM2012B with a defective Firmware\n");
                    948:     }
                    949: 
                    950:     size = sizeof(hostdata) + ((sizeof(struct eata_ccb) + sizeof(long)) 
                    951:                               * ntohs(gc->queuesiz));
                    952: 
                    953:     DBG(DBG_REGISTER, printk("scsi_register size: %ld\n", size));
                    954: 
                    955:     sh = scsi_register(tpnt, size);
                    956:     
                    957:     if(sh == NULL) {
                    958:        if (gc->DMA_valid) 
                    959:            free_dma(dma_channel);
                    960:        
                    961:        reg_IRQ[gc->IRQ]--;
                    962:        if (reg_IRQ[gc->IRQ] == 0)
                    963:            free_irq(gc->IRQ);
                    964:        if (gc->IRQ_TR == FALSE)
                    965:            reg_IRQL[gc->IRQ] = FALSE; 
                    966:        return (FALSE);
                    967:     }
                    968:     
                    969:     hd = SD(sh);                  
                    970:     
                    971:     memset(hd->ccb, 0, sizeof(struct eata_ccb) * ntohs(gc->queuesiz));
                    972:     memset(hd->reads, 0, sizeof(u32) * 26); 
                    973: 
                    974:     hd->broken_INQUIRY = (bugs & BROKEN_INQUIRY);
                    975: 
                    976:     if(hd->broken_INQUIRY == TRUE) {
                    977:        strcpy(SD(sh)->vendor, "DPT");
                    978:        strcpy(SD(sh)->name, "??????????");
                    979:        strcpy(SD(sh)->revision, "???.?");
                    980:     } else {   
                    981:        strncpy(SD(sh)->vendor, &buff[8], 8);
                    982:        SD(sh)->vendor[8] = 0;
                    983:        strncpy(SD(sh)->name, &buff[16], 17);
                    984:        SD(sh)->name[17] = 0;
                    985:        SD(sh)->revision[0] = buff[32];
                    986:        SD(sh)->revision[1] = buff[33];
                    987:        SD(sh)->revision[2] = buff[34];
                    988:        SD(sh)->revision[3] = '.';
                    989:        SD(sh)->revision[4] = buff[35];
                    990:        SD(sh)->revision[5] = 0;
                    991:     }
                    992: 
                    993:     switch (ntohl(gc->len)) {
                    994:     case 0x1c:
                    995:        SD(sh)->EATA_revision = 'a';
                    996:        break;
                    997:     case 0x1e:
                    998:        SD(sh)->EATA_revision = 'b';
                    999:        break;
                   1000:     case 0x22:
                   1001:        SD(sh)->EATA_revision = 'c';
                   1002:        break;
                   1003:     case 0x24:
                   1004:        SD(sh)->EATA_revision = 'z';            
                   1005:     default:
                   1006:        SD(sh)->EATA_revision = '?';
                   1007:     }
                   1008: 
                   1009:     if(ntohl(gc->len) >= 0x22) {
                   1010:        if (gc->is_PCI == TRUE)
                   1011:            hd->bustype = IS_PCI;
                   1012:        else if (gc->is_EISA == TRUE)
                   1013:            hd->bustype = IS_EISA;
                   1014:        else
                   1015:            hd->bustype = IS_ISA;
                   1016:     } else if(hd->broken_INQUIRY == FALSE) {
                   1017:        if (buff[21] == '4')
                   1018:            hd->bustype = IS_PCI;
                   1019:        else if (buff[21] == '2')
                   1020:            hd->bustype = IS_EISA;
                   1021:        else
                   1022:            hd->bustype = IS_ISA;
                   1023:     } else 
                   1024:        hd->bustype = bustype;
                   1025:     
                   1026:     if(ntohl(gc->len) >= 0x22) {
                   1027:        sh->max_id = gc->MAX_ID + 1;
                   1028:        sh->max_lun = gc->MAX_LUN + 1;
                   1029:     } else {
                   1030:        sh->max_id = 8;
                   1031:        sh->max_lun = 8;
                   1032:     }
                   1033: 
                   1034:     hd->channel = gc->MAX_CHAN;            
                   1035:     sh->max_channel = gc->MAX_CHAN; 
                   1036:     sh->unique_id = base;
                   1037:     sh->base = (char *) base;
                   1038:     sh->io_port = base;
                   1039:     sh->n_io_port = 9;
                   1040:     sh->irq = gc->IRQ;
                   1041:     sh->dma_channel = dma_channel;
                   1042:     
                   1043:     /* FIXME:
                   1044:      * SCSI midlevel code should support different HBA ids on every channel
                   1045:      */
                   1046:     sh->this_id = gc->scsi_id[3];
                   1047:     sh->can_queue = ntohs(gc->queuesiz);
                   1048:     
                   1049:     if (gc->OCS_enabled == TRUE) {
                   1050:        if(hd->bustype != IS_ISA)
                   1051:            sh->cmd_per_lun = sh->can_queue/C_P_L_DIV; 
                   1052:        else
                   1053:            sh->cmd_per_lun = 8; /* We artificially limit this to conserve 
                   1054:                                  * memory, which would be needed for ISA 
                   1055:                                  * bounce buffers */
                   1056:     } else 
                   1057:        sh->cmd_per_lun = 1;
                   1058:     
                   1059:     /* FIXME:
                   1060:      * SG should be allocated more dynamically 
                   1061:      */
                   1062:     /*
                   1063:      * If we are using a ISA board, we can't use extended SG,
                   1064:      * because we would need exessive amounts of memory for
                   1065:      * bounce buffers.
                   1066:      */
                   1067:     if (gc->SG_64K == TRUE && ntohs(gc->SGsiz) == 64 && hd->bustype != IS_ISA){
                   1068:        sh->sg_tablesize = SG_SIZE_BIG;
                   1069:        sh->use_clustering = FALSE;
                   1070:     } else {
                   1071:        sh->sg_tablesize = ntohs(gc->SGsiz);
                   1072:        sh->use_clustering = TRUE;
                   1073:        if (sh->sg_tablesize > SG_SIZE || sh->sg_tablesize == 0) {
                   1074:            sh->sg_tablesize = SG_SIZE;
                   1075:            if (ntohs(gc->SGsiz) == 0)
                   1076:                printk("Warning: SG size had to be corrected.\n"
                   1077:                       "This might be a PM2012 with a defective Firmware\n");
                   1078:        }
                   1079:     }
                   1080: 
                   1081:     if (gc->SECOND)
                   1082:        hd->primary = FALSE;
                   1083:     else
                   1084:        hd->primary = TRUE;
                   1085:     
                   1086:     sh->wish_block = FALSE;       
                   1087:     
                   1088:     if (hd->bustype != IS_ISA) {
                   1089:        sh->unchecked_isa_dma = FALSE;
                   1090:     } else {
                   1091:        sh->unchecked_isa_dma = TRUE;   /* We're doing ISA DMA */
                   1092:     }
                   1093:     
                   1094:     for(x = 0; x <= 11; x++){           /* Initialize min. latency */
                   1095:        hd->writes_lat[x][1] = 0xffffffff;
                   1096:        hd->reads_lat[x][1] = 0xffffffff;
                   1097:     }
                   1098: 
                   1099:     hd->next = NULL;   /* build a linked list of all HBAs */
                   1100:     hd->prev = last_HBA;
                   1101:     if(hd->prev != NULL)
                   1102:        SD(hd->prev)->next = sh;
                   1103:     last_HBA = sh;
                   1104:     if (first_HBA == NULL)
                   1105:        first_HBA = sh;
                   1106:     registered_HBAs++;
                   1107:     
                   1108:     return (TRUE);
                   1109: }
                   1110: 
                   1111: 
                   1112: void find_EISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
                   1113: {
                   1114:     u32 base;
                   1115:     int i;
                   1116:     
                   1117: #if CHECKPAL
                   1118:     u8 pal1, pal2, pal3;
                   1119: #endif
                   1120:     
                   1121:     for (i = 0; i < MAXEISA; i++) {
                   1122:        if (EISAbases[i] == TRUE) { /* Still a possibility ?          */
                   1123:            
                   1124:            base = 0x1c88 + (i * 0x1000);
                   1125: #if CHECKPAL
                   1126:            pal1 = inb((u16)base - 8);
                   1127:            pal2 = inb((u16)base - 7);
                   1128:            pal3 = inb((u16)base - 6);
                   1129:            
                   1130:            if (((pal1 == DPT_ID1) && (pal2 == DPT_ID2)) ||
                   1131:                ((pal1 == NEC_ID1) && (pal2 == NEC_ID2) && (pal3 == NEC_ID3))||
                   1132:                ((pal1 == ATT_ID1) && (pal2 == ATT_ID2) && (pal3 == ATT_ID3))){
                   1133:                DBG(DBG_PROBE, printk("EISA EATA id tags found: %x %x %x \n",
                   1134:                                      (int)pal1, (int)pal2, (int)pal3));
                   1135: #endif
                   1136:                if (get_conf_PIO(base, buf) == TRUE) {
                   1137:                    if (buf->IRQ) {  
                   1138:                        DBG(DBG_EISA, printk("Registering EISA HBA\n"));
                   1139:                        register_HBA(base, buf, tpnt, IS_EISA);
                   1140:                    } else
                   1141:                        printk("eata_dma: No valid IRQ. HBA removed from list\n");
                   1142:                } else {
                   1143:                    if (check_blink_state(base)) 
                   1144:                        printk("HBA is in BLINK state. Consult your HBAs "
                   1145:                               "Manual to correct this.\n");
                   1146:                } 
                   1147:                /* Nothing found here so we take it from the list */
                   1148:                EISAbases[i] = 0;  
                   1149: #if CHECKPAL
                   1150:            } 
                   1151: #endif
                   1152:        }
                   1153:     }
                   1154:     return; 
                   1155: }
                   1156: 
                   1157: void find_ISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
                   1158: {
                   1159:     int i;
                   1160:     
                   1161:     for (i = 0; i < MAXISA; i++) {  
                   1162:        if (ISAbases[i]) {  
                   1163:            if (get_conf_PIO(ISAbases[i],buf) == TRUE){
                   1164:                DBG(DBG_ISA, printk("Registering ISA HBA\n"));
                   1165:                register_HBA(ISAbases[i], buf, tpnt, IS_ISA);
                   1166:            } else {
                   1167:                if (check_blink_state(ISAbases[i])) 
                   1168:                    printk("HBA is in BLINK state. Consult your HBAs "
                   1169:                           "Manual to correct this.\n");
                   1170:            }
                   1171:            ISAbases[i] = 0;
                   1172:        }
                   1173:     }
                   1174:     return;
                   1175: }
                   1176: 
                   1177: void find_PCI(struct get_conf *buf, Scsi_Host_Template * tpnt)
                   1178: {
                   1179: 
                   1180: #ifndef CONFIG_PCI
                   1181:     printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
                   1182: #else
                   1183:     
                   1184:     u8 pci_bus, pci_device_fn;
                   1185:     static s16 pci_index = 0;  /* Device index to PCI BIOS calls */
                   1186:     u32 base = 0;
                   1187:     u16 com_adr;
                   1188:     u16 rev_device;
                   1189:     u32 error, i, x;
                   1190:     u8 pal1, pal2, pal3;
                   1191: 
                   1192:     if (pcibios_present()) {
                   1193:        for (i = 0; i <= MAXPCI; ++i, ++pci_index) {
                   1194:            if (pcibios_find_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, 
                   1195:                                    pci_index, &pci_bus, &pci_device_fn))
                   1196:                break;
                   1197:            DBG(DBG_PROBE && DBG_PCI, 
                   1198:                printk("eata_dma: find_PCI, HBA at bus %d, device %d,"
                   1199:                       " function %d, index %d\n", (s32)pci_bus, 
                   1200:                       (s32)((pci_device_fn & 0xf8) >> 3),
                   1201:                       (s32)(pci_device_fn & 7), pci_index));
                   1202:            
                   1203:            if (!(error = pcibios_read_config_word(pci_bus, pci_device_fn, 
                   1204:                                       PCI_CLASS_DEVICE, &rev_device))) {
                   1205:                if (rev_device == PCI_CLASS_STORAGE_SCSI) {
                   1206:                    if (!(error = pcibios_read_config_word(pci_bus, 
                   1207:                                               pci_device_fn, PCI_COMMAND, 
                   1208:                                               (u16 *) & com_adr))) {
                   1209:                        if (!((com_adr & PCI_COMMAND_IO) && 
                   1210:                              (com_adr & PCI_COMMAND_MASTER))) {
                   1211:                            printk("eata_dma: find_PCI, HBA has IO or BUSMASTER mode disabled\n");
                   1212:                            continue;
                   1213:                        }
                   1214:                    } else
                   1215:                        printk("eata_dma: find_PCI, error %x while reading "
                   1216:                               "PCI_COMMAND\n", error);
                   1217:                } else
                   1218:                    printk("eata_dma: find_PCI, DEVICECLASSID %x didn't match\n", 
                   1219:                           rev_device);
                   1220:            } else {
                   1221:                printk("eata_dma: find_PCI, error %x while reading PCI_CLASS_BASE\n", 
                   1222:                       error);
                   1223:                continue;
                   1224:            }
                   1225:            
                   1226:            if (!(error = pcibios_read_config_dword(pci_bus, pci_device_fn,
                   1227:                                       PCI_BASE_ADDRESS_0, (int *) &base))){
                   1228:                
                   1229:                /* Check if the address is valid */
                   1230:                if (base & 0x01) {
                   1231:                    base &= 0xfffffffe;
                   1232:                     /* EISA tag there ? */
                   1233:                    pal1 = inb(base);
                   1234:                    pal2 = inb(base + 1);
                   1235:                    pal3 = inb(base + 2);
                   1236:                    if (((pal1 == DPT_ID1) && (pal2 == DPT_ID2)) ||
                   1237:                        ((pal1 == NEC_ID1) && (pal2 == NEC_ID2) && 
                   1238:                         (pal3 == NEC_ID3)) ||
                   1239:                        ((pal1 == ATT_ID1) && (pal2 == ATT_ID2) && 
                   1240:                         (pal3 == ATT_ID3)))
                   1241:                        base += 0x08;
                   1242:                    else
                   1243:                        base += 0x10;   /* Now, THIS is the real address */
                   1244: 
                   1245:                    if (base != 0x1f8) {
                   1246:                        /* We didn't find it in the primary search */
                   1247:                        if (get_conf_PIO(base, buf) == TRUE) {
                   1248: 
                   1249:                            /* OK. We made it till here, so we can go now  
                   1250:                             * and register it. We  only have to check and 
                   1251:                             * eventually remove it from the EISA and ISA list 
                   1252:                             */
                   1253:                            DBG(DBG_PCI, printk("Registering PCI HBA\n"));
                   1254:                            register_HBA(base, buf, tpnt, IS_PCI);
                   1255:                            
                   1256:                            if (base < 0x1000) {
                   1257:                                for (x = 0; x < MAXISA; ++x) {
                   1258:                                    if (ISAbases[x] == base) {
                   1259:                                        ISAbases[x] = 0;
                   1260:                                        break;
                   1261:                                    }
                   1262:                                }
                   1263:                            } else if ((base & 0x0fff) == 0x0c88) 
                   1264:                                EISAbases[(base >> 12) & 0x0f] = 0;
                   1265:                            continue;  /* break; */
                   1266:                        } else if (check_blink_state(base) == TRUE) {
                   1267:                            printk("eata_dma: HBA is in BLINK state.\n"
                   1268:                                   "Consult your HBAs Manual to correct this.\n");
                   1269:                        }
                   1270:                    }
                   1271:                }
                   1272:            } else {
                   1273:                printk("eata_dma: error %x while reading "
                   1274:                       "PCI_BASE_ADDRESS_0\n", error);
                   1275:            }
                   1276:        }
                   1277:     } else {
                   1278:        printk("eata_dma: No BIOS32 extensions present. This driver release "
                   1279:               "still depends on it.\n"
                   1280:               "          Skipping scan for PCI HBAs. \n");
                   1281:     }
                   1282: #endif /* #ifndef CONFIG_PCI */
                   1283:     return;
                   1284: }
                   1285: 
                   1286: int eata_detect(Scsi_Host_Template * tpnt)
                   1287: {
                   1288:     struct Scsi_Host *HBA_ptr;
                   1289:     struct get_conf gc;
                   1290:     int i;
                   1291:     
                   1292:     DBG((DBG_PROBE && DBG_DELAY) || DPT_DEBUG,
                   1293:        printk("Using lots of delays to let you read the debugging output\n"));
                   1294: 
                   1295:     tpnt->proc_dir = &proc_scsi_eata_dma;
                   1296: 
                   1297:     status = scsi_init_malloc(512, GFP_ATOMIC | GFP_DMA);
                   1298:     dma_scratch = scsi_init_malloc(512, GFP_ATOMIC | GFP_DMA);
                   1299: 
                   1300:     if(status == NULL || dma_scratch == NULL) {
                   1301:        printk("eata_dma: can't allocate enough memory to probe for hosts !\n");
                   1302:        return(0);
                   1303:     }
                   1304: 
                   1305:     find_PCI(&gc, tpnt);
                   1306:     
                   1307:     find_EISA(&gc, tpnt);
                   1308:     
                   1309:     find_ISA(&gc, tpnt);
                   1310:     
                   1311:     for (i = 0; i <= MAXIRQ; i++) { /* Now that we know what we have, we     */
                   1312:        if (reg_IRQ[i]){            /* exchange the interrupt handler which  */
                   1313:            free_irq(i);            /* we used for probing with the real one */
                   1314:            request_irq(i, (void *)(eata_int_handler), SA_INTERRUPT, "eata_dma");
                   1315:        }
                   1316:     }
                   1317:     HBA_ptr = first_HBA;
                   1318:     
                   1319:     if (registered_HBAs != 0) {
                   1320:        printk("EATA (Extended Attachment) driver version: %d.%d%s\n"
                   1321:               "developed in co-operation with DPT\n"             
                   1322:               "(c) 1993-95 Michael Neuffer, [email protected]\n",
                   1323:               VER_MAJOR, VER_MINOR, VER_SUB);
                   1324:        printk("Registered HBAs:");
                   1325:        printk("\nHBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: DMA: Ch: "
                   1326:               "ID: Pr: QS: SG: CPL:\n");
                   1327:        for (i = 1; i <= registered_HBAs; i++) {
                   1328:            printk("scsi%-2d: %.10s v%s 2.0%c  %s %#.4x   %2d",
                   1329:                   HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
                   1330:                   SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P')? 
                   1331:                   "PCI ":(SD(HBA_ptr)->bustype == 'E')?"EISA":"ISA ",
                   1332:                   (u32) HBA_ptr->base, HBA_ptr->irq);
                   1333:            if(HBA_ptr->dma_channel != BUSMASTER)
                   1334:                printk("   %2x ", HBA_ptr->dma_channel);
                   1335:            else
                   1336:                printk("  %s", "BMST");
                   1337:            printk("  %d   %d   %c  %2d  %2d   %2d\n", SD(HBA_ptr)->channel, 
                   1338:                   HBA_ptr->this_id, (SD(HBA_ptr)->primary == TRUE)?'Y':'N', 
                   1339:                   HBA_ptr->can_queue, HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);
                   1340:            HBA_ptr = SD(HBA_ptr)->next;
                   1341:        }
                   1342:     } else {
                   1343:        scsi_init_free((void *)status, 512);
                   1344:     }
                   1345: 
                   1346:     scsi_init_free((void *)dma_scratch, 512);
                   1347: 
                   1348:     DBG(DPT_DEBUG, DELAY(12));
                   1349: 
                   1350:     return(registered_HBAs);
                   1351: }
                   1352: 
                   1353: #ifdef MODULE
                   1354: /* Eventually this will go into an include file, but this will be later */
                   1355: Scsi_Host_Template driver_template = EATA_DMA;
                   1356: #include "scsi_module.c"
                   1357: #endif
                   1358: 
                   1359: /*
                   1360:  * Overrides for Emacs so that we almost follow Linus's tabbing style.
                   1361:  * Emacs will notice this stuff at the end of the file and automatically
                   1362:  * adjust the settings for this buffer only.  This must remain at the end
                   1363:  * of the file.
                   1364:  * ---------------------------------------------------------------------------
                   1365:  * Local variables:
                   1366:  * c-indent-level: 4
                   1367:  * c-brace-imaginary-offset: 0
                   1368:  * c-brace-offset: -4
                   1369:  * c-argdecl-indent: 4
                   1370:  * c-label-offset: -4
                   1371:  * c-continued-statement-offset: 4
                   1372:  * c-continued-brace-offset: 0
                   1373:  * tab-width: 8
                   1374:  * End:
                   1375:  */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.