From patchwork Wed May 9 15:10:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 135295 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp5761261lji; Wed, 9 May 2018 08:13:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqwcZcekq6CZE6SXXfYQH9/8GtvP6HB37fAtrkr0x4ZV4aevLfNsz8YKJFWbBHRf3KxT+rb X-Received: by 2002:a63:9511:: with SMTP id p17-v6mr18244118pgd.132.1525878791461; Wed, 09 May 2018 08:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525878791; cv=none; d=google.com; s=arc-20160816; b=Totc5NECQRe3KWCoMjN+zjNukz9+m1NxTbcxBt6gmOfDa8SiaD/LB3d4YzPqYfsvWf WrPIKKFqdOFnr2aCJzbfAeBVicXfnbLxrt+nALGQbpfrCuLdof23HHQL8KA4ZVy0lYvK v2qNg0ypkbmQ804jLFgvqeo1QBhalqPqrQQkifJNPoSfVo+NpLW2k8kY6lFd79rdCD7C dIZRSi4R0faSGbZjX1TGlXb75opBVaBhf2q3yvK6uTF5S1urMbWtmCjj5PO0ua/i+e4a b7Lwq1UppYYXTjAYvw5dY+EiRTvR/T7byLMuWSq0/DXAIgJ2oSOqVdHdYLQoSwL4IVoK V3cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=WqvKv1/tpj5usA6OTJxq+y2hGc5y33N9r8KDkAx9s0w=; b=v9q92KATxo3N+HKUisnLJF/EiYBU6LteayNL3wk+oJyh4zJw+QBtTJzIOwkBKG8z4w ZnNMtIT7w6+mbbr1a6nA+i18sncSUkAtYTQDr6Pc/SzrplHJ2rQfxyXxRPnyvcBkPzZT N3De5mxKefQAw2epb5Y8mivV7WIeO9oZOie8UWnRcowFuh3kWldj9QpPAh3+ypcWIuY6 uPf/XV1WW5WZx0E737o9ffvhvs5xjOD4V3Egcl6E2DIf7m5WtdJflSy5dv1UdN0Be4VL aMb+bgvJdwTZF2PnRaTMvNzuJxNQyKAYE5X2b5FgM4KWVnQ0ISUott4b3aJVAhlQLRog +ycA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2-v6si2594564pgn.453.2018.05.09.08.13.11; Wed, 09 May 2018 08:13:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964951AbeEIPNI (ORCPT + 29 others); Wed, 9 May 2018 11:13:08 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:47136 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S964844AbeEIPMQ (ORCPT ); Wed, 9 May 2018 11:12:16 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 5D2742C91FA5A; Wed, 9 May 2018 23:12:08 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.361.1; Wed, 9 May 2018 23:12:00 +0800 From: John Garry To: , CC: , , , Xiang Chen , "John Garry" Subject: [PATCH 5/6] scsi: hisi_sas: Use device lock to protect slot alloc/free Date: Wed, 9 May 2018 23:10:49 +0800 Message-ID: <1525878650-213087-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525878650-213087-1-git-send-email-john.garry@huawei.com> References: <1525878650-213087-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiang Chen The IPTT of a slot is unique, and we currently use hisi_hba lock to protect it. Now slot is managed on hisi_sas_device.list, so use DQ lock to protect for allocating and freeing the slot. Signed-off-by: Xiang Chen Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 56 ++++++++++------------------------ drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 3 -- 2 files changed, 16 insertions(+), 43 deletions(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index bf374a7..a451625 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -214,6 +214,8 @@ static void hisi_sas_slot_index_init(struct hisi_hba *hisi_hba) void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task, struct hisi_sas_slot *slot) { + struct hisi_sas_dq *dq = &hisi_hba->dq[slot->dlvry_queue]; + unsigned long flags; if (task) { struct device *dev = hisi_hba->dev; @@ -233,11 +235,15 @@ void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task, if (slot->buf) dma_pool_free(hisi_hba->buffer_pool, slot->buf, slot->buf_dma); + spin_lock_irqsave(&dq->lock, flags); list_del_init(&slot->entry); + spin_unlock_irqrestore(&dq->lock, flags); slot->buf = NULL; slot->task = NULL; slot->port = NULL; + spin_lock_irqsave(&hisi_hba->lock, flags); hisi_sas_slot_index_free(hisi_hba, slot->idx); + spin_unlock_irqrestore(&hisi_hba->lock, flags); /* slot memory is fully zeroed when it is reused */ } @@ -286,7 +292,6 @@ static void hisi_sas_slot_abort(struct work_struct *work) struct scsi_lun lun; struct device *dev = hisi_hba->dev; int tag = abort_slot->idx; - unsigned long flags; if (!(task->task_proto & SAS_PROTOCOL_SSP)) { dev_err(dev, "cannot abort slot for non-ssp task\n"); @@ -300,9 +305,7 @@ static void hisi_sas_slot_abort(struct work_struct *work) hisi_sas_debug_issue_ssp_tmf(task->dev, lun.scsi_lun, &tmf_task); out: /* Do cleanup for this task */ - spin_lock_irqsave(&hisi_hba->lock, flags); hisi_sas_slot_task_free(hisi_hba, task, abort_slot); - spin_unlock_irqrestore(&hisi_hba->lock, flags); if (task->task_done) task->task_done(task); } @@ -471,9 +474,9 @@ static int hisi_sas_task_prep(struct sas_task *task, struct hisi_sas_dq *dq, break; } - spin_lock_irqsave(&hisi_hba->lock, flags); + spin_lock_irqsave(&dq->lock, flags); list_add_tail(&slot->entry, &sas_dev->list); - spin_unlock_irqrestore(&hisi_hba->lock, flags); + spin_unlock_irqrestore(&dq->lock, flags); spin_lock_irqsave(&task->task_state_lock, flags); task->task_state_flags |= SAS_TASK_AT_INITIATOR; spin_unlock_irqrestore(&task->task_state_lock, flags); @@ -1047,7 +1050,6 @@ static int hisi_sas_softreset_ata_disk(struct domain_device *device) struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); struct device *dev = hisi_hba->dev; int s = sizeof(struct host_to_dev_fis); - unsigned long flags; ata_for_each_link(link, ap, EDGE) { int pmp = sata_srst_pmp(link); @@ -1072,11 +1074,8 @@ static int hisi_sas_softreset_ata_disk(struct domain_device *device) dev_err(dev, "ata disk reset failed\n"); } - if (rc == TMF_RESP_FUNC_COMPLETE) { - spin_lock_irqsave(&hisi_hba->lock, flags); + if (rc == TMF_RESP_FUNC_COMPLETE) hisi_sas_release_task(hisi_hba, device); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - } return rc; } @@ -1173,7 +1172,6 @@ static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba) struct device *dev = hisi_hba->dev; struct Scsi_Host *shost = hisi_hba->shost; u32 old_state, state; - unsigned long flags; int rc; if (!hisi_hba->hw->soft_reset) @@ -1197,9 +1195,7 @@ static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba) scsi_unblock_requests(shost); goto out; } - spin_lock_irqsave(&hisi_hba->lock, flags); hisi_sas_release_tasks(hisi_hba); - spin_unlock_irqrestore(&hisi_hba->lock, flags); clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); @@ -1274,11 +1270,8 @@ static int hisi_sas_abort_task(struct sas_task *task) * will have already been completed */ if (rc == TMF_RESP_FUNC_COMPLETE && rc2 != TMF_RESP_FUNC_SUCC) { - if (task->lldd_task) { - spin_lock_irqsave(&hisi_hba->lock, flags); + if (task->lldd_task) hisi_sas_do_release_task(hisi_hba, task, slot); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - } } } else if (task->task_proto & SAS_PROTOCOL_SATA || task->task_proto & SAS_PROTOCOL_STP) { @@ -1300,11 +1293,8 @@ static int hisi_sas_abort_task(struct sas_task *task) rc = hisi_sas_internal_task_abort(hisi_hba, device, HISI_SAS_INT_ABT_CMD, tag); if (((rc < 0) || (rc == TMF_RESP_FUNC_FAILED)) && - task->lldd_task) { - spin_lock_irqsave(&hisi_hba->lock, flags); + task->lldd_task) hisi_sas_do_release_task(hisi_hba, task, slot); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - } } out: @@ -1319,7 +1309,6 @@ static int hisi_sas_abort_task_set(struct domain_device *device, u8 *lun) struct device *dev = hisi_hba->dev; struct hisi_sas_tmf_task tmf_task; int rc = TMF_RESP_FUNC_FAILED; - unsigned long flags; rc = hisi_sas_internal_task_abort(hisi_hba, device, HISI_SAS_INT_ABT_DEV, 0); @@ -1332,11 +1321,8 @@ static int hisi_sas_abort_task_set(struct domain_device *device, u8 *lun) tmf_task.tmf = TMF_ABORT_TASK_SET; rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task); - if (rc == TMF_RESP_FUNC_COMPLETE) { - spin_lock_irqsave(&hisi_hba->lock, flags); + if (rc == TMF_RESP_FUNC_COMPLETE) hisi_sas_release_task(hisi_hba, device); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - } return rc; } @@ -1369,7 +1355,6 @@ static int hisi_sas_I_T_nexus_reset(struct domain_device *device) struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); struct device *dev = hisi_hba->dev; int rc = TMF_RESP_FUNC_FAILED; - unsigned long flags; if (sas_dev->dev_status != HISI_SAS_DEV_EH) return TMF_RESP_FUNC_FAILED; @@ -1385,11 +1370,9 @@ static int hisi_sas_I_T_nexus_reset(struct domain_device *device) rc = hisi_sas_debug_I_T_nexus_reset(device); - if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV)) { - spin_lock_irqsave(&hisi_hba->lock, flags); + if ((rc == TMF_RESP_FUNC_COMPLETE) || (rc == -ENODEV)) hisi_sas_release_task(hisi_hba, device); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - } + return rc; } @@ -1398,7 +1381,6 @@ static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun) struct hisi_sas_device *sas_dev = device->lldd_dev; struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); struct device *dev = hisi_hba->dev; - unsigned long flags; int rc = TMF_RESP_FUNC_FAILED; sas_dev->dev_status = HISI_SAS_DEV_EH; @@ -1418,11 +1400,8 @@ static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun) rc = sas_phy_reset(phy, 1); - if (rc == 0) { - spin_lock_irqsave(&hisi_hba->lock, flags); + if (rc == 0) hisi_sas_release_task(hisi_hba, device); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - } sas_put_local_phy(phy); } else { struct hisi_sas_tmf_task tmf_task = { .tmf = TMF_LU_RESET }; @@ -1436,11 +1415,8 @@ static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun) hisi_sas_dereg_device(hisi_hba, device); rc = hisi_sas_debug_issue_ssp_tmf(device, lun, &tmf_task); - if (rc == TMF_RESP_FUNC_COMPLETE) { - spin_lock_irqsave(&hisi_hba->lock, flags); + if (rc == TMF_RESP_FUNC_COMPLETE) hisi_sas_release_task(hisi_hba, device); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - } } out: if (rc != TMF_RESP_FUNC_COMPLETE) diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 56f1046..c013673 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -2373,7 +2373,6 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state) u32 device_state, status; int rc; u32 reg_val; - unsigned long flags; if (!pdev->pm_cap) { dev_err(dev, "PCI PM not supported\n"); @@ -2418,9 +2417,7 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state) pci_disable_device(pdev); pci_set_power_state(pdev, device_state); - spin_lock_irqsave(&hisi_hba->lock, flags); hisi_sas_release_tasks(hisi_hba); - spin_unlock_irqrestore(&hisi_hba->lock, flags); sas_suspend_ha(sha); return 0;