linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ondrej Zary <linux@rainbow-software.org>
To: linux-scsi@vger.kernel.org
Subject: [PATCH 19/36] aha1542: rework hw_init
Date: Fri,  6 Feb 2015 23:11:40 +0100	[thread overview]
Message-ID: <1423260717-15944-20-git-send-email-linux@rainbow-software.org> (raw)
In-Reply-To: <1423260717-15944-1-git-send-email-linux@rainbow-software.org>

Cleanup hw_init, use goto for error handling.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
---
 drivers/scsi/aha1542.c |  139 ++++++++++++++++++++----------------------------
 drivers/scsi/aha1542.h |    1 +
 2 files changed, 59 insertions(+), 81 deletions(-)

diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index 4849d02..8c915d7 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -657,7 +657,7 @@ static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)
 	aha1542_intr_reset(bse);
 }
 
-static int aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned char *dma_chan, unsigned char *scsi_id)
+static int aha1542_getconfig(int base_io, unsigned int *irq_level, unsigned char *dma_chan, unsigned int *scsi_id)
 {
 	u8 inquiry_result[3];
 	int i;
@@ -901,99 +901,76 @@ fail:
 /* return non-zero on detection */
 static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct device *pdev, int indx)
 {
-	unsigned char dma_chan;
-	unsigned char irq_level;
-	unsigned char scsi_id;
-	unsigned long flags;
-	unsigned int base_io;
-	int trans;
-	struct Scsi_Host *shpnt = NULL;
+	unsigned int base_io = bases[indx];
+	struct Scsi_Host *shpnt;
 	struct aha1542_hostdata *aha1542;
 
-	DEB(printk("aha1542_detect: \n"));
-
-	tpnt->proc_name = "aha1542";
-
-		if (bases[indx] != 0 && request_region(bases[indx], 4, "aha1542")) {
-			shpnt = scsi_host_alloc(tpnt,
-					sizeof(struct aha1542_hostdata));
-
-			if(shpnt==NULL) {
-				release_region(bases[indx], 4);
-				return NULL;
-			}
-			aha1542 = shost_priv(shpnt);
-			if (!aha1542_test_port(bases[indx], shpnt))
-				goto unregister;
+	if (base_io == 0)
+		return NULL;
 
-			base_io = bases[indx];
+	if (!request_region(base_io, AHA1542_REGION_SIZE, "aha1542"))
+		return NULL;
 
-			aha1542_set_bus_times(indx);
+	shpnt = scsi_host_alloc(tpnt, sizeof(struct aha1542_hostdata));
+	if (!shpnt)
+		goto release;
+	aha1542 = shost_priv(shpnt);
 
-			if (aha1542_query(base_io, &trans))
-				goto unregister;
+	if (!aha1542_test_port(base_io, shpnt))
+		goto unregister;
 
-			if (aha1542_getconfig(base_io, &irq_level, &dma_chan, &scsi_id) == -1)
-				goto unregister;
+	aha1542_set_bus_times(indx);
+	if (aha1542_query(base_io, &aha1542->bios_translation))
+		goto unregister;
+	if (aha1542_getconfig(base_io, &shpnt->irq, &shpnt->dma_channel, &shpnt->this_id) == -1)
+		goto unregister;
 
-			printk(KERN_INFO "Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id, base_io, irq_level);
-			if (dma_chan != 0xFF)
-				printk(", DMA priority %d", dma_chan);
-			printk("\n");
+	printk(KERN_INFO "Adaptec AHA-1542 (SCSI-ID %d) at IO 0x%x, IRQ %d", shpnt->this_id, base_io, shpnt->irq);
+	if (shpnt->dma_channel != 0xFF)
+		printk(", DMA %d", shpnt->dma_channel);
+	printk("\n");
+	if (aha1542->bios_translation == BIOS_TRANSLATION_25563)
+		printk(KERN_INFO "aha1542.c: Using extended bios translation\n");
 
-			setup_mailboxes(base_io, shpnt);
+	setup_mailboxes(base_io, shpnt);
 
-			DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
-			spin_lock_irqsave(&aha1542_lock, flags);
-			if (request_irq(irq_level, do_aha1542_intr_handle, 0,
+	if (request_irq(shpnt->irq, do_aha1542_intr_handle, 0,
 					"aha1542", shpnt)) {
-				printk(KERN_ERR "Unable to allocate IRQ for adaptec controller.\n");
-				spin_unlock_irqrestore(&aha1542_lock, flags);
-				goto unregister;
-			}
-			if (dma_chan != 0xFF) {
-				if (request_dma(dma_chan, "aha1542")) {
-					printk(KERN_ERR "Unable to allocate DMA channel for Adaptec.\n");
-					free_irq(irq_level, shpnt);
-					spin_unlock_irqrestore(&aha1542_lock, flags);
-					goto unregister;
-				}
-				if (dma_chan == 0 || dma_chan >= 5) {
-					set_dma_mode(dma_chan, DMA_MODE_CASCADE);
-					enable_dma(dma_chan);
-				}
-			}
+		printk(KERN_ERR "Unable to allocate IRQ for adaptec controller.\n");
+		goto unregister;
+	}
+	if (shpnt->dma_channel != 0xFF) {
+		if (request_dma(shpnt->dma_channel, "aha1542")) {
+			printk(KERN_ERR "Unable to allocate DMA channel for Adaptec.\n");
+			goto free_irq;
+		}
+		if (shpnt->dma_channel == 0 || shpnt->dma_channel >= 5) {
+			set_dma_mode(shpnt->dma_channel, DMA_MODE_CASCADE);
+			enable_dma(shpnt->dma_channel);
+		}
+	}
 
-			shpnt->this_id = scsi_id;
-			shpnt->unique_id = base_io;
-			shpnt->io_port = base_io;
-			shpnt->n_io_port = 4;	/* Number of bytes of I/O space used */
-			shpnt->dma_channel = dma_chan;
-			shpnt->irq = irq_level;
-			aha1542->bios_translation = trans;
-			if (trans == BIOS_TRANSLATION_25563)
-				printk(KERN_INFO "aha1542.c: Using extended bios translation\n");
-			aha1542->aha1542_last_mbi_used = (2 * AHA1542_MAILBOXES - 1);
-			aha1542->aha1542_last_mbo_used = (AHA1542_MAILBOXES - 1);
-			memset(aha1542->SCint, 0, sizeof(aha1542->SCint));
-			spin_unlock_irqrestore(&aha1542_lock, flags);
+	shpnt->unique_id = base_io;
+	shpnt->io_port = base_io;
+	shpnt->n_io_port = AHA1542_REGION_SIZE;
+	aha1542->aha1542_last_mbi_used = 2 * AHA1542_MAILBOXES - 1;
+	aha1542->aha1542_last_mbo_used = AHA1542_MAILBOXES - 1;
 
-			if (scsi_add_host(shpnt, pdev)) {
-				if (shpnt->dma_channel != 0xff)
-					free_dma(shpnt->dma_channel);
-				free_irq(irq_level, shpnt);
-				goto unregister;
-			}
+	if (scsi_add_host(shpnt, pdev))
+		goto free_dma;
 
-			scsi_scan_host(shpnt);
+	scsi_scan_host(shpnt);
 
-			return shpnt;
+	return shpnt;
+free_dma:
+	if (shpnt->dma_channel != 0xff)
+		free_dma(shpnt->dma_channel);
+free_irq:
+	free_irq(shpnt->irq, shpnt);
 unregister:
-			release_region(bases[indx], 4);
-			scsi_host_put(shpnt);
-			return NULL;
-
-		};
+	scsi_host_put(shpnt);
+release:
+	release_region(base_io, AHA1542_REGION_SIZE);
 
 	return NULL;
 }
@@ -1001,10 +978,10 @@ unregister:
 static int aha1542_release(struct Scsi_Host *shost)
 {
 	scsi_remove_host(shost);
-	if (shost->irq)
-		free_irq(shost->irq, shost);
 	if (shost->dma_channel != 0xff)
 		free_dma(shost->dma_channel);
+	if (shost->irq)
+		free_irq(shost->irq, shost);
 	if (shost->io_port && shost->n_io_port)
 		release_region(shost->io_port, shost->n_io_port);
 	scsi_host_put(shost);
diff --git a/drivers/scsi/aha1542.h b/drivers/scsi/aha1542.h
index 1333a23..f58792b 100644
--- a/drivers/scsi/aha1542.h
+++ b/drivers/scsi/aha1542.h
@@ -126,6 +126,7 @@ struct ccb {		/* Command Control Block 5.3 */
 					/* REQUEST SENSE */
 };
 
+#define AHA1542_REGION_SIZE 4
 #define AHA1542_MAILBOXES 8
 
 #endif
-- 
Ondrej Zary


  parent reply	other threads:[~2015-02-06 22:16 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-06 22:11 [PATCH 0/36] aha1542: Various improvements Ondrej Zary
2015-02-06 22:11 ` [PATCH 01/36] aha1542: Stop using scsi_module.c Ondrej Zary
2015-02-06 22:11 ` [PATCH 02/36] aha1542: remove dead code Ondrej Zary
2015-02-06 22:11 ` [PATCH 03/36] aha1542: Remove SCSI_BUF_PA, SCSI_SG_PA, AHA1542_SCATTER and AHA1542_CMDLUN Ondrej Zary
2015-02-06 22:11 ` [PATCH 04/36] aha1542: Remove HOSTDATA macro Ondrej Zary
2015-02-06 22:11 ` [PATCH 05/36] aha1542: Convert aha1542_intr_reset to function Ondrej Zary
2015-02-06 22:11 ` [PATCH 06/36] aha1542: Use u8 instead of unchar Ondrej Zary
2015-02-06 22:11 ` [PATCH 07/36] aha1542: Reorder functions to remove forward declarations Ondrej Zary
2015-02-06 22:11 ` [PATCH 08/36] aha1542: remove empty aha1542_stat Ondrej Zary
2015-02-06 22:11 ` [PATCH 09/36] aha1542: Use BIT() macro Ondrej Zary
2015-02-06 22:11 ` [PATCH 10/36] aha1542: Remove WAIT and WAITd macros Ondrej Zary
2015-02-06 22:11 ` [PATCH 11/36] aha1542: Unify aha1542_in and aha1542_in1 Ondrej Zary
2015-02-06 22:11 ` [PATCH 12/36] aha1542: Split aha1542_out Ondrej Zary
2015-02-06 22:11 ` [PATCH 13/36] aha1542: Remove unneeded gotos Ondrej Zary
2015-02-06 22:11 ` [PATCH 14/36] aha1542: remove useless code from aha1542_test_port Ondrej Zary
2015-02-06 22:11 ` [PATCH 15/36] aha1542: Remove aha1542_restart Ondrej Zary
2015-02-06 22:11 ` [PATCH 16/36] aha1542: Merge aha1542_host_reset and aha1542_bus_reset Ondrej Zary
2015-02-06 22:11 ` [PATCH 17/36] aha1542: split out code from aha1542_hw_init Ondrej Zary
2015-02-06 22:11 ` [PATCH 18/36] aha1542: Call wait_mask from aha1542_out Ondrej Zary
2015-02-06 22:11 ` Ondrej Zary [this message]
2015-02-06 22:11 ` [PATCH 20/36] aha1542: rework configuration parameters Ondrej Zary
2015-02-06 22:11 ` [PATCH 21/36] aha1542: Simplify aha1542_biosparam Ondrej Zary
2015-02-06 22:11 ` [PATCH 22/36] aha1542: clean up cmd variables Ondrej Zary
2015-02-06 22:11 ` [PATCH 23/36] aha1524: Use struct scsi_cmnd Ondrej Zary
2015-02-06 22:11 ` [PATCH 24/36] aha1542: Always name Scsi_Host variables sh Ondrej Zary
2015-02-06 22:11 ` [PATCH 25/36] aha1542: fix include guard and remove useless changelog Ondrej Zary
2015-02-06 22:11 ` [PATCH 26/36] aha1542: " Ondrej Zary
2015-02-06 22:11 ` [PATCH 27/36] aha1542: cleanup includes Ondrej Zary
2015-02-06 22:11 ` [PATCH 28/36] aha1542: Pass struct Scsi_Host * to functions Ondrej Zary
2015-02-06 22:11 ` [PATCH 29/36] aha1542: Change aha1542_set_bus_times parameters Ondrej Zary
2015-02-06 22:11 ` [PATCH 30/36] aha1542: Use shost_printk instead of printk Ondrej Zary
2015-02-06 22:11 ` [PATCH 31/36] aha1542: remove DEB macro and simplify debug code Ondrej Zary
2015-02-06 22:11 ` [PATCH 32/36] aha1542: Use print_hex_dump_bytes in " Ondrej Zary
2015-02-06 22:11 ` [PATCH 33/36] aha1542: Don't reduce functionality with DEBUG enabled Ondrej Zary
2015-02-06 22:11 ` [PATCH 34/36] aha1542: rework locking Ondrej Zary
2015-02-06 22:11 ` [PATCH 35/36] aha1542: Fix bus reset Ondrej Zary
2015-02-06 22:11 ` [PATCH 36/36] aha1542: remove loop from aha1542_outb Ondrej Zary
2015-04-06 15:21 ` [PATCH 0/36] aha1542: Various improvements Christoph Hellwig

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=1423260717-15944-20-git-send-email-linux@rainbow-software.org \
    --to=linux@rainbow-software.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;
as well as URLs for NNTP newsgroup(s).