Merge branch 'fixes' into misc
[cascardo/linux.git] / drivers / scsi / be2iscsi / be_main.c
index 03265b6..f05e773 100644 (file)
@@ -1132,6 +1132,7 @@ static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
 {
        struct sgl_handle *psgl_handle;
 
+       spin_lock_bh(&phba->io_sgl_lock);
        if (phba->io_sgl_hndl_avbl) {
                beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
                            "BM_%d : In alloc_io_sgl_handle,"
@@ -1149,12 +1150,14 @@ static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
                        phba->io_sgl_alloc_index++;
        } else
                psgl_handle = NULL;
+       spin_unlock_bh(&phba->io_sgl_lock);
        return psgl_handle;
 }
 
 static void
 free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
 {
+       spin_lock_bh(&phba->io_sgl_lock);
        beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
                    "BM_%d : In free_,io_sgl_free_index=%d\n",
                    phba->io_sgl_free_index);
@@ -1169,6 +1172,7 @@ free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
                             "value there=%p\n", phba->io_sgl_free_index,
                             phba->io_sgl_hndl_base
                             [phba->io_sgl_free_index]);
+                spin_unlock_bh(&phba->io_sgl_lock);
                return;
        }
        phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
@@ -1177,6 +1181,7 @@ free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
                phba->io_sgl_free_index = 0;
        else
                phba->io_sgl_free_index++;
+       spin_unlock_bh(&phba->io_sgl_lock);
 }
 
 static inline struct wrb_handle *
@@ -1185,12 +1190,14 @@ beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context,
 {
        struct wrb_handle *pwrb_handle;
 
+       spin_lock_bh(&pwrb_context->wrb_lock);
        pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index];
        pwrb_context->wrb_handles_available--;
        if (pwrb_context->alloc_index == (wrbs_per_cxn - 1))
                pwrb_context->alloc_index = 0;
        else
                pwrb_context->alloc_index++;
+       spin_unlock_bh(&pwrb_context->wrb_lock);
 
        return pwrb_handle;
 }
@@ -1222,12 +1229,14 @@ beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context,
                       struct wrb_handle *pwrb_handle,
                       unsigned int wrbs_per_cxn)
 {
+       spin_lock_bh(&pwrb_context->wrb_lock);
        pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
        pwrb_context->wrb_handles_available++;
        if (pwrb_context->free_index == (wrbs_per_cxn - 1))
                pwrb_context->free_index = 0;
        else
                pwrb_context->free_index++;
+       spin_unlock_bh(&pwrb_context->wrb_lock);
 }
 
 /**
@@ -1257,6 +1266,7 @@ static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
 {
        struct sgl_handle *psgl_handle;
 
+       spin_lock_bh(&phba->mgmt_sgl_lock);
        if (phba->eh_sgl_hndl_avbl) {
                psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
                phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
@@ -1274,13 +1284,14 @@ static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
                        phba->eh_sgl_alloc_index++;
        } else
                psgl_handle = NULL;
+       spin_unlock_bh(&phba->mgmt_sgl_lock);
        return psgl_handle;
 }
 
 void
 free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
 {
-
+       spin_lock_bh(&phba->mgmt_sgl_lock);
        beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
                    "BM_%d : In  free_mgmt_sgl_handle,"
                    "eh_sgl_free_index=%d\n",
@@ -1295,6 +1306,7 @@ free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
                            "BM_%d : Double Free in eh SGL ,"
                            "eh_sgl_free_index=%d\n",
                            phba->eh_sgl_free_index);
+               spin_unlock_bh(&phba->mgmt_sgl_lock);
                return;
        }
        phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
@@ -1304,6 +1316,7 @@ free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
                phba->eh_sgl_free_index = 0;
        else
                phba->eh_sgl_free_index++;
+       spin_unlock_bh(&phba->mgmt_sgl_lock);
 }
 
 static void
@@ -2713,8 +2726,10 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
        phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) *
                                          phba->params.cxns_per_ctrl,
                                          GFP_KERNEL);
-       if (!phwi_ctrlr->wrb_context)
+       if (!phwi_ctrlr->wrb_context) {
+               kfree(phba->phwi_ctrlr);
                return -ENOMEM;
+       }
 
        phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
                                 GFP_KERNEL);
@@ -2911,6 +2926,7 @@ static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
                        }
                        num_cxn_wrbh--;
                }
+               spin_lock_init(&pwrb_context->wrb_lock);
        }
        idx = 0;
        for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
@@ -4477,6 +4493,7 @@ put_shost:
        scsi_host_put(phba->shost);
 free_kset:
        iscsi_boot_destroy_kset(phba->boot_kset);
+       phba->boot_kset = NULL;
        return -ENOMEM;
 }
 
@@ -4616,11 +4633,9 @@ beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
        }
 
        if (io_task->psgl_handle) {
-               spin_lock_bh(&phba->mgmt_sgl_lock);
                free_mgmt_sgl_handle(phba,
                                     io_task->psgl_handle);
                io_task->psgl_handle = NULL;
-               spin_unlock_bh(&phba->mgmt_sgl_lock);
        }
 
        if (io_task->mtask_addr) {
@@ -4666,9 +4681,7 @@ static void beiscsi_cleanup_task(struct iscsi_task *task)
                }
 
                if (io_task->psgl_handle) {
-                       spin_lock(&phba->io_sgl_lock);
                        free_io_sgl_handle(phba, io_task->psgl_handle);
-                       spin_unlock(&phba->io_sgl_lock);
                        io_task->psgl_handle = NULL;
                }
 
@@ -4784,9 +4797,7 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
        io_task->pwrb_handle = NULL;
 
        if (task->sc) {
-               spin_lock(&phba->io_sgl_lock);
                io_task->psgl_handle = alloc_io_sgl_handle(phba);
-               spin_unlock(&phba->io_sgl_lock);
                if (!io_task->psgl_handle) {
                        beiscsi_log(phba, KERN_ERR,
                                    BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
@@ -4811,10 +4822,8 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
                if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
                        beiscsi_conn->task = task;
                        if (!beiscsi_conn->login_in_progress) {
-                               spin_lock(&phba->mgmt_sgl_lock);
                                io_task->psgl_handle = (struct sgl_handle *)
                                                alloc_mgmt_sgl_handle(phba);
-                               spin_unlock(&phba->mgmt_sgl_lock);
                                if (!io_task->psgl_handle) {
                                        beiscsi_log(phba, KERN_ERR,
                                                    BEISCSI_LOG_IO |
@@ -4853,9 +4862,7 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
                                                beiscsi_conn->plogin_wrb_handle;
                        }
                } else {
-                       spin_lock(&phba->mgmt_sgl_lock);
                        io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
-                       spin_unlock(&phba->mgmt_sgl_lock);
                        if (!io_task->psgl_handle) {
                                beiscsi_log(phba, KERN_ERR,
                                            BEISCSI_LOG_IO |
@@ -4890,15 +4897,11 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
        return 0;
 
 free_io_hndls:
-       spin_lock(&phba->io_sgl_lock);
        free_io_sgl_handle(phba, io_task->psgl_handle);
-       spin_unlock(&phba->io_sgl_lock);
        goto free_hndls;
 free_mgmt_hndls:
-       spin_lock(&phba->mgmt_sgl_lock);
        free_mgmt_sgl_handle(phba, io_task->psgl_handle);
        io_task->psgl_handle = NULL;
-       spin_unlock(&phba->mgmt_sgl_lock);
 free_hndls:
        phwi_ctrlr = phba->phwi_ctrlr;
        cri_index = BE_GET_CRI_FROM_CID(
@@ -5301,15 +5304,12 @@ static void beiscsi_quiesce(struct beiscsi_hba *phba,
        if (phba->msix_enabled) {
                for (i = 0; i <= phba->num_cpus; i++) {
                        msix_vec = phba->msix_entries[i].vector;
-                       synchronize_irq(msix_vec);
                        free_irq(msix_vec, &phwi_context->be_eq[i]);
                        kfree(phba->msi_name[i]);
                }
        } else
-               if (phba->pcidev->irq) {
-                       synchronize_irq(phba->pcidev->irq);
+               if (phba->pcidev->irq)
                        free_irq(phba->pcidev->irq, phba);
-               }
        pci_disable_msix(phba->pcidev);
        cancel_delayed_work_sync(&phba->beiscsi_hw_check_task);
 
@@ -5570,6 +5570,12 @@ static void beiscsi_eeh_resume(struct pci_dev *pdev)
        phba->shost->max_id = phba->params.cxns_per_ctrl;
        phba->shost->can_queue = phba->params.ios_per_ctrl;
        ret = hwi_init_controller(phba);
+       if (ret) {
+               beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
+                           "BM_%d : beiscsi_eeh_resume -"
+                            "Failed to initialize beiscsi_hba.\n");
+               goto ret_err;
+       }
 
        for (i = 0; i < MAX_MCC_CMD; i++) {
                init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);