Staging: cpc-usb: fix some build problems in the driver
[firefly-linux-kernel-4.4.55.git] / drivers / block / cciss.c
index 2d128831d3cae58ba1121ccb702918637092f0f8..c7a527c08a0980d542c1fffbd30687bbc95289d0 100644 (file)
@@ -38,7 +38,6 @@
 #include <linux/hdreg.h>
 #include <linux/spinlock.h>
 #include <linux/compat.h>
-#include <linux/blktrace_api.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
@@ -184,6 +183,9 @@ static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size,
 static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
                        __u8 page_code, unsigned char scsi3addr[],
                        int cmd_type);
+static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
+       int attempt_retry);
+static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c);
 
 static void fail_all_cmds(unsigned long ctlr);
 static int scan_thread(void *data);
@@ -2292,26 +2294,12 @@ static int check_target_status(ctlr_info_t *h, CommandList_struct *c)
        return IO_ERROR;
 }
 
-static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c)
+static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c)
 {
-       DECLARE_COMPLETION_ONSTACK(wait);
-       u64bit buff_dma_handle;
-       unsigned long flags;
        int return_status = IO_OK;
 
-resend_cmd2:
-       c->waiting = &wait;
-       /* Put the request on the tail of the queue and send it */
-       spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
-       addQ(&h->reqQ, c);
-       h->Qdepth++;
-       start_io(h);
-       spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
-
-       wait_for_completion(&wait);
-
-       if (c->err_info->CommandStatus == 0)
-               goto command_done;
+       if (c->err_info->CommandStatus == CMD_SUCCESS)
+               return IO_OK;
 
        switch (c->err_info->CommandStatus) {
        case CMD_TARGET_STATUS:
@@ -2322,7 +2310,7 @@ resend_cmd2:
                /* expected for inquiry and report lun commands */
                break;
        case CMD_INVALID:
-               printk(KERN_WARNING "cciss: Cmd 0x%02x is "
+               printk(KERN_WARNING "cciss: cmd 0x%02x is "
                       "reported invalid\n", c->Request.CDB[0]);
                return_status = IO_ERROR;
                break;
@@ -2355,19 +2343,7 @@ resend_cmd2:
                printk(KERN_WARNING
                       "cciss%d: unsolicited abort 0x%02x\n", h->ctlr,
                        c->Request.CDB[0]);
-               if (c->retry_count < MAX_CMD_RETRIES) {
-                       printk(KERN_WARNING
-                              "cciss%d: retrying 0x%02x\n", h->ctlr,
-                               c->Request.CDB[0]);
-                       c->retry_count++;
-                       /* erase the old error information */
-                       memset(c->err_info, 0,
-                              sizeof(ErrorInfo_struct));
-                       return_status = IO_OK;
-                       INIT_COMPLETION(wait);
-                       goto resend_cmd2;
-               }
-               return_status = IO_ERROR;
+               return_status = IO_NEEDS_RETRY;
                break;
        default:
                printk(KERN_WARNING "cciss: cmd 0x%02x returned "
@@ -2375,6 +2351,44 @@ resend_cmd2:
                       c->err_info->CommandStatus);
                return_status = IO_ERROR;
        }
+       return return_status;
+}
+
+static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
+       int attempt_retry)
+{
+       DECLARE_COMPLETION_ONSTACK(wait);
+       u64bit buff_dma_handle;
+       unsigned long flags;
+       int return_status = IO_OK;
+
+resend_cmd2:
+       c->waiting = &wait;
+       /* Put the request on the tail of the queue and send it */
+       spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
+       addQ(&h->reqQ, c);
+       h->Qdepth++;
+       start_io(h);
+       spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
+
+       wait_for_completion(&wait);
+
+       if (c->err_info->CommandStatus == 0 || !attempt_retry)
+               goto command_done;
+
+       return_status = process_sendcmd_error(h, c);
+
+       if (return_status == IO_NEEDS_RETRY &&
+               c->retry_count < MAX_CMD_RETRIES) {
+               printk(KERN_WARNING "cciss%d: retrying 0x%02x\n", h->ctlr,
+                       c->Request.CDB[0]);
+               c->retry_count++;
+               /* erase the old error information */
+               memset(c->err_info, 0, sizeof(ErrorInfo_struct));
+               return_status = IO_OK;
+               INIT_COMPLETION(wait);
+               goto resend_cmd2;
+       }
 
 command_done:
        /* unlock the buffers from DMA */
@@ -2399,7 +2413,8 @@ static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
        return_status = fill_cmd(c, cmd, ctlr, buff, size, page_code,
                scsi3addr, cmd_type);
        if (return_status == IO_OK)
-               return_status = sendcmd_withirq_core(h, c);
+               return_status = sendcmd_withirq_core(h, c, 1);
+
        cmd_free(h, c, 0);
        return return_status;
 }
@@ -2596,51 +2611,6 @@ static unsigned long pollcomplete(int ctlr)
        return 1;
 }
 
-static int add_sendcmd_reject(__u8 cmd, int ctlr, unsigned long complete)
-{
-       /* We get in here if sendcmd() is polling for completions
-          and gets some command back that it wasn't expecting --
-          something other than that which it just sent down.
-          Ordinarily, that shouldn't happen, but it can happen when
-          the scsi tape stuff gets into error handling mode, and
-          starts using sendcmd() to try to abort commands and
-          reset tape drives.  In that case, sendcmd may pick up
-          completions of commands that were sent to logical drives
-          through the block i/o system, or cciss ioctls completing, etc.
-          In that case, we need to save those completions for later
-          processing by the interrupt handler.
-        */
-
-#ifdef CONFIG_CISS_SCSI_TAPE
-       struct sendcmd_reject_list *srl = &hba[ctlr]->scsi_rejects;
-
-       /* If it's not the scsi tape stuff doing error handling, (abort */
-       /* or reset) then we don't expect anything weird. */
-       if (cmd != CCISS_RESET_MSG && cmd != CCISS_ABORT_MSG) {
-#endif
-               printk(KERN_WARNING "cciss cciss%d: SendCmd "
-                      "Invalid command list address returned! (%lx)\n",
-                      ctlr, complete);
-               /* not much we can do. */
-#ifdef CONFIG_CISS_SCSI_TAPE
-               return 1;
-       }
-
-       /* We've sent down an abort or reset, but something else
-          has completed */
-       if (srl->ncompletions >= (hba[ctlr]->nr_cmds + 2)) {
-               /* Uh oh.  No room to save it for later... */
-               printk(KERN_WARNING "cciss%d: Sendcmd: Invalid command addr, "
-                      "reject list overflow, command lost!\n", ctlr);
-               return 1;
-       }
-       /* Save it for later */
-       srl->complete[srl->ncompletions] = complete;
-       srl->ncompletions++;
-#endif
-       return 0;
-}
-
 /* Send command c to controller h and poll for it to complete.
  * Turns interrupts off on the board.  Used at driver init time
  * and during SCSI error recovery.
@@ -2685,11 +2655,10 @@ resend_cmd1:
                        break;
                }
 
-               /* If it's not the cmd we're looking for, save it for later */
+               /* Make sure it's the command we're expecting. */
                if ((complete & ~CISS_ERROR_BIT) != c->busaddr) {
-                       if (add_sendcmd_reject(c->Request.CDB[0],
-                               h->ctlr, complete) != 0)
-                               BUG(); /* we are hosed if we get here. */
+                       printk(KERN_WARNING "cciss%d: Unexpected command "
+                               "completion.\n", h->ctlr);
                        continue;
                }
 
@@ -2754,11 +2723,6 @@ resend_cmd1:
        buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
        pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val,
                         c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
-#ifdef CONFIG_CISS_SCSI_TAPE
-       /* if we saved some commands for later, process them now. */
-       if (h->scsi_rejects.ncompletions > 0)
-               do_cciss_intr(0, h);
-#endif
        return status;
 }
 
@@ -3179,44 +3143,18 @@ startio:
 
 static inline unsigned long get_next_completion(ctlr_info_t *h)
 {
-#ifdef CONFIG_CISS_SCSI_TAPE
-       /* Any rejects from sendcmd() lying around? Process them first */
-       if (h->scsi_rejects.ncompletions == 0)
-               return h->access.command_completed(h);
-       else {
-               struct sendcmd_reject_list *srl;
-               int n;
-               srl = &h->scsi_rejects;
-               n = --srl->ncompletions;
-               /* printk("cciss%d: processing saved reject\n", h->ctlr); */
-               printk("p");
-               return srl->complete[n];
-       }
-#else
        return h->access.command_completed(h);
-#endif
 }
 
 static inline int interrupt_pending(ctlr_info_t *h)
 {
-#ifdef CONFIG_CISS_SCSI_TAPE
-       return (h->access.intr_pending(h)
-               || (h->scsi_rejects.ncompletions > 0));
-#else
        return h->access.intr_pending(h);
-#endif
 }
 
 static inline long interrupt_not_for_us(ctlr_info_t *h)
 {
-#ifdef CONFIG_CISS_SCSI_TAPE
-       return (((h->access.intr_pending(h) == 0) ||
-                (h->interrupts_enabled == 0))
-               && (h->scsi_rejects.ncompletions == 0));
-#else
        return (((h->access.intr_pending(h) == 0) ||
                 (h->interrupts_enabled == 0)));
-#endif
 }
 
 static irqreturn_t do_cciss_intr(int irq, void *dev_id)
@@ -4038,15 +3976,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
                printk(KERN_ERR "cciss: out of memory");
                goto clean4;
        }
-#ifdef CONFIG_CISS_SCSI_TAPE
-       hba[i]->scsi_rejects.complete =
-           kmalloc(sizeof(hba[i]->scsi_rejects.complete[0]) *
-                   (hba[i]->nr_cmds + 5), GFP_KERNEL);
-       if (hba[i]->scsi_rejects.complete == NULL) {
-               printk(KERN_ERR "cciss: out of memory");
-               goto clean4;
-       }
-#endif
        spin_lock_init(&hba[i]->lock);
 
        /* Initialize the pdev driver private data.
@@ -4106,9 +4035,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
 
 clean4:
        kfree(inq_buff);
-#ifdef CONFIG_CISS_SCSI_TAPE
-       kfree(hba[i]->scsi_rejects.complete);
-#endif
        kfree(hba[i]->cmd_pool_bits);
        if (hba[i]->cmd_pool)
                pci_free_consistent(hba[i]->pdev,
@@ -4226,9 +4152,6 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
        pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct),
                            hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle);
        kfree(hba[i]->cmd_pool_bits);
-#ifdef CONFIG_CISS_SCSI_TAPE
-       kfree(hba[i]->scsi_rejects.complete);
-#endif
        /*
         * Deliberately omit pci_disable_device(): it does something nasty to
         * Smart Array controllers that pci_enable_device does not undo