tunnels: fix netns vs proto registration ordering
[safe/jmp/linux-2.6] / drivers / scsi / atari_NCR5380.c
index 81e4f56..4240b05 100644 (file)
@@ -272,8 +272,9 @@ static struct scsi_host_template *the_template = NULL;
        (struct NCR5380_hostdata *)(in)->hostdata
 #define        HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata)
 
-#define        NEXT(cmd)       ((cmd)->host_scribble)
-#define        NEXTADDR(cmd)   ((Scsi_Cmnd **)&((cmd)->host_scribble))
+#define        NEXT(cmd)               ((Scsi_Cmnd *)(cmd)->host_scribble)
+#define        SET_NEXT(cmd,next)      ((cmd)->host_scribble = (void *)(next))
+#define        NEXTADDR(cmd)           ((Scsi_Cmnd **)&(cmd)->host_scribble)
 
 #define        HOSTNO          instance->host_no
 #define        H_NO(cmd)       (cmd)->device->host->host_no
@@ -476,10 +477,9 @@ static void merge_contiguous_buffers(Scsi_Cmnd *cmd)
 
        for (endaddr = virt_to_phys(cmd->SCp.ptr + cmd->SCp.this_residual - 1) + 1;
             cmd->SCp.buffers_residual &&
-            virt_to_phys(page_address(cmd->SCp.buffer[1].page) +
-                         cmd->SCp.buffer[1].offset) == endaddr;) {
+            virt_to_phys(sg_virt(&cmd->SCp.buffer[1])) == endaddr;) {
                MER_PRINTK("VTOP(%p) == %08lx -> merging\n",
-                          cmd->SCp.buffer[1].address, endaddr);
+                          page_address(sg_page(&cmd->SCp.buffer[1])), endaddr);
 #if (NDEBUG & NDEBUG_MERGING)
                ++cnt;
 #endif
@@ -511,11 +511,10 @@ static inline void initialize_SCp(Scsi_Cmnd *cmd)
         * various queues are valid.
         */
 
-       if (cmd->use_sg) {
-               cmd->SCp.buffer = (struct scatterlist *)cmd->request_buffer;
-               cmd->SCp.buffers_residual = cmd->use_sg - 1;
-               cmd->SCp.ptr = (char *)page_address(cmd->SCp.buffer->page) +
-                              cmd->SCp.buffer->offset;
+       if (scsi_bufflen(cmd)) {
+               cmd->SCp.buffer = scsi_sglist(cmd);
+               cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
+               cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
                cmd->SCp.this_residual = cmd->SCp.buffer->length;
                /* ++roman: Try to merge some scatter-buffers if they are at
                 * contiguous physical addresses.
@@ -524,8 +523,8 @@ static inline void initialize_SCp(Scsi_Cmnd *cmd)
        } else {
                cmd->SCp.buffer = NULL;
                cmd->SCp.buffers_residual = 0;
-               cmd->SCp.ptr = (char *)cmd->request_buffer;
-               cmd->SCp.this_residual = cmd->request_bufflen;
+               cmd->SCp.ptr = NULL;
+               cmd->SCp.this_residual = 0;
        }
 }
 
@@ -656,7 +655,7 @@ static inline void NCR5380_print_phase(struct Scsi_Host *instance)
 #include <linux/interrupt.h>
 
 static volatile int main_running;
-static DECLARE_WORK(NCR5380_tqueue, (void (*)(void *))NCR5380_main, NULL);
+static DECLARE_WORK(NCR5380_tqueue, NCR5380_main);
 
 static inline void queue_main(void)
 {
@@ -845,7 +844,7 @@ static char *lprint_Scsi_Cmnd(Scsi_Cmnd *cmd, char *pos, char *buffer, int lengt
  *
  */
 
-static int NCR5380_init(struct Scsi_Host *instance, int flags)
+static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
 {
        int i;
        SETUP_HOSTDATA(instance);
@@ -893,45 +892,6 @@ static int NCR5380_init(struct Scsi_Host *instance, int flags)
 }
 
 /*
- * our own old-style timeout update
- */
-/*
- * The strategy is to cause the timer code to call scsi_times_out()
- * when the soonest timeout is pending.
- * The arguments are used when we are queueing a new command, because
- * we do not want to subtract the time used from this time, but when we
- * set the timer, we want to take this value into account.
- */
-
-int atari_scsi_update_timeout(Scsi_Cmnd * SCset, int timeout)
-{
-       int rtn;
-
-       /*
-        * We are using the new error handling code to actually register/deregister
-        * timers for timeout.
-        */
-
-       if (!timer_pending(&SCset->eh_timeout))
-               rtn = 0;
-       else
-               rtn = SCset->eh_timeout.expires - jiffies;
-
-       if (timeout == 0) {
-               del_timer(&SCset->eh_timeout);
-               SCset->eh_timeout.data = (unsigned long)NULL;
-               SCset->eh_timeout.expires = 0;
-       } else {
-               if (SCset->eh_timeout.data != (unsigned long)NULL)
-                       del_timer(&SCset->eh_timeout);
-               SCset->eh_timeout.data = (unsigned long)SCset;
-               SCset->eh_timeout.expires = jiffies + timeout;
-               add_timer(&SCset->eh_timeout);
-       }
-       return rtn;
-}
-
-/*
  * Function : int NCR5380_queue_command (Scsi_Cmnd *cmd,
  *     void (*done)(Scsi_Cmnd *))
  *
@@ -955,7 +915,6 @@ static int NCR5380_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
        Scsi_Cmnd *tmp;
        int oldto;
        unsigned long flags;
-       // extern int update_timeout(Scsi_Cmnd * SCset, int timeout);
 
 #if (NDEBUG & NDEBUG_NO_WRITE)
        switch (cmd->cmnd[0]) {
@@ -977,21 +936,21 @@ static int NCR5380_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
        }
 # endif
 # ifdef NCR5380_STAT_LIMIT
-       if (cmd->request_bufflen > NCR5380_STAT_LIMIT)
+       if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
 # endif
                switch (cmd->cmnd[0]) {
                case WRITE:
                case WRITE_6:
                case WRITE_10:
                        hostdata->time_write[cmd->device->id] -= (jiffies - hostdata->timebase);
-                       hostdata->bytes_write[cmd->device->id] += cmd->request_bufflen;
+                       hostdata->bytes_write[cmd->device->id] += scsi_bufflen(cmd);
                        hostdata->pendingw++;
                        break;
                case READ:
                case READ_6:
                case READ_10:
                        hostdata->time_read[cmd->device->id] -= (jiffies - hostdata->timebase);
-                       hostdata->bytes_read[cmd->device->id] += cmd->request_bufflen;
+                       hostdata->bytes_read[cmd->device->id] += scsi_bufflen(cmd);
                        hostdata->pendingr++;
                        break;
                }
@@ -1002,7 +961,7 @@ static int NCR5380_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
         * in a queue
         */
 
-       NEXT(cmd) = NULL;
+       SET_NEXT(cmd, NULL);
        cmd->scsi_done = done;
 
        cmd->result = 0;
@@ -1028,20 +987,20 @@ static int NCR5380_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
         * alter queues and touch the lock.
         */
        if (!IS_A_TT()) {
-               oldto = atari_scsi_update_timeout(cmd, 0);
+               /* perhaps stop command timer here */
                falcon_get_lock();
-               atari_scsi_update_timeout(cmd, oldto);
+               /* perhaps restart command timer here */
        }
        if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) {
                LIST(cmd, hostdata->issue_queue);
-               NEXT(cmd) = hostdata->issue_queue;
+               SET_NEXT(cmd, hostdata->issue_queue);
                hostdata->issue_queue = cmd;
        } else {
                for (tmp = (Scsi_Cmnd *)hostdata->issue_queue;
                     NEXT(tmp); tmp = NEXT(tmp))
                        ;
                LIST(cmd, tmp);
-               NEXT(tmp) = cmd;
+               SET_NEXT(tmp, cmd);
        }
        local_irq_restore(flags);
 
@@ -1074,7 +1033,7 @@ static int NCR5380_queue_command(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
  *  reenable them.  This prevents reentrancy and kernel stack overflow.
  */
 
-static void NCR5380_main(void *bl)
+static void NCR5380_main(struct work_struct *work)
 {
        Scsi_Cmnd *tmp, *prev;
        struct Scsi_Host *instance = first_instance;
@@ -1149,12 +1108,12 @@ static void NCR5380_main(void *bl)
                                        local_irq_disable();
                                        if (prev) {
                                                REMOVE(prev, NEXT(prev), tmp, NEXT(tmp));
-                                               NEXT(prev) = NEXT(tmp);
+                                               SET_NEXT(prev, NEXT(tmp));
                                        } else {
                                                REMOVE(-1, hostdata->issue_queue, tmp, NEXT(tmp));
                                                hostdata->issue_queue = NEXT(tmp);
                                        }
-                                       NEXT(tmp) = NULL;
+                                       SET_NEXT(tmp, NULL);
                                        falcon_dont_release++;
 
                                        /* reenable interrupts after finding one */
@@ -1192,7 +1151,7 @@ static void NCR5380_main(void *bl)
                                        } else {
                                                local_irq_disable();
                                                LIST(tmp, hostdata->issue_queue);
-                                               NEXT(tmp) = hostdata->issue_queue;
+                                               SET_NEXT(tmp, hostdata->issue_queue);
                                                hostdata->issue_queue = tmp;
 #ifdef SUPPORT_TAGS
                                                cmd_free_tag(tmp);
@@ -1393,21 +1352,21 @@ static irqreturn_t NCR5380_intr(int irq, void *dev_id)
 static void collect_stats(struct NCR5380_hostdata* hostdata, Scsi_Cmnd *cmd)
 {
 # ifdef NCR5380_STAT_LIMIT
-       if (cmd->request_bufflen > NCR5380_STAT_LIMIT)
+       if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
 # endif
                switch (cmd->cmnd[0]) {
                case WRITE:
                case WRITE_6:
                case WRITE_10:
                        hostdata->time_write[cmd->device->id] += (jiffies - hostdata->timebase);
-                       /*hostdata->bytes_write[cmd->device->id] += cmd->request_bufflen;*/
+                       /*hostdata->bytes_write[cmd->device->id] += scsi_bufflen(cmd);*/
                        hostdata->pendingw--;
                        break;
                case READ:
                case READ_6:
                case READ_10:
                        hostdata->time_read[cmd->device->id] += (jiffies - hostdata->timebase);
-                       /*hostdata->bytes_read[cmd->device->id] += cmd->request_bufflen;*/
+                       /*hostdata->bytes_read[cmd->device->id] += scsi_bufflen(cmd);*/
                        hostdata->pendingr--;
                        break;
                }
@@ -1909,7 +1868,7 @@ static int do_abort(struct Scsi_Host *host)
         * the target sees, so we just handshake.
         */
 
-       while (!(tmp = NCR5380_read(STATUS_REG)) & SR_REQ)
+       while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ))
                ;
 
        NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
@@ -2080,7 +2039,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                sink = 1;
                                do_abort(instance);
                                cmd->result = DID_ERROR << 16;
-                               cmd->done(cmd);
+                               cmd->scsi_done(cmd);
                                return;
 #endif
                        case PHASE_DATAIN:
@@ -2093,8 +2052,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                        ++cmd->SCp.buffer;
                                        --cmd->SCp.buffers_residual;
                                        cmd->SCp.this_residual = cmd->SCp.buffer->length;
-                                       cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) +
-                                                  cmd->SCp.buffer->offset;
+                                       cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
                                        /* ++roman: Try to merge some scatter-buffers if
                                         * they are at contiguous physical addresses.
                                         */
@@ -2139,7 +2097,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                                sink = 1;
                                                do_abort(instance);
                                                cmd->result = DID_ERROR << 16;
-                                               cmd->done(cmd);
+                                               cmd->scsi_done(cmd);
                                                /* XXX - need to source or sink data here, as appropriate */
                                        } else {
 #ifdef REAL_DMA
@@ -2274,28 +2232,21 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                                cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
 
 #ifdef AUTOSENSE
+                                       if ((cmd->cmnd[0] == REQUEST_SENSE) &&
+                                               hostdata->ses.cmd_len) {
+                                               scsi_eh_restore_cmnd(cmd, &hostdata->ses);
+                                               hostdata->ses.cmd_len = 0 ;
+                                       }
+
                                        if ((cmd->cmnd[0] != REQUEST_SENSE) &&
                                            (status_byte(cmd->SCp.Status) == CHECK_CONDITION)) {
+                                               scsi_eh_prep_cmnd(cmd, &hostdata->ses, NULL, 0, ~0);
+
                                                ASEN_PRINTK("scsi%d: performing request sense\n", HOSTNO);
-                                               cmd->cmnd[0] = REQUEST_SENSE;
-                                               cmd->cmnd[1] &= 0xe0;
-                                               cmd->cmnd[2] = 0;
-                                               cmd->cmnd[3] = 0;
-                                               cmd->cmnd[4] = sizeof(cmd->sense_buffer);
-                                               cmd->cmnd[5] = 0;
-                                               cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]);
-
-                                               cmd->use_sg = 0;
-                                               /* this is initialized from initialize_SCp
-                                               cmd->SCp.buffer = NULL;
-                                               cmd->SCp.buffers_residual = 0;
-                                               */
-                                               cmd->request_buffer = (char *) cmd->sense_buffer;
-                                               cmd->request_bufflen = sizeof(cmd->sense_buffer);
 
                                                local_irq_save(flags);
                                                LIST(cmd,hostdata->issue_queue);
-                                               NEXT(cmd) = hostdata->issue_queue;
+                                               SET_NEXT(cmd, hostdata->issue_queue);
                                                hostdata->issue_queue = (Scsi_Cmnd *) cmd;
                                                local_irq_restore(flags);
                                                QU_PRINTK("scsi%d: REQUEST SENSE added to head of "
@@ -2357,7 +2308,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
                                        local_irq_save(flags);
                                        cmd->device->disconnect = 1;
                                        LIST(cmd,hostdata->disconnected_queue);
-                                       NEXT(cmd) = hostdata->disconnected_queue;
+                                       SET_NEXT(cmd, hostdata->disconnected_queue);
                                        hostdata->connected = NULL;
                                        hostdata->disconnected_queue = cmd;
                                        local_irq_restore(flags);
@@ -2632,12 +2583,12 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
                        falcon_dont_release++;
                        if (prev) {
                                REMOVE(prev, NEXT(prev), tmp, NEXT(tmp));
-                               NEXT(prev) = NEXT(tmp);
+                               SET_NEXT(prev, NEXT(tmp));
                        } else {
                                REMOVE(-1, hostdata->disconnected_queue, tmp, NEXT(tmp));
                                hostdata->disconnected_queue = NEXT(tmp);
                        }
-                       NEXT(tmp) = NULL;
+                       SET_NEXT(tmp, NULL);
                        break;
                }
        }
@@ -2769,7 +2720,7 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
                if (cmd == tmp) {
                        REMOVE(5, *prev, tmp, NEXT(tmp));
                        (*prev) = NEXT(tmp);
-                       NEXT(tmp) = NULL;
+                       SET_NEXT(tmp, NULL);
                        tmp->result = DID_ABORT << 16;
                        local_irq_restore(flags);
                        ABRT_PRINTK("scsi%d: abort removed command from issue queue.\n",
@@ -2844,7 +2795,7 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
                                if (cmd == tmp) {
                                        REMOVE(5, *prev, tmp, NEXT(tmp));
                                        *prev = NEXT(tmp);
-                                       NEXT(tmp) = NULL;
+                                       SET_NEXT(tmp, NULL);
                                        tmp->result = DID_ABORT << 16;
                                        /* We must unlock the tag/LUN immediately here, since the
                                         * target goes to BUS FREE and doesn't send us another
@@ -2875,8 +2826,7 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
         */
 
        local_irq_restore(flags);
-       printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully\n"
-              KERN_INFO "        before abortion\n", HOSTNO);
+       printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully before abortion\n", HOSTNO);
 
        /* Maybe it is sufficient just to release the ST-DMA lock... (if
         * possible at all) At least, we should check if the lock could be
@@ -2965,7 +2915,7 @@ static int NCR5380_bus_reset(Scsi_Cmnd *cmd)
 
        for (i = 0; (cmd = disconnected_queue); ++i) {
                disconnected_queue = NEXT(cmd);
-               NEXT(cmd) = NULL;
+               SET_NEXT(cmd, NULL);
                cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
                cmd->scsi_done(cmd);
        }