mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-30 06:10:56 +00:00
aha1542: rework hw_init
Cleanup hw_init, use goto for error handling. Signed-off-by: Ondrej Zary <linux@rainbow-software.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: James Bottomley <JBottomley@Odin.com>
This commit is contained in:
parent
23e6940a9e
commit
3a70c006ed
2 changed files with 59 additions and 81 deletions
|
@ -657,7 +657,7 @@ static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)
|
||||||
aha1542_intr_reset(bse);
|
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];
|
u8 inquiry_result[3];
|
||||||
int i;
|
int i;
|
||||||
|
@ -901,99 +901,76 @@ static void aha1542_set_bus_times(int indx)
|
||||||
/* return non-zero on detection */
|
/* return non-zero on detection */
|
||||||
static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct device *pdev, int indx)
|
static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct device *pdev, int indx)
|
||||||
{
|
{
|
||||||
unsigned char dma_chan;
|
unsigned int base_io = bases[indx];
|
||||||
unsigned char irq_level;
|
struct Scsi_Host *shpnt;
|
||||||
unsigned char scsi_id;
|
|
||||||
unsigned long flags;
|
|
||||||
unsigned int base_io;
|
|
||||||
int trans;
|
|
||||||
struct Scsi_Host *shpnt = NULL;
|
|
||||||
struct aha1542_hostdata *aha1542;
|
struct aha1542_hostdata *aha1542;
|
||||||
|
|
||||||
DEB(printk("aha1542_detect: \n"));
|
if (base_io == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
tpnt->proc_name = "aha1542";
|
if (!request_region(base_io, AHA1542_REGION_SIZE, "aha1542"))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (bases[indx] != 0 && request_region(bases[indx], 4, "aha1542")) {
|
shpnt = scsi_host_alloc(tpnt, sizeof(struct aha1542_hostdata));
|
||||||
shpnt = scsi_host_alloc(tpnt,
|
if (!shpnt)
|
||||||
sizeof(struct aha1542_hostdata));
|
goto release;
|
||||||
|
aha1542 = shost_priv(shpnt);
|
||||||
|
|
||||||
if(shpnt==NULL) {
|
if (!aha1542_test_port(base_io, shpnt))
|
||||||
release_region(bases[indx], 4);
|
goto unregister;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
aha1542 = shost_priv(shpnt);
|
|
||||||
if (!aha1542_test_port(bases[indx], shpnt))
|
|
||||||
goto unregister;
|
|
||||||
|
|
||||||
base_io = bases[indx];
|
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;
|
||||||
|
|
||||||
aha1542_set_bus_times(indx);
|
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");
|
||||||
|
|
||||||
if (aha1542_query(base_io, &trans))
|
setup_mailboxes(base_io, shpnt);
|
||||||
goto unregister;
|
|
||||||
|
|
||||||
if (aha1542_getconfig(base_io, &irq_level, &dma_chan, &scsi_id) == -1)
|
if (request_irq(shpnt->irq, do_aha1542_intr_handle, 0,
|
||||||
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");
|
|
||||||
|
|
||||||
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,
|
|
||||||
"aha1542", shpnt)) {
|
"aha1542", shpnt)) {
|
||||||
printk(KERN_ERR "Unable to allocate IRQ for adaptec controller.\n");
|
printk(KERN_ERR "Unable to allocate IRQ for adaptec controller.\n");
|
||||||
spin_unlock_irqrestore(&aha1542_lock, flags);
|
goto unregister;
|
||||||
goto unregister;
|
}
|
||||||
}
|
if (shpnt->dma_channel != 0xFF) {
|
||||||
if (dma_chan != 0xFF) {
|
if (request_dma(shpnt->dma_channel, "aha1542")) {
|
||||||
if (request_dma(dma_chan, "aha1542")) {
|
printk(KERN_ERR "Unable to allocate DMA channel for Adaptec.\n");
|
||||||
printk(KERN_ERR "Unable to allocate DMA channel for Adaptec.\n");
|
goto free_irq;
|
||||||
free_irq(irq_level, shpnt);
|
}
|
||||||
spin_unlock_irqrestore(&aha1542_lock, flags);
|
if (shpnt->dma_channel == 0 || shpnt->dma_channel >= 5) {
|
||||||
goto unregister;
|
set_dma_mode(shpnt->dma_channel, DMA_MODE_CASCADE);
|
||||||
}
|
enable_dma(shpnt->dma_channel);
|
||||||
if (dma_chan == 0 || dma_chan >= 5) {
|
}
|
||||||
set_dma_mode(dma_chan, DMA_MODE_CASCADE);
|
}
|
||||||
enable_dma(dma_chan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shpnt->this_id = scsi_id;
|
shpnt->unique_id = base_io;
|
||||||
shpnt->unique_id = base_io;
|
shpnt->io_port = base_io;
|
||||||
shpnt->io_port = base_io;
|
shpnt->n_io_port = AHA1542_REGION_SIZE;
|
||||||
shpnt->n_io_port = 4; /* Number of bytes of I/O space used */
|
aha1542->aha1542_last_mbi_used = 2 * AHA1542_MAILBOXES - 1;
|
||||||
shpnt->dma_channel = dma_chan;
|
aha1542->aha1542_last_mbo_used = AHA1542_MAILBOXES - 1;
|
||||||
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);
|
|
||||||
|
|
||||||
if (scsi_add_host(shpnt, pdev)) {
|
if (scsi_add_host(shpnt, pdev))
|
||||||
if (shpnt->dma_channel != 0xff)
|
goto free_dma;
|
||||||
free_dma(shpnt->dma_channel);
|
|
||||||
free_irq(irq_level, shpnt);
|
|
||||||
goto unregister;
|
|
||||||
}
|
|
||||||
|
|
||||||
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:
|
unregister:
|
||||||
release_region(bases[indx], 4);
|
scsi_host_put(shpnt);
|
||||||
scsi_host_put(shpnt);
|
release:
|
||||||
return NULL;
|
release_region(base_io, AHA1542_REGION_SIZE);
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1001,10 +978,10 @@ static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct
|
||||||
static int aha1542_release(struct Scsi_Host *shost)
|
static int aha1542_release(struct Scsi_Host *shost)
|
||||||
{
|
{
|
||||||
scsi_remove_host(shost);
|
scsi_remove_host(shost);
|
||||||
if (shost->irq)
|
|
||||||
free_irq(shost->irq, shost);
|
|
||||||
if (shost->dma_channel != 0xff)
|
if (shost->dma_channel != 0xff)
|
||||||
free_dma(shost->dma_channel);
|
free_dma(shost->dma_channel);
|
||||||
|
if (shost->irq)
|
||||||
|
free_irq(shost->irq, shost);
|
||||||
if (shost->io_port && shost->n_io_port)
|
if (shost->io_port && shost->n_io_port)
|
||||||
release_region(shost->io_port, shost->n_io_port);
|
release_region(shost->io_port, shost->n_io_port);
|
||||||
scsi_host_put(shost);
|
scsi_host_put(shost);
|
||||||
|
|
|
@ -126,6 +126,7 @@ struct ccb { /* Command Control Block 5.3 */
|
||||||
/* REQUEST SENSE */
|
/* REQUEST SENSE */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define AHA1542_REGION_SIZE 4
|
||||||
#define AHA1542_MAILBOXES 8
|
#define AHA1542_MAILBOXES 8
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue