From: Jeff Garzik <jeff@garzik.org>
To: achim_leubner@adaptec.com, linux-scsi@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/8] gdth: Split out PCI register into separate function
Date: Wed, 26 Sep 2007 00:34:10 -0400 [thread overview]
Message-ID: <20070926043410.GA16185@havoc.gtf.org> (raw)
In-Reply-To: <20070926043321.GA16055@havoc.gtf.org>
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));
next prev parent reply other threads:[~2007-09-26 4:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070926043410.GA16185@havoc.gtf.org \
--to=jeff@garzik.org \
--cc=achim_leubner@adaptec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox