Revert "Merge remote-tracking branch 'linux-2.6.32.y/master' into develop"
[firefly-linux-kernel-4.4.55.git] / drivers / scsi / mpt2sas / mpt2sas_base.c
index 4c583ff458db6fbda9a8513f571be687a667704e..670241efa4b555041e5b4fcb88cfe27929709d50 100644 (file)
@@ -575,9 +575,10 @@ _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  * @msix_index: MSIX table index supplied by the OS
  * @reply: reply message frame(lower 32bit addr)
  *
- * Return nothing.
+ * Return 1 meaning mf should be freed from _base_interrupt
+ *        0 means the mf is freed from this function.
  */
-void
+u8
 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
     u32 reply)
 {
@@ -585,10 +586,10 @@ mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
 
        mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
        if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
-               return;
+               return 1;
 
        if (ioc->base_cmds.status == MPT2_CMD_NOT_USED)
-               return;
+               return 1;
 
        ioc->base_cmds.status |= MPT2_CMD_COMPLETE;
        if (mpi_reply) {
@@ -597,6 +598,7 @@ mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
        }
        ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
        complete(&ioc->base_cmds.done);
+       return 1;
 }
 
 /**
@@ -605,9 +607,10 @@ mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  * @msix_index: MSIX table index supplied by the OS
  * @reply: reply message frame(lower 32bit addr)
  *
- * Return nothing.
+ * Return 1 meaning mf should be freed from _base_interrupt
+ *        0 means the mf is freed from this function.
  */
-static void
+static u8
 _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
 {
        Mpi2EventNotificationReply_t *mpi_reply;
@@ -616,9 +619,9 @@ _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
 
        mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
        if (!mpi_reply)
-               return;
+               return 1;
        if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
-               return;
+               return 1;
 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
        _base_display_event_data(ioc, mpi_reply);
 #endif
@@ -647,6 +650,8 @@ _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
 
        /* ctl callback handler */
        mpt2sas_ctl_event_callback(ioc, msix_index, reply);
+
+       return 1;
 }
 
 /**
@@ -710,7 +715,6 @@ _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
 {
        u32 him_register;
 
-       writel(0, &ioc->chip->HostInterruptStatus);
        him_register = readl(&ioc->chip->HostInterruptMask);
        him_register &= ~MPI2_HIM_RIM;
        writel(him_register, &ioc->chip->HostInterruptMask);
@@ -745,6 +749,7 @@ _base_interrupt(int irq, void *bus_id)
        u8 msix_index;
        struct MPT2SAS_ADAPTER *ioc = bus_id;
        Mpi2ReplyDescriptorsUnion_t *rpf;
+       u8 rc;
 
        if (ioc->mask_interrupts)
                return IRQ_NONE;
@@ -777,12 +782,13 @@ _base_interrupt(int irq, void *bus_id)
                if (smid)
                        cb_idx = _base_get_cb_idx(ioc, smid);
                if (smid && cb_idx != 0xFF) {
-                       mpt_callbacks[cb_idx](ioc, smid, msix_index,
+                       rc = mpt_callbacks[cb_idx](ioc, smid, msix_index,
                            reply);
                        if (reply)
                                _base_display_reply_info(ioc, smid, msix_index,
                                    reply);
-                       mpt2sas_base_free_smid(ioc, smid);
+                       if (rc)
+                               mpt2sas_base_free_smid(ioc, smid);
                }
                if (!smid)
                        _base_async_event(ioc, msix_index, reply);
@@ -2456,7 +2462,7 @@ _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes,
            ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)),
            &ioc->chip->Doorbell);
 
-       if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
+       if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) {
                printk(MPT2SAS_ERR_FMT "doorbell handshake "
                   "int failed (line=%d)\n", ioc->name, __LINE__);
                return -EFAULT;
@@ -2607,6 +2613,7 @@ mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
            mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET)
                ioc->ioc_link_reset_in_progress = 1;
        mpt2sas_base_put_smid_default(ioc, smid);
+       init_completion(&ioc->base_cmds.done);
        timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
            msecs_to_jiffies(10000));
        if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
@@ -2708,6 +2715,7 @@ mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
        ioc->base_cmds.smid = smid;
        memcpy(request, mpi_request, sizeof(Mpi2SepReply_t));
        mpt2sas_base_put_smid_default(ioc, smid);
+       init_completion(&ioc->base_cmds.done);
        timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
            msecs_to_jiffies(10000));
        if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
@@ -2984,6 +2992,7 @@ _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
        mpi_request->VP_ID = 0;
 
        mpt2sas_base_put_smid_default(ioc, smid);
+       init_completion(&ioc->base_cmds.done);
        timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
            300*HZ);
        if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
@@ -3083,6 +3092,7 @@ _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
                mpi_request->EventMasks[i] =
                    le32_to_cpu(ioc->event_masks[i]);
        mpt2sas_base_put_smid_default(ioc, smid);
+       init_completion(&ioc->base_cmds.done);
        timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ);
        if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
                printk(MPT2SAS_ERR_FMT "%s: timeout\n",
@@ -3158,7 +3168,6 @@ _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
 
        drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "clear interrupts\n",
            ioc->name));
-       writel(0, &ioc->chip->HostInterruptStatus);
 
        count = 0;
        do {
@@ -3323,10 +3332,18 @@ _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
        unsigned long   flags;
        u32 reply_address;
        u16 smid;
+       struct _tr_list *delayed_tr, *delayed_tr_next;
 
        dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name,
            __func__));
 
+       /* clean the delayed target reset list */
+       list_for_each_entry_safe(delayed_tr, delayed_tr_next,
+           &ioc->delayed_tr_list, list) {
+               list_del(&delayed_tr->list);
+               kfree(delayed_tr);
+       }
+
        /* initialize the scsi lookup free list */
        spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
        INIT_LIST_HEAD(&ioc->free_list);
@@ -3471,7 +3488,6 @@ mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
 
        /* base internal command bits */
        mutex_init(&ioc->base_cmds.mutex);
-       init_completion(&ioc->base_cmds.done);
        ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
        ioc->base_cmds.status = MPT2_CMD_NOT_USED;
 
@@ -3479,7 +3495,6 @@ mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
        ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
        ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
        mutex_init(&ioc->transport_cmds.mutex);
-       init_completion(&ioc->transport_cmds.done);
 
        /* task management internal command bits */
        ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
@@ -3495,7 +3510,6 @@ mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
        ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
        ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
        mutex_init(&ioc->ctl_cmds.mutex);
-       init_completion(&ioc->ctl_cmds.done);
 
        for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
                ioc->event_masks[i] = -1;