From patchwork Wed May 2 15:56:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134840 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp846274lji; Wed, 2 May 2018 08:57:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoqjPXzypT4oDeHnKKswTbh9cIHwfkLzgrNVVYi7ZqGIwymiiQJ3V3CwL+ooirsG7g8KWql X-Received: by 10.98.14.7 with SMTP id w7mr19814314pfi.50.1525276655631; Wed, 02 May 2018 08:57:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276655; cv=none; d=google.com; s=arc-20160816; b=QuCrneCcjcrhv6vk/siHEGL013dYe2P7wo5UXf/+9bqWOHCHiFqNrdWE67Eb1XJjv2 Q+X2u8gvaiNMNMXFtnWp0Pdqh5XXzcTnIqzmNocEb3cn1s36OLnOhR2eVqWmJkfBGmxC QHAExSZC3s5IqD1sI33UcZPVQxvThfLfwFpFAPYyEDGgLd9UE0fz0o55anvs1e16ja+J E1MFZwB5hxYBjA93qzu4t3PPFIz50BDCBicGcVyN5BTzkMDFiw0/Ndqn3413cVg1Lr8N VH45DKu8JaZ7gt8o0uq6LxYkGrkiwWFOCShVW72KCdK/H1f36BjALnbtBQufOnw65yOE FKEg== 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=GS9Vnp7u+FOcep9SLpNQFjvo2Okv6LrF0cWTf81dcgs=; b=M+USh6we+tlQ0l9tcRQ4ZB/VsYioriJtAOInIS2RQ7YgU3COmGgfwIv1RRE9xMHNEp DQR1JixvUv30g5sEbxVSSisTY4+jXpNGxLV9YDuNZLWx6hJf8s4OgPUp4xiAI9xEFlm8 Ui99EQcEHl+vFtQUrRkZAAHUL8C0HFhupH64riwAnVbwzMqR6q8vwf5myaMARS6eeqU6 xzUvbhPwg9dOBnR+qFspg3Qb4GjQNw5IdS2OcZ/tmmzaKL1CdgTwC6IhzwnHozJQcgZJ MekBRaGfdm1H1PgfX8c9NDA7dpREBgyiX7h+O/ANga307BdW+mywVfte4uZOYMYPh6u0 blsQ== 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 o184-v6si9681120pga.128.2018.05.02.08.57.35; Wed, 02 May 2018 08:57:35 -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 S1752030AbeEBP5d (ORCPT + 29 others); Wed, 2 May 2018 11:57:33 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:54553 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751635AbeEBP51 (ORCPT ); Wed, 2 May 2018 11:57:27 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 0676F33CD5CD5; Wed, 2 May 2018 23:57:24 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:16 +0800 From: John Garry To: , CC: , , , Xiang Chen , "John Garry" Subject: [PATCH 02/11] scsi: hisi_sas: Add some checks to avoid free'ing a sas_task twice Date: Wed, 2 May 2018 23:56:25 +0800 Message-ID: <1525276594-92173-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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 If the SCSI host enters EH, any pending IO will be processed by SCSI EH. However it is possible that SCSI EH will try to abort the IO and also at the same time the IO completes in the driver. In this situation there is a small changes of freeing the sas_task twice. Then if another IO re-uses freed sas_task before the second time of free'ing sas_task, it is possible that freeing incorrect sas_task. So to avoid this situation, add some checks to crease reliability. The sas_task task state flag SAS_TASK_STATE_ABORTED is used to mutually protect the LLDD and libsas free'ing the task. Signed-off-by: Xiang Chen Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 4 ++++ drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 22 +++++++--------------- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 21 +++++++-------------- 3 files changed, 18 insertions(+), 29 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 d1a61b1..52746e2 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -1174,10 +1174,14 @@ static int hisi_sas_abort_task(struct sas_task *task) return TMF_RESP_FUNC_FAILED; } + spin_lock_irqsave(&task->task_state_lock, flags); if (task->task_state_flags & SAS_TASK_STATE_DONE) { + spin_unlock_irqrestore(&task->task_state_lock, flags); rc = TMF_RESP_FUNC_COMPLETE; goto out; } + task->task_state_flags |= SAS_TASK_STATE_ABORTED; + spin_unlock_irqrestore(&task->task_state_lock, flags); sas_dev->dev_status = HISI_SAS_DEV_EH; if (task->lldd_task && task->task_proto & SAS_PROTOCOL_SSP) { diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index 384e4ef..8ca0044 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -2386,7 +2386,6 @@ static void slot_err_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_complete_v2_hdr *complete_hdr = &complete_queue[slot->cmplt_queue_slot]; unsigned long flags; - int aborted; if (unlikely(!task || !task->lldd_task || !task->dev)) return -EINVAL; @@ -2396,7 +2395,6 @@ static void slot_err_v2_hw(struct hisi_hba *hisi_hba, sas_dev = device->lldd_dev; spin_lock_irqsave(&task->task_state_lock, flags); - aborted = task->task_state_flags & SAS_TASK_STATE_ABORTED; task->task_state_flags &= ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR); spin_unlock_irqrestore(&task->task_state_lock, flags); @@ -2404,15 +2402,6 @@ static void slot_err_v2_hw(struct hisi_hba *hisi_hba, memset(ts, 0, sizeof(*ts)); ts->resp = SAS_TASK_COMPLETE; - if (unlikely(aborted)) { - dev_dbg(dev, "slot_complete: task(%p) aborted\n", task); - ts->stat = SAS_ABORTED_TASK; - spin_lock_irqsave(&hisi_hba->lock, flags); - hisi_sas_slot_task_free(hisi_hba, task, slot); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - return ts->stat; - } - if (unlikely(!sas_dev)) { dev_dbg(dev, "slot complete: port has no device\n"); ts->stat = SAS_PHY_DOWN; @@ -2523,13 +2512,16 @@ static void slot_err_v2_hw(struct hisi_hba *hisi_hba, } out: + hisi_sas_slot_task_free(hisi_hba, task, slot); + sts = ts->stat; spin_lock_irqsave(&task->task_state_lock, flags); + if (task->task_state_flags & SAS_TASK_STATE_ABORTED) { + spin_unlock_irqrestore(&task->task_state_lock, flags); + dev_info(dev, "slot complete: task(%p) aborted\n", task); + return SAS_ABORTED_TASK; + } task->task_state_flags |= SAS_TASK_STATE_DONE; spin_unlock_irqrestore(&task->task_state_lock, flags); - spin_lock_irqsave(&hisi_hba->lock, flags); - hisi_sas_slot_task_free(hisi_hba, task, slot); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - sts = ts->stat; if (task->task_done) task->task_done(task); diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index afc1242..7346110 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -1576,7 +1576,6 @@ static irqreturn_t fatal_axi_int_v3_hw(int irq_no, void *p) hisi_hba->complete_hdr[slot->cmplt_queue]; struct hisi_sas_complete_v3_hdr *complete_hdr = &complete_queue[slot->cmplt_queue_slot]; - int aborted; unsigned long flags; if (unlikely(!task || !task->lldd_task || !task->dev)) @@ -1587,21 +1586,12 @@ static irqreturn_t fatal_axi_int_v3_hw(int irq_no, void *p) sas_dev = device->lldd_dev; spin_lock_irqsave(&task->task_state_lock, flags); - aborted = task->task_state_flags & SAS_TASK_STATE_ABORTED; task->task_state_flags &= ~(SAS_TASK_STATE_PENDING | SAS_TASK_AT_INITIATOR); spin_unlock_irqrestore(&task->task_state_lock, flags); memset(ts, 0, sizeof(*ts)); ts->resp = SAS_TASK_COMPLETE; - if (unlikely(aborted)) { - dev_dbg(dev, "slot complete: task(%p) aborted\n", task); - ts->stat = SAS_ABORTED_TASK; - spin_lock_irqsave(&hisi_hba->lock, flags); - hisi_sas_slot_task_free(hisi_hba, task, slot); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - return ts->stat; - } if (unlikely(!sas_dev)) { dev_dbg(dev, "slot complete: port has not device\n"); @@ -1699,13 +1689,16 @@ static irqreturn_t fatal_axi_int_v3_hw(int irq_no, void *p) } out: + hisi_sas_slot_task_free(hisi_hba, task, slot); + sts = ts->stat; spin_lock_irqsave(&task->task_state_lock, flags); + if (task->task_state_flags & SAS_TASK_STATE_ABORTED) { + spin_unlock_irqrestore(&task->task_state_lock, flags); + dev_info(dev, "slot complete: task(%p) aborted\n", task); + return SAS_ABORTED_TASK; + } task->task_state_flags |= SAS_TASK_STATE_DONE; spin_unlock_irqrestore(&task->task_state_lock, flags); - spin_lock_irqsave(&hisi_hba->lock, flags); - hisi_sas_slot_task_free(hisi_hba, task, slot); - spin_unlock_irqrestore(&hisi_hba->lock, flags); - sts = ts->stat; if (task->task_done) task->task_done(task); From patchwork Wed May 2 15:56:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134844 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp847408lji; Wed, 2 May 2018 08:58:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqD2a8aEGmMUjiCBE5GPX8/k+Jws1Dqtv3l59smtdgCc6XjdcbW/NeMXHkRKXoLpWS0MpXH X-Received: by 2002:a63:41c7:: with SMTP id o190-v6mr16971972pga.57.1525276727054; Wed, 02 May 2018 08:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276727; cv=none; d=google.com; s=arc-20160816; b=Jq3xeym3OmI91L1iAbxRRCduqvVbhB40j4RC3xIbBMKL/69+EeLK1g0FAsN0WX7JiC c2xBdigwaNNl3IrF7Zj7O02JwVRWFUSgf/olPpYEtTsf0xrGizJZu1PHFiKSwX/Of6xC FaT+ahY3z4D/uhm7R6k+92AfoQUTmoIGBVy7J2jbdePUQkjOZg7Ypc/K90thD6QSe/om 2mmLB/m98EFGL171B8rYBOjdk/7L3G65eiMopa/nfVJyMOSkYFGZg0xzvGG8R79lKc/g EZ6NuImftK8QDF8HNuCpRinCpGwPLcUa+W+A6si9ol88HdcW4hVi/oxy24lR8cOd/HuV 0B1w== 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=wsiPeIouvfDPi03du5m4TpBRya9/YWrDfVsPxzXYyUo=; b=0hAEsYoytk4iXiNa6K3qjeFERZPWfSM/UVrPRPkXWag4UTsuh3goYV0uGLqlG8YK9T /WqABAjI6/WoiC6XTtQaUedziiNTy4xysyQNBti60fJeYWX/oAMbbPlmFKPn7N2qQMaP vgV/bJVZLTgysr0FSIXEr/BoEevmGov0GV4u9rxVvhIa44ALJP2MgyTCIywquIGDjkmK 1EmdY4GjavKOmNxYhGMOPOxVy3rTOBMTEDNfKlYP/yZDX8m1iLucKDRoY2Ol18bytJIr ddrWHw7n+w9qnrjjW2APW7FEbVvGpOopvEjpabRDEh+mlzYGfAO/WALHYJ7E1MRUDafY xvXA== 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 j1-v6si9518057pgv.688.2018.05.02.08.58.46; Wed, 02 May 2018 08:58:47 -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 S1752156AbeEBP6o (ORCPT + 29 others); Wed, 2 May 2018 11:58:44 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:54591 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751755AbeEBP53 (ORCPT ); Wed, 2 May 2018 11:57:29 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 333FF25E96A7D; Wed, 2 May 2018 23:57:24 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:16 +0800 From: John Garry To: , CC: , , , Xiang Chen , "John Garry" Subject: [PATCH 03/11] scsi: hisi_sas: check host frozen before calling "done" function Date: Wed, 2 May 2018 23:56:26 +0800 Message-ID: <1525276594-92173-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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 the host is frozen in SCSI EH state, at any point after the LLDD sets SAS_TASK_STATE_DONE for the sas_task task state, libsas may free the task; see sas_scsi_find_task(). This puts the LLDD in a difficult position, in that once it sets SAS_TASK_STATE_DONE for the task state it should not reference the sas_task again. But the LLDD needs will check the sas_task indirectly in calling task->task_done()->sas_scsi_task_done() or sas_ata_task_done() (to check if the host is frozen state actually). And the LLDD cannot set SAS_TASK_STATE_DONE for the task state after task->task_done() is called (as the sas_task is free'd at this point). This situation would seem to be a problem made by libsas. To work around, check in the LLDD whether the host is in frozen state to ensure it is ok to call task->task_done() function. If in the frozen state, we rely on SCSI EH and libsas to free the sas_task directly. We do not do this for the following IO types: - SMP - they are managed in libsas directly, outside SCSI EH - Any internally originated IO, for similar reason Signed-off-by: Xiang Chen Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas.h | 1 + drivers/scsi/hisi_sas/hisi_sas_main.c | 3 +++ drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 14 ++++++++++++++ drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 14 ++++++++++++++ 4 files changed, 32 insertions(+) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h index d413d05..147cfaf 100644 --- a/drivers/scsi/hisi_sas/hisi_sas.h +++ b/drivers/scsi/hisi_sas/hisi_sas.h @@ -196,6 +196,7 @@ struct hisi_sas_slot { dma_addr_t cmd_hdr_dma; struct work_struct abort_slot; struct timer_list internal_abort_timer; + bool is_internal; }; struct hisi_sas_tmf_task { diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 52746e2..8f8e642 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -382,6 +382,8 @@ static int hisi_sas_task_prep(struct sas_task *task, struct hisi_sas_dq slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; slot->task = task; slot->port = port; + if (is_tmf) + slot->is_internal = true; task->lldd_task = slot; INIT_WORK(&slot->abort_slot, hisi_sas_slot_abort); @@ -1486,6 +1488,7 @@ static int hisi_sas_query_task(struct sas_task *task) slot->cmd_hdr = &cmd_hdr_base[dlvry_queue_slot]; slot->task = task; slot->port = port; + slot->is_internal = true; task->lldd_task = slot; slot->buf = dma_pool_alloc(hisi_hba->buffer_pool, diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index 8ca0044..6dda6eb 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -2380,18 +2380,21 @@ static void slot_err_v2_hw(struct hisi_hba *hisi_hba, struct device *dev = hisi_hba->dev; struct task_status_struct *ts; struct domain_device *device; + struct sas_ha_struct *ha; enum exec_status sts; struct hisi_sas_complete_v2_hdr *complete_queue = hisi_hba->complete_hdr[slot->cmplt_queue]; struct hisi_sas_complete_v2_hdr *complete_hdr = &complete_queue[slot->cmplt_queue_slot]; unsigned long flags; + bool is_internal = slot->is_internal; if (unlikely(!task || !task->lldd_task || !task->dev)) return -EINVAL; ts = &task->task_status; device = task->dev; + ha = device->port->ha; sas_dev = device->lldd_dev; spin_lock_irqsave(&task->task_state_lock, flags); @@ -2523,6 +2526,17 @@ static void slot_err_v2_hw(struct hisi_hba *hisi_hba, task->task_state_flags |= SAS_TASK_STATE_DONE; spin_unlock_irqrestore(&task->task_state_lock, flags); + if (!is_internal && (task->task_proto != SAS_PROTOCOL_SMP)) { + spin_lock_irqsave(&device->done_lock, flags); + if (test_bit(SAS_HA_FROZEN, &ha->state)) { + spin_unlock_irqrestore(&device->done_lock, flags); + dev_info(dev, "slot complete: task(%p) ignored\n ", + task); + return sts; + } + spin_unlock_irqrestore(&device->done_lock, flags); + } + if (task->task_done) task->task_done(task); diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 7346110..5c0d968 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -1571,18 +1571,21 @@ static irqreturn_t fatal_axi_int_v3_hw(int irq_no, void *p) struct device *dev = hisi_hba->dev; struct task_status_struct *ts; struct domain_device *device; + struct sas_ha_struct *ha; enum exec_status sts; struct hisi_sas_complete_v3_hdr *complete_queue = hisi_hba->complete_hdr[slot->cmplt_queue]; struct hisi_sas_complete_v3_hdr *complete_hdr = &complete_queue[slot->cmplt_queue_slot]; unsigned long flags; + bool is_internal = slot->is_internal; if (unlikely(!task || !task->lldd_task || !task->dev)) return -EINVAL; ts = &task->task_status; device = task->dev; + ha = device->port->ha; sas_dev = device->lldd_dev; spin_lock_irqsave(&task->task_state_lock, flags); @@ -1700,6 +1703,17 @@ static irqreturn_t fatal_axi_int_v3_hw(int irq_no, void *p) task->task_state_flags |= SAS_TASK_STATE_DONE; spin_unlock_irqrestore(&task->task_state_lock, flags); + if (!is_internal && (task->task_proto != SAS_PROTOCOL_SMP)) { + spin_lock_irqsave(&device->done_lock, flags); + if (test_bit(SAS_HA_FROZEN, &ha->state)) { + spin_unlock_irqrestore(&device->done_lock, flags); + dev_info(dev, "slot complete: task(%p) ignored\n ", + task); + return sts; + } + spin_unlock_irqrestore(&device->done_lock, flags); + } + if (task->task_done) task->task_done(task); From patchwork Wed May 2 15:56:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134847 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp848354lji; Wed, 2 May 2018 08:59:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZopT44uKM2y3nt7g1VOpI5YHLE6YPiKAcDWskx4H5qwDn4OECHClhsPUxk1cfHSjn+v2Xx2 X-Received: by 2002:a17:902:8d8e:: with SMTP id v14-v6mr20841093plo.387.1525276782247; Wed, 02 May 2018 08:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276782; cv=none; d=google.com; s=arc-20160816; b=UE4ci/671fhHPsDRN+iXmtM4BSyDIO9nCdpgmVd3s7UOBzd14ea/jOdCA1bczLSWZy Z7PS+TiN00uf4uNwAnIAx74POpkhevRhdH09PRpXgzLB5z4vI0zWrDWRhZeMOIjf5zhK WSeyUXIrYYWaj8IujCKnFgY39O31cO7MhIcCgbPWNll1rv/FEYW4w+zEkXIkQO4CxDrk R6PSJC4QSnN/7DYa+ge9UqmR2C3GB4A9puP/hcc6hvYvftQzzWaHpfp5wiDzEdhvMBh7 kmdeRh+VsmDQWA8cHs9BYwFvIbWyEf5FGhNHtUkeDDCuQl1MtRpX40xdkOckR8COuzXT rrVg== 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=1T0jQpMCT/1BHPNagL6/+YuEBF+wyCw95APhcUf7/vs=; b=hwRZeeAZA3W7EiqHU445O/8wEfHKLMGUI6k87yPgDyvX8gPxavuXWteWUS8e7W3M6f 7T0j4LGeuw1UybeXDeVcRDeJy6jakfIXTSn81mQ5YfEmjFy8bmFnY1ibWPzVTbE6I2Bw c30jFfoTXiur/U972hEzpUdg8F5kAFKEuY0LqUH8p3Z720qnco0XslDh8+cSBhhwV9/F t+Y/7pmuTd5veAwm7dUalJN/TrLOutviKK3tKE8COFwg267ADdDu/IPTg+eoqIB90oXL U0QF1NYM1vH/z86OzWkaj3i+Wg7zwHin7b65k/EP3MB/3MdIc6p5lksE5Pe4X8DHvItB E5Dw== 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 h62-v6si9552411pgc.548.2018.05.02.08.59.41; Wed, 02 May 2018 08:59:42 -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 S1752047AbeEBP6m (ORCPT + 29 others); Wed, 2 May 2018 11:58:42 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:54592 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751985AbeEBP5a (ORCPT ); Wed, 2 May 2018 11:57:30 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 4266762C4BDB7; Wed, 2 May 2018 23:57:24 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:17 +0800 From: John Garry To: , CC: , , , Xiang Chen , "John Garry" Subject: [PATCH 04/11] scsi: hisi_sas: fix PI memory size Date: Wed, 2 May 2018 23:56:27 +0800 Message-ID: <1525276594-92173-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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 There are 28 bytes of protection information record of SSP for v3 hw, 16 bytes for v2 hw, and probably 24 for v1 hw (forgotten now). So use a value big enough in hisi_sas_command_table_ssp.prot to cover all cases. Signed-off-by: Xiang Chen Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h index 147cfaf..04a40c4 100644 --- a/drivers/scsi/hisi_sas/hisi_sas.h +++ b/drivers/scsi/hisi_sas/hisi_sas.h @@ -410,7 +410,7 @@ struct hisi_sas_command_table_ssp { union { struct { struct ssp_command_iu task; - u32 prot[6]; + u32 prot[7]; }; struct ssp_tmf_iu ssp_task; struct xfer_rdy_iu xfer_rdy; From patchwork Wed May 2 15:56:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134849 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp849504lji; Wed, 2 May 2018 09:00:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoMsE1aDXZuv8YmMwcBxzOavGucik7jlt7re9TNw/ttA36D+Ja440xXo33xw3DlBCokVmg2 X-Received: by 2002:a63:87c6:: with SMTP id i189-v6mr16183781pge.2.1525276838752; Wed, 02 May 2018 09:00:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276838; cv=none; d=google.com; s=arc-20160816; b=jOGTSa9EMG3UuTo+s8P/xSezfJSPy0L3MNo+wlPh9TY+MtxY3OPv05Tr75natySzHB CpY5A+Gz2RmaYU3eDG1WLzpEfuPf4QR1CdaYtTFhpuoEuJrbpKZiX5XgvQlkCzXUM6JQ wzlBzcSRj+yddlU5qqA+KuCDDFRO28tSpi6ZIGKudnnh/OhTvEbE2VM3xwp+WWouKAti oSi3BEnWtwRV+27R1bzFLqkmHzTu4ja3HA4jxwBht0Kg4SoypHhHZCMdYRAhWJ/dq0lP jjNAja/ZFHS1zhZ7pK0vxe1sMZycSXJRhm8N3xOiapJOtC9x7TRt9GK0ao5hAIX0b4hA rhCg== 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=rpYHG5/pw6ZwNTmVsSQo4ahbCeJQWSeQd4g3HM4V1Yc=; b=yk/huLWYxfzagl98I650mt3xxGH5amD1BfVmJWflo1gYoI/0ZnSPsztLgZSAicgOIi huP+/FZPNZRbAMriIxpMq6v7Ye5XTWCKMhLuVf31bCwuFMmvjYvFv8l+gFP3/nV4619q dC/gGewNzYDAadFNWonwCGAxj85YTzbjIqpzSd4CzX6zwDK4r9lL9yqkX2tWRglzkINo up6w16QbXSq7TRAZroUVot2HE3YfoV8CYJzcoFmuZNQQIBQrUcYEQ60b54wqHP8oGkLw 1hfz/2f4CCgViISfYEvn0Pu7hfHTU8ujB4VBGzhWUe9AqrI0Hb7E8tEa7pp3q4DmO2j3 2Dqw== 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 g72si9401876pfb.280.2018.05.02.09.00.38; Wed, 02 May 2018 09:00:38 -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 S1752324AbeEBQAe (ORCPT + 29 others); Wed, 2 May 2018 12:00:34 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:54538 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751637AbeEBP52 (ORCPT ); Wed, 2 May 2018 11:57:28 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D0F3AD342A90E; Wed, 2 May 2018 23:57:23 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:17 +0800 From: John Garry To: , CC: , , , Xiang Chen , "John Garry" Subject: [PATCH 05/11] scsi: hisi_sas: check sas_dev gone earlier in hisi_sas_abort_task() Date: Wed, 2 May 2018 23:56:28 +0800 Message-ID: <1525276594-92173-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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 It is possible to dereference a NULL-pointer in hisi_sas_abort_task() in special scenario when the device has been removed. If an SMP task times-out, it will call hisi_sas_abort_task() to recover. And currently there is a check in hisi_sas_abort_task() to avoid the situation of processing the abort for the removed device. However we have an ordering problem, in that we may reference a task for the removed device before checking if the device has been removed. Fix this by only referencing the sas_dev after we know it is still present. Signed-off-by: Xiang Chen Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 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 8f8e642..24416bb 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -1166,15 +1166,16 @@ static int hisi_sas_abort_task(struct sas_task *task) struct hisi_sas_tmf_task tmf_task; struct domain_device *device = task->dev; struct hisi_sas_device *sas_dev = device->lldd_dev; - struct hisi_hba *hisi_hba = dev_to_hisi_hba(task->dev); - struct device *dev = hisi_hba->dev; + struct hisi_hba *hisi_hba; + struct device *dev; int rc = TMF_RESP_FUNC_FAILED; unsigned long flags; - if (!sas_dev) { - dev_warn(dev, "Device has been removed\n"); + if (!sas_dev) return TMF_RESP_FUNC_FAILED; - } + + hisi_hba = dev_to_hisi_hba(task->dev); + dev = hisi_hba->dev; spin_lock_irqsave(&task->task_state_lock, flags); if (task->task_state_flags & SAS_TASK_STATE_DONE) { From patchwork Wed May 2 15:56:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134838 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp846213lji; Wed, 2 May 2018 08:57:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoSwkVF4BOwFVYaj/gyJppBFcCTKz5zbpIKIHxbhFFm8yIZAvmQHbczRLCPQFrS1lBBmNR/ X-Received: by 2002:a63:7253:: with SMTP id c19-v6mr16594816pgn.425.1525276651103; Wed, 02 May 2018 08:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276651; cv=none; d=google.com; s=arc-20160816; b=Jz9rSuCkhn0W0QsJJ9JATyEa7QexepYEmMKIwzuMwQG/b8TNhFJb8mt3YVPyfj/nGr 3oFGbZBD9yGgwDUXeYN/Ch//tRbmd7yzziLY3mmtPrOc8wtaT1k+Pd6terLo+1ik5Knx ILsx4+vcPo7zS9hipLat0/kwNmrauHPfSgliKEkC/mwcUBThOAGmi4noNeIzx+rMut+U qPGp+uWhnoTE+ROfRxU+wVCXOYZqGfuDPV8w2CTdx/K+YVAMDOcIy6hEyy034NVrEgJD oLeZN50Us5NRA5ZKkS2c+6bF0n5sQcnD4q31uGSX+gMHq0/Ru1Yu05sJ83k7WW6scwkr jB/Q== 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=jVqhfTpeyIf5RIEg0vsbtReEVrre3TCEGoXC7puwtF4=; b=ZxtoURx+8qxwIFjbxn/z/eclPyttMTAXI1ybv7LAE6E/x4E6j+kka/RxPQ5D4aeoOT 78IEoztl5RbY0KxAdVK0SR4oXilXAHHw6kIQlgmd+NJMHynghoKQsaf3NaarCwJ4lckv hfLoacseQeJqdULzeFKqnHLN35B9CIrBFrVT4jlSgM40WFEQmczFpPY5mpN4F2dNylyu IDps7cdoRYevy1EEzJylDRWkJaDTUXhQEonO2Xe91QLQEBusq/3qNE5mBzhvcBPLdXPG Oa9e4TWkouF4EJEkWyEaF2iW/plyxn1x2hvW7mHqMtH+HJ/Vr0u0TAtKvcv4RNl6d2fb PORQ== 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 x10si11891253pfh.85.2018.05.02.08.57.30; Wed, 02 May 2018 08:57:31 -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 S1752014AbeEBP53 (ORCPT + 29 others); Wed, 2 May 2018 11:57:29 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:54548 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751138AbeEBP51 (ORCPT ); Wed, 2 May 2018 11:57:27 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id ED3FB84BE6AC6; Wed, 2 May 2018 23:57:23 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:17 +0800 From: John Garry To: , CC: , , , John Garry , "Xiaofei Tan" Subject: [PATCH 06/11] scsi: hisi_sas: stop controller timer for reset Date: Wed, 2 May 2018 23:56:29 +0800 Message-ID: <1525276594-92173-7-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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 We should only have the timer enabled after PHY up after controller reset, so disable prior to reset. Signed-off-by: John Garry Signed-off-by: Xiaofei Tan --- drivers/scsi/hisi_sas/hisi_sas_main.c | 3 +++ 1 file changed, 3 insertions(+) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 24416bb..1f27f84 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -1130,6 +1130,9 @@ static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba) old_state = hisi_hba->hw->get_phys_state(hisi_hba); scsi_block_requests(shost); + if (timer_pending(&hisi_hba->timer)) + del_timer_sync(&hisi_hba->timer); + set_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); rc = hisi_hba->hw->soft_reset(hisi_hba); if (rc) { From patchwork Wed May 2 15:56:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134845 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp847429lji; Wed, 2 May 2018 08:58:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqPNYSqVkfwV2ov2dMOBrFuZ//0+fyxntKldWbC7mPggTzW7idjAj64+CQw4yIurWOs+/4D X-Received: by 2002:a63:5f0d:: with SMTP id t13-v6mr16788035pgb.145.1525276728390; Wed, 02 May 2018 08:58:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276728; cv=none; d=google.com; s=arc-20160816; b=b0OdqOku5P81Jq304unnb+IWWEZmGNS62gEWM1qaFDQh4Nn0b/7uuPHENKiLyFD/Kx aFxTv8N9vPcJiGTHITx6TKXE8C3aOIV65JHjxx5XSte//KDbcS+juinoK3hzcPJCXSLf zTSY2NxHi5zPQgkQM93JTDKc4OEOhnTZ0Ae9pMdjz+UM3apiYlydMSpwfPlD6fwV1hiW mvJpKHEmp5U6njLgaELj4+Pfoiv+LKOCZa7AxqR1X0Ttsfw8y02n8Cyx50xoRUuRlnLc yQp7mTVY55If2/GkcxAW9j8xcJzRCy1IuGHDtrD3l0SU+m8A4rw4a+1NPyEdzFGXwqrr Bf0g== 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=NUedChO3rPDd/5/u361EnL020KbMqGmPHXFk9r3HM/k=; b=QeZdARaLtq79cZIiX8N3CbluCrfNLbEsX/pMP7OGT7OqVaKiq7piPP5ndCXiiGOy5Z UriYUy7+bP+bKhUdcu7v63VxOXj/wzzxPSTELiLQ4ejQ/pOBfNmDk+fdYiPoAEbfP2bX NNaOXx8m5weTfjwjzb4Rbj3nllWX5EgC5y9xVd9qmlxIZbh9GTmwj8IJPjthdJHSJ+Vo JX4R3bcLddDP9jCwLP7B2Wxcds6mwwsV+IJ/gxzpekySylzCSrXuNXlYnWaBXW6hSp/k xyUYAJvZ2o3QDyRVC5dnqimToJiXDul2FaHHPnuwosBT2C5BQGJt6p8Zxx3bnlGFa7Ik fqZw== 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 f1-v6si11629610pld.168.2018.05.02.08.58.48; Wed, 02 May 2018 08:58:48 -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 S1752217AbeEBP6q (ORCPT + 29 others); Wed, 2 May 2018 11:58:46 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:54589 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751933AbeEBP53 (ORCPT ); Wed, 2 May 2018 11:57:29 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 157753CD4DA30; Wed, 2 May 2018 23:57:24 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:18 +0800 From: John Garry To: , CC: , , , Xiang Chen , "John Garry" Subject: [PATCH 07/11] scsi: hisi_sas: update PHY linkrate after a controller reset Date: Wed, 2 May 2018 23:56:30 +0800 Message-ID: <1525276594-92173-8-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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 After the controller is reset, we currently may not honour the PHY max linkrate set via sysfs, in that after a reset we always revert to max linkrate of 12Gbps, ignoring the value set via sysfs. This patch modifies to policy to set the programmed PHY linkrate, honouring the max linkrate programmed via sysfs. Signed-off-by: Xiang Chen Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas.h | 1 + drivers/scsi/hisi_sas/hisi_sas_main.c | 16 ++++++++++++++++ drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 31 ++++++++++++++++++------------- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 31 ++++++++++++++++++------------- 4 files changed, 53 insertions(+), 26 deletions(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h index 04a40c4..4410538 100644 --- a/drivers/scsi/hisi_sas/hisi_sas.h +++ b/drivers/scsi/hisi_sas/hisi_sas.h @@ -463,4 +463,5 @@ extern void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, extern bool hisi_sas_notify_phy_event(struct hisi_sas_phy *phy, enum hisi_sas_phy_event event); extern void hisi_sas_release_tasks(struct hisi_hba *hisi_hba); +extern u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max); #endif diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 1f27f84..ff5b8d7 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -135,6 +135,22 @@ int hisi_sas_get_ncq_tag(struct sas_task *task, u32 *tag) } EXPORT_SYMBOL_GPL(hisi_sas_get_ncq_tag); +/* + * This function assumes linkrate mask fits in 8 bits, which it + * does for all HW versions supported. + */ +u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max) +{ + u16 rate = 0; + int i; + + max -= SAS_LINK_RATE_1_5_GBPS; + for (i = 0; i <= max; i++) + rate |= 1 << (i * 2); + return rate; +} +EXPORT_SYMBOL_GPL(hisi_sas_get_prog_phy_linkrate_mask); + static struct hisi_hba *dev_to_hisi_hba(struct domain_device *device) { return device->port->ha->lldd_ha; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index 6dda6eb..9e68731 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -1216,7 +1216,22 @@ static void init_reg_v2_hw(struct hisi_hba *hisi_hba) } for (i = 0; i < hisi_hba->n_phy; i++) { - hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, 0x855); + struct hisi_sas_phy *phy = &hisi_hba->phy[i]; + struct asd_sas_phy *sas_phy = &phy->sas_phy; + u32 prog_phy_link_rate = 0x800; + + if (!sas_phy->phy || (sas_phy->phy->maximum_linkrate < + SAS_LINK_RATE_1_5_GBPS)) { + prog_phy_link_rate = 0x855; + } else { + enum sas_linkrate max = sas_phy->phy->maximum_linkrate; + + prog_phy_link_rate = + hisi_sas_get_prog_phy_linkrate_mask(max) | + 0x800; + } + hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, + prog_phy_link_rate); hisi_sas_phy_write32(hisi_hba, i, SAS_PHY_CTRL, sas_phy_ctrl); hisi_sas_phy_write32(hisi_hba, i, SL_TOUT_CFG, 0x7d7d7d7d); hisi_sas_phy_write32(hisi_hba, i, SL_CONTROL, 0x0); @@ -1585,13 +1600,10 @@ static enum sas_linkrate phy_get_max_linkrate_v2_hw(void) static void phy_set_linkrate_v2_hw(struct hisi_hba *hisi_hba, int phy_no, struct sas_phy_linkrates *r) { - u32 prog_phy_link_rate = - hisi_sas_phy_read32(hisi_hba, phy_no, PROG_PHY_LINK_RATE); struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; struct asd_sas_phy *sas_phy = &phy->sas_phy; - int i; enum sas_linkrate min, max; - u32 rate_mask = 0; + u32 prog_phy_link_rate = 0x800; if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { max = sas_phy->phy->maximum_linkrate; @@ -1604,14 +1616,7 @@ static void phy_set_linkrate_v2_hw(struct hisi_hba *hisi_hba, int phy_no, sas_phy->phy->maximum_linkrate = max; sas_phy->phy->minimum_linkrate = min; - - max -= SAS_LINK_RATE_1_5_GBPS; - - for (i = 0; i <= max; i++) - rate_mask |= 1 << (i * 2); - - prog_phy_link_rate &= ~0xff; - prog_phy_link_rate |= rate_mask; + prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max); disable_phy_v2_hw(hisi_hba, phy_no); msleep(100); diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 5c0d968..ffa3cea 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -429,7 +429,22 @@ static void init_reg_v3_hw(struct hisi_hba *hisi_hba) hisi_sas_write32(hisi_hba, HYPER_STREAM_ID_EN_CFG, 1); for (i = 0; i < hisi_hba->n_phy; i++) { - hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, 0x855); + struct hisi_sas_phy *phy = &hisi_hba->phy[i]; + struct asd_sas_phy *sas_phy = &phy->sas_phy; + u32 prog_phy_link_rate = 0x800; + + if (!sas_phy->phy || (sas_phy->phy->maximum_linkrate < + SAS_LINK_RATE_1_5_GBPS)) { + prog_phy_link_rate = 0x855; + } else { + enum sas_linkrate max = sas_phy->phy->maximum_linkrate; + + prog_phy_link_rate = + hisi_sas_get_prog_phy_linkrate_mask(max) | + 0x800; + } + hisi_sas_phy_write32(hisi_hba, i, PROG_PHY_LINK_RATE, + prog_phy_link_rate); hisi_sas_phy_write32(hisi_hba, i, SAS_RX_TRAIN_TIMER, 0x13e80); hisi_sas_phy_write32(hisi_hba, i, CHL_INT0, 0xffffffff); hisi_sas_phy_write32(hisi_hba, i, CHL_INT1, 0xffffffff); @@ -1869,13 +1884,10 @@ static int hisi_sas_v3_init(struct hisi_hba *hisi_hba) static void phy_set_linkrate_v3_hw(struct hisi_hba *hisi_hba, int phy_no, struct sas_phy_linkrates *r) { - u32 prog_phy_link_rate = - hisi_sas_phy_read32(hisi_hba, phy_no, PROG_PHY_LINK_RATE); struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; struct asd_sas_phy *sas_phy = &phy->sas_phy; - int i; enum sas_linkrate min, max; - u32 rate_mask = 0; + u32 prog_phy_link_rate = 0x800; if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) { max = sas_phy->phy->maximum_linkrate; @@ -1888,14 +1900,7 @@ static void phy_set_linkrate_v3_hw(struct hisi_hba *hisi_hba, int phy_no, sas_phy->phy->maximum_linkrate = max; sas_phy->phy->minimum_linkrate = min; - - max -= SAS_LINK_RATE_1_5_GBPS; - - for (i = 0; i <= max; i++) - rate_mask |= 1 << (i * 2); - - prog_phy_link_rate &= ~0xff; - prog_phy_link_rate |= rate_mask; + prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max); disable_phy_v3_hw(hisi_hba, phy_no); msleep(100); From patchwork Wed May 2 15:56:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134846 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp847499lji; Wed, 2 May 2018 08:58:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqUoy60ShSgMKYSl+mffE4OUE5qk+RJ59XrSv3mfAgewuZwOZSfBu5fhVYqzAk62JvS1NJo X-Received: by 2002:a63:642:: with SMTP id 63-v6mr16500885pgg.10.1525276733752; Wed, 02 May 2018 08:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276733; cv=none; d=google.com; s=arc-20160816; b=Ffw/ywAcg2bFBGOkMsUEKsSIWHnExMIB+tBVqeWCfzPdtsw1vDKueEeBnGP1FnUR9L 123XaALAgvY4gQRAp6V1tUXakoCjPTltaS4TOoorUG4rsSdvlJ0/KhkPONAzqySQMaC6 /1vqsjs5+Rawxib5xcs3yZ6UO3GMVjXmxyk04yg+T0vetW6RXDjQ2AH8/smyxAH5ygmC 4hqei+riVeNC9PbLEkXQuTcmRPm04xjGCy3s8zShzx21y1PGmMX0aJYWFAd4U8jR0otT gOkJYZriN26UU3nFNqukX7xKMWODNaYCs8/SMfpDCfGZW3KWMsk+SqbcM/e8Qzt7W1qr MCOQ== 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=EB6sEDlYsBd3cWVrey/b9j5DLUmnxEqFwRhqX1BMtgY=; b=qXRLmQYzfMe7nh2vKu+TNAtZAQyzMlD2ewdEZAZ3ARE7iQElrKz2tfm/vS8ffk0EuR JS6kAhQ+PqgykldHG89A6wNk852wSOrEuU+0YucKh2GJ4YAlP98uIXgQYOYQRn8IlcSJ 1lZnK4mSVKO2jv1zPkhzojrwSPwz21+LPO5moLBtHRV/T1ihaHEzPjLedcpZB8+KXmNl VWXK1XTsG66HTErvd67T2QStx1F4C/48DUiJ1CDMN+fpfoOOV7opoH35pCgNuBFrYOvB Uh++JAX4r9tFQEbcOdeT0EI+a1PZfht86UlT4NcGssNoZvrBpTi47ykghxX3DQLY32Zy +ksw== 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 f1-v6si11629610pld.168.2018.05.02.08.58.53; Wed, 02 May 2018 08:58:53 -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 S1752252AbeEBP6u (ORCPT + 29 others); Wed, 2 May 2018 11:58:50 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:54543 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751704AbeEBP53 (ORCPT ); Wed, 2 May 2018 11:57:29 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id DF28DC59AF84D; Wed, 2 May 2018 23:57:23 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:18 +0800 From: John Garry To: , CC: , , , Xiang Chen , "John Garry" Subject: [PATCH 08/11] scsi: hisi_sas: config ATA de-reset as an constrained command for v3 hw Date: Wed, 2 May 2018 23:56:31 +0800 Message-ID: <1525276594-92173-9-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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 As a unconstrained command, a command can be sent to SATA disk even if SATA disk status is BUSY, ERR or DRQ. If an ATA reset assert is successful but ATA reset de-assert fails, then it will retry the reset de-assert. If reset de- assert retry is successful, we think it is okay to probe the device but actually it still has Err status. Apparently we need to retry the ATA reset assertion and de- assertion instead for this mentioned scenario. As such, we config ATA reset assert as a constrained command, if ATA reset de-assert fails, then ATA reset de-assert retry will also fail. Then we will retry the proper process of ATA reset assert and de-assert again. Signed-off-by: Xiang Chen Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index ffa3cea..026faee 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -351,10 +351,11 @@ struct hisi_sas_err_record_v3 { #define DIR_TO_DEVICE 2 #define DIR_RESERVED 3 -#define CMD_IS_UNCONSTRAINT(cmd) \ - ((cmd == ATA_CMD_READ_LOG_EXT) || \ - (cmd == ATA_CMD_READ_LOG_DMA_EXT) || \ - (cmd == ATA_CMD_DEV_RESET)) +#define FIS_CMD_IS_UNCONSTRAINED(fis) \ + ((fis.command == ATA_CMD_READ_LOG_EXT) || \ + (fis.command == ATA_CMD_READ_LOG_DMA_EXT) || \ + ((fis.command == ATA_CMD_DEV_RESET) && \ + ((fis.control & ATA_SRST) != 0))) static u32 hisi_sas_read32(struct hisi_hba *hisi_hba, u32 off) { @@ -1075,7 +1076,7 @@ static int prep_ata_v3_hw(struct hisi_hba *hisi_hba, << CMD_HDR_FRAME_TYPE_OFF; dw1 |= sas_dev->device_id << CMD_HDR_DEV_ID_OFF; - if (CMD_IS_UNCONSTRAINT(task->ata_task.fis.command)) + if (FIS_CMD_IS_UNCONSTRAINED(task->ata_task.fis)) dw1 |= 1 << CMD_HDR_UNCON_CMD_OFF; hdr->dw1 = cpu_to_le32(dw1); From patchwork Wed May 2 15:56:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134842 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp846531lji; Wed, 2 May 2018 08:57:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpYQgiiv3R4p/MudMhYKFTam34EgBJcCbP+gr6NzxR5r2VPK4Vyaj5b/q0PfZ2dNkwVpvGm X-Received: by 2002:a17:902:f44:: with SMTP id 62-v6mr20808255ply.318.1525276672236; Wed, 02 May 2018 08:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276672; cv=none; d=google.com; s=arc-20160816; b=yrqB39KG51dDdkRjwSAlagMVya7wTQiYkZ8uq0PtyNnEJAE/I+RlFcVrI/WNF6OaPA xcdqLrYsie3lyE3h2wMTneazAUnPhDoAe2w3r73IrQ5stsqu5Udt6v1d+8l1DSsc2Uvt XPet3d8RJW44SNRR1ksYAprwbBjrlYXrAGMthdjTw7yN4cIbChW1fhqYFB0y3eGCFkNA hw5ZDr4UNW3jChUN3WED8xksaPBK8IxBoB74GnxNMhY4aggQikoiwxh4SRgFiiTvWWWq GT/EBMGaZQiJbrRpKTxZZCi3bgwgCJOfPmRv1+76jRdeTd9m7OoVfPaiKZ1T2+BqGPVN evvw== 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=5ABjSvVEYqS65ddZNd6FQqv99lNk9tHviBWKOOXTJxU=; b=AeveDpnHWCP86s8UkewiNV+MPTfAelH9JDwiKFnIHdASyVC6U6jSNYnrEJ3ime+ZnN c/ig//1IJ79Uf8t0HgeKLztsOAvGx+KzDJ3TPFu4Nv4CPNVm7etdZccgUtHuV0qyA1tk z7PY0KFbxjm3z3NW5ChMSkaBICWgO04gTHeCokI30Gw2bqxx1A4yQA/AR6ThH0xIUHlb 9duqjFn+gD2Gr3dqDOLnt/9XIvC0nrhcdPYhIBqhUQ5XeNz1W7x2dV7EBcmwelUvmY5j q4z5JDjFO46Y8n28fgQIOPC948wJZXyrNtDprEne5+cowfP7TL2lXurHuAw7pbj0OmyY TF0g== 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 p11-v6si3058066pgn.267.2018.05.02.08.57.51; Wed, 02 May 2018 08:57:52 -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 S1752112AbeEBP5t (ORCPT + 29 others); Wed, 2 May 2018 11:57:49 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7221 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751988AbeEBP5q (ORCPT ); Wed, 2 May 2018 11:57:46 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 35AA6C28C3DDB; Wed, 2 May 2018 23:57:27 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:18 +0800 From: John Garry To: , CC: , , , Xiaofei Tan , "John Garry" Subject: [PATCH 09/11] scsi: hisi_sas: remove redundant handling to event95 for v3 Date: Wed, 2 May 2018 23:56:32 +0800 Message-ID: <1525276594-92173-10-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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: Xiaofei Tan Event95 is used for DFX purpose. The relevant bit for this interrupt in the ENT_INT_SRC_MSK3 register has been disabled, so remove the processing. Signed-off-by: Xiaofei Tan Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 026faee..d6e705f 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -1331,14 +1331,9 @@ static irqreturn_t int_chnl_int_v3_hw(int irq_no, void *p) { struct hisi_hba *hisi_hba = p; struct device *dev = hisi_hba->dev; - u32 ent_msk, ent_tmp, irq_msk; + u32 irq_msk; int phy_no = 0; - ent_msk = hisi_sas_read32(hisi_hba, ENT_INT_SRC_MSK3); - ent_tmp = ent_msk; - ent_msk |= ENT_INT_SRC_MSK3_ENT95_MSK_MSK; - hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_msk); - irq_msk = hisi_sas_read32(hisi_hba, CHNL_INT_STATUS) & 0xeeeeeeee; @@ -1415,8 +1410,6 @@ static irqreturn_t int_chnl_int_v3_hw(int irq_no, void *p) phy_no++; } - hisi_sas_write32(hisi_hba, ENT_INT_SRC_MSK3, ent_tmp); - return IRQ_HANDLED; } From patchwork Wed May 2 15:56:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134841 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp846446lji; Wed, 2 May 2018 08:57:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpCiB5VmczD/VHBEQgq1es0WIufqXp4+MnHvhqOnveEblogSuuJWIbsBFoL0hHB91FN7QGb X-Received: by 10.98.245.139 with SMTP id b11mr19958740pfm.113.1525276667235; Wed, 02 May 2018 08:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276667; cv=none; d=google.com; s=arc-20160816; b=hBaOcWtx3nAW+o3kHQDJLJGWXoZ+DEHKl+l4DWfDPMVqMxpeLbLL2Q9Z/sR8Xl/5v9 kfry1X6CoO7Q/U+/M1VSTm4FZWwAlVOrADLz2Aopm7KPV2K++5HHzyM3hIGtiG3vkl0+ tc7qR6c91vYupWU6P/1rEGgEUg2NkmcLNcnEzIpvdZOoD2PMeXAjyFKcXNaQ9WPT08sN tZmnJjTZZf5LcZyn3AbqfXPZs/hlmllaSxehYgwdIfsvoklkvtFKHHlB8JH957/V03GB CcQpfwIshoSyQhgc/xuna2gTKUpDtB8AQXYdDU+T8Q+dWPINSeiE6mIdlP17748oCqLM VVlg== 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=ikstuvfQbYyVYzA3ueypD2ZNVcuOt+Jr2LAjG49Sqlk=; b=wk6sNbgYWSQ5PajyNilNISVqrYF/AQWNQOIwf/PsXGDVN7rdxbjYFcrS7IwvSWd0AC MQ1qtEWr7ORNBLt7Zz3hRrkdKjEOmwUKSIqQ4h0ajgwAgVQBK6A+k/mC1+4zzIbmU0dC xbEjWkhS3wDerwPxDeD6FHKb577B/MrDfJY7TbInkshIIEQcGntcNu6rtNABJPPyGmel mhjX5TyXcQMCRw4YcZKBwWRTtWDibJ1aiwt8yAomMdYSq8cS+f4X7ujunTyBI1sk2MXP UjYeSPrl6JrR6/9NMamPeIuovxjrbZ+JMt09kKdWDMko1hB+/LJo3Kgv8+NN7aLvjuEO rWuQ== 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 v24si12176480pfj.292.2018.05.02.08.57.46; Wed, 02 May 2018 08:57:47 -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 S1752079AbeEBP5o (ORCPT + 29 others); Wed, 2 May 2018 11:57:44 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7219 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751891AbeEBP5m (ORCPT ); Wed, 2 May 2018 11:57:42 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 27B6998CBA406; Wed, 2 May 2018 23:57:27 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:19 +0800 From: John Garry To: , CC: , , , John Garry Subject: [PATCH 10/11] scsi: hisi_sas: add readl poll timeout helper wrappers Date: Wed, 2 May 2018 23:56:33 +0800 Message-ID: <1525276594-92173-11-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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 It is common to use readl poll timeout helpers in the driver, so create custom wrappers. Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index d6e705f..28bb71e 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -394,6 +394,20 @@ static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba, return readl(regs); } +#define hisi_sas_read32_poll_timeout(off, val, cond, delay_us, \ + timeout_us) \ +({ \ + void __iomem *regs = hisi_hba->regs + off; \ + readl_poll_timeout(regs, val, cond, delay_us, timeout_us); \ +}) + +#define hisi_sas_read32_poll_timeout_atomic(off, val, cond, delay_us, \ + timeout_us) \ +({ \ + void __iomem *regs = hisi_hba->regs + off; \ + readl_poll_timeout_atomic(regs, val, cond, delay_us, timeout_us);\ +}) + static void init_reg_v3_hw(struct hisi_hba *hisi_hba) { struct pci_dev *pdev = hisi_hba->pci_dev; @@ -684,8 +698,8 @@ static int reset_hw_v3_hw(struct hisi_hba *hisi_hba) udelay(50); /* Ensure axi bus idle */ - ret = readl_poll_timeout(hisi_hba->regs + AXI_CFG, val, !val, - 20000, 1000000); + ret = hisi_sas_read32_poll_timeout(AXI_CFG, val, !val, + 20000, 1000000); if (ret) { dev_err(dev, "axi bus is not idle, ret = %d!\n", ret); return -EIO; @@ -1977,8 +1991,9 @@ static int soft_reset_v3_hw(struct hisi_hba *hisi_hba) hisi_sas_write32(hisi_hba, AXI_MASTER_CFG_BASE + AM_CTRL_GLOBAL, 0x1); /* wait until bus idle */ - rc = readl_poll_timeout(hisi_hba->regs + AXI_MASTER_CFG_BASE + - AM_CURR_TRANS_RETURN, status, status == 0x3, 10, 100); + rc = hisi_sas_read32_poll_timeout(AXI_MASTER_CFG_BASE + + AM_CURR_TRANS_RETURN, status, + status == 0x3, 10, 100); if (rc) { dev_err(dev, "axi bus is not idle, rc = %d\n", rc); return rc; @@ -2396,8 +2411,9 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state) AM_CTRL_GLOBAL, reg_val); /* wait until bus idle */ - rc = readl_poll_timeout(hisi_hba->regs + AXI_MASTER_CFG_BASE + - AM_CURR_TRANS_RETURN, status, status == 0x3, 10, 100); + rc = hisi_sas_read32_poll_timeout(AXI_MASTER_CFG_BASE + + AM_CURR_TRANS_RETURN, status, + status == 0x3, 10, 100); if (rc) { dev_err(dev, "axi bus is not idle, rc = %d\n", rc); clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); From patchwork Wed May 2 15:56:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134843 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp846828lji; Wed, 2 May 2018 08:58:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoAwfZMYuCmxJJdrV3ZXSg13s2P+vfp58tv6rnpK5mZtSydxQLpRW1dc/hQ/ZFbJjL2Luqw X-Received: by 10.98.137.219 with SMTP id n88mr19731407pfk.11.1525276691338; Wed, 02 May 2018 08:58:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525276691; cv=none; d=google.com; s=arc-20160816; b=i6fxH6YgA4J8b1Iym4nKudmr49kqGGW/yBnoTGiLGpXBdd5+MHIuEIOglzHA96M3g6 MPsi04DyV0SNReEKRCTZWPtb2eUHnQK6uYAVuqu8WLpujdwKhiiricIX7G/5tdwNJ+1Y 8UWKUzZNRuZCaHGoAsijEWY8eiYQwFV8wTVkMoZyFRmjNEzDXlbjXSpB+U3R/ZfW+GF6 LIMvUIlRxGrBksCksh+dtMQFDF+W5d/GlnrEK5k5sSKuuWwEWEStC93I4BcEZC9KSCu/ UguZhRMj9jx201uYAMDvIxijR08jqE6UM9ucT5ml4IDjrCbVWycihFzLlGkwVHmiY1He WbCA== 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=RQpl3Th6+siYmVJaqwb6UjublRx03pKHi8ZQwBOzH9k=; b=RrwuGUb4m4T+2Ma/reJ4Jyp2Y7Ms8ejSArcJ1BYOKLfQcqiRnEHJndloPyg9n62KEp MmHgRSAuydaoXeUOE833gBsfPh1lrbtxdjw+L1NOv2aBDGE7vnMimjs3OJ8X5m15zX27 ts9cJsl2+Kk0OxrdchbpjIkqNqMP73MicjiZRvPqsMu15GdJf4W/N7yXeikJ4x/honij sUCFpYKbCUtZ4XaRkG1Z8YfOkoLiPHZxqU6JBcz9AfOJe8zxXW1L4FDBMFlUceWVPfa5 BOJIXpNm4ERf5TWBVz5XvsJRoxzpSGAI25qfhpMeDYlCbTBkhwd4bIuwIselP9MH97+M plRw== 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 g4-v6si9494358pgv.681.2018.05.02.08.58.11; Wed, 02 May 2018 08:58: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 S1752121AbeEBP6I (ORCPT + 29 others); Wed, 2 May 2018 11:58:08 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7220 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752044AbeEBP5o (ORCPT ); Wed, 2 May 2018 11:57:44 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 081F9A85C3521; Wed, 2 May 2018 23:57:27 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Wed, 2 May 2018 23:57:19 +0800 From: John Garry To: , CC: , , , Xiaofei Tan , "John Garry" Subject: [PATCH 11/11] scsi: hisi_sas: workaround a v3 hw hilink bug Date: Wed, 2 May 2018 23:56:34 +0800 Message-ID: <1525276594-92173-12-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525276594-92173-1-git-send-email-john.garry@huawei.com> References: <1525276594-92173-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: Xiaofei Tan There is an SoC bug of v3 hw development version. When hot- unplugging a directly attached disk, the PHY down interrupt may not happen. It is very easy to appear on some boards. When this issue occurs, the controller will receive many invalid dword frames, and the "alos" fields of register HILINK_ERR_DFX can indicate that disk was unplugged. As an workaround solution, this patch detects this issue in the channel interrupt, and workaround it by following steps: - Disable the PHY - Clear error code and interrupt - Enable the PHY Then the HW will reissue PHY down interrupt. Signed-off-by: Xiaofei Tan Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 28bb71e..492c3be 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -106,6 +106,7 @@ #define COMPL_Q_0_RD_PTR 0x4f0 #define AWQOS_AWCACHE_CFG 0xc84 #define ARQOS_ARCACHE_CFG 0xc88 +#define HILINK_ERR_DFX 0xe04 /* phy registers requiring init */ #define PORT_BASE (0x2000) @@ -167,6 +168,7 @@ #define CHL_INT1_DMAC_RX_AXI_RD_ERR_OFF 22 #define CHL_INT2 (PORT_BASE + 0x1bc) #define CHL_INT2_SL_IDAF_TOUT_CONF_OFF 0 +#define CHL_INT2_RX_INVLD_DW_OFF 30 #define CHL_INT2_STP_LINK_TIMEOUT_OFF 31 #define CHL_INT0_MSK (PORT_BASE + 0x1c0) #define CHL_INT1_MSK (PORT_BASE + 0x1c4) @@ -1345,6 +1347,7 @@ static irqreturn_t int_chnl_int_v3_hw(int irq_no, void *p) { struct hisi_hba *hisi_hba = p; struct device *dev = hisi_hba->dev; + struct pci_dev *pci_dev = hisi_hba->pci_dev; u32 irq_msk; int phy_no = 0; @@ -1410,8 +1413,28 @@ static irqreturn_t int_chnl_int_v3_hw(int irq_no, void *p) hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2, irq_value2); - } + if ((irq_value2 & BIT(CHL_INT2_RX_INVLD_DW_OFF)) && + (pci_dev->revision == 0x20)) { + u32 reg_value; + int rc; + + rc = hisi_sas_read32_poll_timeout_atomic( + HILINK_ERR_DFX, reg_value, + !((reg_value >> 8) & BIT(phy_no)), + 1000, 10000); + if (rc) { + disable_phy_v3_hw(hisi_hba, phy_no); + hisi_sas_phy_write32(hisi_hba, phy_no, + CHL_INT2, + BIT(CHL_INT2_RX_INVLD_DW_OFF)); + hisi_sas_phy_read32(hisi_hba, phy_no, + ERR_CNT_INVLD_DW); + mdelay(1); + enable_phy_v3_hw(hisi_hba, phy_no); + } + } + } if (irq_msk & (2 << (phy_no * 4)) && irq_value0) { hisi_sas_phy_write32(hisi_hba, phy_no,