public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] gdth: Split out EISA and ISA register into separate functions
@ 2007-09-26  4:33 Jeff Garzik
  2007-09-26  4:34 ` [PATCH 2/8] gdth: Split out PCI register into separate function Jeff Garzik
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Jeff Garzik @ 2007-09-26  4:33 UTC (permalink / raw)
  To: achim_leubner, linux-scsi, LKML


An equivalent-transformation change.  No functional changes beyond
those necessary to call the new, split-out functions.

Signed-off-by: Jeff Garzik <jeff@garzik.org>
---

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index b20c188..f330d34 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -4277,6 +4277,274 @@ int __init option_setup(char *str)
     return 1;
 }
 
+static int __init gdth_start_isa(struct scsi_host_template *shtp,
+				 ulong32 isa_bios)
+{
+	struct Scsi_Host *shp;
+	gdth_ha_str *ha;
+	int i, hanum;
+	dma_addr_t scratch_dma_handle = 0;
+
+	shp = scsi_register(shtp, sizeof(gdth_ext_str));
+	if (shp == NULL)
+		return 1;	/* continue looping */
+
+	ha = HADATA(shp);
+	if (!gdth_init_isa(isa_bios, ha)) {
+		scsi_unregister(shp);
+		return 1;	/* continue looping */
+	}
+
+#ifdef __ia64__
+	return 0;		/* end loop: success */
+#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, IRQF_DISABLED, "gdth", ha)) {
+		printk("GDT-ISA: Unable to allocate IRQ\n");
+		scsi_unregister(shp);
+		return 1;	/* continue looping */
+	}
+	if (request_dma(ha->drq, "gdth")) {
+		printk("GDT-ISA: Unable to allocate DMA channel\n");
+		free_irq(ha->irq, ha);
+		scsi_unregister(shp);
+		return 1;	/* continue looping */
+	}
+
+	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);
+		return 1;	/* continue looping */
+	}
+
+	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) {
+		unchar b;
+
+		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__ */
+
+	return 1;	/* continue looping */
+}
+
+static int __init gdth_start_eisa(struct scsi_host_template *shtp,
+				  ushort eisa_slot)
+{
+	struct Scsi_Host *shp;
+	gdth_ha_str *ha;
+	int i, hanum;
+	dma_addr_t scratch_dma_handle = 0;
+
+	shp = scsi_register(shtp,sizeof(gdth_ext_str));
+	if (shp == NULL)
+		return 1;	/* continue looping */
+
+	ha = HADATA(shp);
+	if (!gdth_init_eisa(eisa_slot,ha)) {
+		scsi_unregister(shp);
+		return 1;	/* continue looping */
+	}
+
+	/* 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,IRQF_DISABLED,"gdth",ha)) {
+		printk("GDT-EISA: Unable to allocate IRQ\n");
+		scsi_unregister(shp);
+		return 1;	/* continue looping */
+	}
+
+	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);
+		return 1;	/* continue looping */
+	}
+
+	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) {
+		unchar b;
+
+		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);
+
+	return 1;	/* continue looping */
+}
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 static int __init gdth_detect(struct scsi_host_template *shtp)
 #else
@@ -4286,11 +4554,8 @@ static 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",
@@ -4322,255 +4587,30 @@ static int __init gdth_detect(Scsi_Host_Template *shtp)
 
     /* As default we do not probe for EISA or ISA controllers */
     if (probe_eisa_isa) {    
+        ulong32 isa_bios;
+        ushort eisa_slot;
+
         /* 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,IRQF_DISABLED,"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__ */
+	        err = gdth_start_isa(shtp, isa_bios);
+		if (err <= 0)
+			break;
+	    	/* err > 0 == continue looping */
             }
         }
 
         /* 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,IRQF_DISABLED,"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);
+	        err = gdth_start_eisa(shtp, eisa_slot);
+		if (err <= 0)
+			break;
+	    	/* err > 0 == continue looping */
             }
         }
     }

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/8] gdth: Split out PCI register into separate function
  2007-09-26  4:33 [PATCH 1/8] gdth: Split out EISA and ISA register into separate functions Jeff Garzik
@ 2007-09-26  4:34 ` Jeff Garzik
  2007-09-26  4:34 ` [PATCH 3/8] gdth: Remove 2.4.x support, in-kernel changelog Jeff Garzik
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Garzik @ 2007-09-26  4:34 UTC (permalink / raw)
  To: achim_leubner, linux-scsi, LKML


An equivalent-transformation change.  No functional changes beyond those
necessary to call the new function.
    
Signed-off-by: Jeff Garzik <jeff@garzik.org>
---

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index f330d34..840bdf6 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -4545,16 +4545,167 @@ LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 	return 1;	/* continue looping */
 }
 
+static int __init gdth_start_pci(struct scsi_host_template *shtp,
+				 gdth_pci_str *pcistr, int ctr)
+{
+	struct Scsi_Host *shp;
+	dma_addr_t scratch_dma_handle = 0;
+	gdth_ha_str *ha;
+	int i, hanum, err;
+
+	if (gdth_ctr_count >= MAXHA)
+		return 0;	/* end loop: success */
+	shp = scsi_register(shtp,sizeof(gdth_ext_str));
+	if (shp == NULL)
+		return 1;	/* continue looping */
+
+	ha = HADATA(shp);
+	if (!gdth_init_pci(&pcistr[ctr],ha)) {
+		scsi_unregister(shp);
+		return 1;	/* continue looping */
+	}
+
+	/* controller found and initialized */
+	printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
+	       pcistr[ctr].pdev->bus->number,
+	       PCI_SLOT(pcistr[ctr].pdev->devfn), ha->irq);
+
+	if (request_irq(ha->irq, gdth_interrupt,
+			IRQF_DISABLED | IRQF_SHARED, "gdth", ha)) {
+		printk("GDT-PCI: Unable to allocate IRQ\n");
+		scsi_unregister(shp);
+		return 1;	/* continue looping */
+	}
+
+	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].pdev->device >= 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_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, DMA_32BIT_MASK)){
+				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,DMA_64BIT_MASK)){
+				printk("GDT-PCI %d: 64-bit DMA enabled\n",
+				       hanum);
+			} else if (pci_set_dma_mask(pcistr[ctr].pdev,
+						    DMA_32BIT_MASK)) {
+				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);
+		return 1;	/* continue looping */
+	}
+
+	shp->max_id      = ha->tid_cnt;
+	shp->max_lun     = MAXLUN;
+	shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
+
+	if (virt_ctr) {
+		unchar b;
+
+		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);
+
+	return 1;	/* continue looping */
+}
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 static int __init gdth_detect(struct scsi_host_template *shtp)
 #else
 static int __init gdth_detect(Scsi_Host_Template *shtp)
 #endif
 {
-    struct Scsi_Host *shp;
     gdth_pci_str pcistr[MAXHA];
-    gdth_ha_str *ha;
-    int i,hanum,cnt,ctr,err;
+    int cnt,ctr;
     unchar b;
  
 #ifdef DEBUG_GDTH
@@ -4595,7 +4746,7 @@ static int __init gdth_detect(Scsi_Host_Template *shtp)
             if (gdth_ctr_count >= MAXHA) 
                 break;
             if (gdth_search_isa(isa_bios)) {        /* controller found */
-	        err = gdth_start_isa(shtp, isa_bios);
+	        int err = gdth_start_isa(shtp, isa_bios);
 		if (err <= 0)
 			break;
 	    	/* err > 0 == continue looping */
@@ -4607,7 +4758,7 @@ static int __init gdth_detect(Scsi_Host_Template *shtp)
             if (gdth_ctr_count >= MAXHA) 
                 break;
             if (gdth_search_eisa(eisa_slot)) {      /* controller found */
-	        err = gdth_start_eisa(shtp, eisa_slot);
+	        int err = gdth_start_eisa(shtp, eisa_slot);
 		if (err <= 0)
 			break;
 	    	/* err > 0 == continue looping */
@@ -4620,137 +4771,10 @@ static int __init gdth_detect(Scsi_Host_Template *shtp)
     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].pdev->bus->number,
-	       PCI_SLOT(pcistr[ctr].pdev->devfn), ha->irq);
-
-        if (request_irq(ha->irq, gdth_interrupt,
-                        IRQF_DISABLED|IRQF_SHARED, "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].pdev->device >= 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_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, DMA_32BIT_MASK)) {
-                    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, DMA_64BIT_MASK)) {
-                    printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);
-                } else if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
-                    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);
+        int err = gdth_start_pci(shtp, pcistr, ctr);
+	if (err <= 0)
+		break;
+    	/* err > 0 == continue looping */
     }
     
     TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count));

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/8] gdth: Remove 2.4.x support, in-kernel changelog
  2007-09-26  4:33 [PATCH 1/8] gdth: Split out EISA and ISA register into separate functions Jeff Garzik
  2007-09-26  4:34 ` [PATCH 2/8] gdth: Split out PCI register into separate function Jeff Garzik
@ 2007-09-26  4:34 ` Jeff Garzik
  2007-09-26  4:35 ` [PATCH 4/8] gdth: Isolate driver-global variables using helpers Jeff Garzik
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Garzik @ 2007-09-26  4:34 UTC (permalink / raw)
  To: achim_leubner, linux-scsi, LKML


* Remove in-source changelog.  It's archived permanently in git and
  various kernel archives, and changelogs should exist purely in git.

* Remove 2.4.x kernel support.  It is an active obstacle to
  modernizing this driver, at this point.  This includes killing
  gdth_kcompat.h which is 100% redundant in modern kernels.

Signed-off-by: Jeff Garzik <jeff@garzik.org>
---

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 840bdf6..a6b5717 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -27,280 +27,8 @@
  * along with this kernel; if not, write to the Free Software           *
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
  *                                                                      *
- * Linux kernel 2.4.x, 2.6.x supported                                  *
+ * Linux kernel 2.6.x supported						*
  *                                                                      *
- * $Log: gdth.c,v $
- * Revision 1.74  2006/04/10 13:44:47  achim
- * Community changes for 2.6.x
- * Kernel 2.2.x no longer supported
- * scsi_request interface removed, thanks to Christoph Hellwig
- *
- * Revision 1.73  2004/03/31 13:33:03  achim
- * Special command 0xfd implemented to detect 64-bit DMA support
- *
- * Revision 1.72  2004/03/17 08:56:04  achim
- * 64-bit DMA only enabled if FW >= x.43
- *
- * Revision 1.71  2004/03/05 15:51:29  achim
- * Screen service: separate message buffer, bugfixes
- *
- * Revision 1.70  2004/02/27 12:19:07  achim
- * Bugfix: Reset bit in config (0xfe) call removed
- *
- * Revision 1.69  2004/02/20 09:50:24  achim
- * Compatibility changes for kernels < 2.4.20
- * Bugfix screen service command size
- * pci_set_dma_mask() error handling added
- *
- * Revision 1.68  2004/02/19 15:46:54  achim
- * 64-bit DMA bugfixes
- * Drive size bugfix for drives > 1TB
- *
- * Revision 1.67  2004/01/14 13:11:57  achim
- * Tool access over /proc no longer supported
- * Bugfixes IOCTLs
- *
- * Revision 1.66  2003/12/19 15:04:06  achim
- * Bugfixes support for drives > 2TB
- *
- * Revision 1.65  2003/12/15 11:21:56  achim
- * 64-bit DMA support added
- * Support for drives > 2 TB implemented
- * Kernels 2.2.x, 2.4.x, 2.6.x supported
- *
- * Revision 1.64  2003/09/17 08:30:26  achim
- * EISA/ISA controller scan disabled
- * Command line switch probe_eisa_isa added
- *
- * Revision 1.63  2003/07/12 14:01:00  Daniele Bellucci <bellucda@tiscali.it>
- * Minor cleanups in gdth_ioctl.
- *
- * Revision 1.62  2003/02/27 15:01:59  achim
- * Dynamic DMA mapping implemented
- * New (character device) IOCTL interface added
- * Other controller related changes made
- *
- * Revision 1.61  2002/11/08 13:09:52  boji
- * Added support for XSCALE based RAID Controllers
- * Fixed SCREENSERVICE initialization in SMP cases
- * Added checks for gdth_polling before GDTH_HA_LOCK
- *
- * Revision 1.60  2002/02/05 09:35:22  achim
- * MODULE_LICENSE only if kernel >= 2.4.11
- *
- * Revision 1.59  2002/01/30 09:46:33  achim
- * Small changes
- *
- * Revision 1.58  2002/01/29 15:30:02  achim
- * Set default value of shared_access to Y
- * New status S_CACHE_RESERV for clustering added
- *
- * Revision 1.57  2001/08/21 11:16:35  achim
- * Bugfix free_irq()
- *
- * Revision 1.56  2001/08/09 11:19:39  achim
- * Scsi_Host_Template changes
- *
- * Revision 1.55  2001/08/09 10:11:28  achim
- * Command HOST_UNFREEZE_IO before cache service init.
- *
- * Revision 1.54  2001/07/20 13:48:12  achim
- * Expand: gdth_analyse_hdrive() removed
- *
- * Revision 1.53  2001/07/17 09:52:49  achim
- * Small OEM related change
- *
- * Revision 1.52  2001/06/19 15:06:20  achim
- * New host command GDT_UNFREEZE_IO added
- *
- * Revision 1.51  2001/05/22 06:42:37  achim
- * PCI: Subdevice ID added
- *
- * Revision 1.50  2001/05/17 13:42:16  achim
- * Support for Intel Storage RAID Controllers added
- *
- * Revision 1.50  2001/05/17 12:12:34  achim
- * Support for Intel Storage RAID Controllers added
- *
- * Revision 1.49  2001/03/15 15:07:17  achim
- * New __setup interface for boot command line options added
- *
- * Revision 1.48  2001/02/06 12:36:28  achim
- * Bugfix Cluster protocol
- *
- * Revision 1.47  2001/01/10 14:42:06  achim
- * New switch shared_access added
- *
- * Revision 1.46  2001/01/09 08:11:35  achim
- * gdth_command() removed
- * meaning of Scsi_Pointer members changed
- *
- * Revision 1.45  2000/11/16 12:02:24  achim
- * Changes for kernel 2.4
- *
- * Revision 1.44  2000/10/11 08:44:10  achim
- * Clustering changes: New flag media_changed added
- *
- * Revision 1.43  2000/09/20 12:59:01  achim
- * DPMEM remap functions for all PCI controller types implemented
- * Small changes for ia64 platform
- *
- * Revision 1.42  2000/07/20 09:04:50  achim
- * Small changes for kernel 2.4
- *
- * Revision 1.41  2000/07/04 14:11:11  achim
- * gdth_analyse_hdrive() added to rescan drives after online expansion
- *
- * Revision 1.40  2000/06/27 11:24:16  achim
- * Changes Clustering, Screenservice
- *
- * Revision 1.39  2000/06/15 13:09:04  achim
- * Changes for gdth_do_cmd()
- *
- * Revision 1.38  2000/06/15 12:08:43  achim
- * Bugfix gdth_sync_event(), service SCREENSERVICE
- * Data direction for command 0xc2 changed to DOU
- *
- * Revision 1.37  2000/05/25 13:50:10  achim
- * New driver parameter virt_ctr added
- *
- * Revision 1.36  2000/05/04 08:50:46  achim
- * Event buffer now in gdth_ha_str
- *
- * Revision 1.35  2000/03/03 10:44:08  achim
- * New event_string only valid for the RP controller family
- *
- * Revision 1.34  2000/03/02 14:55:29  achim
- * New mechanism for async. event handling implemented
- *
- * Revision 1.33  2000/02/21 15:37:37  achim
- * Bugfix Alpha platform + DPMEM above 4GB
- *
- * Revision 1.32  2000/02/14 16:17:37  achim
- * Bugfix sense_buffer[] + raw devices
- *
- * Revision 1.31  2000/02/10 10:29:00  achim
- * Delete sense_buffer[0], if command OK
- *
- * Revision 1.30  1999/11/02 13:42:39  achim
- * ARRAY_DRV_LIST2 implemented
- * Now 255 log. and 100 host drives supported
- *
- * Revision 1.29  1999/10/05 13:28:47  achim
- * GDT_CLUST_RESET added
- *
- * Revision 1.28  1999/08/12 13:44:54  achim
- * MOUNTALL removed
- * Cluster drives -> removeable drives
- *
- * Revision 1.27  1999/06/22 07:22:38  achim
- * Small changes
- *
- * Revision 1.26  1999/06/10 16:09:12  achim
- * Cluster Host Drive support: Bugfixes
- *
- * Revision 1.25  1999/06/01 16:03:56  achim
- * gdth_init_pci(): Manipulate config. space to start RP controller
- *
- * Revision 1.24  1999/05/26 11:53:06  achim
- * Cluster Host Drive support added
- *
- * Revision 1.23  1999/03/26 09:12:31  achim
- * Default value for hdr_channel set to 0
- *
- * Revision 1.22  1999/03/22 16:27:16  achim
- * Bugfix: gdth_store_event() must not be locked with GDTH_LOCK_HA()
- *
- * Revision 1.21  1999/03/16 13:40:34  achim
- * Problems with reserved drives solved
- * gdth_eh_bus_reset() implemented
- *
- * Revision 1.20  1999/03/10 09:08:13  achim
- * Bugfix: Corrections in gdth_direction_tab[] made
- * Bugfix: Increase command timeout (gdth_update_timeout()) NOT in gdth_putq()
- *
- * Revision 1.19  1999/03/05 14:38:16  achim
- * Bugfix: Heads/Sectors mapping for reserved devices possibly wrong
- * -> gdth_eval_mapping() implemented, changes in gdth_bios_param()
- * INIT_RETRIES set to 100s to avoid DEINIT-Timeout for controllers
- * with BIOS disabled and memory test set to Intensive
- * Enhanced /proc support
- *
- * Revision 1.18  1999/02/24 09:54:33  achim
- * Command line parameter hdr_channel implemented
- * Bugfix for EISA controllers + Linux 2.2.x
- *
- * Revision 1.17  1998/12/17 15:58:11  achim
- * Command line parameters implemented
- * Changes for Alpha platforms
- * PCI controller scan changed
- * SMP support improved (spin_lock_irqsave(),...)
- * New async. events, new scan/reserve commands included
- *
- * Revision 1.16  1998/09/28 16:08:46  achim
- * GDT_PCIMPR: DPMEM remapping, if required
- * mdelay() added
- *
- * Revision 1.15  1998/06/03 14:54:06  achim
- * gdth_delay(), gdth_flush() implemented
- * Bugfix: gdth_release() changed
- *
- * Revision 1.14  1998/05/22 10:01:17  achim
- * mj: pcibios_strerror() removed
- * Improved SMP support (if version >= 2.1.95)
- * gdth_halt(): halt_called flag added (if version < 2.1)
- *
- * Revision 1.13  1998/04/16 09:14:57  achim
- * Reserve drives (for raw service) implemented
- * New error handling code enabled
- * Get controller name from board_info() IOCTL
- * Final round of PCI device driver patches by Martin Mares
- *
- * Revision 1.12  1998/03/03 09:32:37  achim
- * Fibre channel controller support added
- *
- * Revision 1.11  1998/01/27 16:19:14  achim
- * SA_SHIRQ added
- * add_timer()/del_timer() instead of GDTH_TIMER
- * scsi_add_timer()/scsi_del_timer() instead of SCSI_TIMER
- * New error handling included
- *
- * Revision 1.10  1997/10/31 12:29:57  achim
- * Read heads/sectors from host drive
- *
- * Revision 1.9  1997/09/04 10:07:25  achim
- * IO-mapping with virt_to_bus(), gdth_readb(), gdth_writeb(), ...
- * register_reboot_notifier() to get a notify on shutown used
- *
- * Revision 1.8  1997/04/02 12:14:30  achim
- * Version 1.00 (see gdth.h), tested with kernel 2.0.29
- *
- * Revision 1.7  1997/03/12 13:33:37  achim
- * gdth_reset() changed, new async. events
- *
- * Revision 1.6  1997/03/04 14:01:11  achim
- * Shutdown routine gdth_halt() implemented
- *
- * Revision 1.5  1997/02/21 09:08:36  achim
- * New controller included (RP, RP1, RP2 series)
- * IOCTL interface implemented
- *
- * Revision 1.4  1996/07/05 12:48:55  achim
- * Function gdth_bios_param() implemented
- * New constant GDTH_MAXC_P_L inserted
- * GDT_WRITE_THR, GDT_EXT_INFO implemented
- * Function gdth_reset() changed
- *
- * Revision 1.3  1996/05/10 09:04:41  achim
- * Small changes for Linux 1.2.13
- *
- * Revision 1.2  1996/05/09 12:45:27  achim
- * Loadable module support implemented
- * /proc support corrections made
- *
- * Revision 1.1  1996/04/11 07:35:57  achim
- * Initial revision
- *
  ************************************************************************/
 
 /* All GDT Disk Array Controllers are fully supported by this driver.
@@ -392,12 +120,7 @@
 #include <linux/proc_fs.h>
 #include <linux/time.h>
 #include <linux/timer.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,6)
 #include <linux/dma-mapping.h>
-#else
-#define DMA_32BIT_MASK	0x00000000ffffffffULL
-#define DMA_64BIT_MASK	0xffffffffffffffffULL
-#endif
 
 #ifdef GDTH_RTC
 #include <linux/mc146818rtc.h>
@@ -409,16 +132,10 @@
 #include <asm/io.h>
 #include <asm/uaccess.h>
 #include <linux/spinlock.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 #include <linux/blkdev.h>
-#else
-#include <linux/blk.h>
-#include "sd.h"
-#endif
 
 #include "scsi.h"
 #include <scsi/scsi_host.h>
-#include "gdth_kcompat.h"
 #include "gdth.h"
 
 static void gdth_delay(int milliseconds);
@@ -655,7 +372,6 @@ static int probe_eisa_isa = 0;
 static int force_dma32 = 0;
 
 /* parameters for modprobe/insmod */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
 module_param_array(irq, int, NULL, 0);
 module_param(disable, int, 0);
 module_param(reserve_mode, int, 0);
@@ -668,20 +384,6 @@ module_param(virt_ctr, int, 0);
 module_param(shared_access, int, 0);
 module_param(probe_eisa_isa, int, 0);
 module_param(force_dma32, int, 0);
-#else
-MODULE_PARM(irq, "i");
-MODULE_PARM(disable, "i");
-MODULE_PARM(reserve_mode, "i");
-MODULE_PARM(reserve_list, "4-" __MODULE_STRING(MAX_RES_ARGS) "i");
-MODULE_PARM(reverse_scan, "i");
-MODULE_PARM(hdr_channel, "i");
-MODULE_PARM(max_ids, "i");
-MODULE_PARM(rescan, "i");
-MODULE_PARM(virt_ctr, "i");
-MODULE_PARM(shared_access, "i");
-MODULE_PARM(probe_eisa_isa, "i");
-MODULE_PARM(force_dma32, "i");
-#endif
 MODULE_AUTHOR("Achim Leubner");
 MODULE_LICENSE("GPL");
 
@@ -710,7 +412,6 @@ static void gdth_delay(int milliseconds)
     }
 }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 static void gdth_scsi_done(struct scsi_cmnd *scp)
 {
     TRACE2(("gdth_scsi_done()\n"));
@@ -748,42 +449,6 @@ int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
     kfree(scp);
     return rval;
 }
-#else
-static void gdth_scsi_done(Scsi_Cmnd *scp)
-{
-    TRACE2(("gdth_scsi_done()\n"));
-
-    scp->request.rq_status = RQ_SCSI_DONE;
-    if (scp->request.waiting)
-        complete(scp->request.waiting);
-}
-
-int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
-                   int timeout, u32 *info)
-{
-    Scsi_Cmnd *scp = scsi_allocate_device(sdev, 1, FALSE);
-    unsigned bufflen = gdtcmd ? sizeof(gdth_cmd_str) : 0;
-    DECLARE_COMPLETION_ONSTACK(wait);
-    int rval;
-
-    if (!scp)
-        return -ENOMEM;
-    scp->cmd_len = 12;
-    scp->use_sg = 0;
-    scp->SCp.this_residual = IOCTL_PRI;   /* priority */
-    scp->request.rq_status = RQ_SCSI_BUSY;
-    scp->request.waiting = &wait;
-    scsi_do_cmd(scp, cmnd, gdtcmd, bufflen, gdth_scsi_done, timeout*HZ, 1);
-    wait_for_completion(&wait);
-
-    rval = scp->SCp.Status;
-    if (info)
-        *info = scp->SCp.Message;
-
-    scsi_release_command(scp);
-    return rval;
-}
-#endif
 
 int gdth_execute(struct Scsi_Host *shost, gdth_cmd_str *gdtcmd, char *cmnd,
                  int timeout, u32 *info)
@@ -2243,29 +1908,17 @@ static int __init gdth_search_drives(int hanum)
         printk("GDT-HA %d: Vendor: %s Name: %s\n",
                hanum,oemstr->text.oem_company_name,ha->binfo.type_string);
         /* Save the Host Drive inquiry data */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
         strlcpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,
                 sizeof(ha->oem_name));
-#else
-        strncpy(ha->oem_name,oemstr->text.scsi_host_drive_inquiry_vendor_id,7);
-        ha->oem_name[7] = '\0';
-#endif
     } else {
         /* Old method, based on PCI ID */
         TRACE2(("gdth_search_drives(): CACHE_READ_OEM_STRING_RECORD failed\n"));
         printk("GDT-HA %d: Name: %s\n",
                hanum,ha->binfo.type_string);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
         if (ha->oem_id == OEM_ID_INTEL)
             strlcpy(ha->oem_name,"Intel  ", sizeof(ha->oem_name));
         else
             strlcpy(ha->oem_name,"ICP    ", sizeof(ha->oem_name));
-#else 
-        if (ha->oem_id == OEM_ID_INTEL)
-            strcpy(ha->oem_name,"Intel  ");
-        else
-            strcpy(ha->oem_name,"ICP    ");
-#endif
     }
 
     /* scanning for host drives */
@@ -2674,17 +2327,10 @@ static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
                 return;
             }
             local_irq_save(flags);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
             address = kmap_atomic(sl->page, KM_BIO_SRC_IRQ) + sl->offset;
             memcpy(address,buffer,cpnow);
             flush_dcache_page(sl->page);
             kunmap_atomic(address, KM_BIO_SRC_IRQ);
-#else
-            address = kmap_atomic(sl->page, KM_BH_IRQ) + sl->offset;
-            memcpy(address,buffer,cpnow);
-            flush_dcache_page(sl->page);
-            kunmap_atomic(address, KM_BH_IRQ);
-#endif
             local_irq_restore(flags);
             if (cpsum == cpcount)
                 break;
@@ -4381,10 +4027,6 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 		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;
 
@@ -4513,10 +4155,6 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 		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;
 
@@ -4622,10 +4260,6 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 			hdr_channel = ha->bus_cnt;
 		ha->virt_bus = hdr_channel;
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-		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 */
@@ -4698,11 +4332,7 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 	return 1;	/* continue looping */
 }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 static int __init gdth_detect(struct scsi_host_template *shtp)
-#else
-static int __init gdth_detect(Scsi_Host_Template *shtp)
-#endif
 {
     gdth_pci_str pcistr[MAXHA];
     int cnt,ctr;
@@ -4948,11 +4578,7 @@ static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
     return SUCCESS;
 }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip)
-#else
-static int gdth_bios_param(Disk *disk,kdev_t dev,int *ip)
-#endif
 {
     unchar b, t;
     int hanum;
@@ -4960,13 +4586,8 @@ static int gdth_bios_param(Disk *disk,kdev_t dev,int *ip)
     struct scsi_device *sd;
     unsigned capacity;
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
     sd = sdev;
     capacity = cap;
-#else
-    sd = disk->device;
-    capacity = disk->capacity;
-#endif
     hanum = NUMDATA(sd->host)->hanum;
     b = virt_ctr ? NUMDATA(sd->host)->busnum : sd->channel;
     t = sd->id;
@@ -5581,7 +5202,6 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
         hanum = res.ionode; 
         ha = HADATA(gdth_ctr_tab[hanum]);
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
         scp  = kzalloc(sizeof(*scp), GFP_KERNEL);
         if (!scp)
             return -ENOMEM;
@@ -5592,17 +5212,7 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
         rval = gdth_eh_bus_reset(scp);
         res.status = (rval == SUCCESS ? S_OK : S_GENERR);
         kfree(scp);
-#else
-        scp  = scsi_allocate_device(ha->sdev, 1, FALSE);
-        if (!scp)
-            return -ENOMEM;
-        scp->cmd_len = 12;
-        scp->use_sg = 0;
-        scp->channel = virt_ctr ? 0 : res.number;
-        rval = gdth_eh_bus_reset(scp);
-        res.status = (rval == SUCCESS ? S_OK : S_GENERR);
-        scsi_release_command(scp);
-#endif
+
         if (copy_to_user(argp, &res, sizeof(gdth_ioctl_reset)))
             return -EFAULT;
         break;
@@ -5690,7 +5300,6 @@ static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
     return NOTIFY_OK;
 }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 /* configure lun */
 static int gdth_slave_configure(struct scsi_device *sdev)
 {
@@ -5699,13 +5308,8 @@ static int gdth_slave_configure(struct scsi_device *sdev)
     sdev->skip_ms_page_8 = 1;
     return 0;
 }
-#endif
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 static struct scsi_host_template driver_template = {
-#else
-static Scsi_Host_Template driver_template = {
-#endif
         .proc_name              = "gdth", 
         .proc_info              = gdth_proc_info,
         .name                   = "GDT SCSI Disk Array Controller",
@@ -5716,20 +5320,12 @@ static Scsi_Host_Template driver_template = {
         .eh_bus_reset_handler   = gdth_eh_bus_reset,
         .bios_param             = gdth_bios_param,
         .can_queue              = GDTH_MAXCMDS,
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
         .slave_configure        = gdth_slave_configure,
-#endif
         .this_id                = -1,
         .sg_tablesize           = GDTH_MAXSG,
         .cmd_per_lun            = GDTH_MAXC_P_L,
         .unchecked_isa_dma      = 1,
         .use_clustering         = ENABLE_CLUSTERING,
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-        .use_new_eh_code        = 1,
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
-        .highmem_io             = 1,
-#endif
-#endif
 };
 
 #include "scsi_module.c"
diff --git a/drivers/scsi/gdth.h b/drivers/scsi/gdth.h
index 3742330..6884587 100644
--- a/drivers/scsi/gdth.h
+++ b/drivers/scsi/gdth.h
@@ -13,7 +13,6 @@
  * $Id: gdth.h,v 1.58 2006/01/11 16:14:09 achim Exp $
  */
 
-#include <linux/version.h>
 #include <linux/types.h>
 
 #ifndef TRUE
diff --git a/drivers/scsi/gdth_kcompat.h b/drivers/scsi/gdth_kcompat.h
deleted file mode 100644
index 2a302ee..0000000
--- a/drivers/scsi/gdth_kcompat.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef IRQ_HANDLED
-typedef void irqreturn_t;
-#define IRQ_NONE
-#define IRQ_HANDLED
-#endif
-
-#ifndef MODULE_LICENSE
-#define MODULE_LICENSE(x)
-#endif
-
-#ifndef __iomem
-#define __iomem
-#endif
-
-#ifndef __attribute_used__
-#define __attribute_used__	__devinitdata
-#endif
-
-#ifndef __user
-#define __user
-#endif
-
-#ifndef SERVICE_ACTION_IN
-#define SERVICE_ACTION_IN	0x9e
-#endif
-#ifndef READ_16
-#define READ_16			0x88
-#endif
-#ifndef WRITE_16
-#define WRITE_16		0x8a
-#endif
diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
index 32982eb..5fccb15 100644
--- a/drivers/scsi/gdth_proc.c
+++ b/drivers/scsi/gdth_proc.c
@@ -4,7 +4,6 @@
 
 #include <linux/completion.h>
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 int gdth_proc_info(struct Scsi_Host *host, char *buffer,char **start,off_t offset,int length,   
                    int inout)
 {
@@ -21,32 +20,6 @@ int gdth_proc_info(struct Scsi_Host *host, char *buffer,char **start,off_t offse
     else
         return(gdth_get_info(buffer,start,offset,length,host,hanum,busnum));
 }
-#else
-int gdth_proc_info(char *buffer,char **start,off_t offset,int length,int hostno,   
-                   int inout)
-{
-    int hanum,busnum,i;
-
-    TRACE2(("gdth_proc_info() length %d offs %d inout %d\n",
-            length,(int)offset,inout));
-
-    for (i = 0; i < gdth_ctr_vcount; ++i) {
-        if (gdth_ctr_vtab[i]->host_no == hostno)
-            break;
-    }
-    if (i == gdth_ctr_vcount)
-        return(-EINVAL);
-
-    hanum = NUMDATA(gdth_ctr_vtab[i])->hanum;
-    busnum= NUMDATA(gdth_ctr_vtab[i])->busnum;
-
-    if (inout)
-        return(gdth_set_info(buffer,length,gdth_ctr_vtab[i],hanum,busnum));
-    else
-        return(gdth_get_info(buffer,start,offset,length,
-                             gdth_ctr_vtab[i],hanum,busnum));
-}
-#endif
 
 static int gdth_set_info(char *buffer,int length,struct Scsi_Host *host,
                          int hanum,int busnum)

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/8] gdth: Isolate driver-global variables using helpers
  2007-09-26  4:33 [PATCH 1/8] gdth: Split out EISA and ISA register into separate functions Jeff Garzik
  2007-09-26  4:34 ` [PATCH 2/8] gdth: Split out PCI register into separate function Jeff Garzik
  2007-09-26  4:34 ` [PATCH 3/8] gdth: Remove 2.4.x support, in-kernel changelog Jeff Garzik
@ 2007-09-26  4:35 ` Jeff Garzik
  2007-09-26  4:35 ` [PATCH 5/8] gdth: kill gdth_{read,write}[bwl] wrappers Jeff Garzik
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Garzik @ 2007-09-26  4:35 UTC (permalink / raw)
  To: achim_leubner, linux-scsi, LKML


Sanitizes access to some driver-global variables, in preparation for
making them dynamic rather than statically-sized.

This equivalent-transform style change blissfully ignores the fact that
gdth_ctr_vtab[] is never used (only assigned), and that the driver
itself seems to get a bit confused between gdth_ctr_count and
gdth_ctr_vcount.  The whole virtual-controller stuff needs reviewing
for edge cases.

Signed-off-by: Jeff Garzik <jeff@garzik.org>
---

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index a6b5717..b9d1f69 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -394,6 +394,44 @@ static const struct file_operations gdth_fops = {
     .release = gdth_close,
 };
 
+static struct Scsi_Host *gdth_find_shp(int ha_idx)
+{
+	return gdth_ctr_tab[ha_idx];
+}
+
+static gdth_ha_str *gdth_find_ha(int ha_idx)
+{
+	struct Scsi_Host *shp = gdth_find_shp(ha_idx);
+	if (!shp)
+		return NULL;
+	return HADATA(shp);
+}
+
+static void gdth_push_vshp(struct Scsi_Host *shp)
+{
+	gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+}
+
+static int gdth_push_shp(struct Scsi_Host *shp)
+{
+	int idx;
+
+	idx = gdth_ctr_count;
+	gdth_ctr_count++;
+
+	gdth_ctr_tab[idx] = shp;
+
+	gdth_push_vshp(shp);
+
+	return idx;
+}
+
+static void gdth_pop_shp(void)
+{
+	gdth_ctr_count--;
+	gdth_ctr_vcount--;
+}
+
 #include "gdth_proc.h"
 #include "gdth_proc.c"
 
@@ -1220,7 +1258,7 @@ static void __init gdth_enable_int(int hanum)
     gdt6m_dpram_str __iomem *dp6m_ptr;
 
     TRACE(("gdth_enable_int() hanum %d\n",hanum));
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     spin_lock_irqsave(&ha->smp_lock, flags);
 
     if (ha->type == GDT_EISA) {
@@ -1260,7 +1298,7 @@ static int gdth_get_status(unchar *pIStatus,int irq)
     
     *pIStatus = 0;
     for (i=0; i<gdth_ctr_count; ++i) {
-        ha = HADATA(gdth_ctr_tab[i]);
+        ha = gdth_find_ha(i);
         if (ha->irq != (unchar)irq)             /* check IRQ */
             continue;
         if (ha->type == GDT_EISA)
@@ -1291,7 +1329,7 @@ static int gdth_test_busy(int hanum)
 
     TRACE(("gdth_test_busy() hanum %d\n",hanum));
     
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     if (ha->type == GDT_EISA)
         gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
     else if (ha->type == GDT_ISA)
@@ -1315,7 +1353,7 @@ static int gdth_get_cmd_index(int hanum)
 
     TRACE(("gdth_get_cmd_index() hanum %d\n",hanum));
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     for (i=0; i<GDTH_MAXCMDS; ++i) {
         if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
             ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
@@ -1334,7 +1372,7 @@ static void gdth_set_sema0(int hanum)
 
     TRACE(("gdth_set_sema0() hanum %d\n",hanum));
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     if (ha->type == GDT_EISA) {
         outb(1, ha->bmic + SEMA0REG);
     } else if (ha->type == GDT_ISA) {
@@ -1361,7 +1399,7 @@ static void gdth_copy_command(int hanum)
     
     TRACE(("gdth_copy_command() hanum %d\n",hanum));
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     cp_count = ha->cmd_len;
     dp_offset= ha->cmd_offs_dpmem;
     cmd_no   = ha->cmd_cnt;
@@ -1415,7 +1453,7 @@ static void gdth_release_event(int hanum)
     register gdth_ha_str *ha;
 
     TRACE(("gdth_release_event() hanum %d\n",hanum));
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
 
 #ifdef GDTH_STATISTICS
     {
@@ -1457,7 +1495,7 @@ static int gdth_wait(int hanum,int index,ulong32 time)
 
     TRACE(("gdth_wait() hanum %d index %d time %d\n",hanum,index,time));
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     if (index == 0)
         return 1;                               /* no wait required */
 
@@ -1488,7 +1526,7 @@ static int gdth_internal_cmd(int hanum,unchar service,ushort opcode,ulong32 p1,
 
     TRACE2(("gdth_internal_cmd() service %d opcode %d\n",service,opcode));
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     cmd_ptr = ha->pccb;
     memset((char*)cmd_ptr,0,sizeof(gdth_cmd_str));
 
@@ -1581,7 +1619,7 @@ static int __init gdth_search_drives(int hanum)
 #endif     
    
     TRACE(("gdth_search_drives() hanum %d\n",hanum));
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     ok = 0;
 
     /* initialize controller services, at first: screen service */
@@ -1938,7 +1976,7 @@ static int gdth_analyse_hdrive(int hanum,ushort hdrive)
     TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n",hanum,hdrive));
     if (hdrive >= MAX_HDRIVES)
         return 0;
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
 
     if (!gdth_internal_cmd(hanum,CACHESERVICE,GDT_INFO,hdrive,0,0)) 
         return 0;
@@ -2005,7 +2043,7 @@ static void gdth_putq(int hanum,Scsi_Cmnd *scp,unchar priority)
     unchar b, t;
 
     TRACE(("gdth_putq() priority %d\n",priority));
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     spin_lock_irqsave(&ha->smp_lock, flags);
 
     if (scp->done != gdth_scsi_done) {
@@ -2059,7 +2097,7 @@ static void gdth_next(int hanum)
     int cmd_index;
 
     TRACE(("gdth_next() hanum %d\n",hanum));
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     if (!gdth_polling) 
         spin_lock_irqsave(&ha->smp_lock, flags);
 
@@ -2309,7 +2347,7 @@ static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
     char *address;
 
     cpcount = count<=(ushort)scp->request_bufflen ? count:(ushort)scp->request_bufflen;
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
 
     if (scp->use_sg) {
         sl = (struct scatterlist *)scp->request_buffer;
@@ -2351,7 +2389,7 @@ static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp)
     gdth_sense_data sd;
     gdth_modep_data mpd;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     t  = scp->device->id;
     TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %d\n",
            scp->cmnd[0],t));
@@ -2456,7 +2494,7 @@ static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive)
     struct page *page;
     ulong offset;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     cmdp = ha->pccb;
     TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %d\n",
                  scp->cmnd[0],scp->cmd_len,hdrive));
@@ -2666,7 +2704,7 @@ static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b)
     struct page *page;
     ulong offset;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     t = scp->device->id;
     l = scp->device->lun;
     cmdp = ha->pccb;
@@ -2865,7 +2903,7 @@ static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp)
     register gdth_cmd_str *cmdp;
     int cmd_index;
 
-    ha  = HADATA(gdth_ctr_tab[hanum]);
+    ha  = gdth_find_ha(hanum);
     cmdp= ha->pccb;
     TRACE2(("gdth_special_cmd(): "));
 
@@ -3087,7 +3125,7 @@ static irqreturn_t gdth_interrupt(int irq,void *dev_id)
             spin_unlock_irqrestore(&ha2->smp_lock, flags);
             return IRQ_HANDLED;
     }
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
 
 #ifdef GDTH_STATISTICS
     ++act_ints;
@@ -3315,7 +3353,7 @@ static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp)
     gdth_cmd_str *cmdp;
     unchar b, t;
 
-    ha   = HADATA(gdth_ctr_tab[hanum]);
+    ha   = gdth_find_ha(hanum);
     cmdp = ha->pccb;
     TRACE(("gdth_sync_event() serv %d status %d\n",
            service,ha->status));
@@ -3686,7 +3724,7 @@ static int gdth_async_event(int hanum)
     gdth_cmd_str *cmdp;
     int cmd_index;
 
-    ha  = HADATA(gdth_ctr_tab[hanum]);
+    ha  = gdth_find_ha(hanum);
     cmdp= ha->pccb;
     TRACE2(("gdth_async_event() ha %d serv %d\n",
             hanum,ha->service));
@@ -3812,7 +3850,7 @@ static void gdth_timeout(ulong data)
     ulong flags;
     int hanum = 0;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     spin_lock_irqsave(&ha->smp_lock, flags);
 
     for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i) 
@@ -3965,9 +4003,7 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 	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;
+	hanum = gdth_push_shp(shp);
 
 	NUMDATA(shp)->hanum = (ushort)hanum;
 	NUMDATA(shp)->busnum= 0;
@@ -4001,8 +4037,7 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 	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;
+		gdth_pop_shp();
 
 #ifdef INT_COAL
 		if (ha->coal_stat)
@@ -4043,7 +4078,7 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 			shp->unchecked_isa_dma = 1;
 			shp->irq = ha->irq;
 			shp->dma_channel = ha->drq;
-			gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+			gdth_push_vshp(shp);
 			NUMDATA(shp)->hanum = (ushort)hanum;
 			NUMDATA(shp)->busnum = b;
 		}
@@ -4087,9 +4122,7 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 	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;
+	hanum = gdth_push_shp(shp);
 
 	NUMDATA(shp)->hanum = (ushort)hanum;
 	NUMDATA(shp)->busnum= 0;
@@ -4129,8 +4162,8 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 	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;
+		gdth_pop_shp();
+
 #ifdef INT_COAL
 		if (ha->coal_stat)
 			pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
@@ -4171,7 +4204,7 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 			shp->unchecked_isa_dma = 0;
 			shp->irq = ha->irq;
 			shp->dma_channel = 0xff;
-			gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+			gdth_push_vshp(shp);
 			NUMDATA(shp)->hanum = (ushort)hanum;
 			NUMDATA(shp)->busnum = b;
 		}
@@ -4218,9 +4251,7 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 	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;
+	hanum = gdth_push_shp(shp);
 
 	NUMDATA(shp)->hanum = (ushort)hanum;
 	NUMDATA(shp)->busnum= 0;
@@ -4285,8 +4316,7 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 
 	if (err) {
 		printk("GDT-PCI %d: Error during device scan\n", hanum);
-		--gdth_ctr_count;
-		--gdth_ctr_vcount;
+		gdth_pop_shp();
 
 #ifdef INT_COAL
 		if (ha->coal_stat)
@@ -4320,7 +4350,7 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 			shp->unchecked_isa_dma = 0;
 			shp->irq = ha->irq;
 			shp->dma_channel = 0xff;
-			gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
+			gdth_push_vshp(shp);
 			NUMDATA(shp)->hanum = (ushort)hanum;
 			NUMDATA(shp)->busnum = b;
 		}
@@ -4433,7 +4463,7 @@ static int gdth_release(struct Scsi_Host *shp)
     TRACE2(("gdth_release()\n"));
     if (NUMDATA(shp)->busnum == 0) {
         hanum = NUMDATA(shp)->hanum;
-        ha    = HADATA(gdth_ctr_tab[hanum]);
+        ha    = gdth_find_ha(hanum);
         if (ha->sdev) {
             scsi_free_host_dev(ha->sdev);
             ha->sdev = NULL;
@@ -4486,7 +4516,7 @@ static const char *gdth_ctr_name(int hanum)
 
     TRACE2(("gdth_ctr_name()\n"));
 
-    ha    = HADATA(gdth_ctr_tab[hanum]);
+    ha    = gdth_find_ha(hanum);
 
     if (ha->type == GDT_EISA) {
         switch (ha->stype) {
@@ -4519,7 +4549,7 @@ static const char *gdth_info(struct Scsi_Host *shp)
 
     TRACE2(("gdth_info()\n"));
     hanum = NUMDATA(shp)->hanum;
-    ha    = HADATA(gdth_ctr_tab[hanum]);
+    ha    = gdth_find_ha(hanum);
 
     return ((const char *)ha->binfo.type_string);
 }
@@ -4536,7 +4566,7 @@ static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
 
     hanum = NUMDATA(scp->device->host)->hanum;
     b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
-    ha    = HADATA(gdth_ctr_tab[hanum]);
+    ha    = gdth_find_ha(hanum);
 
     /* clear command tab */
     spin_lock_irqsave(&ha->smp_lock, flags);
@@ -4592,7 +4622,7 @@ static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,se
     b = virt_ctr ? NUMDATA(sd->host)->busnum : sd->channel;
     t = sd->id;
     TRACE2(("gdth_bios_param() ha %d bus %d target %d\n", hanum, b, t)); 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
 
     if (b != ha->virt_bus || ha->hdr[t].heads == 0) {
         /* raw device or host drive without mapping information */
@@ -4643,13 +4673,15 @@ static int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *))
 
 static int gdth_open(struct inode *inode, struct file *filep)
 {
+    struct Scsi_Host *shp;
     gdth_ha_str *ha;
     int i;
 
     for (i = 0; i < gdth_ctr_count; i++) {
-        ha = HADATA(gdth_ctr_tab[i]);
+	shp = gdth_find_shp(i);
+	ha = HADATA(shp);
         if (!ha->sdev)
-            ha->sdev = scsi_get_host_dev(gdth_ctr_tab[i]);
+            ha->sdev = scsi_get_host_dev(shp);
     }
 
     TRACE(("gdth_open()\n"));
@@ -4671,7 +4703,7 @@ static int ioc_event(void __user *arg)
     if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event)) ||
         evt.ionode >= gdth_ctr_count)
         return -EFAULT;
-    ha = HADATA(gdth_ctr_tab[evt.ionode]);
+    ha = gdth_find_ha(evt.ionode);
 
     if (evt.erase == 0xff) {
         if (evt.event.event_source == ES_TEST)
@@ -4708,7 +4740,7 @@ static int ioc_lockdrv(void __user *arg)
     if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)) ||
         ldrv.ionode >= gdth_ctr_count)
         return -EFAULT;
-    ha = HADATA(gdth_ctr_tab[ldrv.ionode]);
+    ha = gdth_find_ha(ldrv.ionode);
  
     for (i = 0; i < ldrv.drive_cnt && i < MAX_HDRIVES; ++i) {
         j = ldrv.drives[i];
@@ -4743,7 +4775,7 @@ static int ioc_resetdrv(void __user *arg, char *cmnd)
         res.ionode >= gdth_ctr_count || res.number >= MAX_HDRIVES)
         return -EFAULT;
     hanum = res.ionode;
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
  
     if (!ha->hdr[res.number].present)
         return 0;
@@ -4778,7 +4810,7 @@ static int ioc_general(void __user *arg, char *cmnd)
         gen.ionode >= gdth_ctr_count)
         return -EFAULT;
     hanum = gen.ionode; 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     if (gen.data_len + gen.sense_len != 0) {
         if (!(buf = gdth_ioctl_alloc(hanum, gen.data_len + gen.sense_len, 
                                      FALSE, &paddr)))
@@ -4903,7 +4935,7 @@ static int ioc_hdrlist(void __user *arg, char *cmnd)
         goto free_fail;
     }
     hanum = rsc->ionode;
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     memset(cmd, 0, sizeof(gdth_cmd_str));
    
     for (i = 0; i < MAX_HDRIVES; ++i) { 
@@ -4960,7 +4992,7 @@ static int ioc_rescan(void __user *arg, char *cmnd)
         goto free_fail;
     }
     hanum = rsc->ionode;
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     memset(cmd, 0, sizeof(gdth_cmd_str));
 
     if (rsc->flag == 0) {
@@ -5119,7 +5151,7 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
         if (copy_from_user(&ctrt, argp, sizeof(gdth_ioctl_ctrtype)) ||
             ctrt.ionode >= gdth_ctr_count)
             return -EFAULT;
-        ha = HADATA(gdth_ctr_tab[ctrt.ionode]);
+        ha = gdth_find_ha(ctrt.ionode);
         if (ha->type == GDT_ISA || ha->type == GDT_EISA) {
             ctrt.type = (unchar)((ha->stype>>20) - 0x10);
         } else {
@@ -5160,7 +5192,7 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
         if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) ||
             lchn.ionode >= gdth_ctr_count)
             return -EFAULT;
-        ha = HADATA(gdth_ctr_tab[lchn.ionode]);
+        ha = gdth_find_ha(lchn.ionode);
         
         i = lchn.channel;
         if (i < ha->bus_cnt) {
@@ -5200,7 +5232,7 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
             res.ionode >= gdth_ctr_count)
             return -EFAULT;
         hanum = res.ionode; 
-        ha = HADATA(gdth_ctr_tab[hanum]);
+        ha = gdth_find_ha(hanum);
 
         scp  = kzalloc(sizeof(*scp), GFP_KERNEL);
         if (!scp)
@@ -5238,7 +5270,7 @@ static void gdth_flush(int hanum)
     memset(cmnd, 0xff, MAX_COMMAND_SIZE);
 
     TRACE2(("gdth_flush() hanum %d\n",hanum));
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
 
     for (i = 0; i < MAX_HDRIVES; ++i) {
         if (ha->hdr[i].present) {
@@ -5256,7 +5288,7 @@ static void gdth_flush(int hanum)
             }
             TRACE2(("gdth_flush(): flush ha %d drive %d\n", hanum, i));
 
-            gdth_execute(gdth_ctr_tab[hanum], &gdtcmd, cmnd, 30, NULL);
+            gdth_execute(gdth_find_shp(hanum), &gdtcmd, cmnd, 30, NULL);
         }
     }
 }
@@ -5289,7 +5321,7 @@ static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
         gdtcmd.Service = CACHESERVICE;
         gdtcmd.OpCode = GDT_RESET;
         TRACE2(("gdth_halt(): reset controller %d\n", hanum));
-        gdth_execute(gdth_ctr_tab[hanum], &gdtcmd, cmnd, 10, NULL);
+        gdth_execute(gdth_find_shp(hanum), &gdtcmd, cmnd, 10, NULL);
 #endif
     }
     printk("Done.\n");
diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
index 5fccb15..0c7696f 100644
--- a/drivers/scsi/gdth_proc.c
+++ b/drivers/scsi/gdth_proc.c
@@ -54,7 +54,7 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
     memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
 
     TRACE2(("gdth_set_asc_info() ha %d\n",hanum));
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     orig_length = length + 5;
     drive = -1;
     wb_mode = 0;
@@ -188,7 +188,7 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
     memset(gdtcmd, 0, sizeof(gdth_cmd_str));
 
     TRACE2(("gdth_get_info() ha %d bus %d\n",hanum,busnum));
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
 
     
     /* request is i.e. "cat /proc/scsi/gdth/0" */ 
@@ -682,7 +682,7 @@ static char *gdth_ioctl_alloc(int hanum, int size, int scratch,
     if (size == 0)
         return NULL;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     spin_lock_irqsave(&ha->smp_lock, flags);
 
     if (!ha->scratch_busy && size <= GDTH_SCRATCH) {
@@ -707,7 +707,7 @@ static void gdth_ioctl_free(int hanum, int size, char *buf, ulong64 paddr)
     gdth_ha_str *ha;
     ulong flags;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     spin_lock_irqsave(&ha->smp_lock, flags);
 
     if (buf == ha->pscratch) {
@@ -726,7 +726,7 @@ static int gdth_ioctl_check_bin(int hanum, ushort size)
     ulong flags;
     int ret_val;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     spin_lock_irqsave(&ha->smp_lock, flags);
 
     ret_val = FALSE;
@@ -747,7 +747,7 @@ static void gdth_wait_completion(int hanum, int busnum, int id)
     Scsi_Cmnd *scp;
     unchar b, t;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     spin_lock_irqsave(&ha->smp_lock, flags);
 
     for (i = 0; i < GDTH_MAXCMDS; ++i) {
@@ -774,7 +774,7 @@ static void gdth_stop_timeout(int hanum, int busnum, int id)
     Scsi_Cmnd *scp;
     unchar b, t;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     spin_lock_irqsave(&ha->smp_lock, flags);
 
     for (scp = ha->req_first; scp; scp = (Scsi_Cmnd *)scp->SCp.ptr) {
@@ -798,7 +798,7 @@ static void gdth_start_timeout(int hanum, int busnum, int id)
     Scsi_Cmnd *scp;
     unchar b, t;
 
-    ha = HADATA(gdth_ctr_tab[hanum]);
+    ha = gdth_find_ha(hanum);
     spin_lock_irqsave(&ha->smp_lock, flags);
 
     for (scp = ha->req_first; scp; scp = (Scsi_Cmnd *)scp->SCp.ptr) {

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/8] gdth: kill gdth_{read,write}[bwl] wrappers
  2007-09-26  4:33 [PATCH 1/8] gdth: Split out EISA and ISA register into separate functions Jeff Garzik
                   ` (2 preceding siblings ...)
  2007-09-26  4:35 ` [PATCH 4/8] gdth: Isolate driver-global variables using helpers Jeff Garzik
@ 2007-09-26  4:35 ` Jeff Garzik
  2007-09-26  4:35 ` [PATCH 6/8] gdth: Move probe-time error handling code to end of each function Jeff Garzik
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Garzik @ 2007-09-26  4:35 UTC (permalink / raw)
  To: achim_leubner, linux-scsi, LKML


They are direct equivalents to {read,write}[bwl].

Signed-off-by: Jeff Garzik <jeff@garzik.org>
---

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index b9d1f69..d7ef159 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -294,13 +294,6 @@ static struct timer_list gdth_timer;
 
 #define BUS_L2P(a,b)    ((b)>(a)->virt_bus ? (b-1):(b))
 
-#define gdth_readb(addr)        readb(addr)
-#define gdth_readw(addr)        readw(addr)
-#define gdth_readl(addr)        readl(addr)
-#define gdth_writeb(b,addr)     writeb((b),(addr))
-#define gdth_writew(b,addr)     writew((b),(addr))
-#define gdth_writel(b,addr)     writel((b),(addr))
-
 static unchar   gdth_drq_tab[4] = {5,6,7,7};            /* DRQ table */
 static unchar   gdth_irq_tab[6] = {0,10,11,12,14,0};    /* IRQ table */
 static unchar   gdth_polling;                           /* polling if TRUE */
@@ -544,7 +537,7 @@ static int __init gdth_search_isa(ulong32 bios_adr)
 
     TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
     if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) {
-        id = gdth_readl(addr);
+        id = readl(addr);
         iounmap(addr);
         if (id == GDT2_ID)                          /* GDT2000 */
             return 1;
@@ -778,22 +771,22 @@ static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
         return 0;
     }
     dp2_ptr = ha->brd;
-    gdth_writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
+    writeb(1, &dp2_ptr->io.memlock); /* switch off write protection */
     /* reset interface area */
     memset_io(&dp2_ptr->u, 0, sizeof(dp2_ptr->u));
-    if (gdth_readl(&dp2_ptr->u) != 0) {
+    if (readl(&dp2_ptr->u) != 0) {
         printk("GDT-ISA: Initialization error (DPMEM write error)\n");
         iounmap(ha->brd);
         return 0;
     }
 
     /* disable board interrupts, read DRQ and IRQ */
-    gdth_writeb(0xff, &dp2_ptr->io.irqdel);
-    gdth_writeb(0x00, &dp2_ptr->io.irqen);
-    gdth_writeb(0x00, &dp2_ptr->u.ic.S_Status);
-    gdth_writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
+    writeb(0xff, &dp2_ptr->io.irqdel);
+    writeb(0x00, &dp2_ptr->io.irqen);
+    writeb(0x00, &dp2_ptr->u.ic.S_Status);
+    writeb(0x00, &dp2_ptr->u.ic.Cmd_Index);
 
-    irq_drq = gdth_readb(&dp2_ptr->io.rq);
+    irq_drq = readb(&dp2_ptr->io.rq);
     for (i=0; i<3; ++i) {
         if ((irq_drq & 1)==0)
             break;
@@ -801,7 +794,7 @@ static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
     }
     ha->drq = gdth_drq_tab[i];
 
-    irq_drq = gdth_readb(&dp2_ptr->io.rq) >> 3;
+    irq_drq = readb(&dp2_ptr->io.rq) >> 3;
     for (i=1; i<5; ++i) {
         if ((irq_drq & 1)==0)
             break;
@@ -810,12 +803,12 @@ static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
     ha->irq = gdth_irq_tab[i];
 
     /* deinitialize services */
-    gdth_writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
-    gdth_writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
-    gdth_writeb(0, &dp2_ptr->io.event);
+    writel(bios_adr, &dp2_ptr->u.ic.S_Info[0]);
+    writeb(0xff, &dp2_ptr->u.ic.S_Cmd_Indx);
+    writeb(0, &dp2_ptr->io.event);
     retries = INIT_RETRIES;
     gdth_delay(20);
-    while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
+    while (readb(&dp2_ptr->u.ic.S_Status) != 0xff) {
         if (--retries == 0) {
             printk("GDT-ISA: Initialization error (DEINIT failed)\n");
             iounmap(ha->brd);
@@ -823,9 +816,9 @@ static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
         }
         gdth_delay(1);
     }
-    prot_ver = (unchar)gdth_readl(&dp2_ptr->u.ic.S_Info[0]);
-    gdth_writeb(0, &dp2_ptr->u.ic.Status);
-    gdth_writeb(0xff, &dp2_ptr->io.irqdel);
+    prot_ver = (unchar)readl(&dp2_ptr->u.ic.S_Info[0]);
+    writeb(0, &dp2_ptr->u.ic.Status);
+    writeb(0xff, &dp2_ptr->io.irqdel);
     if (prot_ver != PROTOCOL_VERSION) {
         printk("GDT-ISA: Illegal protocol version\n");
         iounmap(ha->brd);
@@ -839,15 +832,15 @@ static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
     ha->brd_phys = bios_adr >> 4;
 
     /* special request to controller BIOS */
-    gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
-    gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
-    gdth_writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
-    gdth_writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
-    gdth_writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
-    gdth_writeb(0, &dp2_ptr->io.event);
+    writel(0x00, &dp2_ptr->u.ic.S_Info[0]);
+    writel(0x00, &dp2_ptr->u.ic.S_Info[1]);
+    writel(0x01, &dp2_ptr->u.ic.S_Info[2]);
+    writel(0x00, &dp2_ptr->u.ic.S_Info[3]);
+    writeb(0xfe, &dp2_ptr->u.ic.S_Cmd_Indx);
+    writeb(0, &dp2_ptr->io.event);
     retries = INIT_RETRIES;
     gdth_delay(20);
-    while (gdth_readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
+    while (readb(&dp2_ptr->u.ic.S_Status) != 0xfe) {
         if (--retries == 0) {
             printk("GDT-ISA: Initialization error\n");
             iounmap(ha->brd);
@@ -855,8 +848,8 @@ static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
         }
         gdth_delay(1);
     }
-    gdth_writeb(0, &dp2_ptr->u.ic.Status);
-    gdth_writeb(0xff, &dp2_ptr->io.irqdel);
+    writeb(0, &dp2_ptr->u.ic.Status);
+    writeb(0xff, &dp2_ptr->io.irqdel);
 
     ha->dma64_support = 0;
     return 1;
@@ -893,8 +886,8 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
         }
         /* check and reset interface area */
         dp6_ptr = ha->brd;
-        gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
-        if (gdth_readl(&dp6_ptr->u) != DPMEM_MAGIC) {
+        writel(DPMEM_MAGIC, &dp6_ptr->u);
+        if (readl(&dp6_ptr->u) != DPMEM_MAGIC) {
             printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n", 
                    pcistr->dpmem);
             found = FALSE;
@@ -905,7 +898,7 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
                     printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
                     return 0;
                 }
-                if (gdth_readw(ha->brd) != 0xffff) {
+                if (readw(ha->brd) != 0xffff) {
                     TRACE2(("init_pci_old() address 0x%x busy\n", i));
                     continue;
                 }
@@ -918,8 +911,8 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
                     return 0;
                 }
                 dp6_ptr = ha->brd;
-                gdth_writel(DPMEM_MAGIC, &dp6_ptr->u);
-                if (gdth_readl(&dp6_ptr->u) == DPMEM_MAGIC) {
+                writel(DPMEM_MAGIC, &dp6_ptr->u);
+                if (readl(&dp6_ptr->u) == DPMEM_MAGIC) {
                     printk("GDT-PCI: Use free address at 0x%x\n", i);
                     found = TRUE;
                     break;
@@ -932,24 +925,24 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
             }
         }
         memset_io(&dp6_ptr->u, 0, sizeof(dp6_ptr->u));
-        if (gdth_readl(&dp6_ptr->u) != 0) {
+        if (readl(&dp6_ptr->u) != 0) {
             printk("GDT-PCI: Initialization error (DPMEM write error)\n");
             iounmap(ha->brd);
             return 0;
         }
         
         /* disable board interrupts, deinit services */
-        gdth_writeb(0xff, &dp6_ptr->io.irqdel);
-        gdth_writeb(0x00, &dp6_ptr->io.irqen);
-        gdth_writeb(0x00, &dp6_ptr->u.ic.S_Status);
-        gdth_writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
-
-        gdth_writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
-        gdth_writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
-        gdth_writeb(0, &dp6_ptr->io.event);
+        writeb(0xff, &dp6_ptr->io.irqdel);
+        writeb(0x00, &dp6_ptr->io.irqen);
+        writeb(0x00, &dp6_ptr->u.ic.S_Status);
+        writeb(0x00, &dp6_ptr->u.ic.Cmd_Index);
+
+        writel(pcistr->dpmem, &dp6_ptr->u.ic.S_Info[0]);
+        writeb(0xff, &dp6_ptr->u.ic.S_Cmd_Indx);
+        writeb(0, &dp6_ptr->io.event);
         retries = INIT_RETRIES;
         gdth_delay(20);
-        while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
+        while (readb(&dp6_ptr->u.ic.S_Status) != 0xff) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
                 iounmap(ha->brd);
@@ -957,9 +950,9 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
             }
             gdth_delay(1);
         }
-        prot_ver = (unchar)gdth_readl(&dp6_ptr->u.ic.S_Info[0]);
-        gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
-        gdth_writeb(0xff, &dp6_ptr->io.irqdel);
+        prot_ver = (unchar)readl(&dp6_ptr->u.ic.S_Info[0]);
+        writeb(0, &dp6_ptr->u.ic.S_Status);
+        writeb(0xff, &dp6_ptr->io.irqdel);
         if (prot_ver != PROTOCOL_VERSION) {
             printk("GDT-PCI: Illegal protocol version\n");
             iounmap(ha->brd);
@@ -970,15 +963,15 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
         ha->ic_all_size = sizeof(dp6_ptr->u);
         
         /* special command to controller BIOS */
-        gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
-        gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
-        gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[2]);
-        gdth_writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
-        gdth_writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
-        gdth_writeb(0, &dp6_ptr->io.event);
+        writel(0x00, &dp6_ptr->u.ic.S_Info[0]);
+        writel(0x00, &dp6_ptr->u.ic.S_Info[1]);
+        writel(0x00, &dp6_ptr->u.ic.S_Info[2]);
+        writel(0x00, &dp6_ptr->u.ic.S_Info[3]);
+        writeb(0xfe, &dp6_ptr->u.ic.S_Cmd_Indx);
+        writeb(0, &dp6_ptr->io.event);
         retries = INIT_RETRIES;
         gdth_delay(20);
-        while (gdth_readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
+        while (readb(&dp6_ptr->u.ic.S_Status) != 0xfe) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error\n");
                 iounmap(ha->brd);
@@ -986,8 +979,8 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
             }
             gdth_delay(1);
         }
-        gdth_writeb(0, &dp6_ptr->u.ic.S_Status);
-        gdth_writeb(0xff, &dp6_ptr->io.irqdel);
+        writeb(0, &dp6_ptr->u.ic.S_Status);
+        writeb(0xff, &dp6_ptr->io.irqdel);
 
         ha->dma64_support = 0;
 
@@ -1003,8 +996,8 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
         }
         /* check and reset interface area */
         dp6c_ptr = ha->brd;
-        gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
-        if (gdth_readl(&dp6c_ptr->u) != DPMEM_MAGIC) {
+        writel(DPMEM_MAGIC, &dp6c_ptr->u);
+        if (readl(&dp6c_ptr->u) != DPMEM_MAGIC) {
             printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n", 
                    pcistr->dpmem);
             found = FALSE;
@@ -1015,7 +1008,7 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
                     printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
                     return 0;
                 }
-                if (gdth_readw(ha->brd) != 0xffff) {
+                if (readw(ha->brd) != 0xffff) {
                     TRACE2(("init_pci_plx() address 0x%x busy\n", i));
                     continue;
                 }
@@ -1028,8 +1021,8 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
                     return 0;
                 }
                 dp6c_ptr = ha->brd;
-                gdth_writel(DPMEM_MAGIC, &dp6c_ptr->u);
-                if (gdth_readl(&dp6c_ptr->u) == DPMEM_MAGIC) {
+                writel(DPMEM_MAGIC, &dp6c_ptr->u);
+                if (readl(&dp6c_ptr->u) == DPMEM_MAGIC) {
                     printk("GDT-PCI: Use free address at 0x%x\n", i);
                     found = TRUE;
                     break;
@@ -1042,7 +1035,7 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
             }
         }
         memset_io(&dp6c_ptr->u, 0, sizeof(dp6c_ptr->u));
-        if (gdth_readl(&dp6c_ptr->u) != 0) {
+        if (readl(&dp6c_ptr->u) != 0) {
             printk("GDT-PCI: Initialization error (DPMEM write error)\n");
             iounmap(ha->brd);
             return 0;
@@ -1052,17 +1045,17 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
         outb(0x00,PTR2USHORT(&ha->plx->control1));
         outb(0xff,PTR2USHORT(&ha->plx->edoor_reg));
         
-        gdth_writeb(0x00, &dp6c_ptr->u.ic.S_Status);
-        gdth_writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
+        writeb(0x00, &dp6c_ptr->u.ic.S_Status);
+        writeb(0x00, &dp6c_ptr->u.ic.Cmd_Index);
 
-        gdth_writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
-        gdth_writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
+        writel(pcistr->dpmem, &dp6c_ptr->u.ic.S_Info[0]);
+        writeb(0xff, &dp6c_ptr->u.ic.S_Cmd_Indx);
 
         outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
 
         retries = INIT_RETRIES;
         gdth_delay(20);
-        while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
+        while (readb(&dp6c_ptr->u.ic.S_Status) != 0xff) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
                 iounmap(ha->brd);
@@ -1070,8 +1063,8 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
             }
             gdth_delay(1);
         }
-        prot_ver = (unchar)gdth_readl(&dp6c_ptr->u.ic.S_Info[0]);
-        gdth_writeb(0, &dp6c_ptr->u.ic.Status);
+        prot_ver = (unchar)readl(&dp6c_ptr->u.ic.S_Info[0]);
+        writeb(0, &dp6c_ptr->u.ic.Status);
         if (prot_ver != PROTOCOL_VERSION) {
             printk("GDT-PCI: Illegal protocol version\n");
             iounmap(ha->brd);
@@ -1082,17 +1075,17 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
         ha->ic_all_size = sizeof(dp6c_ptr->u);
 
         /* special command to controller BIOS */
-        gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
-        gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
-        gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[2]);
-        gdth_writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
-        gdth_writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
+        writel(0x00, &dp6c_ptr->u.ic.S_Info[0]);
+        writel(0x00, &dp6c_ptr->u.ic.S_Info[1]);
+        writel(0x00, &dp6c_ptr->u.ic.S_Info[2]);
+        writel(0x00, &dp6c_ptr->u.ic.S_Info[3]);
+        writeb(0xfe, &dp6c_ptr->u.ic.S_Cmd_Indx);
         
         outb(1,PTR2USHORT(&ha->plx->ldoor_reg));
 
         retries = INIT_RETRIES;
         gdth_delay(20);
-        while (gdth_readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
+        while (readb(&dp6c_ptr->u.ic.S_Status) != 0xfe) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error\n");
                 iounmap(ha->brd);
@@ -1100,7 +1093,7 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
             }
             gdth_delay(1);
         }
-        gdth_writeb(0, &dp6c_ptr->u.ic.S_Status);
+        writeb(0, &dp6c_ptr->u.ic.S_Status);
 
         ha->dma64_support = 0;
 
@@ -1128,12 +1121,12 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
 
         /* Ensure that it is safe to access the non HW portions of DPMEM.
          * Aditional check needed for Xscale based RAID controllers */
-        while( ((int)gdth_readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 )
+        while( ((int)readb(&dp6m_ptr->i960r.sema0_reg) ) & 3 )
             gdth_delay(1);
         
         /* check and reset interface area */
-        gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
-        if (gdth_readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
+        writel(DPMEM_MAGIC, &dp6m_ptr->u);
+        if (readl(&dp6m_ptr->u) != DPMEM_MAGIC) {
             printk("GDT-PCI: Cannot access DPMEM at 0x%lx (shadowed?)\n", 
                    pcistr->dpmem);
             found = FALSE;
@@ -1144,7 +1137,7 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
                     printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
                     return 0;
                 }
-                if (gdth_readw(ha->brd) != 0xffff) {
+                if (readw(ha->brd) != 0xffff) {
                     TRACE2(("init_pci_mpr() address 0x%x busy\n", i));
                     continue;
                 }
@@ -1157,8 +1150,8 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
                     return 0;
                 }
                 dp6m_ptr = ha->brd;
-                gdth_writel(DPMEM_MAGIC, &dp6m_ptr->u);
-                if (gdth_readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
+                writel(DPMEM_MAGIC, &dp6m_ptr->u);
+                if (readl(&dp6m_ptr->u) == DPMEM_MAGIC) {
                     printk("GDT-PCI: Use free address at 0x%x\n", i);
                     found = TRUE;
                     break;
@@ -1173,18 +1166,18 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
         memset_io(&dp6m_ptr->u, 0, sizeof(dp6m_ptr->u));
         
         /* disable board interrupts, deinit services */
-        gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
+        writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) | 4,
                     &dp6m_ptr->i960r.edoor_en_reg);
-        gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
-        gdth_writeb(0x00, &dp6m_ptr->u.ic.S_Status);
-        gdth_writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
+        writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
+        writeb(0x00, &dp6m_ptr->u.ic.S_Status);
+        writeb(0x00, &dp6m_ptr->u.ic.Cmd_Index);
 
-        gdth_writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
-        gdth_writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
-        gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
+        writel(pcistr->dpmem, &dp6m_ptr->u.ic.S_Info[0]);
+        writeb(0xff, &dp6m_ptr->u.ic.S_Cmd_Indx);
+        writeb(1, &dp6m_ptr->i960r.ldoor_reg);
         retries = INIT_RETRIES;
         gdth_delay(20);
-        while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
+        while (readb(&dp6m_ptr->u.ic.S_Status) != 0xff) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
                 iounmap(ha->brd);
@@ -1192,8 +1185,8 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
             }
             gdth_delay(1);
         }
-        prot_ver = (unchar)gdth_readl(&dp6m_ptr->u.ic.S_Info[0]);
-        gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
+        prot_ver = (unchar)readl(&dp6m_ptr->u.ic.S_Info[0]);
+        writeb(0, &dp6m_ptr->u.ic.S_Status);
         if (prot_ver != PROTOCOL_VERSION) {
             printk("GDT-PCI: Illegal protocol version\n");
             iounmap(ha->brd);
@@ -1204,15 +1197,15 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
         ha->ic_all_size = sizeof(dp6m_ptr->u);
         
         /* special command to controller BIOS */
-        gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
-        gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
-        gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[2]);
-        gdth_writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
-        gdth_writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
-        gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
+        writel(0x00, &dp6m_ptr->u.ic.S_Info[0]);
+        writel(0x00, &dp6m_ptr->u.ic.S_Info[1]);
+        writel(0x00, &dp6m_ptr->u.ic.S_Info[2]);
+        writel(0x00, &dp6m_ptr->u.ic.S_Info[3]);
+        writeb(0xfe, &dp6m_ptr->u.ic.S_Cmd_Indx);
+        writeb(1, &dp6m_ptr->i960r.ldoor_reg);
         retries = INIT_RETRIES;
         gdth_delay(20);
-        while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
+        while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfe) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error\n");
                 iounmap(ha->brd);
@@ -1220,14 +1213,14 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
             }
             gdth_delay(1);
         }
-        gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
+        writeb(0, &dp6m_ptr->u.ic.S_Status);
 
         /* read FW version to detect 64-bit DMA support */
-        gdth_writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx);
-        gdth_writeb(1, &dp6m_ptr->i960r.ldoor_reg);
+        writeb(0xfd, &dp6m_ptr->u.ic.S_Cmd_Indx);
+        writeb(1, &dp6m_ptr->i960r.ldoor_reg);
         retries = INIT_RETRIES;
         gdth_delay(20);
-        while (gdth_readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) {
+        while (readb(&dp6m_ptr->u.ic.S_Status) != 0xfd) {
             if (--retries == 0) {
                 printk("GDT-PCI: Initialization error (DEINIT failed)\n");
                 iounmap(ha->brd);
@@ -1235,8 +1228,8 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
             }
             gdth_delay(1);
         }
-        prot_ver = (unchar)(gdth_readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
-        gdth_writeb(0, &dp6m_ptr->u.ic.S_Status);
+        prot_ver = (unchar)(readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
+        writeb(0, &dp6m_ptr->u.ic.S_Status);
         if (prot_ver < 0x2b)      /* FW < x.43: no 64-bit DMA support */
             ha->dma64_support = 0;
         else 
@@ -1267,21 +1260,21 @@ static void __init gdth_enable_int(int hanum)
         outb(0x01, ha->bmic + EINTENABREG);
     } else if (ha->type == GDT_ISA) {
         dp2_ptr = ha->brd;
-        gdth_writeb(1, &dp2_ptr->io.irqdel);
-        gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);
-        gdth_writeb(1, &dp2_ptr->io.irqen);
+        writeb(1, &dp2_ptr->io.irqdel);
+        writeb(0, &dp2_ptr->u.ic.Cmd_Index);
+        writeb(1, &dp2_ptr->io.irqen);
     } else if (ha->type == GDT_PCI) {
         dp6_ptr = ha->brd;
-        gdth_writeb(1, &dp6_ptr->io.irqdel);
-        gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);
-        gdth_writeb(1, &dp6_ptr->io.irqen);
+        writeb(1, &dp6_ptr->io.irqdel);
+        writeb(0, &dp6_ptr->u.ic.Cmd_Index);
+        writeb(1, &dp6_ptr->io.irqen);
     } else if (ha->type == GDT_PCINEW) {
         outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
         outb(0x03, PTR2USHORT(&ha->plx->control1));
     } else if (ha->type == GDT_PCIMPR) {
         dp6m_ptr = ha->brd;
-        gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
-        gdth_writeb(gdth_readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
+        writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
+        writeb(readb(&dp6m_ptr->i960r.edoor_en_reg) & ~4,
                     &dp6m_ptr->i960r.edoor_en_reg);
     }
     spin_unlock_irqrestore(&ha->smp_lock, flags);
@@ -1305,15 +1298,15 @@ static int gdth_get_status(unchar *pIStatus,int irq)
             *pIStatus = inb((ushort)ha->bmic + EDOORREG);
         else if (ha->type == GDT_ISA)
             *pIStatus =
-                gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
+                readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
         else if (ha->type == GDT_PCI)
             *pIStatus =
-                gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
+                readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
         else if (ha->type == GDT_PCINEW) 
             *pIStatus = inb(PTR2USHORT(&ha->plx->edoor_reg));
         else if (ha->type == GDT_PCIMPR)
             *pIStatus =
-                gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg);
+                readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.edoor_reg);
    
         if (*pIStatus)                                  
             return i;                           /* board found */
@@ -1333,14 +1326,14 @@ static int gdth_test_busy(int hanum)
     if (ha->type == GDT_EISA)
         gdtsema0 = (int)inb(ha->bmic + SEMA0REG);
     else if (ha->type == GDT_ISA)
-        gdtsema0 = (int)gdth_readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
+        gdtsema0 = (int)readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
     else if (ha->type == GDT_PCI)
-        gdtsema0 = (int)gdth_readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
+        gdtsema0 = (int)readb(&((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
     else if (ha->type == GDT_PCINEW) 
         gdtsema0 = (int)inb(PTR2USHORT(&ha->plx->sema0_reg));
     else if (ha->type == GDT_PCIMPR)
         gdtsema0 = 
-            (int)gdth_readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
+            (int)readb(&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
 
     return (gdtsema0 & 1);
 }
@@ -1376,13 +1369,13 @@ static void gdth_set_sema0(int hanum)
     if (ha->type == GDT_EISA) {
         outb(1, ha->bmic + SEMA0REG);
     } else if (ha->type == GDT_ISA) {
-        gdth_writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
+        writeb(1, &((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
     } else if (ha->type == GDT_PCI) {
-        gdth_writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
+        writeb(1, &((gdt6_dpram_str __iomem *)ha->brd)->u.ic.Sema0);
     } else if (ha->type == GDT_PCINEW) { 
         outb(1, PTR2USHORT(&ha->plx->sema0_reg));
     } else if (ha->type == GDT_PCIMPR) {
-        gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
+        writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.sema0_reg);
     }
 }
 
@@ -1418,30 +1411,30 @@ static void gdth_copy_command(int hanum)
     /* set offset and service, copy command to DPMEM */
     if (ha->type == GDT_ISA) {
         dp2_ptr = ha->brd;
-        gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET, 
+        writew(dp_offset + DPMEM_COMMAND_OFFSET, 
                     &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
-        gdth_writew((ushort)cmd_ptr->Service, 
+        writew((ushort)cmd_ptr->Service, 
                     &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
         memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
     } else if (ha->type == GDT_PCI) {
         dp6_ptr = ha->brd;
-        gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET, 
+        writew(dp_offset + DPMEM_COMMAND_OFFSET, 
                     &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
-        gdth_writew((ushort)cmd_ptr->Service, 
+        writew((ushort)cmd_ptr->Service, 
                     &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
         memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
     } else if (ha->type == GDT_PCINEW) {
         dp6c_ptr = ha->brd;
-        gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET, 
+        writew(dp_offset + DPMEM_COMMAND_OFFSET, 
                     &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
-        gdth_writew((ushort)cmd_ptr->Service, 
+        writew((ushort)cmd_ptr->Service, 
                     &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
         memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
     } else if (ha->type == GDT_PCIMPR) {
         dp6m_ptr = ha->brd;
-        gdth_writew(dp_offset + DPMEM_COMMAND_OFFSET, 
+        writew(dp_offset + DPMEM_COMMAND_OFFSET, 
                     &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
-        gdth_writew((ushort)cmd_ptr->Service, 
+        writew((ushort)cmd_ptr->Service, 
                     &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
         memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
     }
@@ -1477,13 +1470,13 @@ static void gdth_release_event(int hanum)
             outl(ha->ccb_phys, ha->bmic + MAILBOXREG);
         outb(ha->pccb->Service, ha->bmic + LDOORREG);
     } else if (ha->type == GDT_ISA) {
-        gdth_writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event);
+        writeb(0, &((gdt2_dpram_str __iomem *)ha->brd)->io.event);
     } else if (ha->type == GDT_PCI) {
-        gdth_writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event);
+        writeb(0, &((gdt6_dpram_str __iomem *)ha->brd)->io.event);
     } else if (ha->type == GDT_PCINEW) { 
         outb(1, PTR2USHORT(&ha->plx->ldoor_reg));
     } else if (ha->type == GDT_PCIMPR) {
-        gdth_writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg);
+        writeb(1, &((gdt6m_dpram_str __iomem *)ha->brd)->i960r.ldoor_reg);
     }
 }
 
@@ -3166,32 +3159,32 @@ static irqreturn_t gdth_interrupt(int irq,void *dev_id)
             dp2_ptr = ha->brd;
             if (IStatus & 0x80) {                       /* error flag */
                 IStatus &= ~0x80;
-                ha->status = gdth_readw(&dp2_ptr->u.ic.Status);
+                ha->status = readw(&dp2_ptr->u.ic.Status);
                 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
             } else                                      /* no error */
                 ha->status = S_OK;
-            ha->info = gdth_readl(&dp2_ptr->u.ic.Info[0]);
-            ha->service = gdth_readw(&dp2_ptr->u.ic.Service);
-            ha->info2 = gdth_readl(&dp2_ptr->u.ic.Info[1]);
+            ha->info = readl(&dp2_ptr->u.ic.Info[0]);
+            ha->service = readw(&dp2_ptr->u.ic.Service);
+            ha->info2 = readl(&dp2_ptr->u.ic.Info[1]);
 
-            gdth_writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
-            gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */
-            gdth_writeb(0, &dp2_ptr->io.Sema1);     /* reset status semaphore */
+            writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
+            writeb(0, &dp2_ptr->u.ic.Cmd_Index);/* reset command index */
+            writeb(0, &dp2_ptr->io.Sema1);     /* reset status semaphore */
         } else if (ha->type == GDT_PCI) {
             dp6_ptr = ha->brd;
             if (IStatus & 0x80) {                       /* error flag */
                 IStatus &= ~0x80;
-                ha->status = gdth_readw(&dp6_ptr->u.ic.Status);
+                ha->status = readw(&dp6_ptr->u.ic.Status);
                 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
             } else                                      /* no error */
                 ha->status = S_OK;
-            ha->info = gdth_readl(&dp6_ptr->u.ic.Info[0]);
-            ha->service = gdth_readw(&dp6_ptr->u.ic.Service);
-            ha->info2 = gdth_readl(&dp6_ptr->u.ic.Info[1]);
+            ha->info = readl(&dp6_ptr->u.ic.Info[0]);
+            ha->service = readw(&dp6_ptr->u.ic.Service);
+            ha->info2 = readl(&dp6_ptr->u.ic.Info[1]);
 
-            gdth_writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
-            gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */
-            gdth_writeb(0, &dp6_ptr->io.Sema1);     /* reset status semaphore */
+            writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
+            writeb(0, &dp6_ptr->u.ic.Cmd_Index);/* reset command index */
+            writeb(0, &dp6_ptr->io.Sema1);     /* reset status semaphore */
         } else if (ha->type == GDT_PCINEW) {
             if (IStatus & 0x80) {                       /* error flag */
                 IStatus &= ~0x80;
@@ -3214,7 +3207,7 @@ static irqreturn_t gdth_interrupt(int irq,void *dev_id)
                     ha->status = pcs->ext_status & 0xffff;
                 else 
 #endif
-                    ha->status = gdth_readw(&dp6m_ptr->i960r.status);
+                    ha->status = readw(&dp6m_ptr->i960r.status);
                 TRACE2(("gdth_interrupt() error %d/%d\n",IStatus,ha->status));
             } else                                      /* no error */
                 ha->status = S_OK;
@@ -3227,18 +3220,18 @@ static irqreturn_t gdth_interrupt(int irq,void *dev_id)
             } else
 #endif
             {
-                ha->info = gdth_readl(&dp6m_ptr->i960r.info[0]);
-                ha->service = gdth_readw(&dp6m_ptr->i960r.service);
-                ha->info2 = gdth_readl(&dp6m_ptr->i960r.info[1]);
+                ha->info = readl(&dp6m_ptr->i960r.info[0]);
+                ha->service = readw(&dp6m_ptr->i960r.service);
+                ha->info2 = readl(&dp6m_ptr->i960r.info[1]);
             }
             /* event string */
             if (IStatus == ASYNCINDEX) {
                 if (ha->service != SCREENSERVICE &&
                     (ha->fw_vers & 0xff) >= 0x1a) {
-                    ha->dvr.severity = gdth_readb
+                    ha->dvr.severity = readb
                         (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.severity);
                     for (i = 0; i < 256; ++i) {
-                        ha->dvr.event_string[i] = gdth_readb
+                        ha->dvr.event_string[i] = readb
                             (&((gdt6m_dpram_str __iomem *)ha->brd)->i960r.evt_str[i]);
                         if (ha->dvr.event_string[i] == 0)
                             break;
@@ -3251,8 +3244,8 @@ static irqreturn_t gdth_interrupt(int irq,void *dev_id)
             if (!coalesced)
 #endif                          
             {
-                gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
-                gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
+                writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
+                writeb(0, &dp6m_ptr->i960r.sema1_reg);
             }
         } else {
             TRACE2(("gdth_interrupt() unknown controller type\n"));
@@ -3337,8 +3330,8 @@ static irqreturn_t gdth_interrupt(int irq,void *dev_id)
 
     /* coalescing only for new GDT_PCIMPR controllers available */      
     if (ha->type == GDT_PCIMPR && coalesced) {
-        gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
-        gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
+        writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
+        writeb(0, &dp6m_ptr->i960r.sema1_reg);
     }
 #endif
 

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/8] gdth: Move probe-time error handling code to end of each function
  2007-09-26  4:33 [PATCH 1/8] gdth: Split out EISA and ISA register into separate functions Jeff Garzik
                   ` (3 preceding siblings ...)
  2007-09-26  4:35 ` [PATCH 5/8] gdth: kill gdth_{read,write}[bwl] wrappers Jeff Garzik
@ 2007-09-26  4:35 ` Jeff Garzik
  2007-09-26  4:36 ` [PATCH 7/8] gdth: make some virt ctrlr code common; shuffle SHT members Jeff Garzik
  2007-09-26  4:36 ` [PATCH 8/8] gdth: convert to modern SCSI host alloc/scan Jeff Garzik
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Garzik @ 2007-09-26  4:35 UTC (permalink / raw)
  To: achim_leubner, linux-scsi, LKML


Use standard laddered-goto error handling approach in three probe-time
functions.

Signed-off-by: Jeff Garzik <jeff@garzik.org>
---

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index d7ef159..89ac155 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -3964,13 +3964,11 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 
 	shp = scsi_register(shtp, sizeof(gdth_ext_str));
 	if (shp == NULL)
-		return 1;	/* continue looping */
+		goto err_out;
 
 	ha = HADATA(shp);
-	if (!gdth_init_isa(isa_bios, ha)) {
-		scsi_unregister(shp);
-		return 1;	/* continue looping */
-	}
+	if (!gdth_init_isa(isa_bios, ha))
+		goto err_out_shp;
 
 #ifdef __ia64__
 	return 0;		/* end loop: success */
@@ -3981,14 +3979,11 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 
 	if (request_irq(ha->irq, gdth_interrupt, IRQF_DISABLED, "gdth", ha)) {
 		printk("GDT-ISA: Unable to allocate IRQ\n");
-		scsi_unregister(shp);
-		return 1;	/* continue looping */
+		goto err_out_shp;
 	}
 	if (request_dma(ha->drq, "gdth")) {
 		printk("GDT-ISA: Unable to allocate DMA channel\n");
-		free_irq(ha->irq, ha);
-		scsi_unregister(shp);
-		return 1;	/* continue looping */
+		goto err_out_irq;
 	}
 
 	set_dma_mode(ha->drq, DMA_MODE_CASCADE);
@@ -4030,25 +4025,7 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 	if (ha->pscratch == NULL || ha->pmsg == NULL || 
 	    !gdth_search_drives(hanum)) {
 		printk("GDT-ISA: Error during device scan\n");
-		gdth_pop_shp();
-
-#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);
-		return 1;	/* continue looping */
+		goto err_out_ha;
 	}
 
 	if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
@@ -4079,9 +4056,32 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 
 	spin_lock_init(&ha->smp_lock);
 	gdth_enable_int(hanum);
-#endif /* !__ia64__ */
 
 	return 1;	/* continue looping */
+
+err_out_ha:
+	gdth_pop_shp();
+
+#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);
+err_out_irq:
+	free_irq(ha->irq, ha);
+#endif /* !__ia64__ */
+err_out_shp:
+	scsi_unregister(shp);
+err_out:
+	return 1;	/* continue looping */
 }
 
 static int __init gdth_start_eisa(struct scsi_host_template *shtp,
@@ -4094,13 +4094,11 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 
 	shp = scsi_register(shtp,sizeof(gdth_ext_str));
 	if (shp == NULL)
-		return 1;	/* continue looping */
+		goto err_out;
 
 	ha = HADATA(shp);
-	if (!gdth_init_eisa(eisa_slot,ha)) {
-		scsi_unregister(shp);
-		return 1;	/* continue looping */
-	}
+	if (!gdth_init_eisa(eisa_slot,ha))
+		goto err_out_shp;
 
 	/* controller found and initialized */
 	printk("Configuring GDT-EISA HA at Slot %d IRQ %u\n",
@@ -4108,8 +4106,7 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 
 	if (request_irq(ha->irq,gdth_interrupt,IRQF_DISABLED,"gdth",ha)) {
 		printk("GDT-EISA: Unable to allocate IRQ\n");
-		scsi_unregister(shp);
-		return 1;	/* continue looping */
+		goto err_out_shp;
 	}
 
 	shp->unchecked_isa_dma = 0;
@@ -4155,26 +4152,7 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 	if (ha->pscratch == NULL || ha->pmsg == NULL || 
 	    !gdth_search_drives(hanum)) {
 		printk("GDT-EISA: Error during device scan\n");
-		gdth_pop_shp();
-
-#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);
-		return 1;	/* continue looping */
+		goto err_out_ha;
 	}
 
 	if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
@@ -4207,6 +4185,30 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 	gdth_enable_int(hanum);
 
 	return 1;	/* continue looping */
+
+err_out_ha:
+	gdth_pop_shp();
+
+#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);
+err_out_shp:
+	scsi_unregister(shp);
+err_out:
+	return 1;	/* continue looping */
 }
 
 static int __init gdth_start_pci(struct scsi_host_template *shtp,
@@ -4215,19 +4217,17 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 	struct Scsi_Host *shp;
 	dma_addr_t scratch_dma_handle = 0;
 	gdth_ha_str *ha;
-	int i, hanum, err;
+	int i, hanum;
 
 	if (gdth_ctr_count >= MAXHA)
 		return 0;	/* end loop: success */
 	shp = scsi_register(shtp,sizeof(gdth_ext_str));
 	if (shp == NULL)
-		return 1;	/* continue looping */
+		goto err_out;
 
 	ha = HADATA(shp);
-	if (!gdth_init_pci(&pcistr[ctr],ha)) {
-		scsi_unregister(shp);
-		return 1;	/* continue looping */
-	}
+	if (!gdth_init_pci(&pcistr[ctr],ha))
+		goto err_out_shp;
 
 	/* controller found and initialized */
 	printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
@@ -4237,8 +4237,7 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 	if (request_irq(ha->irq, gdth_interrupt,
 			IRQF_DISABLED | IRQF_SHARED, "gdth", ha)) {
 		printk("GDT-PCI: Unable to allocate IRQ\n");
-		scsi_unregister(shp);
-		return 1;	/* continue looping */
+		goto err_out_shp;
 	}
 
 	shp->unchecked_isa_dma = 0;
@@ -4275,58 +4274,32 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 		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 (!(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, DMA_32BIT_MASK)){
-				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,DMA_64BIT_MASK)){
-				printk("GDT-PCI %d: 64-bit DMA enabled\n",
-				       hanum);
-			} else if (pci_set_dma_mask(pcistr[ctr].pdev,
-						    DMA_32BIT_MASK)) {
-				printk(KERN_WARNING "GDT-PCI %d: Unable to set "
-				       "64/32-bit DMA\n", hanum);
-				err = TRUE;
-			}
-		}
-	}
+	    !gdth_search_drives(hanum))
+		goto err_out_ha;
 
-	if (err) {
-		printk("GDT-PCI %d: Error during device scan\n", hanum);
-		gdth_pop_shp();
-
-#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 (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
+		hdr_channel = ha->bus_cnt;
+	ha->virt_bus = hdr_channel;
 
-		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);
-		return 1;	/* continue looping */
+	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, DMA_32BIT_MASK)){
+			printk(KERN_WARNING "GDT-PCI %d: Unable to "
+			       "set 32-bit DMA\n", hanum);
+			goto err_out_ha;
+		}
+	} else {
+		shp->max_cmd_len = 16;
+		if (!pci_set_dma_mask(pcistr[ctr].pdev, DMA_64BIT_MASK)) {
+			printk("GDT-PCI %d: 64-bit DMA enabled\n",
+			       hanum);
+		} else if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
+			printk(KERN_WARNING "GDT-PCI %d: Unable to set "
+			       "64/32-bit DMA\n", hanum);
+			goto err_out_ha;
+		}
 	}
 
 	shp->max_id      = ha->tid_cnt;
@@ -4353,6 +4326,28 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 	gdth_enable_int(hanum);
 
 	return 1;	/* continue looping */
+
+err_out_ha:
+	gdth_pop_shp();
+
+#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);
+err_out_shp:
+	scsi_unregister(shp);
+err_out:
+	return 1;	/* continue looping */
 }
 
 static int __init gdth_detect(struct scsi_host_template *shtp)

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 7/8] gdth: make some virt ctrlr code common; shuffle SHT members
  2007-09-26  4:33 [PATCH 1/8] gdth: Split out EISA and ISA register into separate functions Jeff Garzik
                   ` (4 preceding siblings ...)
  2007-09-26  4:35 ` [PATCH 6/8] gdth: Move probe-time error handling code to end of each function Jeff Garzik
@ 2007-09-26  4:36 ` Jeff Garzik
  2007-09-26  4:36 ` [PATCH 8/8] gdth: convert to modern SCSI host alloc/scan Jeff Garzik
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Garzik @ 2007-09-26  4:36 UTC (permalink / raw)
  To: achim_leubner, linux-scsi, LKML


* New function gdth_register_virt() replaces the three
  basically-duplicate copies of virtual controller registration.

* shuffle scsi_host_template members such that they appear in the
  order in which they are defined in the header.  this makes is easier
  to verify when initializers are missing members.

Signed-off-by: Jeff Garzik <jeff@garzik.org>
---

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 89ac155..f382664 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -3954,6 +3954,44 @@ int __init option_setup(char *str)
     return 1;
 }
 
+static int __init gdth_register_virt(struct scsi_host_template *shtp,
+				     gdth_ha_str *ha, int hanum,
+				     struct device *dev, bool isa_dma)
+{
+	struct Scsi_Host *shp;
+	unchar b;
+	int done = 0;
+
+	if (!virt_ctr)
+		return 0;
+	
+	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));
+
+		if (isa_dma) {
+			shp->unchecked_isa_dma = 1;
+			shp->dma_channel = ha->drq;
+		} else {
+			shp->unchecked_isa_dma = 0;
+			shp->dma_channel = 0xff;
+		}
+
+		shp->irq = ha->irq;
+
+		gdth_push_vshp(shp);
+
+		NUMDATA(shp)->hanum = (ushort)hanum;
+		NUMDATA(shp)->busnum = b;
+
+		done++;
+	}
+
+	return done ? 0 : -ENODEV;
+}
+
 static int __init gdth_start_isa(struct scsi_host_template *shtp,
 				 ulong32 isa_bios)
 {
@@ -4038,21 +4076,8 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 	shp->max_id      = ha->tid_cnt;
 	shp->max_lun     = MAXLUN;
 	shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
-	if (virt_ctr) {
-		unchar b;
 
-		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_push_vshp(shp);
-			NUMDATA(shp)->hanum = (ushort)hanum;
-			NUMDATA(shp)->busnum = b;
-		}
-	}  
+	gdth_register_virt(shtp, ha, hanum, NULL, true);
 
 	spin_lock_init(&ha->smp_lock);
 	gdth_enable_int(hanum);
@@ -4165,21 +4190,8 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 	shp->max_id      = ha->tid_cnt;
 	shp->max_lun     = MAXLUN;
 	shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
-	if (virt_ctr) {
-		unchar b;
 
-		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_push_vshp(shp);
-			NUMDATA(shp)->hanum = (ushort)hanum;
-			NUMDATA(shp)->busnum = b;
-		}
-	}  
+	gdth_register_virt(shtp, ha, hanum, NULL, false);
 
 	spin_lock_init(&ha->smp_lock);
 	gdth_enable_int(hanum);
@@ -4306,21 +4318,7 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 	shp->max_lun     = MAXLUN;
 	shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
 
-	if (virt_ctr) {
-		unchar b;
-
-		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_push_vshp(shp);
-			NUMDATA(shp)->hanum = (ushort)hanum;
-			NUMDATA(shp)->busnum = b;
-		}
-	}  
+	gdth_register_virt(shtp, ha, hanum, &pcistr[ctr].pdev->dev, false);
 
 	spin_lock_init(&ha->smp_lock);
 	gdth_enable_int(hanum);
@@ -5330,17 +5328,17 @@ static int gdth_slave_configure(struct scsi_device *sdev)
 }
 
 static struct scsi_host_template driver_template = {
-        .proc_name              = "gdth", 
-        .proc_info              = gdth_proc_info,
         .name                   = "GDT SCSI Disk Array Controller",
         .detect                 = gdth_detect, 
         .release                = gdth_release,
         .info                   = gdth_info, 
         .queuecommand           = gdth_queuecommand,
         .eh_bus_reset_handler   = gdth_eh_bus_reset,
+        .slave_configure        = gdth_slave_configure,
         .bios_param             = gdth_bios_param,
+        .proc_info              = gdth_proc_info,
+        .proc_name              = "gdth", 
         .can_queue              = GDTH_MAXCMDS,
-        .slave_configure        = gdth_slave_configure,
         .this_id                = -1,
         .sg_tablesize           = GDTH_MAXSG,
         .cmd_per_lun            = GDTH_MAXC_P_L,

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 8/8] gdth: convert to modern SCSI host alloc/scan
  2007-09-26  4:33 [PATCH 1/8] gdth: Split out EISA and ISA register into separate functions Jeff Garzik
                   ` (5 preceding siblings ...)
  2007-09-26  4:36 ` [PATCH 7/8] gdth: make some virt ctrlr code common; shuffle SHT members Jeff Garzik
@ 2007-09-26  4:36 ` Jeff Garzik
  6 siblings, 0 replies; 8+ messages in thread
From: Jeff Garzik @ 2007-09-26  4:36 UTC (permalink / raw)
  To: achim_leubner, linux-scsi, LKML


Signed-off-by: Jeff Garzik <jeff@garzik.org>
---

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index f382664..3f3ef4b 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -3960,7 +3960,7 @@ static int __init gdth_register_virt(struct scsi_host_template *shtp,
 {
 	struct Scsi_Host *shp;
 	unchar b;
-	int done = 0;
+	int rc, done = 0;
 
 	if (!virt_ctr)
 		return 0;
@@ -3969,7 +3969,7 @@ static int __init gdth_register_virt(struct scsi_host_template *shtp,
 
 	/* 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 = scsi_host_alloc(shtp, sizeof(gdth_num_str));
 
 		if (isa_dma) {
 			shp->unchecked_isa_dma = 1;
@@ -3981,12 +3981,17 @@ static int __init gdth_register_virt(struct scsi_host_template *shtp,
 
 		shp->irq = ha->irq;
 
-		gdth_push_vshp(shp);
+		rc = scsi_add_host(shp, dev);
+		if (rc)
+			scsi_host_put(shp);
+		else {
+			gdth_push_vshp(shp);
 
-		NUMDATA(shp)->hanum = (ushort)hanum;
-		NUMDATA(shp)->busnum = b;
+			NUMDATA(shp)->hanum = (ushort)hanum;
+			NUMDATA(shp)->busnum = b;
 
-		done++;
+			done++;
+		}
 	}
 
 	return done ? 0 : -ENODEV;
@@ -3997,10 +4002,10 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 {
 	struct Scsi_Host *shp;
 	gdth_ha_str *ha;
-	int i, hanum;
+	int i, hanum, rc;
 	dma_addr_t scratch_dma_handle = 0;
 
-	shp = scsi_register(shtp, sizeof(gdth_ext_str));
+	shp = scsi_host_alloc(shtp, sizeof(gdth_ext_str));
 	if (shp == NULL)
 		goto err_out;
 
@@ -4009,6 +4014,8 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 		goto err_out_shp;
 
 #ifdef __ia64__
+	if (scsi_add_host(shp, NULL))
+		scsi_host_put(shp);
 	return 0;		/* end loop: success */
 #else
 	/* controller found and initialized */
@@ -4077,13 +4084,26 @@ static int __init gdth_start_isa(struct scsi_host_template *shtp,
 	shp->max_lun     = MAXLUN;
 	shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
 
-	gdth_register_virt(shtp, ha, hanum, NULL, true);
-
 	spin_lock_init(&ha->smp_lock);
+
+	rc = scsi_add_host(shp, NULL);
+	if (rc) {
+		printk("GDT-ISA: Error adding host\n");
+		goto err_out_ha;
+	}
+
+	rc = gdth_register_virt(shtp, ha, hanum, NULL, true);
+	if (rc) {
+		printk("GDT-ISA: Error adding virt controllers\n");
+		goto err_out_host;
+	}
+
 	gdth_enable_int(hanum);
 
 	return 1;	/* continue looping */
 
+err_out_host:
+	scsi_remove_host(shp);
 err_out_ha:
 	gdth_pop_shp();
 
@@ -4104,7 +4124,7 @@ err_out_irq:
 	free_irq(ha->irq, ha);
 #endif /* !__ia64__ */
 err_out_shp:
-	scsi_unregister(shp);
+	scsi_host_put(shp);
 err_out:
 	return 1;	/* continue looping */
 }
@@ -4114,10 +4134,10 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 {
 	struct Scsi_Host *shp;
 	gdth_ha_str *ha;
-	int i, hanum;
+	int i, hanum, rc;
 	dma_addr_t scratch_dma_handle = 0;
 
-	shp = scsi_register(shtp,sizeof(gdth_ext_str));
+	shp = scsi_host_alloc(shtp, sizeof(gdth_ext_str));
 	if (shp == NULL)
 		goto err_out;
 
@@ -4191,13 +4211,26 @@ static int __init gdth_start_eisa(struct scsi_host_template *shtp,
 	shp->max_lun     = MAXLUN;
 	shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
 
-	gdth_register_virt(shtp, ha, hanum, NULL, false);
-
 	spin_lock_init(&ha->smp_lock);
+
+	rc = scsi_add_host(shp, NULL);
+	if (rc) {
+		printk("GDT-EISA: Error adding host\n");
+		goto err_out_ha;
+	}
+
+	rc = gdth_register_virt(shtp, ha, hanum, NULL, false);
+	if (rc) {
+		printk("GDT-EISA: Error adding virt controllers\n");
+		goto err_out_host;
+	}
+
 	gdth_enable_int(hanum);
 
 	return 1;	/* continue looping */
 
+err_out_host:
+	scsi_remove_host(shp);
 err_out_ha:
 	gdth_pop_shp();
 
@@ -4218,7 +4251,7 @@ err_out_ha:
 			    sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
 	free_irq(ha->irq, ha);
 err_out_shp:
-	scsi_unregister(shp);
+	scsi_host_put(shp);
 err_out:
 	return 1;	/* continue looping */
 }
@@ -4229,11 +4262,11 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 	struct Scsi_Host *shp;
 	dma_addr_t scratch_dma_handle = 0;
 	gdth_ha_str *ha;
-	int i, hanum;
+	int i, hanum, rc;
 
 	if (gdth_ctr_count >= MAXHA)
 		return 0;	/* end loop: success */
-	shp = scsi_register(shtp,sizeof(gdth_ext_str));
+	shp = scsi_host_alloc(shtp, sizeof(gdth_ext_str));
 	if (shp == NULL)
 		goto err_out;
 
@@ -4318,13 +4351,26 @@ static int __init gdth_start_pci(struct scsi_host_template *shtp,
 	shp->max_lun     = MAXLUN;
 	shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
 
-	gdth_register_virt(shtp, ha, hanum, &pcistr[ctr].pdev->dev, false);
-
 	spin_lock_init(&ha->smp_lock);
+
+	rc = scsi_add_host(shp, NULL);
+	if (rc) {
+		printk("GDT-PCI: Error adding host\n");
+		goto err_out_ha;
+	}
+
+	rc = gdth_register_virt(shtp, ha, hanum, &pcistr[ctr].pdev->dev, false);
+	if (rc) {
+		printk("GDT-PCI: Error adding virt controllers\n");
+		goto err_out_host;
+	}
+
 	gdth_enable_int(hanum);
 
 	return 1;	/* continue looping */
 
+err_out_host:
+	scsi_remove_host(shp);
 err_out_ha:
 	gdth_pop_shp();
 
@@ -4343,7 +4389,7 @@ err_out_ha:
 				ha->pmsg, ha->msg_phys);
 	free_irq(ha->irq, ha);
 err_out_shp:
-	scsi_unregister(shp);
+	scsi_host_put(shp);
 err_out:
 	return 1;	/* continue looping */
 }
@@ -4351,7 +4397,7 @@ err_out:
 static int __init gdth_detect(struct scsi_host_template *shtp)
 {
     gdth_pci_str pcistr[MAXHA];
-    int cnt,ctr;
+    int cnt, ctr, i;
     unchar b;
  
 #ifdef DEBUG_GDTH
@@ -4374,7 +4420,7 @@ static int __init gdth_detect(struct scsi_host_template *shtp)
 
     if (disable) {
         printk("GDT-HA: Controller driver disabled from command line !\n");
-        return 0;
+        return -ENODEV;
     }
 
     printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n",GDTH_VERSION_STR);
@@ -4438,14 +4484,22 @@ static int __init gdth_detect(struct scsi_host_template *shtp)
         register_reboot_notifier(&gdth_notifier);
     }
     gdth_polling = FALSE;
-    return gdth_ctr_vcount;
+
+    for (i = 0; i < gdth_ctr_vcount; i++)
+    	if (gdth_ctr_vtab[i])
+    	    scsi_scan_host(gdth_ctr_vtab[i]);
+
+    return gdth_ctr_vcount > 0 ? 0 : -ENODEV;
 }
 
-static int gdth_release(struct Scsi_Host *shp)
+static void __exit gdth_release(struct Scsi_Host *shp)
 {
     int hanum;
     gdth_ha_str *ha;
 
+    if (!shp)
+    	return;
+
     TRACE2(("gdth_release()\n"));
     if (NUMDATA(shp)->busnum == 0) {
         hanum = NUMDATA(shp)->hanum;
@@ -4491,8 +4545,7 @@ static int gdth_release(struct Scsi_Host *shp)
         }
     }
 
-    scsi_unregister(shp);
-    return 0;
+    scsi_host_put(shp);
 }
             
 
@@ -5328,9 +5381,8 @@ static int gdth_slave_configure(struct scsi_device *sdev)
 }
 
 static struct scsi_host_template driver_template = {
+	.module			= THIS_MODULE,
         .name                   = "GDT SCSI Disk Array Controller",
-        .detect                 = gdth_detect, 
-        .release                = gdth_release,
         .info                   = gdth_info, 
         .queuecommand           = gdth_queuecommand,
         .eh_bus_reset_handler   = gdth_eh_bus_reset,
@@ -5346,7 +5398,26 @@ static struct scsi_host_template driver_template = {
         .use_clustering         = ENABLE_CLUSTERING,
 };
 
-#include "scsi_module.c"
 #ifndef MODULE
 __setup("gdth=", option_setup);
 #endif
+
+static int __init gdth_mod_init(void)
+{
+	return gdth_detect(&driver_template);
+}
+
+static void __exit gdth_mod_exit(void)
+{
+	int i;
+
+	for (i = 0; i < gdth_ctr_vcount; i++)
+		if (gdth_ctr_vtab[i])
+			scsi_remove_host(gdth_ctr_vtab[i]);
+	for (i = 0; i < gdth_ctr_vcount; i++)
+		gdth_release(gdth_ctr_vtab[i]);
+}
+
+module_init(gdth_mod_init);
+module_exit(gdth_mod_exit);
+

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-09-26  4:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-26  4:33 [PATCH 1/8] gdth: Split out EISA and ISA register into separate functions Jeff Garzik
2007-09-26  4:34 ` [PATCH 2/8] gdth: Split out PCI register into separate function Jeff Garzik
2007-09-26  4:34 ` [PATCH 3/8] gdth: Remove 2.4.x support, in-kernel changelog Jeff Garzik
2007-09-26  4:35 ` [PATCH 4/8] gdth: Isolate driver-global variables using helpers Jeff Garzik
2007-09-26  4:35 ` [PATCH 5/8] gdth: kill gdth_{read,write}[bwl] wrappers Jeff Garzik
2007-09-26  4:35 ` [PATCH 6/8] gdth: Move probe-time error handling code to end of each function Jeff Garzik
2007-09-26  4:36 ` [PATCH 7/8] gdth: make some virt ctrlr code common; shuffle SHT members Jeff Garzik
2007-09-26  4:36 ` [PATCH 8/8] gdth: convert to modern SCSI host alloc/scan Jeff Garzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox