fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / scsi / NCR53C9x.c
index 22ee2db..3c912ee 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <linux/module.h>
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
 #include <linux/types.h>
@@ -36,7 +35,7 @@
 #include <linux/init.h>
 
 #include "scsi.h"
-#include "hosts.h"
+#include <scsi/scsi_host.h>
 #include "NCR53C9x.h"
 
 #include <asm/system.h>
@@ -94,13 +93,13 @@ enum {
 };
 
 /* The master ring of all esp hosts we are managing in this driver. */
-struct NCR_ESP *espchain = 0;
+static struct NCR_ESP *espchain;
 int nesps = 0, esps_in_use = 0, esps_running = 0;
 
-irqreturn_t esp_intr(int irq, void *dev_id, struct pt_regs *pregs);
+irqreturn_t esp_intr(int irq, void *dev_id);
 
 /* Debugging routines */
-struct esp_cmdstrings {
+static struct esp_cmdstrings {
        unchar cmdchar;
        char *text;
 } esp_cmd_strings[] = {
@@ -290,7 +289,7 @@ static inline void esp_advance_phase(Scsi_Cmnd *s, int newphase)
 #endif
 
 #ifdef DEBUG_ESP_CMDS
-inline void esp_cmd(struct NCR_ESP *esp, struct ESP_regs *eregs,
+static inline void esp_cmd(struct NCR_ESP *esp, struct ESP_regs *eregs,
                           unchar cmd)
 {
        esp->espcmdlog[esp->espcmdent] = cmd;
@@ -529,7 +528,7 @@ void esp_bootup_reset(struct NCR_ESP *esp, struct ESP_regs *eregs)
 /* Allocate structure and insert basic data such as SCSI chip frequency
  * data and a pointer to the device
  */
-struct NCR_ESP* esp_allocate(Scsi_Host_Template *tpnt, void *esp_dev)
+struct NCR_ESP* esp_allocate(struct scsi_host_template *tpnt, void *esp_dev)
 {
        struct NCR_ESP *esp, *elink;
        struct Scsi_Host *esp_host;
@@ -555,7 +554,7 @@ struct NCR_ESP* esp_allocate(Scsi_Host_Template *tpnt, void *esp_dev)
        } else {
                espchain = esp;
        }
-       esp->next = 0;
+       esp->next = NULL;
 
        return esp;
 }
@@ -565,7 +564,7 @@ void esp_deallocate(struct NCR_ESP *esp)
        struct NCR_ESP *elink;
 
        if(espchain == esp) {
-               espchain = 0;
+               espchain = NULL;
        } else {
                for(elink = espchain; elink && (elink->next != esp); elink = elink->next);
                if(elink) 
@@ -708,9 +707,9 @@ void esp_initialize(struct NCR_ESP *esp)
        }                               
 
        /* Initialize the command queues */
-       esp->current_SC = 0;
-       esp->disconnected_SC = 0;
-       esp->issue_SC = 0;
+       esp->current_SC = NULL;
+       esp->disconnected_SC = NULL;
+       esp->issue_SC = NULL;
 
        /* Clear the state machines. */
        esp->targets_present = 0;
@@ -912,7 +911,7 @@ static void esp_get_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp)
                        sp->SCp.ptr =
                                (char *) virt_to_phys(sp->request_buffer);
        } else {
-               sp->SCp.buffer = (struct scatterlist *) sp->buffer;
+               sp->SCp.buffer = (struct scatterlist *) sp->request_buffer;
                sp->SCp.buffers_residual = sp->use_sg - 1;
                sp->SCp.this_residual = sp->SCp.buffer->length;
                if (esp->dma_mmu_get_scsi_sgl)
@@ -936,7 +935,7 @@ static void esp_release_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp)
 
 static void esp_restore_pointers(struct NCR_ESP *esp, Scsi_Cmnd *sp)
 {
-       struct esp_pointers *ep = &esp->data_pointers[sp->device->id];
+       struct esp_pointers *ep = &esp->data_pointers[scmd_id(sp)];
 
        sp->SCp.ptr = ep->saved_ptr;
        sp->SCp.buffer = ep->saved_buffer;
@@ -946,7 +945,7 @@ static void esp_restore_pointers(struct NCR_ESP *esp, Scsi_Cmnd *sp)
 
 static void esp_save_pointers(struct NCR_ESP *esp, Scsi_Cmnd *sp)
 {
-       struct esp_pointers *ep = &esp->data_pointers[sp->device->id];
+       struct esp_pointers *ep = &esp->data_pointers[scmd_id(sp)];
 
        ep->saved_ptr = sp->SCp.ptr;
        ep->saved_buffer = sp->SCp.buffer;
@@ -1006,7 +1005,7 @@ static void esp_exec_cmd(struct NCR_ESP *esp)
        struct ESP_regs *eregs = esp->eregs;
        struct esp_device *esp_dev;
        Scsi_Cmnd *SCptr;
-       Scsi_Device *SDptr;
+       struct scsi_device *SDptr;
        volatile unchar *cmdp = esp->esp_command;
        unsigned char the_esp_command;
        int lun, target;
@@ -1271,17 +1270,6 @@ int esp_queue(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
        return 0;
 }
 
-/* Only queuing supported in this ESP driver. */
-int esp_command(Scsi_Cmnd *SCpnt)
-{
-#ifdef DEBUG_ESP
-       struct NCR_ESP *esp = (struct NCR_ESP *) SCpnt->device->host->hostdata;
-#endif
-
-       ESPLOG(("esp%d: esp_command() called...\n", esp->esp_id));
-       return -1;
-}
-
 /* Dump driver state. */
 static void esp_dump_cmd(Scsi_Cmnd *SCptr)
 {
@@ -1478,14 +1466,12 @@ int esp_reset(Scsi_Cmnd *SCptr)
 {
        struct NCR_ESP *esp = (struct NCR_ESP *) SCptr->device->host->hostdata;
 
+       spin_lock_irq(esp->ehost->host_lock);
        (void) esp_do_resetbus(esp, esp->eregs);
-
        spin_unlock_irq(esp->ehost->host_lock);
 
        wait_event(esp->reset_queue, (esp->resetting_bus == 0));
 
-       spin_lock_irq(esp->ehost->host_lock);
-
        return SUCCESS;
 }
 
@@ -1700,19 +1686,19 @@ static inline int reconnect_lun(struct NCR_ESP *esp, struct ESP_regs *eregs)
 static inline void esp_connect(struct NCR_ESP *esp, struct ESP_regs *eregs,
                               Scsi_Cmnd *sp)
 {
-       Scsi_Device *dp = sp->device;
+       struct scsi_device *dp = sp->device;
        struct esp_device *esp_dev = dp->hostdata;
 
        if(esp->prev_soff  != esp_dev->sync_max_offset ||
           esp->prev_stp   != esp_dev->sync_min_period ||
           (esp->erev > esp100a &&
-           esp->prev_cfg3 != esp->config3[sp->device->id])) {
+           esp->prev_cfg3 != esp->config3[scmd_id(sp)])) {
                esp->prev_soff = esp_dev->sync_max_offset;
                esp_write(eregs->esp_soff, esp->prev_soff);
                esp->prev_stp = esp_dev->sync_min_period;
                esp_write(eregs->esp_stp, esp->prev_stp);
                if(esp->erev > esp100a) {
-                       esp->prev_cfg3 = esp->config3[sp->device->id];
+                       esp->prev_cfg3 = esp->config3[scmd_id(sp)];
                        esp_write(eregs->esp_cfg3, esp->prev_cfg3);
                } 
        }
@@ -1728,7 +1714,7 @@ static inline void esp_reconnect(struct NCR_ESP *esp, Scsi_Cmnd *sp)
                ESPLOG(("esp%d: Weird, being reselected but disconnected "
                        "command queue is empty.\n", esp->esp_id));
        esp->snip = 0;
-       esp->current_SC = 0;
+       esp->current_SC = NULL;
        sp->SCp.phase = not_issued;
        append_SC(&esp->issue_SC, sp);
 }
@@ -1812,6 +1798,7 @@ static int esp_do_data(struct NCR_ESP *esp, struct ESP_regs *eregs)
                 */
                int oldphase, i = 0; /* or where we left off last time ?? esp->current_data ?? */
                int fifocnt = 0;
+               unsigned char *p = phys_to_virt((unsigned long)SCptr->SCp.ptr);
 
                oldphase = esp_read(eregs->esp_status) & ESP_STAT_PMASK;
 
@@ -1835,7 +1822,10 @@ static int esp_do_data(struct NCR_ESP *esp, struct ESP_regs *eregs)
                /* loop */
                while (hmuch) {
                        int j, fifo_stuck = 0, newphase;
-                       unsigned long flags, timeout;
+                       unsigned long timeout;
+#if 0
+                       unsigned long flags;
+#endif
 #if 0
                        if ( i % 10 )
                                ESPDATA(("\r"));
@@ -1870,7 +1860,7 @@ static int esp_do_data(struct NCR_ESP *esp, struct ESP_regs *eregs)
 
                                /* read fifo */
                                for(j=0;j<fifocnt;j++)
-                                       SCptr->SCp.ptr[i++] = esp_read(eregs->esp_fdata);
+                                       p[i++] = esp_read(eregs->esp_fdata);
 
                                ESPDATA(("(%d) ", i));
 
@@ -1892,7 +1882,7 @@ static int esp_do_data(struct NCR_ESP *esp, struct ESP_regs *eregs)
 
                                /* fill fifo */
                                for(j=0;j<this_count;j++)
-                                       esp_write(eregs->esp_fdata, SCptr->SCp.ptr[i++]);
+                                       esp_write(eregs->esp_fdata, p[i++]);
 
                                /* how many left if this goes out ?? */
                                hmuch -= this_count;
@@ -2162,29 +2152,23 @@ static int esp_do_data_finale(struct NCR_ESP *esp,
  */
 static int esp_should_clear_sync(Scsi_Cmnd *sp)
 {
-       unchar cmd1 = sp->cmnd[0];
-       unchar cmd2 = sp->data_cmnd[0];
+       unchar cmd = sp->cmnd[0];
 
        /* These cases are for spinning up a disk and
         * waiting for that spinup to complete.
         */
-       if(cmd1 == START_STOP ||
-          cmd2 == START_STOP)
+       if(cmd == START_STOP)
                return 0;
 
-       if(cmd1 == TEST_UNIT_READY ||
-          cmd2 == TEST_UNIT_READY)
+       if(cmd == TEST_UNIT_READY)
                return 0;
 
        /* One more special case for SCSI tape drives,
         * this is what is used to probe the device for
         * completion of a rewind or tape load operation.
         */
-       if(sp->device->type == TYPE_TAPE) {
-               if(cmd1 == MODE_SENSE ||
-                  cmd2 == MODE_SENSE)
-                       return 0;
-       }
+       if(sp->device->type == TYPE_TAPE && cmd == MODE_SENSE)
+               return 0;
 
        return 1;
 }
@@ -2215,7 +2199,7 @@ static int esp_do_freebus(struct NCR_ESP *esp, struct ESP_regs *eregs)
 
                if(SCptr->SCp.Status != GOOD &&
                   SCptr->SCp.Status != CONDITION_GOOD &&
-                  ((1<<SCptr->device->id) & esp->targets_present) &&
+                  ((1<<scmd_id(SCptr)) & esp->targets_present) &&
                   esp_dev->sync && esp_dev->sync_max_offset) {
                        /* SCSI standard says that the synchronous capabilities
                         * should be renegotiated at this point.  Most likely
@@ -2607,7 +2591,7 @@ static int esp_select_complete(struct NCR_ESP *esp, struct ESP_regs *eregs)
         */
        if(esp->ireg == (ESP_INTR_FDONE | ESP_INTR_BSERV)) {
                /* target speaks... */
-               esp->targets_present |= (1<<SCptr->device->id);
+               esp->targets_present |= (1<<scmd_id(SCptr));
 
                /* What if the target ignores the sdtr? */
                if(esp->snip)
@@ -3074,7 +3058,7 @@ static int check_multibyte_msg(struct NCR_ESP *esp,
                        ESPSDTR(("soff=%2x stp=%2x cfg3=%2x\n",
                                esp_dev->sync_max_offset,
                                esp_dev->sync_min_period,
-                               esp->config3[SCptr->device->id]));
+                               esp->config3[scmd_id(SCptr)]));
 
                        esp->snip = 0;
                } else if(esp_dev->sync_max_offset) {
@@ -3393,7 +3377,7 @@ static int esp_work_bus(struct NCR_ESP *esp, struct ESP_regs *eregs)
 }
 
 static espfunc_t isvc_vector[] = {
-       0,
+       NULL,
        esp_do_phase_determine,
        esp_do_resetbus,
        esp_finish_reset,
@@ -3549,7 +3533,7 @@ state_machine:
 }
 
 #ifndef CONFIG_SMP
-irqreturn_t esp_intr(int irq, void *dev_id, struct pt_regs *pregs)
+irqreturn_t esp_intr(int irq, void *dev_id)
 {
        struct NCR_ESP *esp;
        unsigned long flags;
@@ -3586,7 +3570,7 @@ repeat:
 }
 #else
 /* For SMP we only service one ESP on the list list at our IRQ level! */
-irqreturn_t esp_intr(int irq, void *dev_id, struct pt_regs *pregs)
+irqreturn_t esp_intr(int irq, void *dev_id)
 {
        struct NCR_ESP *esp;
        unsigned long flags;
@@ -3615,7 +3599,7 @@ out:
 }
 #endif
 
-int esp_slave_alloc(Scsi_Device *SDptr)
+int esp_slave_alloc(struct scsi_device *SDptr)
 {
        struct esp_device *esp_dev =
                kmalloc(sizeof(struct esp_device), GFP_ATOMIC);
@@ -3627,11 +3611,11 @@ int esp_slave_alloc(Scsi_Device *SDptr)
        return 0;
 }
 
-void esp_slave_destroy(Scsi_Device *SDptr)
+void esp_slave_destroy(struct scsi_device *SDptr)
 {
        struct NCR_ESP *esp = (struct NCR_ESP *) SDptr->host->hostdata;
 
-       esp->targets_present &= ~(1 << SDptr->id);
+       esp->targets_present &= ~(1 << sdev_id(SDptr));
        kfree(SDptr->hostdata);
        SDptr->hostdata = NULL;
 }
@@ -3646,4 +3630,15 @@ void esp_release(void)
 }
 #endif
 
+EXPORT_SYMBOL(esp_abort);
+EXPORT_SYMBOL(esp_allocate);
+EXPORT_SYMBOL(esp_deallocate);
+EXPORT_SYMBOL(esp_initialize);
+EXPORT_SYMBOL(esp_intr);
+EXPORT_SYMBOL(esp_queue);
+EXPORT_SYMBOL(esp_reset);
+EXPORT_SYMBOL(esp_slave_alloc);
+EXPORT_SYMBOL(esp_slave_destroy);
+EXPORT_SYMBOL(esps_in_use);
+
 MODULE_LICENSE("GPL");