int __init gdth_detect(Scsi_Host_Template *shtp) 
static int __init gdth_detect(Scsi_Host_Template *shtp) 
int __init gdth_detect(Scsi_Host_Template *shtp){    struct Scsi_Host *shp;    gdth_pci_str pcistr[MAXHA];    gdth_ha_str *ha;    ulong32 isa_bios;    ushort eisa_slot;    int i,hanum,cnt,ctr,err;    unchar b;     #ifdef DEBUG_GDTH    printk("GDT: This driver contains debugging information !! Trace level = %d\n",        DebugState);    printk("     Destination of debugging information: ");#ifdef __SERIAL__#ifdef __COM2__    printk("Serial port COM2\n");#else    printk("Serial port COM1\n");#endif#else    printk("Console\n");#endif    gdth_delay(3000);#endif    TRACE(("gdth_detect()\n"));    if (disable) {        printk("GDT-HA: Controller driver disabled from command line !\n");        return 0;    }    printk("GDT-HA: Storage RAID Controller Driver. Version: %s \n",GDTH_VERSION_STR);    /* initializations */    gdth_polling = TRUE; b = 0;    gdth_clear_events();    /* As default we do not probe for EISA or ISA controllers */    if (probe_eisa_isa) {            /* scanning for controllers, at first: ISA controller */        for (isa_bios=0xc8000UL; isa_bios<=0xd8000UL; isa_bios+=0x8000UL) {            dma_addr_t scratch_dma_handle;            scratch_dma_handle = 0;            if (gdth_ctr_count >= MAXHA)                 break;            if (gdth_search_isa(isa_bios)) {        /* controller found */                shp = scsi_register(shtp,sizeof(gdth_ext_str));                if (shp == NULL)                    continue;                  ha = HADATA(shp);                if (!gdth_init_isa(isa_bios,ha)) {                    scsi_unregister(shp);                    continue;                }#ifdef __ia64__                break;#else                /* controller found and initialized */                printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %u\n",                       isa_bios,ha->irq,ha->drq);                if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha)) {                    printk("GDT-ISA: Unable to allocate IRQ\n");                    scsi_unregister(shp);                    continue;                }                if (request_dma(ha->drq,"gdth")) {                    printk("GDT-ISA: Unable to allocate DMA channel\n");                    free_irq(ha->irq,ha);                    scsi_unregister(shp);                    continue;                }                set_dma_mode(ha->drq,DMA_MODE_CASCADE);                enable_dma(ha->drq);                shp->unchecked_isa_dma = 1;                shp->irq = ha->irq;                shp->dma_channel = ha->drq;                hanum = gdth_ctr_count;                         gdth_ctr_tab[gdth_ctr_count++] = shp;                gdth_ctr_vtab[gdth_ctr_vcount++] = shp;                NUMDATA(shp)->hanum = (ushort)hanum;                NUMDATA(shp)->busnum= 0;                ha->pccb = CMDDATA(shp);                ha->ccb_phys = 0L;                ha->pdev = NULL;                ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,                                                     &scratch_dma_handle);                ha->scratch_phys = scratch_dma_handle;                ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),                                                 &scratch_dma_handle);                ha->msg_phys = scratch_dma_handle;#ifdef INT_COAL                ha->coal_stat = (gdth_coal_status *)                    pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *                        MAXOFFSETS, &scratch_dma_handle);                ha->coal_stat_phys = scratch_dma_handle;#endif                ha->scratch_busy = FALSE;                ha->req_first = NULL;                ha->tid_cnt = MAX_HDRIVES;                if (max_ids > 0 && max_ids < ha->tid_cnt)                    ha->tid_cnt = max_ids;                for (i=0; i<GDTH_MAXCMDS; ++i)                    ha->cmd_tab[i].cmnd = UNUSED_CMND;                ha->scan_mode = rescan ? 0x10 : 0;                if (ha->pscratch == NULL || ha->pmsg == NULL ||                     !gdth_search_drives(hanum)) {                    printk("GDT-ISA: Error during device scan\n");                    --gdth_ctr_count;                    --gdth_ctr_vcount;#ifdef INT_COAL                    if (ha->coal_stat)                        pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *                                            MAXOFFSETS, ha->coal_stat,                                            ha->coal_stat_phys);#endif                    if (ha->pscratch)                        pci_free_consistent(ha->pdev, GDTH_SCRATCH,                                             ha->pscratch, ha->scratch_phys);                    if (ha->pmsg)                        pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),                                             ha->pmsg, ha->msg_phys);                    free_irq(ha->irq,ha);                    scsi_unregister(shp);                    continue;                }                if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)                    hdr_channel = ha->bus_cnt;                ha->virt_bus = hdr_channel;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \    LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)                shp->highmem_io  = 0;#endif                if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)                     shp->max_cmd_len = 16;                shp->max_id      = ha->tid_cnt;                shp->max_lun     = MAXLUN;                shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;                if (virt_ctr) {                    virt_ctr = 1;                    /* register addit. SCSI channels as virtual controllers */                    for (b = 1; b < ha->bus_cnt + 1; ++b) {                        shp = scsi_register(shtp,sizeof(gdth_num_str));                        shp->unchecked_isa_dma = 1;                        shp->irq = ha->irq;                        shp->dma_channel = ha->drq;                        gdth_ctr_vtab[gdth_ctr_vcount++] = shp;                        NUMDATA(shp)->hanum = (ushort)hanum;                        NUMDATA(shp)->busnum = b;                    }                }                  spin_lock_init(&ha->smp_lock);                gdth_enable_int(hanum);#endif /* !__ia64__ */            }        }        /* scanning for EISA controllers */        for (eisa_slot=0x1000; eisa_slot<=0x8000; eisa_slot+=0x1000) {            dma_addr_t scratch_dma_handle;            scratch_dma_handle = 0;            if (gdth_ctr_count >= MAXHA)                 break;            if (gdth_search_eisa(eisa_slot)) {      /* controller found */                shp = scsi_register(shtp,sizeof(gdth_ext_str));                if (shp == NULL)                    continue;                  ha = HADATA(shp);                if (!gdth_init_eisa(eisa_slot,ha)) {                    scsi_unregister(shp);                    continue;                }                /* controller found and initialized */                printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",                       eisa_slot>>12,ha->irq);                if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha)) {                    printk("GDT-EISA: Unable to allocate IRQ\n");                    scsi_unregister(shp);                    continue;                }                shp->unchecked_isa_dma = 0;                shp->irq = ha->irq;                shp->dma_channel = 0xff;                hanum = gdth_ctr_count;                gdth_ctr_tab[gdth_ctr_count++] = shp;                gdth_ctr_vtab[gdth_ctr_vcount++] = shp;                NUMDATA(shp)->hanum = (ushort)hanum;                NUMDATA(shp)->busnum= 0;                TRACE2(("EISA detect Bus 0: hanum %d\n",                        NUMDATA(shp)->hanum));                ha->pccb = CMDDATA(shp);                ha->ccb_phys = 0L;                 ha->pdev = NULL;                ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,                                                     &scratch_dma_handle);                ha->scratch_phys = scratch_dma_handle;                ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),                                                 &scratch_dma_handle);                ha->msg_phys = scratch_dma_handle;#ifdef INT_COAL                ha->coal_stat = (gdth_coal_status *)                    pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *                                         MAXOFFSETS, &scratch_dma_handle);                ha->coal_stat_phys = scratch_dma_handle;#endif                ha->ccb_phys =                     pci_map_single(ha->pdev,ha->pccb,                                   sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);                ha->scratch_busy = FALSE;                ha->req_first = NULL;                ha->tid_cnt = MAX_HDRIVES;                if (max_ids > 0 && max_ids < ha->tid_cnt)                    ha->tid_cnt = max_ids;                for (i=0; i<GDTH_MAXCMDS; ++i)                    ha->cmd_tab[i].cmnd = UNUSED_CMND;                ha->scan_mode = rescan ? 0x10 : 0;                if (ha->pscratch == NULL || ha->pmsg == NULL ||                     !gdth_search_drives(hanum)) {                    printk("GDT-EISA: Error during device scan\n");                    --gdth_ctr_count;                    --gdth_ctr_vcount;#ifdef INT_COAL                    if (ha->coal_stat)                        pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *                                            MAXOFFSETS, ha->coal_stat,                                            ha->coal_stat_phys);#endif                    if (ha->pscratch)                        pci_free_consistent(ha->pdev, GDTH_SCRATCH,                                             ha->pscratch, ha->scratch_phys);                    if (ha->pmsg)                        pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),                                             ha->pmsg, ha->msg_phys);                    if (ha->ccb_phys)                        pci_unmap_single(ha->pdev,ha->ccb_phys,                                        sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);                    free_irq(ha->irq,ha);                    scsi_unregister(shp);                    continue;                }                if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)                    hdr_channel = ha->bus_cnt;                ha->virt_bus = hdr_channel;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && \    LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)                shp->highmem_io  = 0;#endif                if (ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT)                     shp->max_cmd_len = 16;                shp->max_id      = ha->tid_cnt;                shp->max_lun     = MAXLUN;                shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;                if (virt_ctr) {                    virt_ctr = 1;                    /* register addit. SCSI channels as virtual controllers */                    for (b = 1; b < ha->bus_cnt + 1; ++b) {                        shp = scsi_register(shtp,sizeof(gdth_num_str));                        shp->unchecked_isa_dma = 0;                        shp->irq = ha->irq;                        shp->dma_channel = 0xff;                        gdth_ctr_vtab[gdth_ctr_vcount++] = shp;                        NUMDATA(shp)->hanum = (ushort)hanum;                        NUMDATA(shp)->busnum = b;                    }                }                  spin_lock_init(&ha->smp_lock);                gdth_enable_int(hanum);            }        }    }    /* scanning for PCI controllers */    cnt = gdth_search_pci(pcistr);    printk("GDT-HA: Found %d PCI Storage RAID Controllers\n",cnt);    gdth_sort_pci(pcistr,cnt);    for (ctr = 0; ctr < cnt; ++ctr) {        dma_addr_t scratch_dma_handle;        scratch_dma_handle = 0;        if (gdth_ctr_count >= MAXHA)            break;        shp = scsi_register(shtp,sizeof(gdth_ext_str));        if (shp == NULL)            continue;          ha = HADATA(shp);        if (!gdth_init_pci(&pcistr[ctr],ha)) {            scsi_unregister(shp);            continue;        }        /* controller found and initialized */        printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",               pcistr[ctr].bus,PCI_SLOT(pcistr[ctr].device_fn),ha->irq);        if (request_irq(ha->irq, gdth_interrupt,                        SA_INTERRUPT|SA_SHIRQ, "gdth", ha))        {            printk("GDT-PCI: Unable to allocate IRQ\n");            scsi_unregister(shp);            continue;        }        shp->unchecked_isa_dma = 0;        shp->irq = ha->irq;        shp->dma_channel = 0xff;        hanum = gdth_ctr_count;        gdth_ctr_tab[gdth_ctr_count++] = shp;        gdth_ctr_vtab[gdth_ctr_vcount++] = shp;        NUMDATA(shp)->hanum = (ushort)hanum;        NUMDATA(shp)->busnum= 0;        ha->pccb = CMDDATA(shp);        ha->ccb_phys = 0L;        ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,                                             &scratch_dma_handle);        ha->scratch_phys = scratch_dma_handle;        ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),                                         &scratch_dma_handle);        ha->msg_phys = scratch_dma_handle;#ifdef INT_COAL        ha->coal_stat = (gdth_coal_status *)            pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *                                 MAXOFFSETS, &scratch_dma_handle);        ha->coal_stat_phys = scratch_dma_handle;#endif        ha->scratch_busy = FALSE;        ha->req_first = NULL;        ha->tid_cnt = pcistr[ctr].device_id >= 0x200 ? MAXID : MAX_HDRIVES;        if (max_ids > 0 && max_ids < ha->tid_cnt)            ha->tid_cnt = max_ids;        for (i=0; i<GDTH_MAXCMDS; ++i)            ha->cmd_tab[i].cmnd = UNUSED_CMND;        ha->scan_mode = rescan ? 0x10 : 0;        err = FALSE;        if (ha->pscratch == NULL || ha->pmsg == NULL ||             !gdth_search_drives(hanum)) {            err = TRUE;        } else {            if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)                hdr_channel = ha->bus_cnt;            ha->virt_bus = hdr_channel;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)            scsi_set_device(shp, &pcistr[ctr].pdev->dev);#else            scsi_set_pci_device(shp, pcistr[ctr].pdev);#endif            if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat &GDT_64BIT)||                /* 64-bit DMA only supported from FW >= x.43 */                (!ha->dma64_support)) {                if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) {                    printk(KERN_WARNING "GDT-PCI %d: Unable to set 32-bit DMA\n", hanum);                    err = TRUE;                }            } else {                shp->max_cmd_len = 16;                if (!pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffffffffffffULL)) {                    printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);                } else if (pci_set_dma_mask(pcistr[ctr].pdev, 0xffffffff)) {                    printk(KERN_WARNING "GDT-PCI %d: Unable to set 64/32-bit DMA\n", hanum);                    err = TRUE;                }            }        }        if (err) {            printk("GDT-PCI %d: Error during device scan\n", hanum);            --gdth_ctr_count;            --gdth_ctr_vcount;#ifdef INT_COAL            if (ha->coal_stat)                pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *                                    MAXOFFSETS, ha->coal_stat,                                    ha->coal_stat_phys);#endif            if (ha->pscratch)                pci_free_consistent(ha->pdev, GDTH_SCRATCH,                                     ha->pscratch, ha->scratch_phys);            if (ha->pmsg)                pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),                                     ha->pmsg, ha->msg_phys);            free_irq(ha->irq,ha);            scsi_unregister(shp);            continue;        }        shp->max_id      = ha->tid_cnt;        shp->max_lun     = MAXLUN;        shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;        if (virt_ctr) {            virt_ctr = 1;            /* register addit. SCSI channels as virtual controllers */            for (b = 1; b < ha->bus_cnt + 1; ++b) {                shp = scsi_register(shtp,sizeof(gdth_num_str));                shp->unchecked_isa_dma = 0;                shp->irq = ha->irq;                shp->dma_channel = 0xff;                gdth_ctr_vtab[gdth_ctr_vcount++] = shp;                NUMDATA(shp)->hanum = (ushort)hanum;                NUMDATA(shp)->busnum = b;            }        }          spin_lock_init(&ha->smp_lock);        gdth_enable_int(hanum);    }        TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count));    if (gdth_ctr_count > 0) {#ifdef GDTH_STATISTICS        TRACE2(("gdth_detect(): Initializing timer !\n"));        init_timer(&gdth_timer);        gdth_timer.expires = jiffies + HZ;        gdth_timer.data = 0L;        gdth_timer.function = gdth_timeout;        add_timer(&gdth_timer);#endif        major = register_chrdev(0,"gdth",&gdth_fops);        register_reboot_notifier(&gdth_notifier);    }    gdth_polling = FALSE;    return gdth_ctr_vcount;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/8e8790415e91964096f862a58cacb55d2bc9a817/gdth.c/buggy/drivers/scsi/gdth.c