From patchwork Mon May 21 10:09:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 136445 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp121280lji; Mon, 21 May 2018 03:13:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqKH0mbm2RwRjXNY1TbAl3w1bQOcTZXZYAJIe7GC4glVmRYuGKY3R8XtuqvO5Wa/aU1LmhZ X-Received: by 2002:a63:bd49:: with SMTP id d9-v6mr15582719pgp.14.1526897636046; Mon, 21 May 2018 03:13:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526897636; cv=none; d=google.com; s=arc-20160816; b=U5UbYXhdA5WfFQWE+Q/oc1RVZ7AOl0pas0HbkBR6lSJGhN5bbzyYwN0glfnYcdaJBV 8ajLQ3sH0IDzLL+QEJBdCChLsSvGA40isdtyl7lq0tSgmT4dYiFrHmNc5kpIkZotc3/P 8NGvInWfbAFiZDVMLIv0G6j4Ozzm0ouJlCzM6kAoTFod/7wOIZcwpdD/AAJ0XW3w9onS 8UZg9YCKx5eUI301ksXC9glxyX+uJhA5n4xC+FQ4A4996sok57iL0YWULKm1FnLhhbkT tA73Blt6uAHyFBgzfXKN3XEY08rtVHIW5rdCxuEuLqJqMRCPTG9V8suouY1xDFCXbajs mP8Q== 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=9uEsBrwhm8lgUCyDX6BYZ5lG4LXchBRItfi8rr1fIf4=; b=q/8xC3gWWmGfYQMTmbSwtFY3JI5ZvAeLvhs/PimXg98iL8Pd9gWQN7TxXAQCuVcjNj 4OiaArCbBrIJJtJd52Tn2zVHQ9+QKOCGp+AXiDnOwrY3gWdXZEzm5T2Rva54TCeW2Voa Dkklld5lEjZDWy3YATIvb52+goyDIwAP6VyiaBZL3fPljigoTcfK75coUz4G2n1pWCgU mVSpM+9DJZgY9VFPfvhVr4DXfXelHw3+RVjOYHYa2XvkgsPrYVZqmdT89x4qGBLG+Q4X CBz79RlHg1i37kMHL3tTCPFY02KBf33cCrYFdjCa8665U9KnIc8sgF6KU1xkYoOF8YMy l5JA== 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 h187-v6si11111420pgc.540.2018.05.21.03.13.55; Mon, 21 May 2018 03:13:56 -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 S1752731AbeEUKNx (ORCPT + 29 others); Mon, 21 May 2018 06:13:53 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:55794 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752631AbeEUKLn (ORCPT ); Mon, 21 May 2018 06:11:43 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8D561FE75B18D; Mon, 21 May 2018 18:11:35 +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.382.0; Mon, 21 May 2018 18:11:30 +0800 From: John Garry To: , CC: , , , Xiang Chen , Xiaofei Tan , John Garry Subject: [PATCH 05/13] scsi: hisi_sas: Reset disks when discovered Date: Mon, 21 May 2018 18:09:17 +0800 Message-ID: <1526897365-228549-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1526897365-228549-1-git-send-email-john.garry@huawei.com> References: <1526897365-228549-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 When a disk is discovered, it may be in an error state, or there may be residual commands remaining in the disk. To ensure any disk is in good state after discovery, reset via TMF (for SAS disk) or softreset (for a SATA disk). Signed-off-by: Xiang Chen Signed-off-by: Xiaofei Tan Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 50 ++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 04a3eb4..0596553 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -24,6 +24,9 @@ static int hisi_sas_debug_issue_ssp_tmf(struct domain_device *device, static int hisi_sas_softreset_ata_disk(struct domain_device *device); static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func, void *funcdata); +static void hisi_sas_release_task(struct hisi_hba *hisi_hba, + struct domain_device *device); +static void hisi_sas_dev_gone(struct domain_device *device); u8 hisi_sas_get_ata_protocol(struct host_to_dev_fis *fis, int direction) { @@ -624,12 +627,49 @@ static struct hisi_sas_device *hisi_sas_alloc_dev(struct domain_device *device) return sas_dev; } +#define HISI_SAS_SRST_ATA_DISK_CNT 3 +static int hisi_sas_init_device(struct domain_device *device) +{ + int rc = TMF_RESP_FUNC_COMPLETE; + struct scsi_lun lun; + struct hisi_sas_tmf_task tmf_task; + int retry = HISI_SAS_SRST_ATA_DISK_CNT; + struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); + + switch (device->dev_type) { + case SAS_END_DEVICE: + int_to_scsilun(0, &lun); + + tmf_task.tmf = TMF_CLEAR_TASK_SET; + rc = hisi_sas_debug_issue_ssp_tmf(device, lun.scsi_lun, + &tmf_task); + if (rc == TMF_RESP_FUNC_COMPLETE) + hisi_sas_release_task(hisi_hba, device); + break; + case SAS_SATA_DEV: + case SAS_SATA_PM: + case SAS_SATA_PM_PORT: + case SAS_SATA_PENDING: + while (retry-- > 0) { + rc = hisi_sas_softreset_ata_disk(device); + if (!rc) + break; + } + break; + default: + break; + } + + return rc; +} + static int hisi_sas_dev_found(struct domain_device *device) { struct hisi_hba *hisi_hba = dev_to_hisi_hba(device); struct domain_device *parent_dev = device->parent; struct hisi_sas_device *sas_dev; struct device *dev = hisi_hba->dev; + int rc; if (hisi_hba->hw->alloc_dev) sas_dev = hisi_hba->hw->alloc_dev(device); @@ -661,14 +701,22 @@ static int hisi_sas_dev_found(struct domain_device *device) "dev:%016llx at ex:%016llx\n", SAS_ADDR(device->sas_addr), SAS_ADDR(parent_dev->sas_addr)); - return -EINVAL; + rc = -EINVAL; + goto err_out; } } dev_info(dev, "dev[%d:%x] found\n", sas_dev->device_id, sas_dev->dev_type); + rc = hisi_sas_init_device(device); + if (rc) + goto err_out; return 0; + +err_out: + hisi_sas_dev_gone(device); + return rc; } static int hisi_sas_slave_configure(struct scsi_device *sdev)