aha1542: Various improvements
cover aha1542: Various improvements
This (incomplete) patch series updates aha1542 driver to not use deprecated initialization, removes dead code, ugly macros and simplifies the code. It's probably not checkpatch-clean yet.
aha1542.c | 984 ++++++++++++++++++++++---------------------------------------- aha1542.h | 99 ++---- 2 files changed, 402 insertions(+), 681 deletions(-)
Signature · 1 line
Ondrej Zary
PATCH 1/13 aha1542: Stop using scsi_module.c
Convert aha1542 to use scsi_add_host instead of scsi_module.c Use pnp_driver and isa_driver to manage cards.
--- drivers/scsi/aha1542.c | 300 +++++++++++++++++++++++++++--------------------- drivers/scsi/aha1542.h | 2 +- 2 files changed, 169 insertions(+), 133 deletions(-)
drivers/scsi/aha1542.c +168 -132
@@ -35,7 +35,8 @@#include <linux/proc_fs.h> #include <linux/init.h> #include <linux/spinlock.h> -#include <linux/isapnp.h> +#include <linux/isa.h> +#include <linux/pnp.h> #include <linux/blkdev.h> #include <linux/slab.h>
@@ -71,7 +72,7 @@/* Boards 3,4 slots are reserved for ISAPnP scans */ -static unsigned int bases[MAXBOARDS ]__initdata = {0x330 ,0x334 ,0 ,0 }; +static unsigned int bases[MAXBOARDS ] = {0x330 ,0x334 ,0 ,0 };/* set by aha1542_setup according to the command line; they also may be marked __initdata, but require zero initializers then */
@@ -79,7 +80,7 @@ static unsigned int bases[MAXBOARDS] __initdata = {0x330, 0x334, 0, 0};static int setup_called[MAXBOARDS ];static int setup_buson[MAXBOARDS ];static int setup_busoff[MAXBOARDS ]; -static int setup_dmaspeed[MAXBOARDS ]__initdata = {-1 ,-1 ,-1 ,-1 }; +static int setup_dmaspeed[MAXBOARDS ] = {-1 ,-1 ,-1 ,-1 };/* * LILO/Module params: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]
@@ -103,18 +104,6 @@ static bool isapnp = 0;static int aha1542[] = {0x330 ,11 ,4 ,-1 };module_param_array (aha1542, int,NULL ,0 );module_param (isapnp, bool,0 ); - -static struct isapnp_device_id id_table[]__initdata = { - { -ISAPNP_ANY_ID ,ISAPNP_ANY_ID , -ISAPNP_VENDOR ('A' ,'D' ,'P' ),ISAPNP_FUNCTION (0x1542 ), -0 - }, - {0 } -}; - -MODULE_DEVICE_TABLE (isapnp, id_table); -#else static int isapnp =1 ;#endif
@@ -221,7 +210,7 @@ fail:/* Only used at boot time, so we do not need to worry about latency as much here */ -static int __init aha1542_in (unsigned int base,unchar * cmdp,int len) +static int aha1542_in (unsigned int base,unchar *cmdp,int len) {unsigned long flags;
@@ -242,7 +231,7 @@ fail:/* Similar to aha1542_in, except that we wait a very short period of time. We use this if we know the board is alive and awake, but we are not sure if the board will respond to the command we are about to send or not */ -static int __init aha1542_in1 (unsigned int base,unchar * cmdp,int len) +static int aha1542_in1 (unsigned int base,unchar *cmdp,int len) {unsigned long flags;
@@ -314,7 +303,7 @@ static int makecode(unsigned hosterr, unsigned scsierr)return scsierr | (hosterr <<16 ); } -static int __init aha1542_test_port (int bse,struct Scsi_Host *shpnt) +static int aha1542_test_port (int bse,struct Scsi_Host *shpnt) {unchar inquiry_cmd[] = {CMD_INQUIRY };unchar inquiry_result[4 ];
@@ -744,7 +733,7 @@ fail:aha1542_intr_reset (bse); } -static int __init 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 char *irq_level,unsigned char *dma_chan,unsigned char *scsi_id) {unchar inquiry_cmd[] = {CMD_RETCONF };unchar inquiry_result[3 ];
@@ -813,7 +802,7 @@ fail:/* This function should only be called for 1542C boards - we can detect the special firmware settings and unlock the board */ -static int __init aha1542_mbenable (int base) +static int aha1542_mbenable (int base) {static unchar mbenable_cmd[3 ];static unchar mbenable_result[2 ];
@@ -848,7 +837,7 @@ fail: }/* Query the board to find out if it is a 1542 or a 1740, or whatever. */ -static int __init aha1542_query (int base_io,int *transl) +static int aha1542_query (int base_io,int *transl) {unchar inquiry_cmd[] = {CMD_INQUIRY };unchar inquiry_result[4 ];
@@ -963,7 +952,7 @@ __setup("aha1542=",do_setup);#endif /* return non-zero on detection */ -static int __init aha1542_detect (struct scsi_host_template * tpnt) +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;
@@ -972,87 +961,18 @@ static int __init aha1542_detect(struct scsi_host_template * tpnt)unsigned int base_io;int trans;struct Scsi_Host *shpnt =NULL ; -int count =0 ; -int indx;DEB (printk ("aha1542_detect: \n" )); tpnt->proc_name ="aha1542" ; -#ifdef MODULE - bases[0 ] = aha1542[0 ]; - setup_buson[0 ] = aha1542[1 ]; - setup_busoff[0 ] = aha1542[2 ]; - { -int atbt =-1 ; -switch (aha1542[3 ]) { -case 5 : - atbt =0x00 ; -break ; -case 6 : - atbt =0x04 ; -break ; -case 7 : - atbt =0x01 ; -break ; -case 8 : - atbt =0x02 ; -break ; -case 10 : - atbt =0x03 ; -break ; - }; - setup_dmaspeed[0 ] = atbt; - } -#endif - -/* -* Hunt for ISA Plug'n'Pray Adaptecs (AHA1535) -*/ - -if (isapnp) - { -struct pnp_dev *pdev =NULL ; -for (indx =0 ; indx <ARRAY_SIZE (bases); indx++) { -if (bases[indx]) -continue ; - pdev =pnp_find_dev (NULL ,ISAPNP_VENDOR ('A' ,'D' ,'P' ), -ISAPNP_FUNCTION (0x1542 ), pdev); -if (pdev==NULL ) -break ; -/* -* Activate the PnP card -*/ - -if (pnp_device_attach (pdev)<0 ) -continue ; - -if (pnp_activate_dev (pdev)<0 ) { -pnp_device_detach (pdev); -continue ; - } - -if (!pnp_port_valid (pdev,0 )) { -pnp_device_detach (pdev); -continue ; - } - - bases[indx] =pnp_port_start (pdev,0 ); - -/* The card can be queried for its DMA, we have -the DMA set up that is enough */ - -printk (KERN_INFO "ISAPnP found an AHA1535 at I/O 0x%03X\n" , bases[indx]); - } - } -for (indx =0 ; indx <ARRAY_SIZE (bases); indx++)if (bases[indx] !=0 &&request_region (bases[indx],4 ,"aha1542" )) { - shpnt =scsi_register (tpnt, + shpnt =scsi_host_alloc (tpnt,sizeof (struct aha1542_hostdata ));if (shpnt==NULL ) {release_region (bases[indx],4 ); -continue ; +return NULL ; }if (!aha1542_test_port (bases[indx], shpnt)) goto unregister;
@@ -1137,60 +1057,37 @@ fail:HOSTDATA (shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES -1 );memset (HOSTDATA (shpnt)->SCint,0 ,sizeof (HOSTDATA (shpnt)->SCint));spin_unlock_irqrestore (&aha1542_lock, flags); -#if 0 -DEB (printk (" *** READ CAPACITY ***\n" )); - { -unchar buf[8 ]; -static unchar cmd[] = {READ_CAPACITY ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; -int i; - -for (i =0 ; i <sizeof (buf); ++i) - buf[i] =0x87 ; -for (i =0 ; i <2 ; ++i) -if (!aha1542_command (i, cmd, buf,sizeof (buf))) { -printk (KERN_DEBUG "aha_detect: LU %d sector_size %d device_size %d\n" , - i,xscsi2int (buf +4 ),xscsi2int (buf)); - } +if (scsi_add_host (shpnt, pdev)) { +if (shpnt->dma_channel !=0xff ) +free_dma (shpnt->dma_channel); +free_irq (irq_level, shpnt); + goto unregister; } -DEB (printk (" *** NOW RUNNING MY OWN TEST *** \n" )); +scsi_scan_host (shpnt); -for (i =0 ; i <4 ; ++i) { -unsigned char cmd[10 ]; - static buffer[512]; - - cmd[0 ] =READ_10 ; - cmd[1 ] =0 ; -xany2scsi (cmd +2 , i); - cmd[6 ] =0 ; - cmd[7 ] =0 ; - cmd[8 ] =1 ; - cmd[9 ] =0 ; -aha1542_command (0 , cmd, buffer,512 ); - } -#endif - count++; -continue ; +return shpnt; unregister:release_region (bases[indx],4 ); -scsi_unregister (shpnt); -continue ; +scsi_host_put (shpnt); +return NULL ; }; -return count; +return NULL ; }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->io_port && shost->n_io_port)release_region (shost->io_port, shost->n_io_port); -scsi_unregister (shost); +scsi_host_put (shost);return 0 ; }
@@ -1661,12 +1558,10 @@ static int aha1542_biosparam(struct scsi_device *sdev, }MODULE_LICENSE ("GPL" ); -static struct scsi_host_template driver_template = { + .module =THIS_MODULE , .proc_name ="aha1542" , .name ="Adaptec 1542" , - .detect = aha1542_detect, - .release = aha1542_release, .queuecommand = aha1542_queuecommand, .eh_device_reset_handler= aha1542_dev_reset, .eh_bus_reset_handler = aha1542_bus_reset,
@@ -1679,4 +1574,145 @@ static struct scsi_host_template driver_template = { .unchecked_isa_dma = 1, .use_clustering = ENABLE_CLUSTERING, }; -#include "scsi_module.c" + +static int aha1542_isa_match (struct device *pdev,unsigned int ndev) +{ +struct Scsi_Host *sh =aha1542_hw_init (&driver_template, pdev, ndev); + +if (!sh) +return 0 ; + +dev_set_drvdata (pdev, sh); +return 1 ; +} + +static int aha1542_isa_remove (struct device *pdev, +unsigned int ndev) +{ +aha1542_release (dev_get_drvdata (pdev)); +dev_set_drvdata (pdev,NULL ); +return 0 ; +} + +static struct isa_driver aha1542_isa_driver = { + .match = aha1542_isa_match, + .remove = aha1542_isa_remove, + .driver = { + .name ="aha1542" + }, +}; +static int isa_registered; + +#ifdef CONFIG_PNP +static struct pnp_device_id aha1542_pnp_ids[] = { + { .id ="ADP1542" }, + { .id ="" } +}; +MODULE_DEVICE_TABLE (pnp, aha1542_pnp_ids); + +static int aha1542_pnp_probe (struct pnp_dev *pdev,const struct pnp_device_id *id) +{ +int indx; +struct Scsi_Host *sh; + +for (indx =0 ; indx <ARRAY_SIZE (bases); indx++) { +if (bases[indx]) +continue ; + +if (pnp_activate_dev (pdev) <0 ) +continue ; + + bases[indx] =pnp_port_start (pdev,0 ); + +/* The card can be queried for its DMA, we have +the DMA set up that is enough */ + +printk (KERN_INFO "ISAPnP found an AHA1535 at I/O 0x%03X\n" , bases[indx]); + } + + sh =aha1542_hw_init (&driver_template, &pdev->dev, indx); +if (!sh) +return -ENODEV ; + +pnp_set_drvdata (pdev, sh); +return 0 ; +} + +static void aha1542_pnp_remove (struct pnp_dev *pdev) +{ +aha1542_release (pnp_get_drvdata (pdev)); +pnp_set_drvdata (pdev,NULL ); +} + +static struct pnp_driver aha1542_pnp_driver = { + .name ="aha1542" , + .id_table = aha1542_pnp_ids, + .probe = aha1542_pnp_probe, + .remove = aha1542_pnp_remove, +}; +static int pnp_registered; +#endif /* CONFIG_PNP */ + +static int __init aha1542_init (void ) +{ +int ret =0 ; +#ifdef MODULE +int atbt =-1 ; + + bases[0 ] = aha1542[0 ]; + setup_buson[0 ] = aha1542[1 ]; + setup_busoff[0 ] = aha1542[2 ]; + +switch (aha1542[3 ]) { +case 5 : + atbt =0x00 ; +break ; +case 6 : + atbt =0x04 ; +break ; +case 7 : + atbt =0x01 ; +break ; +case 8 : + atbt =0x02 ; +break ; +case 10 : + atbt =0x03 ; +break ; + }; + setup_dmaspeed[0 ] = atbt; +#endif + +#ifdef CONFIG_PNP +if (isapnp) { + ret =pnp_register_driver (&aha1542_pnp_driver); +if (!ret) + pnp_registered =1 ; + } +#endif + ret =isa_register_driver (&aha1542_isa_driver,MAXBOARDS ); +if (!ret) + isa_registered =1 ; + +#ifdef CONFIG_PNP +if (pnp_registered) + ret =0 ; +#endif +if (isa_registered) + ret =0 ; + +return ret; +} + +static void __exit aha1542_exit(void) +{ +#ifdef CONFIG_PNP +if (pnp_registered) +pnp_unregister_driver (&aha1542_pnp_driver); +#endif +if (isa_registered) +isa_unregister_driver (&aha1542_isa_driver); +} + +module_init (aha1542_init); +module_exit (aha1542_exit);
drivers/scsi/aha1542.h +1 -1
@@ -131,7 +131,7 @@ struct ccb { /* Command Control Block 5.3 *//* REQUEST SENSE */ }; -static int aha1542_detect (struct scsi_host_template *); +static struct Scsi_Host *aha1542_hw_init (struct scsi_host_template *tpnt,struct device *pdev,int indx);static int aha1542_queuecommand (struct Scsi_Host *,struct scsi_cmnd *);static int aha1542_bus_reset (Scsi_Cmnd * SCpnt);static int aha1542_dev_reset (Scsi_Cmnd * SCpnt);
Signature · 1 line
Ondrej Zary
PATCH 2/13 aha1542: remove dead code
In reply to Ondrej ZaryRemove dead code.
--- drivers/scsi/aha1542.c | 243 +----------------------------------------------- drivers/scsi/aha1542.h | 6 -- 2 files changed, 1 insertion(+), 248 deletions(-)
drivers/scsi/aha1542.c +1 -242
@@ -570,13 +570,6 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *if (*cmd ==REQUEST_SENSE ) {/* Don't do the command - we have the sense data already */ -#if 0 -/* scsi_request_sense() provides a buffer of size 256, -so there is no reason to expect equality */ -if (bufflen !=SCSI_SENSE_BUFFERSIZE ) -printk (KERN_CRIT "aha1542: Wrong buffer length supplied " -"for request sense (%d)\n" , bufflen); -#endif SCpnt->result =0 ;done (SCpnt);return 0 ;
@@ -1095,24 +1088,14 @@ static int aha1542_restart(struct Scsi_Host *shost) {int i;int count =0 ; -#if 0 -unchar ahacmd =CMD_START_SCSI ; -#endif for (i =0 ; i <AHA1542_MAILBOXES ; i++)if (HOSTDATA (shost)->SCint[i] && !(HOSTDATA (shost)->SCint[i]->device->soft_reset)) { -#if 0 -HOSTDATA (shost)->mb[i].status =1 ;/* Indicate ready to restart... */ -#endif count++; }printk (KERN_DEBUG "Potential to restart %d stalled commands...\n" , count); -#if 0 -/* start scsi command */ -if (count) -aha1542_out (shost->io_port, &ahacmd,1 ); -#endif +return 0 ; }
@@ -1177,39 +1160,6 @@ static int aha1542_dev_reset(Scsi_Cmnd * SCpnt) "Trying device reset for target\n");return SUCCESS ; - - -#ifdef ERIC_neverdef -/* -* With the 1542 we apparently never get an interrupt to -* acknowledge a device reset being sent. Then again, Leonard -* says we are doing this wrong in the first place... -* -* Take a wait and see attitude. If we get spurious interrupts, -* then the device reset is doing something sane and useful, and -* we will wait for the interrupt to post completion. -*/ -printk (KERN_WARNING "Sent BUS DEVICE RESET to target %d\n" , SCpnt->target); - -/* -* Free the command block for all commands running on this -* target... -*/ -for (i =0 ; i <AHA1542_MAILBOXES ; i++) { -if (HOSTDATA (SCpnt->host)->SCint[i] && -HOSTDATA (SCpnt->host)->SCint[i]->target == SCpnt->target) { -Scsi_Cmnd *SCtmp; - SCtmp =HOSTDATA (SCpnt->host)->SCint[i]; -kfree (SCtmp->host_scribble); - SCtmp->host_scribble =NULL ; -HOSTDATA (SCpnt->host)->SCint[i] =NULL ; -HOSTDATA (SCpnt->host)->mb[i].status =0 ; - } - } -return SUCCESS ; - -return FAILED ; -#endif /* ERIC_neverdef */ }static int aha1542_bus_reset (Scsi_Cmnd * SCpnt)
@@ -1344,197 +1294,6 @@ fail:return FAILED ; } -#if 0 -/* -* These are the old error handling routines. They are only temporarily -* here while we play with the new error handling code. -*/ -static int aha1542_old_abort (Scsi_Cmnd * SCpnt) -{ -#if 0 -unchar ahacmd =CMD_START_SCSI ; -unsigned long flags; -struct mailbox *mb; -int mbi, mbo, i; - -printk (KERN_DEBUG "In aha1542_abort: %x %x\n" , -inb (STATUS (SCpnt->host->io_port)), -inb (INTRFLAGS (SCpnt->host->io_port))); - -spin_lock_irqsave (&aha1542_lock, flags); - mb =HOSTDATA (SCpnt->host)->mb; - mbi =HOSTDATA (SCpnt->host)->aha1542_last_mbi_used +1 ; -if (mbi >=2 *AHA1542_MAILBOXES ) - mbi =AHA1542_MAILBOXES ; - -do { -if (mb[mbi].status !=0 ) -break ; - mbi++; -if (mbi >=2 *AHA1542_MAILBOXES ) - mbi =AHA1542_MAILBOXES ; - }while (mbi !=HOSTDATA (SCpnt->host)->aha1542_last_mbi_used); -spin_unlock_irqrestore (&aha1542_lock, flags); - -if (mb[mbi].status) { -printk (KERN_ERR "Lost interrupt discovered on irq %d - attempting to recover\n" , - SCpnt->host->irq); -aha1542_intr_handle (SCpnt->host,NULL ); -return 0 ; - } -/* OK, no lost interrupt. Try looking to see how many pending commands -we think we have. */ - -for (i =0 ; i <AHA1542_MAILBOXES ; i++) -if (HOSTDATA (SCpnt->host)->SCint[i]) { -if (HOSTDATA (SCpnt->host)->SCint[i] == SCpnt) { -printk (KERN_ERR "Timed out command pending for %s\n" , - SCpnt->request->rq_disk ? - SCpnt->request->rq_disk->disk_name :"?" - ); -if (HOSTDATA (SCpnt->host)->mb[i].status) { -printk (KERN_ERR "OGMB still full - restarting\n" ); -aha1542_out (SCpnt->host->io_port, &ahacmd,1 ); - }; - }else -printk (KERN_ERR "Other pending command %s\n" , - SCpnt->request->rq_disk ? - SCpnt->request->rq_disk->disk_name :"?" - ); - } -#endif - -DEB (printk ("aha1542_abort\n" )); -#if 0 -spin_lock_irqsave (&aha1542_lock, flags); -for (mbo =0 ; mbo <AHA1542_MAILBOXES ; mbo++) { -if (SCpnt ==HOSTDATA (SCpnt->host)->SCint[mbo]) { - mb[mbo].status =2 ;/* Abort command */ -aha1542_out (SCpnt->host->io_port, &ahacmd,1 );/* start scsi command */ -spin_unlock_irqrestore (&aha1542_lock, flags); -break ; - } - } -if (AHA1542_MAILBOXES == mbo) -spin_unlock_irqrestore (&aha1542_lock, flags); -#endif -return SCSI_ABORT_SNOOZE ; -} - -/* We do not implement a reset function here, but the upper level code -assumes that it will get some kind of response for the command in -SCpnt. We must oblige, or the command will hang the scsi system. -For a first go, we assume that the 1542 notifies us with all of the -pending commands (it does implement soft reset, after all). */ - -static int aha1542_old_reset (Scsi_Cmnd * SCpnt,unsigned int reset_flags) -{ -unchar ahacmd =CMD_START_SCSI ; -int i; - -/* -* See if a bus reset was suggested. -*/ -if (reset_flags &SCSI_RESET_SUGGEST_BUS_RESET ) { -/* -* This does a scsi reset for all devices on the bus. -* In principle, we could also reset the 1542 - should -* we do this? Try this first, and we can add that later -* if it turns out to be useful. -*/ -outb (HRST |SCRST ,CONTROL (SCpnt->host->io_port)); - -/* -* Wait for the thing to settle down a bit. Unfortunately -* this is going to basically lock up the machine while we -* wait for this to complete. To be 100% correct, we need to -* check for timeout, and if we are doing something like this -* we are pretty desperate anyways. -*/ -WAIT (STATUS (SCpnt->host->io_port), -STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ); - -/* -* We need to do this too before the 1542 can interact with -* us again. -*/ -setup_mailboxes (SCpnt->host->io_port, SCpnt->host); - -/* -* Now try to pick up the pieces. Restart all commands -* that are currently active on the bus, and reset all of -* the datastructures. We have some time to kill while -* things settle down, so print a nice message. -*/ -printk (KERN_WARNING "Sent BUS RESET to scsi host %d\n" , SCpnt->host->host_no); - -for (i =0 ; i <AHA1542_MAILBOXES ; i++) -if (HOSTDATA (SCpnt->host)->SCint[i] !=NULL ) { -Scsi_Cmnd *SCtmp; - SCtmp =HOSTDATA (SCpnt->host)->SCint[i]; - SCtmp->result =DID_RESET <<16 ; -kfree (SCtmp->host_scribble); - SCtmp->host_scribble =NULL ; -printk (KERN_WARNING "Sending DID_RESET for target %d\n" , SCpnt->target); - SCtmp->scsi_done (SCpnt); - -HOSTDATA (SCpnt->host)->SCint[i] =NULL ; -HOSTDATA (SCpnt->host)->mb[i].status =0 ; - } -/* -* Now tell the mid-level code what we did here. Since -* we have restarted all of the outstanding commands, -* then report SUCCESS. -*/ -return (SCSI_RESET_SUCCESS |SCSI_RESET_BUS_RESET ); -fail: -printk (KERN_CRIT "aha1542.c: Unable to perform hard reset.\n" ); -printk (KERN_CRIT "Power cycle machine to reset\n" ); -return (SCSI_RESET_ERROR |SCSI_RESET_BUS_RESET ); - - - }else { -/* This does a selective reset of just the one device */ -/* First locate the ccb for this command */ -for (i =0 ; i <AHA1542_MAILBOXES ; i++) -if (HOSTDATA (SCpnt->host)->SCint[i] == SCpnt) { -HOSTDATA (SCpnt->host)->ccb[i].op =0x81 ;/* BUS DEVICE RESET */ -/* Now tell the 1542 to flush all pending commands for this target */ -aha1542_out (SCpnt->host->io_port, &ahacmd,1 ); - -/* Here is the tricky part. What to do next. Do we get an interrupt -for the commands that we aborted with the specified target, or -do we generate this on our own? Try it without first and see -what happens */ -printk (KERN_WARNING "Sent BUS DEVICE RESET to target %d\n" , SCpnt->target); - -/* If the first does not work, then try the second. I think the -first option is more likely to be correct. Free the command -block for all commands running on this target... */ -for (i =0 ; i <AHA1542_MAILBOXES ; i++) -if (HOSTDATA (SCpnt->host)->SCint[i] && -HOSTDATA (SCpnt->host)->SCint[i]->target == SCpnt->target) { -Scsi_Cmnd *SCtmp; - SCtmp =HOSTDATA (SCpnt->host)->SCint[i]; - SCtmp->result =DID_RESET <<16 ; -kfree (SCtmp->host_scribble); - SCtmp->host_scribble =NULL ; -printk (KERN_WARNING "Sending DID_RESET for target %d\n" , SCpnt->target); - SCtmp->scsi_done (SCpnt); - -HOSTDATA (SCpnt->host)->SCint[i] =NULL ; -HOSTDATA (SCpnt->host)->mb[i].status =0 ; - } -return SCSI_RESET_SUCCESS ; - } - } -/* No active command at this time, so this means that each time we got -some kind of response the last time through. Tell the mid-level code -to request sense information in order to decide what to do next. */ -return SCSI_RESET_PUNT ; -} -#endif /* end of big comment block around old_abort + old_reset */ -static int aha1542_biosparam (struct scsi_device *sdev,struct block_device *bdev,sector_t capacity,int *ip) {
drivers/scsi/aha1542.h +0 -6
@@ -100,12 +100,6 @@ static inline void any2scsi(u8 *p, u32 v)#define scsi2int (up) ( (((long)*(up)) << 16) + (((long)(up)[1]) << 8) + ((long)(up)[2]) ) -#define xany2scsi (up, p) \ -(up)[0] = ((long)(p)) >> 24; \ -(up)[1] = ((long)(p)) >> 16; \ -(up)[2] = ((long)(p)) >> 8; \ -(up)[3] = ((long)(p)); -#define xscsi2int (up) ( (((long)(up)[0]) << 24) + (((long)(up)[1]) << 16) \ + (((long)(up)[2]) << 8) + ((long)(up)[3]) )
Signature · 1 line
Ondrej Zary
PATCH 3/13 aha1542: Remove SCSI_BUF_PA, SCSI_SG_PA, AHA1542_SCATTER and AHA1542_CMDLUN
In reply to Ondrej ZaryRemove SCSI_BUF_PA, SCSI_SG_PA, AHA1542_SCATTER and AHA1542_CMDLUN macros
--- drivers/scsi/aha1542.c | 23 ++++++++++------------- drivers/scsi/aha1542.h | 2 -- 2 files changed, 10 insertions(+), 15 deletions(-)
drivers/scsi/aha1542.c +10 -13
@@ -46,10 +46,6 @@#include "scsi.h" #include <scsi/scsi_host.h> #include "aha1542.h" - -#define SCSI_BUF_PA (address) isa_virt_to_bus(address) -#define SCSI_SG_PA (sgent) (isa_page_to_bus(sg_page((sgent))) + (sgent)->offset) -#include <linux/stat.h> #ifdef DEBUG
@@ -463,7 +459,7 @@ static void aha1542_intr_handle(struct Scsi_Host *shost)return ; }; - mbo = (scsi2int (mb[mbi].ccbptr) - (SCSI_BUF_PA (&ccb[0 ]))) /sizeof (struct ccb ); + mbo = (scsi2int (mb[mbi].ccbptr) - (isa_virt_to_bus (&ccb[0 ]))) /sizeof (struct ccb ); mbistatus = mb[mbi].status; mb[mbi].status =0 ;HOSTDATA (shost)->aha1542_last_mbi_used = mbi;
@@ -622,7 +618,7 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *printk (KERN_DEBUG "Sending command (%d %x)..." , mbo, done);#endif -any2scsi (mb[mbo].ccbptr,SCSI_BUF_PA (&ccb[mbo]));/* This gets trashed for some reason */ +any2scsi (mb[mbo].ccbptr,isa_virt_to_bus (&ccb[mbo]));/* This gets trashed for some reason */ memset (&ccb[mbo],0 ,sizeof (struct ccb ));
@@ -653,11 +649,12 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *return SCSI_MLQUEUE_HOST_BUSY ; }scsi_for_each_sg (SCpnt, sg, sg_count, i) { -any2scsi (cptr[i].dataptr,SCSI_SG_PA (sg)); +any2scsi (cptr[i].dataptr,isa_page_to_bus (sg_page (sg)) + + sg->offset);any2scsi (cptr[i].datalen, sg->length); };any2scsi (ccb[mbo].datalen, sg_count *sizeof (struct chain )); -any2scsi (ccb[mbo].dataptr,SCSI_BUF_PA (cptr)); +any2scsi (ccb[mbo].dataptr,isa_virt_to_bus (cptr));#ifdef DEBUG printk ("cptr %x: " , cptr); ptr = (unsigned char *) cptr;
@@ -713,10 +710,10 @@ static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)for (i =0 ; i <AHA1542_MAILBOXES ; i++) { mb[i].status = mb[AHA1542_MAILBOXES + i].status =0 ; -any2scsi (mb[i].ccbptr,SCSI_BUF_PA (&ccb[i])); +any2scsi (mb[i].ccbptr,isa_virt_to_bus (&ccb[i])); };aha1542_intr_reset (bse);/* reset interrupts, so they don't block */ -any2scsi ((cmd +2 ),SCSI_BUF_PA (mb)); +any2scsi ((cmd +2 ),isa_virt_to_bus (mb));aha1542_out (bse, cmd,5 );WAIT (INTRFLAGS (bse),INTRMASK ,HACC ,0 );while (0 ) {
@@ -1139,7 +1136,7 @@ static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)HOSTDATA (SCpnt->device->host)->aha1542_last_mbo_used = mbo;spin_unlock_irqrestore (&aha1542_lock, flags); -any2scsi (mb[mbo].ccbptr,SCSI_BUF_PA (&ccb[mbo]));/* This gets trashed for some reason */ +any2scsi (mb[mbo].ccbptr,isa_virt_to_bus (&ccb[mbo]));/* This gets trashed for some reason */ memset (&ccb[mbo],0 ,sizeof (struct ccb ));
@@ -1328,8 +1325,8 @@ static struct scsi_host_template driver_template = { .bios_param = aha1542_biosparam, .can_queue = AHA1542_MAILBOXES, .this_id = 7, - .sg_tablesize = AHA1542_SCATTER, - .cmd_per_lun = AHA1542_CMDLUN, + .sg_tablesize = 16, + .cmd_per_lun = 1, .unchecked_isa_dma = 1, .use_clustering = ENABLE_CLUSTERING, };
drivers/scsi/aha1542.h +0 -2
@@ -138,7 +138,5 @@ static int aha1542_biosparam(struct scsi_device *, struct block_device *, sector_t, int *);#define AHA1542_MAILBOXES 8 -#define AHA1542_SCATTER 16 -#define AHA1542_CMDLUN 1#endif
Signature · 1 line
Ondrej Zary
PATCH 4/13 aha1542: Remove HOSTDATA macro
In reply to Ondrej ZaryRemove HOSTDATA macro and use shost_priv instead
--- drivers/scsi/aha1542.c | 114 +++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 59 deletions(-)
drivers/scsi/aha1542.c +55 -59
@@ -118,8 +118,6 @@ struct aha1542_hostdata {struct ccb ccb[AHA1542_MAILBOXES ]; }; -#define HOSTDATA (host) ((struct aha1542_hostdata *) &host->hostdata) -static DEFINE_SPINLOCK (aha1542_lock);
@@ -382,6 +380,7 @@ static irqreturn_t do_aha1542_intr_handle(int dummy, void *dev_id)/* A "high" level interrupt handler */ static void aha1542_intr_handle (struct Scsi_Host *shost) { +struct aha1542_hostdata *aha1542 =shost_priv (shost);void (*my_done) (Scsi_Cmnd *) =NULL ;int errstatus, mbi, mbo, mbistatus;int number_serviced;
@@ -389,11 +388,8 @@ static void aha1542_intr_handle(struct Scsi_Host *shost)Scsi_Cmnd *SCtmp;int flag;int needs_restart; -struct mailbox *mb; -struct ccb *ccb; - - mb =HOSTDATA (shost)->mb; - ccb =HOSTDATA (shost)->ccb; +struct mailbox *mb = aha1542->mb; +struct ccb *ccb = aha1542->ccb;#ifdef DEBUG {
@@ -435,7 +431,7 @@ static void aha1542_intr_handle(struct Scsi_Host *shost)aha1542_intr_reset (shost->io_port);spin_lock_irqsave (&aha1542_lock, flags); - mbi =HOSTDATA (shost)->aha1542_last_mbi_used +1 ; + mbi = aha1542->aha1542_last_mbi_used +1 ;if (mbi >=2 *AHA1542_MAILBOXES ) mbi =AHA1542_MAILBOXES ;
@@ -445,7 +441,7 @@ static void aha1542_intr_handle(struct Scsi_Host *shost) mbi++;if (mbi >=2 *AHA1542_MAILBOXES ) mbi =AHA1542_MAILBOXES ; - }while (mbi !=HOSTDATA (shost)->aha1542_last_mbi_used); + }while (mbi != aha1542->aha1542_last_mbi_used);if (mb[mbi].status ==0 ) {spin_unlock_irqrestore (&aha1542_lock, flags);
@@ -462,7 +458,7 @@ static void aha1542_intr_handle(struct Scsi_Host *shost) mbo = (scsi2int (mb[mbi].ccbptr) - (isa_virt_to_bus (&ccb[0 ]))) /sizeof (struct ccb ); mbistatus = mb[mbi].status; mb[mbi].status =0 ; -HOSTDATA (shost)->aha1542_last_mbi_used = mbi; + aha1542->aha1542_last_mbi_used = mbi;spin_unlock_irqrestore (&aha1542_lock, flags);#ifdef DEBUG
@@ -480,7 +476,7 @@ static void aha1542_intr_handle(struct Scsi_Host *shost)printk (KERN_DEBUG "...done %d %d\n" , mbo, mbi);#endif - SCtmp =HOSTDATA (shost)->SCint[mbo]; + SCtmp = aha1542->SCint[mbo];if (!SCtmp || !SCtmp->scsi_done) {printk (KERN_WARNING "aha1542_intr_handle: Unexpected interrupt\n" );
@@ -533,8 +529,8 @@ static void aha1542_intr_handle(struct Scsi_Host *shost) } DEB(if (errstatus) printk("aha1542_intr_handle: returning %6x\n", errstatus)); SCtmp->result = errstatus; -HOSTDATA (shost)->SCint[mbo] =NULL ;/* This effectively frees up the mailbox slot, as -far as queuecommand is concerned */ + aha1542->SCint[mbo] =NULL ;/* This effectively frees up the mailbox slot, as +far as queuecommand is concerned */ my_done (SCtmp); number_serviced++; };
@@ -542,6 +538,7 @@ static void aha1542_intr_handle(struct Scsi_Host *shost)static int aha1542_queuecommand_lck (Scsi_Cmnd * SCpnt,void (*done) (Scsi_Cmnd *)) { +struct aha1542_hostdata *aha1542 =shost_priv (SCpnt->device->host);unchar ahacmd =CMD_START_SCSI ;unchar direction;unchar *cmd = (unchar *) SCpnt->cmnd;
@@ -550,14 +547,11 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *unsigned long flags;int bufflen =scsi_bufflen (SCpnt);int mbo; -struct mailbox *mb; -struct ccb *ccb; +struct mailbox *mb = aha1542->mb; +struct ccb *ccb = aha1542->ccb; DEB(int i); - mb =HOSTDATA (SCpnt->device->host)->mb; - ccb =HOSTDATA (SCpnt->device->host)->ccb; - DEB(if (target > 1) { SCpnt->result = DID_TIME_OUT << 16; done(SCpnt); return 0;
@@ -593,25 +587,25 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *is how the host adapter will scan for them */ spin_lock_irqsave (&aha1542_lock, flags); - mbo =HOSTDATA (SCpnt->device->host)->aha1542_last_mbo_used +1 ; + mbo = aha1542->aha1542_last_mbo_used +1 ;if (mbo >=AHA1542_MAILBOXES ) mbo =0 ;do { -if (mb[mbo].status ==0 &&HOSTDATA (SCpnt->device->host)->SCint[mbo] ==NULL ) +if (mb[mbo].status ==0 && aha1542->SCint[mbo] ==NULL )break ; mbo++;if (mbo >=AHA1542_MAILBOXES ) mbo =0 ; - }while (mbo !=HOSTDATA (SCpnt->device->host)->aha1542_last_mbo_used); + }while (mbo != aha1542->aha1542_last_mbo_used); -if (mb[mbo].status ||HOSTDATA (SCpnt->device->host)->SCint[mbo]) +if (mb[mbo].status || aha1542->SCint[mbo])panic ("Unable to find empty mailbox for aha1542.\n" ); -HOSTDATA (SCpnt->device->host)->SCint[mbo] = SCpnt;/* This will effectively prevent someone else from -screwing with this cdb. */ + aha1542->SCint[mbo] = SCpnt;/* This will effectively prevent someone else from +screwing with this cdb. */ -HOSTDATA (SCpnt->device->host)->aha1542_last_mbo_used = mbo; + aha1542->aha1542_last_mbo_used = mbo;spin_unlock_irqrestore (&aha1542_lock, flags);#ifdef DEBUG
@@ -645,7 +639,7 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd * cptr = (struct chain *) SCpnt->host_scribble;if (cptr ==NULL ) {/* free the claimed mailbox slot */ -HOSTDATA (SCpnt->device->host)->SCint[mbo] =NULL ; + aha1542->SCint[mbo] =NULL ;return SCSI_MLQUEUE_HOST_BUSY ; }scsi_for_each_sg (SCpnt, sg, sg_count, i) {
@@ -699,15 +693,13 @@ static DEF_SCSI_QCMD(aha1542_queuecommand)/* Initialize mailboxes */ static void setup_mailboxes (int bse,struct Scsi_Host *shpnt) { +struct aha1542_hostdata *aha1542 =shost_priv (shpnt);int i; -struct mailbox *mb; -struct ccb *ccb; +struct mailbox *mb = aha1542->mb; +struct ccb *ccb = aha1542->ccb;unchar cmd[5 ] = {CMD_MBINIT ,AHA1542_MAILBOXES ,0 ,0 ,0 }; - mb =HOSTDATA (shpnt)->mb; - ccb =HOSTDATA (shpnt)->ccb; -for (i =0 ; i <AHA1542_MAILBOXES ; i++) { mb[i].status = mb[AHA1542_MAILBOXES + i].status =0 ;any2scsi (mb[i].ccbptr,isa_virt_to_bus (&ccb[i]));
@@ -951,6 +943,7 @@ static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, structunsigned int base_io;int trans;struct Scsi_Host *shpnt =NULL ; +struct aha1542_hostdata *aha1542;DEB (printk ("aha1542_detect: \n" ));
@@ -964,6 +957,7 @@ static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, structrelease_region (bases[indx],4 );return NULL ; } + aha1542 =shost_priv (shpnt);if (!aha1542_test_port (bases[indx], shpnt)) goto unregister;
@@ -1040,12 +1034,12 @@ fail: shpnt->n_io_port =4 ;/* Number of bytes of I/O space used */ shpnt->dma_channel = dma_chan; shpnt->irq = irq_level; -HOSTDATA (shpnt)->bios_translation = trans; + aha1542->bios_translation = trans;if (trans ==BIOS_TRANSLATION_25563 )printk (KERN_INFO "aha1542.c: Using extended bios translation\n" ); -HOSTDATA (shpnt)->aha1542_last_mbi_used = (2 *AHA1542_MAILBOXES -1 ); -HOSTDATA (shpnt)->aha1542_last_mbo_used = (AHA1542_MAILBOXES -1 ); -memset (HOSTDATA (shpnt)->SCint,0 ,sizeof (HOSTDATA (shpnt)->SCint)); + 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)) {
@@ -1083,12 +1077,13 @@ static int aha1542_release(struct Scsi_Host *shost)static int aha1542_restart (struct Scsi_Host *shost) { +struct aha1542_hostdata *aha1542 =shost_priv (shost);int i;int count =0 ;for (i =0 ; i <AHA1542_MAILBOXES ; i++) -if (HOSTDATA (shost)->SCint[i] && - !(HOSTDATA (shost)->SCint[i]->device->soft_reset)) { +if (aha1542->SCint[i] && + !(aha1542->SCint[i]->device->soft_reset)) { count++; }printk (KERN_DEBUG "Potential to restart %d stalled commands...\n" , count);
@@ -1102,38 +1097,36 @@ static int aha1542_restart(struct Scsi_Host *shost)*/ static int aha1542_dev_reset (Scsi_Cmnd * SCpnt) { +struct aha1542_hostdata *aha1542 =shost_priv (SCpnt->device->host);unsigned long flags; -struct mailbox *mb; +struct mailbox *mb = aha1542->mb;unchar target = SCpnt->device->id;unchar lun = SCpnt->device->lun;int mbo; -struct ccb *ccb; +struct ccb *ccb = aha1542->ccb;unchar ahacmd =CMD_START_SCSI ; - ccb =HOSTDATA (SCpnt->device->host)->ccb; - mb =HOSTDATA (SCpnt->device->host)->mb; -spin_lock_irqsave (&aha1542_lock, flags); - mbo =HOSTDATA (SCpnt->device->host)->aha1542_last_mbo_used +1 ; + mbo = aha1542->aha1542_last_mbo_used +1 ;if (mbo >=AHA1542_MAILBOXES ) mbo =0 ;do { -if (mb[mbo].status ==0 &&HOSTDATA (SCpnt->device->host)->SCint[mbo] ==NULL ) +if (mb[mbo].status ==0 && aha1542->SCint[mbo] ==NULL )break ; mbo++;if (mbo >=AHA1542_MAILBOXES ) mbo =0 ; - }while (mbo !=HOSTDATA (SCpnt->device->host)->aha1542_last_mbo_used); + }while (mbo != aha1542->aha1542_last_mbo_used); -if (mb[mbo].status ||HOSTDATA (SCpnt->device->host)->SCint[mbo]) +if (mb[mbo].status || aha1542->SCint[mbo])panic ("Unable to find empty mailbox for aha1542.\n" ); -HOSTDATA (SCpnt->device->host)->SCint[mbo] = SCpnt;/* This will effectively -prevent someone else from -screwing with this cdb. */ + aha1542->SCint[mbo] = SCpnt;/* This will effectively +prevent someone else from +screwing with this cdb. */ -HOSTDATA (SCpnt->device->host)->aha1542_last_mbo_used = mbo; + aha1542->aha1542_last_mbo_used = mbo;spin_unlock_irqrestore (&aha1542_lock, flags);any2scsi (mb[mbo].ccbptr,isa_virt_to_bus (&ccb[mbo]));/* This gets trashed for some reason */
@@ -1161,6 +1154,7 @@ static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)static int aha1542_bus_reset (Scsi_Cmnd * SCpnt) { +struct aha1542_hostdata *aha1542 =shost_priv (SCpnt->device->host);int i;/*
@@ -1194,9 +1188,9 @@ static int aha1542_bus_reset(Scsi_Cmnd * SCpnt)printk (KERN_WARNING "Sent BUS RESET to scsi host %d\n" , SCpnt->device->host->host_no);for (i =0 ; i <AHA1542_MAILBOXES ; i++) { -if (HOSTDATA (SCpnt->device->host)->SCint[i] !=NULL ) { +if (aha1542->SCint[i] !=NULL ) {Scsi_Cmnd *SCtmp; - SCtmp =HOSTDATA (SCpnt->device->host)->SCint[i]; + SCtmp = aha1542->SCint[i];if (SCtmp->device->soft_reset) {
@@ -1210,8 +1204,8 @@ static int aha1542_bus_reset(Scsi_Cmnd * SCpnt) }kfree (SCtmp->host_scribble); SCtmp->host_scribble =NULL ; -HOSTDATA (SCpnt->device->host)->SCint[i] =NULL ; -HOSTDATA (SCpnt->device->host)->mb[i].status =0 ; + aha1542->SCint[i] =NULL ; + aha1542->mb[i].status =0 ; } }
@@ -1225,6 +1219,7 @@ fail:static int aha1542_host_reset (Scsi_Cmnd * SCpnt) { +struct aha1542_hostdata *aha1542 =shost_priv (SCpnt->device->host);int i;/*
@@ -1263,9 +1258,9 @@ static int aha1542_host_reset(Scsi_Cmnd * SCpnt)printk (KERN_WARNING "Sent BUS RESET to scsi host %d\n" , SCpnt->device->host->host_no);for (i =0 ; i <AHA1542_MAILBOXES ; i++) { -if (HOSTDATA (SCpnt->device->host)->SCint[i] !=NULL ) { +if (aha1542->SCint[i] !=NULL ) {Scsi_Cmnd *SCtmp; - SCtmp =HOSTDATA (SCpnt->device->host)->SCint[i]; + SCtmp = aha1542->SCint[i];if (SCtmp->device->soft_reset) {/*
@@ -1278,8 +1273,8 @@ static int aha1542_host_reset(Scsi_Cmnd * SCpnt) }kfree (SCtmp->host_scribble); SCtmp->host_scribble =NULL ; -HOSTDATA (SCpnt->device->host)->SCint[i] =NULL ; -HOSTDATA (SCpnt->device->host)->mb[i].status =0 ; + aha1542->SCint[i] =NULL ; + aha1542->mb[i].status =0 ; } }
@@ -1294,10 +1289,11 @@ fail:static int aha1542_biosparam (struct scsi_device *sdev,struct block_device *bdev,sector_t capacity,int *ip) { +struct aha1542_hostdata *aha1542 =shost_priv (sdev->host);int translation_algorithm;int size = capacity; - translation_algorithm =HOSTDATA (sdev->host)->bios_translation; + translation_algorithm = aha1542->bios_translation;if ((size >>11 ) >1024 && translation_algorithm ==BIOS_TRANSLATION_25563 ) {/* Please verify that this is the same as what DOS returns */
Signature · 1 line
Ondrej Zary
PATCH 5/13 aha1542: Convert aha1542_intr_reset to function
In reply to Ondrej ZaryConvert aha1542_intr_reset macro to inline function
--- drivers/scsi/aha1542.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/scsi/aha1542.c +4 -1
@@ -128,7 +128,10 @@ static void setup_mailboxes(int base_io, struct Scsi_Host *shpnt);static int aha1542_restart (struct Scsi_Host *shost);static void aha1542_intr_handle (struct Scsi_Host *shost); -#define aha1542_intr_reset (base) outb(IRST, CONTROL(base)) +static inline void aha1542_intr_reset (u16 base) +{ +outb (IRST ,CONTROL (base)); +}#define WAIT (port, mask, allof, noneof) \ { register int WAITbits; \
Signature · 1 line
Ondrej Zary
PATCH 6/13 aha1542: Use u8 instead of unchar
In reply to Ondrej Zary--- drivers/scsi/aha1542.c | 50 ++++++++++++++++++++++++------------------------ drivers/scsi/aha1542.h | 42 ++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 46 deletions(-)
drivers/scsi/aha1542.c +25 -25
@@ -168,7 +168,7 @@ static void aha1542_stat(void)routine does not send something out while we are in the middle of this. Fortunately, it is only at boot time that multi-byte messages are ever sent. */ -static int aha1542_out (unsigned int base,unchar * cmdp,int len) +static int aha1542_out (unsigned int base,u8 *cmdp,int len) {unsigned long flags =0 ;int got_lock;
@@ -207,7 +207,7 @@ fail:/* Only used at boot time, so we do not need to worry about latency as much here */ -static int aha1542_in (unsigned int base,unchar *cmdp,int len) +static int aha1542_in (unsigned int base,u8 *cmdp,int len) {unsigned long flags;
@@ -228,7 +228,7 @@ fail:/* Similar to aha1542_in, except that we wait a very short period of time. We use this if we know the board is alive and awake, but we are not sure if the board will respond to the command we are about to send or not */ -static int aha1542_in1 (unsigned int base,unchar *cmdp,int len) +static int aha1542_in1 (unsigned int base,u8 *cmdp,int len) {unsigned long flags;
@@ -302,9 +302,9 @@ static int makecode(unsigned hosterr, unsigned scsierr)static int aha1542_test_port (int bse,struct Scsi_Host *shpnt) { -unchar inquiry_cmd[] = {CMD_INQUIRY }; -unchar inquiry_result[4 ]; -unchar *cmdp; +u8 inquiry_cmd[] = {CMD_INQUIRY }; +u8 inquiry_result[4 ]; +u8 *cmdp;int len;volatile int debug =0 ;
@@ -542,11 +542,11 @@ static void aha1542_intr_handle(struct Scsi_Host *shost)static int aha1542_queuecommand_lck (Scsi_Cmnd * SCpnt,void (*done) (Scsi_Cmnd *)) {struct aha1542_hostdata *aha1542 =shost_priv (SCpnt->device->host); -unchar ahacmd =CMD_START_SCSI ; -unchar direction; -unchar *cmd = (unchar *) SCpnt->cmnd; -unchar target = SCpnt->device->id; -unchar lun = SCpnt->device->lun; +u8 ahacmd =CMD_START_SCSI ; +u8 direction; +u8 *cmd = (u8 *) SCpnt->cmnd; +u8 target = SCpnt->device->id; +u8 lun = SCpnt->device->lun;unsigned long flags;int bufflen =scsi_bufflen (SCpnt);int mbo;
@@ -674,7 +674,7 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *int i;printk (KERN_DEBUG "aha1542_command: sending.. " );for (i =0 ; i <sizeof (ccb[mbo]) -10 ; i++) - printk("%02x ", ((unchar *) & ccb[mbo])[i]); + printk("%02x ", ((u8 *) &ccb[mbo])[i]); };#endif
@@ -701,7 +701,7 @@ static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)struct mailbox *mb = aha1542->mb;struct ccb *ccb = aha1542->ccb; -unchar cmd[5 ] = {CMD_MBINIT ,AHA1542_MAILBOXES ,0 ,0 ,0 }; +u8 cmd[5 ] = {CMD_MBINIT ,AHA1542_MAILBOXES ,0 ,0 ,0 };for (i =0 ; i <AHA1542_MAILBOXES ; i++) { mb[i].status = mb[AHA1542_MAILBOXES + i].status =0 ;
@@ -720,8 +720,8 @@ fail:static int aha1542_getconfig (int base_io,unsigned char *irq_level,unsigned char *dma_chan,unsigned char *scsi_id) { -unchar inquiry_cmd[] = {CMD_RETCONF }; -unchar inquiry_result[3 ]; +u8 inquiry_cmd[] = {CMD_RETCONF }; +u8 inquiry_result[3 ];int i; i =inb (STATUS (base_io));if (i &DF ) {
@@ -789,8 +789,8 @@ fail:static int aha1542_mbenable (int base) { -static unchar mbenable_cmd[3 ]; -static unchar mbenable_result[2 ]; +static u8 mbenable_cmd[3 ]; +static u8 mbenable_result[2 ];int retval; retval =BIOS_TRANSLATION_6432 ;
@@ -824,8 +824,8 @@ fail:/* Query the board to find out if it is a 1542 or a 1740, or whatever. */ static int aha1542_query (int base_io,int *transl) { -unchar inquiry_cmd[] = {CMD_INQUIRY }; -unchar inquiry_result[4 ]; +u8 inquiry_cmd[] = {CMD_INQUIRY }; +u8 inquiry_result[4 ];int i; i =inb (STATUS (base_io));if (i &DF ) {
@@ -968,8 +968,8 @@ static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct/* Set the Bus on/off-times as not to ruin floppy performance */ { -unchar oncmd[] = {CMD_BUSON_TIME ,7 }; -unchar offcmd[] = {CMD_BUSOFF_TIME ,5 }; +u8 oncmd[] = {CMD_BUSON_TIME ,7 }; +u8 offcmd[] = {CMD_BUSOFF_TIME ,5 };if (setup_called[indx]) { oncmd[1 ] = setup_buson[indx];
@@ -982,7 +982,7 @@ static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, structaha1542_out (base_io, offcmd,2 );WAIT (INTRFLAGS (base_io),INTRMASK ,HACC ,0 );if (setup_dmaspeed[indx] >=0 ) { -unchar dmacmd[] = {CMD_DMASPEED ,0 }; +u8 dmacmd[] = {CMD_DMASPEED ,0 }; dmacmd[1 ] = setup_dmaspeed[indx];aha1542_intr_reset (base_io);aha1542_out (base_io, dmacmd,2 );
@@ -1103,11 +1103,11 @@ static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)struct aha1542_hostdata *aha1542 =shost_priv (SCpnt->device->host);unsigned long flags;struct mailbox *mb = aha1542->mb; -unchar target = SCpnt->device->id; -unchar lun = SCpnt->device->lun; +u8 target = SCpnt->device->id; +u8 lun = SCpnt->device->lun;int mbo;struct ccb *ccb = aha1542->ccb; -unchar ahacmd =CMD_START_SCSI ; +u8 ahacmd =CMD_START_SCSI ;spin_lock_irqsave (&aha1542_lock, flags); mbo = aha1542->aha1542_last_mbo_used +1 ;
drivers/scsi/aha1542.h +21 -21
58 lines not on this page · raw message
Signature · 1 line
Ondrej Zary
PATCH 7/13 aha1542: Reorder functions to remove forward declarations
In reply to Ondrej Zary--- drivers/scsi/aha1542.c | 51 +++++++++++++++++++++++------------------------- drivers/scsi/aha1542.h | 12 ------------ 2 files changed, 24 insertions(+), 39 deletions(-)
drivers/scsi/aha1542.c +24 -27
@@ -124,10 +124,6 @@ static DEFINE_SPINLOCK(aha1542_lock);#define WAITnexttimeout 3000000 -static void setup_mailboxes (int base_io,struct Scsi_Host *shpnt); -static int aha1542_restart (struct Scsi_Host *shost); -static void aha1542_intr_handle (struct Scsi_Host *shost); -static inline void aha1542_intr_reset (u16 base) {outb (IRST ,CONTROL (base));
@@ -368,16 +364,20 @@ fail:return 0 ;/* 0 = not ok */ } -/* A quick wrapper for do_aha1542_intr_handle to grab the spin lock */ -static irqreturn_t do_aha1542_intr_handle (int dummy,void *dev_id) +static int aha1542_restart (struct Scsi_Host *shost) { -unsigned long flags; -struct Scsi_Host *shost = dev_id; +struct aha1542_hostdata *aha1542 =shost_priv (shost); +int i; +int count =0 ; -spin_lock_irqsave (shost->host_lock, flags); -aha1542_intr_handle (shost); -spin_unlock_irqrestore (shost->host_lock, flags); -return IRQ_HANDLED ; +for (i =0 ; i <AHA1542_MAILBOXES ; i++) +if (aha1542->SCint[i] && + !(aha1542->SCint[i]->device->soft_reset)) { + count++; + } +printk (KERN_DEBUG "Potential to restart %d stalled commands...\n" , count); + +return 0 ; }/* A "high" level interrupt handler */
@@ -539,6 +539,18 @@ static void aha1542_intr_handle(struct Scsi_Host *shost) }; } +/* A quick wrapper for do_aha1542_intr_handle to grab the spin lock */ +static irqreturn_t do_aha1542_intr_handle (int dummy,void *dev_id) +{ +unsigned long flags; +struct Scsi_Host *shost = dev_id; + +spin_lock_irqsave (shost->host_lock, flags); +aha1542_intr_handle (shost); +spin_unlock_irqrestore (shost->host_lock, flags); +return IRQ_HANDLED ; +} +static int aha1542_queuecommand_lck (Scsi_Cmnd * SCpnt,void (*done) (Scsi_Cmnd *)) {struct aha1542_hostdata *aha1542 =shost_priv (SCpnt->device->host);
@@ -1078,21 +1090,6 @@ static int aha1542_release(struct Scsi_Host *shost)return 0 ; } -static int aha1542_restart (struct Scsi_Host *shost) -{ -struct aha1542_hostdata *aha1542 =shost_priv (shost); -int i; -int count =0 ; - -for (i =0 ; i <AHA1542_MAILBOXES ; i++) -if (aha1542->SCint[i] && - !(aha1542->SCint[i]->device->soft_reset)) { - count++; - } -printk (KERN_DEBUG "Potential to restart %d stalled commands...\n" , count); - -return 0 ; -}/* * This is a device reset. This is handled by sending a special command
drivers/scsi/aha1542.h +0 -12
@@ -125,18 +125,6 @@ struct ccb { /* Command Control Block 5.3 */ /* REQUEST SENSE */ }; -static struct Scsi_Host *aha1542_hw_init (struct scsi_host_template *tpnt,struct device *pdev,int indx); -static int aha1542_queuecommand (struct Scsi_Host *,struct scsi_cmnd *); -static int aha1542_bus_reset (Scsi_Cmnd * SCpnt); -static int aha1542_dev_reset (Scsi_Cmnd * SCpnt); -static int aha1542_host_reset (Scsi_Cmnd * SCpnt); -#if 0 -static int aha1542_old_abort (Scsi_Cmnd * SCpnt); -static int aha1542_old_reset (Scsi_Cmnd *,unsigned int ); -#endif -static int aha1542_biosparam (struct scsi_device *,struct block_device *, -sector_t ,int *); -#define AHA1542_MAILBOXES 8#endif
Signature · 1 line
Ondrej Zary
PATCH 8/13 aha1542: remove empty aha1542_stat
In reply to Ondrej Zary--- drivers/scsi/aha1542.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
drivers/scsi/aha1542.c +1 -15
@@ -154,12 +154,6 @@ static inline void aha1542_intr_reset(u16 base) } \ } -static void aha1542_stat (void ) -{ -/* int s = inb(STATUS), i = inb(INTRFLAGS); -printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */ -} -/* This is a bit complicated, but we need to make sure that an interrupt routine does not send something out while we are in the middle of this. Fortunately, it is only at boot time that multi-byte messages
@@ -196,7 +190,6 @@ fail:if (got_lock)spin_unlock_irqrestore (&aha1542_lock, flags);printk (KERN_ERR "aha1542_out failed(%d): " , len +1 ); -aha1542_stat ();return 1 ; }
@@ -217,7 +210,6 @@ static int aha1542_in(unsigned int base, u8 *cmdp, int len) fail:spin_unlock_irqrestore (&aha1542_lock, flags);printk (KERN_ERR "aha1542_in failed(%d): " , len +1 ); -aha1542_stat ();return 1 ; }
@@ -590,7 +582,6 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *printk (KERN_DEBUG "aha1542_queuecommand: dev %d cmd %02x pos %d len %d " , target, *cmd, i, bufflen); else printk(KERN_DEBUG "aha1542_command: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen); -aha1542_stat ();printk (KERN_DEBUG "aha1542_queuecommand: dumping scsi cmd:" );for (i =0 ; i < SCpnt->cmd_len; i++)printk ("%02x " , cmd[i]);
@@ -691,12 +682,10 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *#endif if (done) { - DEB(printk("aha1542_queuecommand: now waiting for interrupt "); -aha1542_stat ()); +DEB (printk ("aha1542_queuecommand: now waiting for interrupt " )); SCpnt->scsi_done = done; mb[mbo].status =1 ;aha1542_out (SCpnt->device->host->io_port, &ahacmd,1 );/* start scsi command */ -DEB (aha1542_stat ()); }else printk ("aha1542_queuecommand: done can't be NULL\n" );
@@ -1017,11 +1006,8 @@ fail:printk (", DMA priority %d" , dma_chan);printk ("\n" ); -DEB (aha1542_stat ());setup_mailboxes (base_io, shpnt); -DEB (aha1542_stat ()); -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,
Signature · 1 line
Ondrej Zary
PATCH 9/13 aha1542: Use BIT() macro
In reply to Ondrej Zary--- drivers/scsi/aha1542.h | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/scsi/aha1542.h +19 -18
@@ -36,29 +36,30 @@/* I/O Port interface 4.2 */ /* READ */ #define STATUS (base) base -#define STST 0x80/* Self Test in Progress */ -#define DIAGF 0x40/* Internal Diagnostic Failure */ -#define INIT 0x20/* Mailbox Initialization Required */ -#define IDLE 0x10/* SCSI Host Adapter Idle */ -#define CDF 0x08/* Command/Data Out Port Full */ -#define DF 0x04/* Data In Port Full */ -#define INVDCMD 0x01/* Invalid H A Command */ -#define STATMASK 0xfd/* 0x02 is reserved */ +#define STST BIT(7)/* Self Test in Progress */ +#define DIAGF BIT(6)/* Internal Diagnostic Failure */ +#define INIT BIT(5)/* Mailbox Initialization Required */ +#define IDLE BIT(4)/* SCSI Host Adapter Idle */ +#define CDF BIT(3)/* Command/Data Out Port Full */ +#define DF BIT(2)/* Data In Port Full */ +/* BIT(1) is reserved */ +#define INVDCMD BIT(0)/* Invalid H A Command */ +#define STATMASK (STST | DIAGF | INIT | IDLE | CDF | DF | INVDCMD)#define INTRFLAGS (base) (STATUS(base)+2) -#define ANYINTR 0x80/* Any Interrupt */ -#define SCRD 0x08/* SCSI Reset Detected */ -#define HACC 0x04/* HA Command Complete */ -#define MBOA 0x02/* MBO Empty */ -#define MBIF 0x01/* MBI Full */ -#define INTRMASK 0x8f +#define ANYINTR BIT(7)/* Any Interrupt */ +#define SCRD BIT(3)/* SCSI Reset Detected */ +#define HACC BIT(2)/* HA Command Complete */ +#define MBOA BIT(1)/* MBO Empty */ +#define MBIF BIT(0)/* MBI Full */ +#define INTRMASK (ANYINTR | SCRD | HACC | MBOA | MBIF)/* WRITE */ #define CONTROL (base) STATUS(base) -#define HRST 0x80/* Hard Reset */ -#define SRST 0x40/* Soft Reset */ -#define IRST 0x20/* Interrupt Reset */ -#define SCRST 0x10/* SCSI Bus Reset */ +#define HRST BIT(7)/* Hard Reset */ +#define SRST BIT(6)/* Soft Reset */ +#define IRST BIT(5)/* Interrupt Reset */ +#define SCRST BIT(4)/* SCSI Bus Reset */ /* READ/WRITE */ #define DATA (base) (STATUS(base)+1)
Signature · 1 line
Ondrej Zary
PATCH 10/13 aha1542: Remove WAIT and WAITd macros
In reply to Ondrej ZaryConvert the ugly WAIT and WAITd macros into wait_mask function.
--- drivers/scsi/aha1542.c | 104 ++++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 47 deletions(-)
drivers/scsi/aha1542.c +57 -47
@@ -120,39 +120,32 @@ struct aha1542_hostdata {static DEFINE_SPINLOCK (aha1542_lock); - - -#define WAITnexttimeout 3000000 -static inline void aha1542_intr_reset (u16 base) {outb (IRST ,CONTROL (base)); } -#define WAIT (port, mask, allof, noneof) \ - { register int WAITbits; \ - register int WAITtimeout = WAITnexttimeout; \ - while (1) { \ - WAITbits = inb(port) & (mask); \ - if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \ - break; \ - if (--WAITtimeout == 0) goto fail; \ - } \ - } - -/* Similar to WAIT, except we use the udelay call to regulate the -amount of time we wait. */ -#define WAITd (port, mask, allof, noneof, timeout) \ - { register int WAITbits; \ - register int WAITtimeout = timeout; \ - while (1) { \ - WAITbits = inb(port) & (mask); \ - if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \ - break; \ - mdelay(1); \ - if (--WAITtimeout == 0) goto fail; \ - } \ - } +static inline bool wait_mask (u16 port,u8 mask,u8 allof,u8 noneof,int timeout) +{ +bool delayed = true; + +if (timeout ==0 ) { + timeout =3000000 ; + delayed = false; + } + +while (1 ) { +u8 bits =inb (port) & mask; +if ((bits & allof) == allof && ((bits & noneof) ==0 )) +break ; +if (delayed) +mdelay (1 ); +if (--timeout ==0 ) +return false; + } + +return true; +}/* This is a bit complicated, but we need to make sure that an interrupt routine does not send something out while we are in the middle of this.
@@ -166,7 +159,8 @@ static int aha1542_out(unsigned int base, u8 *cmdp, int len)if (len ==1 ) { got_lock =0 ;while (1 ==1 ) { -WAIT (STATUS (base),CDF ,0 ,CDF ); +if (!wait_mask (STATUS (base),CDF ,0 ,CDF ,0 )) + goto fail;spin_lock_irqsave (&aha1542_lock, flags);if (inb (STATUS (base)) &CDF ) {spin_unlock_irqrestore (&aha1542_lock, flags);
@@ -180,7 +174,8 @@ static int aha1542_out(unsigned int base, u8 *cmdp, int len)spin_lock_irqsave (&aha1542_lock, flags); got_lock =1 ;while (len--) { -WAIT (STATUS (base),CDF ,0 ,CDF ); +if (!wait_mask (STATUS (base),CDF ,0 ,CDF ,0 )) + goto fail;outb (*cmdp++,DATA (base)); }spin_unlock_irqrestore (&aha1542_lock, flags);
@@ -202,7 +197,8 @@ static int aha1542_in(unsigned int base, u8 *cmdp, int len)spin_lock_irqsave (&aha1542_lock, flags);while (len--) { -WAIT (STATUS (base),DF ,DF ,0 ); +if (!wait_mask (STATUS (base),DF ,DF ,0 ,0 )) + goto fail; *cmdp++ =inb (DATA (base)); }spin_unlock_irqrestore (&aha1542_lock, flags);
@@ -222,7 +218,8 @@ static int aha1542_in1(unsigned int base, u8 *cmdp, int len)spin_lock_irqsave (&aha1542_lock, flags);while (len--) { -WAITd (STATUS (base),DF ,DF ,0 ,100 ); +if (!wait_mask (STATUS (base),DF ,DF ,0 ,100 )) + goto fail; *cmdp++ =inb (DATA (base)); }spin_unlock_irqrestore (&aha1542_lock, flags);
@@ -313,7 +310,8 @@ static int aha1542_test_port(int bse, struct Scsi_Host *shpnt) debug =1 ;/* Expect INIT and IDLE, any of the others are bad */ -WAIT (STATUS (bse),STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ); +if (!wait_mask (STATUS (bse),STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ,0 )) + goto fail; debug =2 ;/* Shouldn't have generated any interrupts during reset */
@@ -331,7 +329,8 @@ static int aha1542_test_port(int bse, struct Scsi_Host *shpnt) cmdp = &inquiry_result[0 ];while (len--) { -WAIT (STATUS (bse),DF ,DF ,0 ); +if (!wait_mask (STATUS (bse),DF ,DF ,0 ,0 )) + goto fail; *cmdp++ =inb (DATA (bse)); }
@@ -342,7 +341,8 @@ static int aha1542_test_port(int bse, struct Scsi_Host *shpnt) debug =9 ;/* When HACC, command is completed, and we're though testing */ -WAIT (INTRFLAGS (bse),HACC ,HACC ,0 ); +if (!wait_mask (INTRFLAGS (bse),HACC ,HACC ,0 ,0 )) + goto fail;/* now initialize adapter */ debug =10 ;
@@ -711,7 +711,8 @@ static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)aha1542_intr_reset (bse);/* reset interrupts, so they don't block */ any2scsi ((cmd +2 ),isa_virt_to_bus (mb));aha1542_out (bse, cmd,5 ); -WAIT (INTRFLAGS (bse),INTRMASK ,HACC ,0 ); +if (!wait_mask (INTRFLAGS (bse),INTRMASK ,HACC ,0 ,0 )) + goto fail;while (0 ) { fail:printk (KERN_ERR "aha1542_detect: failed setting up mailboxes\n" );
@@ -730,7 +731,8 @@ static int aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned cha };aha1542_out (base_io, inquiry_cmd,1 );aha1542_in (base_io, inquiry_result,3 ); -WAIT (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ); +if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) + goto fail;while (0 ) { fail:printk (KERN_ERR "aha1542_detect: query board settings\n" );
@@ -800,7 +802,8 @@ static int aha1542_mbenable(int base)aha1542_out (base, mbenable_cmd,1 );if (aha1542_in1 (base, mbenable_result,2 ))return retval; -WAITd (INTRFLAGS (base),INTRMASK ,HACC ,0 ,100 ); +if (!wait_mask (INTRFLAGS (base),INTRMASK ,HACC ,0 ,100 )) + goto fail;aha1542_intr_reset (base);if ((mbenable_result[0 ] &0x08 ) || mbenable_result[1 ]) {
@@ -812,7 +815,8 @@ static int aha1542_mbenable(int base) retval =BIOS_TRANSLATION_25563 ;aha1542_out (base, mbenable_cmd,3 ); -WAIT (INTRFLAGS (base),INTRMASK ,HACC ,0 ); +if (!wait_mask (INTRFLAGS (base),INTRMASK ,HACC ,0 ,0 )) + goto fail; };while (0 ) { fail:
@@ -834,7 +838,8 @@ static int aha1542_query(int base_io, int *transl) };aha1542_out (base_io, inquiry_cmd,1 );aha1542_in (base_io, inquiry_result,4 ); -WAIT (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ); +if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) + goto fail;while (0 ) { fail:printk (KERN_ERR "aha1542_detect: query card type\n" );
@@ -978,16 +983,19 @@ static struct Scsi_Host *aha1542_hw_init(struct scsi_host_template *tpnt, struct }aha1542_intr_reset (base_io);aha1542_out (base_io, oncmd,2 ); -WAIT (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ); +if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) + goto fail;aha1542_intr_reset (base_io);aha1542_out (base_io, offcmd,2 ); -WAIT (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ); +if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) + goto fail;if (setup_dmaspeed[indx] >=0 ) {u8 dmacmd[] = {CMD_DMASPEED ,0 }; dmacmd[1 ] = setup_dmaspeed[indx];aha1542_intr_reset (base_io);aha1542_out (base_io, dmacmd,2 ); -WAIT (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ); +if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) + goto fail; }while (0 ) { fail:
@@ -1162,8 +1170,9 @@ static int aha1542_bus_reset(Scsi_Cmnd * SCpnt)spin_lock_irq (SCpnt->device->host->host_lock); -WAIT (STATUS (SCpnt->device->host->io_port), -STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ); +if (!wait_mask (STATUS (SCpnt->device->host->io_port), +STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ,0 )) + goto fail;/* * Now try to pick up the pieces. For all pending commands,
@@ -1226,8 +1235,9 @@ static int aha1542_host_reset(Scsi_Cmnd * SCpnt)ssleep (4 );spin_lock_irq (SCpnt->device->host->host_lock); -WAIT (STATUS (SCpnt->device->host->io_port), -STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ); +if (!wait_mask (STATUS (SCpnt->device->host->io_port), +STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ,0 )) + goto fail;/* * We need to do this too before the 1542 can interact with
Signature · 1 line
Ondrej Zary
PATCH 11/13 aha1542: Unify aha1542_in and aha1542_in1
In reply to Ondrej ZaryUnify aha1542_in and aha1542_in1 functions, they differ only in timeout and printk.
--- drivers/scsi/aha1542.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-)
drivers/scsi/aha1542.c +7 -26
@@ -191,34 +191,13 @@ fail:/* Only used at boot time, so we do not need to worry about latency as much here */ -static int aha1542_in (unsigned int base,u8 *cmdp,int len) +static int aha1542_in (unsigned int base,u8 *cmdp,int len,int timeout) {unsigned long flags;spin_lock_irqsave (&aha1542_lock, flags);while (len--) { -if (!wait_mask (STATUS (base),DF ,DF ,0 ,0 )) - goto fail; - *cmdp++ =inb (DATA (base)); - } -spin_unlock_irqrestore (&aha1542_lock, flags); -return 0 ; -fail: -spin_unlock_irqrestore (&aha1542_lock, flags); -printk (KERN_ERR "aha1542_in failed(%d): " , len +1 ); -return 1 ; -} - -/* Similar to aha1542_in, except that we wait a very short period of time. -We use this if we know the board is alive and awake, but we are not sure -if the board will respond to the command we are about to send or not */ -static int aha1542_in1 (unsigned int base,u8 *cmdp,int len) -{ -unsigned long flags; - -spin_lock_irqsave (&aha1542_lock, flags); -while (len--) { -if (!wait_mask (STATUS (base),DF ,DF ,0 ,100 )) +if (!wait_mask (STATUS (base),DF ,DF ,0 , timeout)) goto fail; *cmdp++ =inb (DATA (base)); }
@@ -226,6 +205,8 @@ static int aha1542_in1(unsigned int base, u8 *cmdp, int len)return 0 ; fail:spin_unlock_irqrestore (&aha1542_lock, flags); +if (timeout ==0 ) +printk (KERN_ERR "aha1542_in failed(%d): " , len +1 );return 1 ; }
@@ -730,7 +711,7 @@ static int aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned cha i =inb (DATA (base_io)); };aha1542_out (base_io, inquiry_cmd,1 ); -aha1542_in (base_io, inquiry_result,3 ); +aha1542_in (base_io, inquiry_result,3 ,0 );if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) goto fail;while (0 ) {
@@ -800,7 +781,7 @@ static int aha1542_mbenable(int base) mbenable_cmd[0 ] =CMD_EXTBIOS ;aha1542_out (base, mbenable_cmd,1 ); -if (aha1542_in1 (base, mbenable_result,2 )) +if (aha1542_in (base, mbenable_result,2 ,100 ))return retval;if (!wait_mask (INTRFLAGS (base),INTRMASK ,HACC ,0 ,100 )) goto fail;
@@ -837,7 +818,7 @@ static int aha1542_query(int base_io, int *transl) i =inb (DATA (base_io)); };aha1542_out (base_io, inquiry_cmd,1 ); -aha1542_in (base_io, inquiry_result,4 ); +aha1542_in (base_io, inquiry_result,4 ,0 );if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) goto fail;while (0 ) {
Signature · 1 line
Ondrej Zary
PATCH 12/13 aha1542: Split aha1542_out
In reply to Ondrej Zaryaha1542_out are in fact two separate functions.
Split them into aha1542_out and aha1542_outb to simplify the code.
--- drivers/scsi/aha1542.c | 75 ++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 40 deletions(-)
drivers/scsi/aha1542.c +35 -40
@@ -151,41 +151,42 @@ static inline bool wait_mask(u16 port, u8 mask, u8 allof, u8 noneof, int timeoutroutine does not send something out while we are in the middle of this. Fortunately, it is only at boot time that multi-byte messages are ever sent. */ -static int aha1542_out (unsigned int base,u8 *cmdp,int len) +static int aha1542_outb (unsigned int base,u8 cmd) { -unsigned long flags =0 ; -int got_lock; - -if (len ==1 ) { - got_lock =0 ; -while (1 ==1 ) { -if (!wait_mask (STATUS (base),CDF ,0 ,CDF ,0 )) - goto fail; -spin_lock_irqsave (&aha1542_lock, flags); -if (inb (STATUS (base)) &CDF ) { -spin_unlock_irqrestore (&aha1542_lock, flags); -continue ; - } -outb (*cmdp,DATA (base)); -spin_unlock_irqrestore (&aha1542_lock, flags); -return 0 ; +unsigned long flags; + +while (1 ) { +if (!wait_mask (STATUS (base),CDF ,0 ,CDF ,0 )) { +printk (KERN_ERR "aha1542_outb failed" ); +return 1 ; } - }else {spin_lock_irqsave (&aha1542_lock, flags); - got_lock =1 ; -while (len--) { -if (!wait_mask (STATUS (base),CDF ,0 ,CDF ,0 )) - goto fail; -outb (*cmdp++,DATA (base)); +if (inb (STATUS (base)) &CDF ) { +spin_unlock_irqrestore (&aha1542_lock, flags); +continue ; } +outb (cmd,DATA (base));spin_unlock_irqrestore (&aha1542_lock, flags); +return 0 ; } +} + +static int aha1542_out (unsigned int base,u8 *cmdp,int len) +{ +unsigned long flags; + +spin_lock_irqsave (&aha1542_lock, flags); +while (len--) { +if (!wait_mask (STATUS (base),CDF ,0 ,CDF ,0 )) { +spin_unlock_irqrestore (&aha1542_lock, flags); +printk (KERN_ERR "aha1542_out failed(%d): " , len +1 ); +return 1 ; + } +outb (*cmdp++,DATA (base)); + } +spin_unlock_irqrestore (&aha1542_lock, flags); +return 0 ; -fail: -if (got_lock) -spin_unlock_irqrestore (&aha1542_lock, flags); -printk (KERN_ERR "aha1542_out failed(%d): " , len +1 ); -return 1 ; }/* Only used at boot time, so we do not need to worry about latency as much
@@ -268,7 +269,6 @@ static int makecode(unsigned hosterr, unsigned scsierr)static int aha1542_test_port (int bse,struct Scsi_Host *shpnt) { -u8 inquiry_cmd[] = {CMD_INQUIRY };u8 inquiry_result[4 ];u8 *cmdp;int len;
@@ -303,7 +303,7 @@ static int aha1542_test_port(int bse, struct Scsi_Host *shpnt)/* Perform a host adapter inquiry instead so we do not need to set up the mailboxes ahead of time */ -aha1542_out (bse, inquiry_cmd,1 ); +aha1542_outb (bse,CMD_INQUIRY ); debug =3 ; len =4 ;
@@ -527,7 +527,6 @@ static irqreturn_t do_aha1542_intr_handle(int dummy, void *dev_id)static int aha1542_queuecommand_lck (Scsi_Cmnd * SCpnt,void (*done) (Scsi_Cmnd *)) {struct aha1542_hostdata *aha1542 =shost_priv (SCpnt->device->host); -u8 ahacmd =CMD_START_SCSI ;u8 direction;u8 *cmd = (u8 *) SCpnt->cmnd;u8 target = SCpnt->device->id;
@@ -666,7 +665,7 @@ static int aha1542_queuecommand_lck(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *DEB (printk ("aha1542_queuecommand: now waiting for interrupt " )); SCpnt->scsi_done = done; mb[mbo].status =1 ; -aha1542_out (SCpnt->device->host->io_port, &ahacmd,1 );/* start scsi command */ +aha1542_outb (SCpnt->device->host->io_port,CMD_START_SCSI ); }else printk ("aha1542_queuecommand: done can't be NULL\n" );
@@ -703,14 +702,13 @@ fail:static int aha1542_getconfig (int base_io,unsigned char *irq_level,unsigned char *dma_chan,unsigned char *scsi_id) { -u8 inquiry_cmd[] = {CMD_RETCONF };u8 inquiry_result[3 ];int i; i =inb (STATUS (base_io));if (i &DF ) { i =inb (DATA (base_io)); }; -aha1542_out (base_io, inquiry_cmd,1 ); +aha1542_outb (base_io,CMD_RETCONF );aha1542_in (base_io, inquiry_result,3 ,0 );if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) goto fail;
@@ -779,8 +777,7 @@ static int aha1542_mbenable(int base) retval =BIOS_TRANSLATION_6432 ; - mbenable_cmd[0 ] =CMD_EXTBIOS ; -aha1542_out (base, mbenable_cmd,1 ); +aha1542_outb (base,CMD_EXTBIOS );if (aha1542_in (base, mbenable_result,2 ,100 ))return retval;if (!wait_mask (INTRFLAGS (base),INTRMASK ,HACC ,0 ,100 ))
@@ -810,14 +807,13 @@ fail:/* Query the board to find out if it is a 1542 or a 1740, or whatever. */ static int aha1542_query (int base_io,int *transl) { -u8 inquiry_cmd[] = {CMD_INQUIRY };u8 inquiry_result[4 ];int i; i =inb (STATUS (base_io));if (i &DF ) { i =inb (DATA (base_io)); }; -aha1542_out (base_io, inquiry_cmd,1 ); +aha1542_outb (base_io,CMD_INQUIRY );aha1542_in (base_io, inquiry_result,4 ,0 );if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) goto fail;
@@ -1079,7 +1075,6 @@ static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)u8 lun = SCpnt->device->lun;int mbo;struct ccb *ccb = aha1542->ccb; -u8 ahacmd =CMD_START_SCSI ;spin_lock_irqsave (&aha1542_lock, flags); mbo = aha1542->aha1542_last_mbo_used +1 ;
@@ -1119,7 +1114,7 @@ static int aha1542_dev_reset(Scsi_Cmnd * SCpnt)* Now tell the 1542 to flush all pending commands for this * target */ -aha1542_out (SCpnt->device->host->io_port, &ahacmd,1 ); +aha1542_outb (SCpnt->device->host->io_port,CMD_START_SCSI );scmd_printk (KERN_WARNING , SCpnt,"Trying device reset for target\n" );
Signature · 1 line
Ondrej Zary
PATCH 13/13 aha1542: Remove unneeded gotos
In reply to Ondrej ZaryRemove gotos that are no longer needed.
--- drivers/scsi/aha1542.c | 58 ++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 39 deletions(-)
drivers/scsi/aha1542.c +19 -39
@@ -198,17 +198,16 @@ static int aha1542_in(unsigned int base, u8 *cmdp, int len, int timeout)spin_lock_irqsave (&aha1542_lock, flags);while (len--) { -if (!wait_mask (STATUS (base),DF ,DF ,0 , timeout)) - goto fail; +if (!wait_mask (STATUS (base),DF ,DF ,0 , timeout)) { +spin_unlock_irqrestore (&aha1542_lock, flags); +if (timeout ==0 ) +printk (KERN_ERR "aha1542_in failed(%d): " , len +1 ); +return 1 ; + } *cmdp++ =inb (DATA (base)); }spin_unlock_irqrestore (&aha1542_lock, flags);return 0 ; -fail: -spin_unlock_irqrestore (&aha1542_lock, flags); -if (timeout ==0 ) -printk (KERN_ERR "aha1542_in failed(%d): " , len +1 ); -return 1 ; }static int makecode (unsigned hosterr,unsigned scsierr)
@@ -292,12 +291,12 @@ static int aha1542_test_port(int bse, struct Scsi_Host *shpnt) debug =1 ;/* Expect INIT and IDLE, any of the others are bad */ if (!wait_mask (STATUS (bse),STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ,0 )) - goto fail; +return 0 ; debug =2 ;/* Shouldn't have generated any interrupts during reset */ if (inb (INTRFLAGS (bse)) &INTRMASK ) - goto fail; +return 0 ;/* Perform a host adapter inquiry instead so we do not need to set
@@ -311,19 +310,19 @@ static int aha1542_test_port(int bse, struct Scsi_Host *shpnt)while (len--) {if (!wait_mask (STATUS (bse),DF ,DF ,0 ,0 )) - goto fail; +return 0 ; *cmdp++ =inb (DATA (bse)); } debug =8 ;/* Reading port should reset DF */ if (inb (STATUS (bse)) &DF ) - goto fail; +return 0 ; debug =9 ;/* When HACC, command is completed, and we're though testing */ if (!wait_mask (INTRFLAGS (bse),HACC ,HACC ,0 ,0 )) - goto fail; +return 0 ;/* now initialize adapter */ debug =10 ;
@@ -333,8 +332,6 @@ static int aha1542_test_port(int bse, struct Scsi_Host *shpnt) debug =11 ;return debug;/* 1 = ok */ -fail: -return 0 ;/* 0 = not ok */ }static int aha1542_restart (struct Scsi_Host *shost)
@@ -692,11 +689,7 @@ static void setup_mailboxes(int bse, struct Scsi_Host *shpnt)any2scsi ((cmd +2 ),isa_virt_to_bus (mb));aha1542_out (bse, cmd,5 );if (!wait_mask (INTRFLAGS (bse),INTRMASK ,HACC ,0 ,0 )) - goto fail; -while (0 ) { -fail:printk (KERN_ERR "aha1542_detect: failed setting up mailboxes\n" ); - }aha1542_intr_reset (bse); }
@@ -711,11 +704,7 @@ static int aha1542_getconfig(int base_io, unsigned char *irq_level, unsigned chaaha1542_outb (base_io,CMD_RETCONF );aha1542_in (base_io, inquiry_result,3 ,0 );if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) - goto fail; -while (0 ) { -fail:printk (KERN_ERR "aha1542_detect: query board settings\n" ); - }aha1542_intr_reset (base_io);switch (inquiry_result[0 ]) {case 0x80 :
@@ -816,11 +805,7 @@ static int aha1542_query(int base_io, int *transl)aha1542_outb (base_io,CMD_INQUIRY );aha1542_in (base_io, inquiry_result,4 ,0 );if (!wait_mask (INTRFLAGS (base_io),INTRMASK ,HACC ,0 ,0 )) - goto fail; -while (0 ) { -fail:printk (KERN_ERR "aha1542_detect: query card type\n" ); - }aha1542_intr_reset (base_io); *transl =BIOS_TRANSLATION_6432 ;/* Default case */
@@ -1147,8 +1132,10 @@ static int aha1542_bus_reset(Scsi_Cmnd * SCpnt)spin_lock_irq (SCpnt->device->host->host_lock);if (!wait_mask (STATUS (SCpnt->device->host->io_port), -STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ,0 )) - goto fail; +STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ,0 )) { +spin_unlock_irq (SCpnt->device->host->host_lock); +return FAILED ; + }/* * Now try to pick up the pieces. For all pending commands,
@@ -1182,10 +1169,6 @@ static int aha1542_bus_reset(Scsi_Cmnd * SCpnt)spin_unlock_irq (SCpnt->device->host->host_lock);return SUCCESS ; - -fail: -spin_unlock_irq (SCpnt->device->host->host_lock); -return FAILED ; }static int aha1542_host_reset (Scsi_Cmnd * SCpnt)
@@ -1212,9 +1195,10 @@ static int aha1542_host_reset(Scsi_Cmnd * SCpnt)spin_lock_irq (SCpnt->device->host->host_lock);if (!wait_mask (STATUS (SCpnt->device->host->io_port), -STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ,0 )) - goto fail; - +STATMASK ,INIT |IDLE ,STST |DIAGF |INVDCMD |DF |CDF ,0 )) { +spin_unlock_irq (SCpnt->device->host->host_lock); +return FAILED ; + }/* * We need to do this too before the 1542 can interact with * us again.
@@ -1252,10 +1236,6 @@ static int aha1542_host_reset(Scsi_Cmnd * SCpnt)spin_unlock_irq (SCpnt->device->host->host_lock);return SUCCESS ; - -fail: -spin_unlock_irq (SCpnt->device->host->host_lock); -return FAILED ; } static int aha1542_biosparam(struct scsi_device *sdev,
Signature · 1 line
Ondrej Zary