From patchwork Thu May 31 12:50:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 137378 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6561276lji; Thu, 31 May 2018 05:52:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLR18Q4GVJPXfvgvoBzPtxKglrndmZM3IMfdUQZglWRpvOOQhCxnk9s4Li/NSodgPKUfrgi X-Received: by 2002:a17:902:1566:: with SMTP id b35-v6mr6912362plh.107.1527771152305; Thu, 31 May 2018 05:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527771152; cv=none; d=google.com; s=arc-20160816; b=q65ihf8M+B+AbrwCXLMoYHkfuFFIjr2WvVbMYkA6WrmZtNuqGMBeqCanlxoRguMRxN ahMFQR1g1QOVJvElXsgs5MZTxwZ9wOwmie7+tvnErqOGyT68eiDn8MqU0iUDVJRDXqyg yhDFUbYDT85VwGM8oPs+r5+FYfIW8SNKfp9B8ydbKjxF0KjOdHzXXwx8ylAjEEUyebZV 7ZDMf7H3lQQjvlBrgwpb11rsd/DY7T8vOpO6wD7WJjxFo2EM6VGhu/YYBxSfaPXmnyPJ Po8LmszughwNYoxfrkgKJrsBToOSPh6MSjstHIS/IBKhzPPybQ6X+yeywsiMttj8Idpr KTeQ== 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=/OZDqdTZyOCjVAoiEv2xhlRVshaTcQqp1VUHfjzaN9Y=; b=fkCPdX3OZchVKk7N+9Hy7HsGddEGBokJW6zHPyAVsFqBv5KX6oMjlqDCNdU8/L9RxT oxXi9bulzWwiyf/sZmEUSJ3mxO1sIPvdTGH78BDbgvWUCCIF1/eB1FOrSlt1X7hW56VF BCXBtsLcESoqnkVaDkRaVcLQgvClZxmy+u2+sbOyfntZoiDXH3IEW1/R/mjNp0xeWH/6 lQfh8GGfKxYLyGqW9++rNf/e1scAnQYsVefX+o1Psl4cjeK1e0TU/jfHu5h7BeFta7mK 9ZEuYy8e8dEwCC3DSlsHqySTDfkRVBIQineqzQz6d76fQPY0E6AAe/SBnUhIZvHgsre5 beug== 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 w5-v6si29296979pgq.550.2018.05.31.05.52.32; Thu, 31 May 2018 05:52:32 -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 S1755169AbeEaMwb (ORCPT + 30 others); Thu, 31 May 2018 08:52:31 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:38658 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754733AbeEaMwT (ORCPT ); Thu, 31 May 2018 08:52:19 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 862EB39E4FFBA; Thu, 31 May 2018 20:52:15 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 20:52:10 +0800 From: John Garry To: , CC: , , , Xiang Chen Subject: [PATCH 1/9] scsi: hisi_sas: Use dmam_alloc_coherent() Date: Thu, 31 May 2018 20:50:42 +0800 Message-ID: <1527771050-200916-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527771050-200916-1-git-send-email-john.garry@huawei.com> References: <1527771050-200916-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 This patch replaces the usage of dma_alloc_coherent() with the managed version, dmam_alloc_coherent(), hereby reducing replicated code. Signed-off-by: Xiang Chen Signed-off-by; John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 80 +++++++++-------------------------- 1 file changed, 20 insertions(+), 60 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 6f56297..1c424bb 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -2045,15 +2045,17 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) /* Delivery queue */ s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS; - hisi_hba->cmd_hdr[i] = dma_alloc_coherent(dev, s, - &hisi_hba->cmd_hdr_dma[i], GFP_KERNEL); + hisi_hba->cmd_hdr[i] = dmam_alloc_coherent(dev, s, + &hisi_hba->cmd_hdr_dma[i], + GFP_KERNEL); if (!hisi_hba->cmd_hdr[i]) goto err_out; /* Completion queue */ s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; - hisi_hba->complete_hdr[i] = dma_alloc_coherent(dev, s, - &hisi_hba->complete_hdr_dma[i], GFP_KERNEL); + hisi_hba->complete_hdr[i] = dmam_alloc_coherent(dev, s, + &hisi_hba->complete_hdr_dma[i], + GFP_KERNEL); if (!hisi_hba->complete_hdr[i]) goto err_out; } @@ -2064,10 +2066,11 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) goto err_out; s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct); - hisi_hba->itct = dma_zalloc_coherent(dev, s, &hisi_hba->itct_dma, - GFP_KERNEL); + hisi_hba->itct = dmam_alloc_coherent(dev, s, &hisi_hba->itct_dma, + GFP_KERNEL); if (!hisi_hba->itct) goto err_out; + memset(hisi_hba->itct, 0, s); hisi_hba->slot_info = devm_kcalloc(dev, max_command_entries, sizeof(struct hisi_sas_slot), @@ -2076,14 +2079,15 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) goto err_out; s = max_command_entries * sizeof(struct hisi_sas_iost); - hisi_hba->iost = dma_alloc_coherent(dev, s, &hisi_hba->iost_dma, - GFP_KERNEL); + hisi_hba->iost = dmam_alloc_coherent(dev, s, &hisi_hba->iost_dma, + GFP_KERNEL); if (!hisi_hba->iost) goto err_out; s = max_command_entries * sizeof(struct hisi_sas_breakpoint); - hisi_hba->breakpoint = dma_alloc_coherent(dev, s, - &hisi_hba->breakpoint_dma, GFP_KERNEL); + hisi_hba->breakpoint = dmam_alloc_coherent(dev, s, + &hisi_hba->breakpoint_dma, + GFP_KERNEL); if (!hisi_hba->breakpoint) goto err_out; @@ -2094,14 +2098,16 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) goto err_out; s = sizeof(struct hisi_sas_initial_fis) * HISI_SAS_MAX_PHYS; - hisi_hba->initial_fis = dma_alloc_coherent(dev, s, - &hisi_hba->initial_fis_dma, GFP_KERNEL); + hisi_hba->initial_fis = dmam_alloc_coherent(dev, s, + &hisi_hba->initial_fis_dma, + GFP_KERNEL); if (!hisi_hba->initial_fis) goto err_out; s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_sata_breakpoint); - hisi_hba->sata_breakpoint = dma_alloc_coherent(dev, s, - &hisi_hba->sata_breakpoint_dma, GFP_KERNEL); + hisi_hba->sata_breakpoint = dmam_alloc_coherent(dev, s, + &hisi_hba->sata_breakpoint_dma, + GFP_KERNEL); if (!hisi_hba->sata_breakpoint) goto err_out; hisi_sas_init_mem(hisi_hba); @@ -2122,54 +2128,8 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) void hisi_sas_free(struct hisi_hba *hisi_hba) { - struct device *dev = hisi_hba->dev; - int i, s, max_command_entries = hisi_hba->hw->max_command_entries; - - for (i = 0; i < hisi_hba->queue_count; i++) { - s = sizeof(struct hisi_sas_cmd_hdr) * HISI_SAS_QUEUE_SLOTS; - if (hisi_hba->cmd_hdr[i]) - dma_free_coherent(dev, s, - hisi_hba->cmd_hdr[i], - hisi_hba->cmd_hdr_dma[i]); - - s = hisi_hba->hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS; - if (hisi_hba->complete_hdr[i]) - dma_free_coherent(dev, s, - hisi_hba->complete_hdr[i], - hisi_hba->complete_hdr_dma[i]); - } - dma_pool_destroy(hisi_hba->buffer_pool); - s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct); - if (hisi_hba->itct) - dma_free_coherent(dev, s, - hisi_hba->itct, hisi_hba->itct_dma); - - s = max_command_entries * sizeof(struct hisi_sas_iost); - if (hisi_hba->iost) - dma_free_coherent(dev, s, - hisi_hba->iost, hisi_hba->iost_dma); - - s = max_command_entries * sizeof(struct hisi_sas_breakpoint); - if (hisi_hba->breakpoint) - dma_free_coherent(dev, s, - hisi_hba->breakpoint, - hisi_hba->breakpoint_dma); - - - s = sizeof(struct hisi_sas_initial_fis) * HISI_SAS_MAX_PHYS; - if (hisi_hba->initial_fis) - dma_free_coherent(dev, s, - hisi_hba->initial_fis, - hisi_hba->initial_fis_dma); - - s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_sata_breakpoint); - if (hisi_hba->sata_breakpoint) - dma_free_coherent(dev, s, - hisi_hba->sata_breakpoint, - hisi_hba->sata_breakpoint_dma); - if (hisi_hba->wq) destroy_workqueue(hisi_hba->wq); } From patchwork Thu May 31 12:50:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 137384 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6563453lji; Thu, 31 May 2018 05:54:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ9La2edVvlis6zZ99rZpU2zf0XYmsZ0HPb28KKvEa2WBv/oekTOSHTpU+IbpAJ34S0/2f8 X-Received: by 2002:a65:65c8:: with SMTP id y8-v6mr5510823pgv.320.1527771253170; Thu, 31 May 2018 05:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527771253; cv=none; d=google.com; s=arc-20160816; b=W5cM0uV5KqUxlkX0aJxnCbOTTii/iL2Y/MVZzJ0aXqVoY9ycrcJ6k+FITpynAf+gzN ZInT/S8Pwe0VvdL/TavlPST/BEOFdnIDB2aIxuHkBsSy07RmSrCRaXCm4fqJac3apzZH frYFq8b/tDzjfiT0WkF5LNY86OlDw1ywoVKsdDGF0nLeUYLBIYk3f4zPViUhd/woILcd oS+1o/KNXra40uGhN0hYWnFApEnUZ3ktp7fym9MDSejdicUBLej37qAita6RIzPMkHbW ku/xcg/reqQvZQwAzrwJRD1vXsAXpmUkZGg2qAEoO8C3Se19cmHyQPM5B9aEh6hbND8c s5IA== 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=euqTva8NR/TLhpx7x8QlQ0uKLcNI4wv5Vqy04cEe4RI=; b=wuZ4awDTwM1vX53Pce0Ols8i/uIR9ae6x7QIJxHCUxNBco33UBa4PZZeS2Is29xL2X 5dBlViPw4kPUUSK9o/v0E8tWMT6XML2qVwHuJbIqSFiuhHpaOOYaLlJrtaqog2RptGhQ 8txRcK2e6BuL737CjShYVhNx1vE1D+oEmHqid5X+RJxcbltHdh8Em6fktevhACcB1RZM yYa79g59vg9/MKzUbWWmXrHApRLQLVOD1vCXDZJufV1NP6IeU9ZcGyqz2sJEoDoJ4t4B FxcftDA4qaw1U4bjsKeioIBMLUsyJttr0rD693VvL3/XegBrJ0yiRgkuDLOM8FaLQjm3 C3FA== 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 b60-v6si37427586plc.270.2018.05.31.05.54.12; Thu, 31 May 2018 05:54:13 -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 S1755287AbeEaMyK (ORCPT + 30 others); Thu, 31 May 2018 08:54:10 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:38663 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755050AbeEaMwW (ORCPT ); Thu, 31 May 2018 08:52:22 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9A90154E10C2D; Thu, 31 May 2018 20:52:15 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 20:52:10 +0800 From: John Garry To: , CC: , , , Xiaofei Tan , "John Garry" Subject: [PATCH 2/9] scsi: hisi_sas: Only process broadcast change in phy_bcast_v3_hw() Date: Thu, 31 May 2018 20:50:43 +0800 Message-ID: <1527771050-200916-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527771050-200916-1-git-send-email-john.garry@huawei.com> References: <1527771050-200916-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 are many BROADCAST primitives generated by the host. We are only interested in BROADCAST (CHANGE) primitives currently, so only process this. We have applied this processing for v2 hw before, and it is also needed for v3 hw. Signed-off-by: Xiaofei Tan Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 8 +++++++- 1 file changed, 7 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 9f1e2d0..0a126a82 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -131,6 +131,9 @@ #define SL_CONTROL_NOTIFY_EN_MSK (0x1 << SL_CONTROL_NOTIFY_EN_OFF) #define SL_CTA_OFF 17 #define SL_CTA_MSK (0x1 << SL_CTA_OFF) +#define RX_PRIMS_STATUS (PORT_BASE + 0x98) +#define RX_BCAST_CHG_OFF 1 +#define RX_BCAST_CHG_MSK (0x1 << RX_BCAST_CHG_OFF) #define TX_ID_DWORD0 (PORT_BASE + 0x9c) #define TX_ID_DWORD1 (PORT_BASE + 0xa0) #define TX_ID_DWORD2 (PORT_BASE + 0xa4) @@ -1256,9 +1259,12 @@ static irqreturn_t phy_bcast_v3_hw(int phy_no, struct hisi_hba *hisi_hba) struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; struct asd_sas_phy *sas_phy = &phy->sas_phy; struct sas_ha_struct *sas_ha = &hisi_hba->sha; + u32 bcast_status; hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1); - sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); + bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS); + if (bcast_status & RX_BCAST_CHG_MSK) + sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_SL_RX_BCST_ACK_MSK); hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 0); From patchwork Thu May 31 12:50:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 137377 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6561216lji; Thu, 31 May 2018 05:52:29 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIaX0tjomf++C6ScV7FlkbS/8geZZGf7BUhu0+gb8T3j68zT/7SuiTag1omwfKJQi8J86mL X-Received: by 2002:a17:902:a714:: with SMTP id w20-v6mr6705338plq.374.1527771148976; Thu, 31 May 2018 05:52:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527771148; cv=none; d=google.com; s=arc-20160816; b=cCrn7DFk3efSSppowXDkO/Mj5d9RhLZsHvSQqB47WHjVtmb2IiKZqsPXNxXJrpYDEP 08kDP8I4AUQQDa8b9NMR/UpD0yM/mImVu+xbFeMDpDAaTLzO1/sYYA9edFkaaKAhEct4 dEWYYDtqBsgpJphF411zZSfycHwTE7mJluZTzM5fncyemREKFU4pLVklcHpVI/1nkAHJ 3nDA9iqWEzC26D/n9YKfbZ8IQPuxP3RtaiJ685RTwHMmjaDGjn6QPwMQzTPFrndDTaJL GH3FPrUPPVSkJzE33xjEY8FppO+f4JGqkbwhhvSujdiVRHfndF9ZAdCcB6N0Xr8NzvfC PJmw== 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=Tb0qRMUZmwx+H0DMRsKfjFevqdsxHCsIusk8TJdfRNU=; b=rhA/GjEiTtqPTho550yLTPb7z0+OPPfrSnEDkqrIGGIfxMiqar04iDzriEN58NVSVw weJO1Alj6yb3ROvC0R7OVNue3LRi+kGNrRfUkb6YL3e3OD+Hea7g+7qgFlfHUlvgAewd 2RoOSOUsu3TengIzs9munJmRVujU2jDOAjjE1V61OKkueAYV+EVzPH09XtOQ8V54d3qk j60RgohOiqw4VU65qJj3YjgHwgEd8Gb1K25Q4ZlX7mD5shNrQdY7+3AW8kvAa4vNcGtA T2qDnAtyc71hZnYdnU/RIZMxPuejmXEgDnVAAfeeL2rDbR4kbbQDAGFR53gHb9wtI45b XhrQ== 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 w5-v6si29296979pgq.550.2018.05.31.05.52.28; Thu, 31 May 2018 05:52:28 -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 S1755134AbeEaMw0 (ORCPT + 30 others); Thu, 31 May 2018 08:52:26 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:38674 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754918AbeEaMwT (ORCPT ); Thu, 31 May 2018 08:52:19 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A8CA4779A2093; Thu, 31 May 2018 20:52:15 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 20:52:10 +0800 From: John Garry To: , CC: , , , Xiaofei Tan , "John Garry" Subject: [PATCH 3/9] scsi: hisi_sas: Fix the conflict between dev gone and host reset Date: Thu, 31 May 2018 20:50:44 +0800 Message-ID: <1527771050-200916-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527771050-200916-1-git-send-email-john.garry@huawei.com> References: <1527771050-200916-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 a possible conflict when a device is removed and host reset occurs concurrently. The reason is that then the device is notified as gone, we try to clear the ITCT, which is notified via an interrupt. The dev gone function pends on this event with a completion, which is completed when the ITCT interrupt occurs. But host reset will disable all interrupts, the wait_for_completion() may wait indefinitely. This patch adds an semaphore to synchronise this two processes. The semaphore is taken by the host reset as the basis of synchronising. Signed-off-by: Xiaofei Tan Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas.h | 1 + drivers/scsi/hisi_sas/hisi_sas_main.c | 6 ++++++ 2 files changed, 7 insertions(+) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h index 7052a5d..78e5a92 100644 --- a/drivers/scsi/hisi_sas/hisi_sas.h +++ b/drivers/scsi/hisi_sas/hisi_sas.h @@ -277,6 +277,7 @@ struct hisi_hba { int n_phy; spinlock_t lock; + struct semaphore sem; struct timer_list timer; struct workqueue_struct *wq; diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 1c424bb..823386f 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -914,7 +914,9 @@ static void hisi_sas_dev_gone(struct domain_device *device) hisi_sas_dereg_device(hisi_hba, device); + down(&hisi_hba->sem); hisi_hba->hw->clear_itct(hisi_hba, sas_dev); + up(&hisi_hba->sem); device->lldd_dev = NULL; } @@ -1364,6 +1366,7 @@ static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba) if (test_and_set_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) return -1; + down(&hisi_hba->sem); dev_info(dev, "controller resetting...\n"); old_state = hisi_hba->hw->get_phys_state(hisi_hba); @@ -1378,6 +1381,7 @@ static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba) if (rc) { dev_warn(dev, "controller reset failed (%d)\n", rc); clear_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags); + up(&hisi_hba->sem); scsi_unblock_requests(shost); goto out; } @@ -1388,6 +1392,7 @@ static int hisi_sas_controller_reset(struct hisi_hba *hisi_hba) hisi_hba->hw->phys_init(hisi_hba); msleep(1000); hisi_sas_refresh_port_id(hisi_hba); + up(&hisi_hba->sem); if (hisi_hba->reject_stp_links_msk) hisi_sas_terminate_stp_reject(hisi_hba); @@ -2016,6 +2021,7 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) struct device *dev = hisi_hba->dev; int i, s, max_command_entries = hisi_hba->hw->max_command_entries; + sema_init(&hisi_hba->sem, 1); spin_lock_init(&hisi_hba->lock); for (i = 0; i < hisi_hba->n_phy; i++) { hisi_sas_phy_init(hisi_hba, i); From patchwork Thu May 31 12:50:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 137381 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6561624lji; Thu, 31 May 2018 05:52:48 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJWk68BU7mevhzZWnPyVdWYxV56c4jFHTvtRaYr3OCl/z7WDyTRkwRzANPlc0oHZH1csOsa X-Received: by 2002:a63:62c7:: with SMTP id w190-v6mr5598220pgb.104.1527771167934; Thu, 31 May 2018 05:52:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527771167; cv=none; d=google.com; s=arc-20160816; b=gKF3omhGEzGh3FquaDdHRMyJkpF8dv69+Fumlmt48wDgwwL+toEEdTT7+seX0OEKjs Pc8KxD/e1w/BpqQyvz40ktn6cPdkD/By/CBBxnTodUGdMILS7ic6b2c9LqPJQnHvwDcX H38IdjIti2LYgfAsETHV30ue/3x2UN4jmnBHkT3jOg4A5pxQyGohawrQPy7NUNvQr9mb tsAQJlFDFoAgNs+gk8R+4pObOJHsVKu8yLaMaNGyL10Mp1kyJrFDWJYdi5jd6G1VgrRv JDzIBVyPf/09a2wOFg6qiDK0v2CQgRzgSvl77CAxhpJ5RXZI13lSCeG8gX1vgTn2x628 8iOQ== 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=YdZ4xL6T8L8PA2kgT57RJ4G4Uan3e9JHiyCpRH58t/w=; b=quQPhjtGjRSPfkwQixXh/IKn4xTiCSBeHwmUEpt7rtqBwP1n3kXMPow+TxAYoccax3 PPConMCOVOadXl5C4u2i+H76qF16WsWVO7ehiNgHLFAwhq9W7+0rajfi1bJgC2yrUJeK +5vEx7K+1P9LYCUvPQxv+xMbVxBz7GB2jwJEi1VSmPvK+oBdhqB207kKzeOpU3i4vteF N9KGmR5YEtVz6X3hyN0orEzPaYAzdZM9upacTscd95qcAmQfxjN11ceQE2Rf0h2A6+fm VHW7FFJMKFl2kki6HiANQTLaTBFuXig89C277vnTDrxYRVHQT0Ntfz3G6AsFP2JtHvYl wU0w== 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 q2-v6si37041758plh.136.2018.05.31.05.52.47; Thu, 31 May 2018 05:52: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 S1755247AbeEaMwp (ORCPT + 30 others); Thu, 31 May 2018 08:52:45 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8239 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755175AbeEaMwg (ORCPT ); Thu, 31 May 2018 08:52:36 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 59C1E80D2C8DC; Thu, 31 May 2018 20:52:20 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 20:52:11 +0800 From: John Garry To: , CC: , , , Xiaofei Tan , "John Garry" Subject: [PATCH 5/9] scsi: hisi_sas: Add a flag to filter PHY events during reset Date: Thu, 31 May 2018 20:50:46 +0800 Message-ID: <1527771050-200916-6-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527771050-200916-1-git-send-email-john.garry@huawei.com> References: <1527771050-200916-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 During reset, we don't want PHY events reported to libsas for PHYs which were previously attached prior to reset. So check hisi_hba->flags for HISI_SAS_RESET_BIT to filter PHY events during reset. Signed-off-by: Xiaofei Tan Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 3 ++- drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 3 ++- drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 3 ++- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 3 ++- 4 files changed, 8 insertions(+), 4 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 090d3e0..006e776 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -1927,7 +1927,8 @@ void hisi_sas_phy_down(struct hisi_hba *hisi_hba, int phy_no, int rdy) } else { struct hisi_sas_port *port = phy->port; - if (phy->in_reset) { + if (test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags) || + phy->in_reset) { dev_info(dev, "ignore flutter phy%d down\n", phy_no); return; } diff --git a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c index 89ab18c..3277442 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c @@ -1469,7 +1469,8 @@ static irqreturn_t int_bcast_v1_hw(int irq, void *p) goto end; } - sha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); + if (!test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) + sha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); end: hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT2, diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index 213c530..159576e 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -2840,7 +2840,8 @@ static void phy_bcast_v2_hw(int phy_no, struct hisi_hba *hisi_hba) hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1); bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS); - if (bcast_status & RX_BCAST_CHG_MSK) + if ((bcast_status & RX_BCAST_CHG_MSK) && + !test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_SL_RX_BCST_ACK_MSK); diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index c40fdb8..e43881d 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -1263,7 +1263,8 @@ static irqreturn_t phy_bcast_v3_hw(int phy_no, struct hisi_hba *hisi_hba) hisi_sas_phy_write32(hisi_hba, phy_no, SL_RX_BCAST_CHK_MSK, 1); bcast_status = hisi_sas_phy_read32(hisi_hba, phy_no, RX_PRIMS_STATUS); - if (bcast_status & RX_BCAST_CHG_MSK) + if ((bcast_status & RX_BCAST_CHG_MSK) && + !test_bit(HISI_SAS_RESET_BIT, &hisi_hba->flags)) sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD); hisi_sas_phy_write32(hisi_hba, phy_no, CHL_INT0, CHL_INT0_SL_RX_BCST_ACK_MSK); From patchwork Thu May 31 12:50:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 137380 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6561534lji; Thu, 31 May 2018 05:52:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJyJafYc3n5d1QEHisWsuwcnC9/H/BgDZ8WXsTbL8g9BMtS3HrDWTeXHpnOdMlhQpqo+BSA X-Received: by 2002:a17:902:a5c7:: with SMTP id t7-v6mr6950589plq.360.1527771163916; Thu, 31 May 2018 05:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527771163; cv=none; d=google.com; s=arc-20160816; b=kvMOgkcth6WcwyJarse0ZDkl0RBs95DJm3dUCmXbk+4E04V8gC3tQxUCjEpEi5b+Dc yXledFsi8iDkr8rgpJvFjLGOtzdJKE4X0CHVPSZBtuBVtibbgyjONoVNndsxxRehwLt4 UrtI85dhULsv78vmcHe/ZV20VGXIhqcK6ogHLT0RvKNrrL+pL7eU+pqoc4LRBvx7TOT+ 1Xgn+ke8DslqmigDmV3dzR5utyA2gDMSnwJ2v7d7DjfR3z+j5mmrCYNufuyJNpvpS10K Qg23p7W0Re5UIc/A5EEl/e2CqnMdMTy8jMjzpIwyV+tvETTJvgf4JEQGkArnxwpNTHoL ye3Q== 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=9SIJsYtmMZVBNE41neSSgQ3xOeFL341w79GbWHef5YE=; b=dkIU+FIHChe3muGZsho1rdQojLq4pOLgL6PRoR9O9Fqrz5nFboWvWMOPu915IH5Vlr DjzpDrPXH1FX3FWaWfuwjqQK5qA/6srRoGTcx+2w63uRJM6TrmdVeu0ck9c2hw6Omp0+ H9FAnFyEBZkTJTzHdBQibSx1c3q+hYCJPQhUiSuMy0p7O2LjbFYd8InLvacavgI3DnV7 BbXeEHpEWEVQBMyUYvaecW5xlbZRz5SGrXEXGXr7t1fg97CzSQR891CEDXJr8i3J5tGG dOicil1QufxYRhqExl5xhQzA1+DUDb9GaJjpMbF6qroqAGNv1CCkP4To9r+aP2fW1YUG HR0A== 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 q2-v6si37041758plh.136.2018.05.31.05.52.43; Thu, 31 May 2018 05:52:43 -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 S1755228AbeEaMwl (ORCPT + 30 others); Thu, 31 May 2018 08:52:41 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8237 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755171AbeEaMwe (ORCPT ); Thu, 31 May 2018 08:52:34 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3BCA51E64C9CB; Thu, 31 May 2018 20:52:20 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 20:52:12 +0800 From: John Garry To: , CC: , , , Xiaofei Tan , "John Garry" Subject: [PATCH 6/9] scsi: hisi_sas: Release all remaining resources in clear nexus ha Date: Thu, 31 May 2018 20:50:47 +0800 Message-ID: <1527771050-200916-7-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527771050-200916-1-git-send-email-john.garry@huawei.com> References: <1527771050-200916-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 In host reset, we use TMF or soft-reset to re-init device, and if success, we will release all LLDD resources of this device. If the init fails - maybe because the device was removed or link has not come up - then do not release the LLDD resources, but rather rely on SCSI EH to handle the timeout for these resources later on. But if clear nexus ha calls host reset, which is the last effort of SCSI EH, we should release all LLDD remain resources. Because SCSI EH will release all tasks after clear nexus ha. Before release, we do I_T nexus reset to try to clear target remain IOs. Signed-off-by: Xiaofei Tan Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 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 006e776..da1d5fe 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -1652,14 +1652,32 @@ static int hisi_sas_lu_reset(struct domain_device *device, u8 *lun) static int hisi_sas_clear_nexus_ha(struct sas_ha_struct *sas_ha) { struct hisi_hba *hisi_hba = sas_ha->lldd_ha; + struct device *dev = hisi_hba->dev; HISI_SAS_DECLARE_RST_WORK_ON_STACK(r); + int rc, i; queue_work(hisi_hba->wq, &r.work); wait_for_completion(r.completion); - if (r.done) - return TMF_RESP_FUNC_COMPLETE; + if (!r.done) + return TMF_RESP_FUNC_FAILED; + + for (i = 0; i < HISI_SAS_MAX_DEVICES; i++) { + struct hisi_sas_device *sas_dev = &hisi_hba->devices[i]; + struct domain_device *device = sas_dev->sas_device; + + if ((sas_dev->dev_type == SAS_PHY_UNUSED) || !device || + DEV_IS_EXPANDER(device->dev_type)) + continue; + + rc = hisi_sas_debug_I_T_nexus_reset(device); + if (rc != TMF_RESP_FUNC_COMPLETE) + dev_info(dev, "clear nexus ha: for device[%d] rc=%d\n", + sas_dev->device_id, rc); + } + + hisi_sas_release_tasks(hisi_hba); - return TMF_RESP_FUNC_FAILED; + return TMF_RESP_FUNC_COMPLETE; } static int hisi_sas_query_task(struct sas_task *task) From patchwork Thu May 31 12:50:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 137382 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6562387lji; Thu, 31 May 2018 05:53:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLriKbAaI/aVNdbwgdGvStix4ssIw/VyeelU8DXa1tXG1MTmpNXVhsi39BBBTh8n+f8kpaO X-Received: by 2002:a17:902:1025:: with SMTP id b34-v6mr6802740pla.207.1527771202497; Thu, 31 May 2018 05:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527771202; cv=none; d=google.com; s=arc-20160816; b=R4ARpAmKgCmrHPiIeudqLoZposDbDVPOmmphdHamyIMVU6f26rIbCecugObFYwIRYb Ckh5I/z2IdP7s8shORIDEEplQ8coRdmseJBamAzaOAhjftmnyOeZs0FVhha9zhVQFvOx ubV3yi+J5vL1TZL8DZ5Jzpl+ZFv1Zd4gNGz4BFkhdMhT80fnn5TKtC+QDWI5v6Y1opGp VUEPblZOoJToiOVna69B+zjt1hCKJGsfq0+dMZ6z8GqqK5KftlBxtiDC7wUOUfdjNavN LeMQQl5tcDGVcoskFOEBpdFxrt+bArTyCqBDDMQljwdi8ylddaFuia+nFx4lIJpCch5O 6e2A== 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=C8zu1tN/ZsSZSXuP6l44nKabv93flE8w0XiARI1cugo=; b=0dx8t8jNO1IMtFJLvEC88ZefmDNgSw0WgvzLfTezHC6dPu83fOLYpidfqiLxREOMNn ybxUJUpJS9BUaicmo8RCgG2NB18KeELX02HTTb3GvI996n1wvJ//1qGHyADUh5s/jssl oXVYCeEHYBhvCfDZBxyD5D3Vtfi0yCmN0Yk3dJ3UGRr23SKqBttXyVa6aU9gHgqthipL WJRw4QrMr7kVhHnZBUW31HvJ9+Eh190BjrGnJW1/VXfWd0StQLVLAQh3SmKqnJpnexhR +sEdeY4NFkkJcd3TBOsMjX7jLQXfVoiyqATbsF7Y0qO5ZMntCvayPwemIivbCad4W0Mf 6fTQ== 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 q9-v6si1026537pll.370.2018.05.31.05.53.22; Thu, 31 May 2018 05:53:22 -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 S1755261AbeEaMxT (ORCPT + 30 others); Thu, 31 May 2018 08:53:19 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8238 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755172AbeEaMwg (ORCPT ); Thu, 31 May 2018 08:52:36 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 49F3589E82323; Thu, 31 May 2018 20:52:20 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 20:52:12 +0800 From: John Garry To: , CC: , , , Xiang Chen , "John Garry" Subject: [PATCH 7/9] scsi: hisi_sas: Pre-allocate slot DMA buffers Date: Thu, 31 May 2018 20:50:48 +0800 Message-ID: <1527771050-200916-8-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527771050-200916-1-git-send-email-john.garry@huawei.com> References: <1527771050-200916-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 Currently the driver spends much time allocating and freeing the slot DMA buffer for command delivery/completion. To boost the performance, pre-allocate the buffers for all IPTT. The downside of this approach is that we are reallocating all buffer memory upfront, so hog memory which we may not need. However, the current method - DMA buffer pool - also caches all buffers and does not free them until the pool is destroyed, so is not exactly efficient either. On top of this, since the slot DMA buffer is slightly bigger than a 4K page, we need to allocate 2x4K pages per buffer (for 4K page kernel), which is quite wasteful. For 64K page size this is not such an issue. So, for the 4K page case, in order to make memory usage more efficient, pre-allocating larger blocks of DMA memory for the buffers can be more efficient. To make DMA memory usage most efficient, we would choose a single contiguous DMA memory block, but this could use up all the DMA memory in the system (when CMA enabled and no IOMMU), or we may just not be able to allocate a DMA buffer large enough when no CMA or IOMMU. To decide the block size we use the LCM (least common multiple) of the buffer size and the page size. We roundup(64) to ensure the LCM is not too large, even though a little memory may be wasted per block. So, with this, the total memory requirement is about is about 17MB for 4096 max IPTT. Previously (for 4K pages case), it would be 32MB (for all slots allocated). With this change, the relative increase of IOPS for bs=4K read when PAGE_SIZE=4K and PAGE_SIZE=64K is as follows: IODEPTH 4K PAGE_SIZE 64K PAGE_SIZE 32 56% 47% 64 53% 44% 128 64% 43% 256 67% 45% Signed-off-by: Xiang Chen Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas.h | 9 ++-- drivers/scsi/hisi_sas/hisi_sas_main.c | 78 +++++++++++++++++------------------ 2 files changed, 42 insertions(+), 45 deletions(-) -- 1.9.1 diff --git a/drivers/scsi/hisi_sas/hisi_sas.h b/drivers/scsi/hisi_sas/hisi_sas.h index 78e5a92..beda412 100644 --- a/drivers/scsi/hisi_sas/hisi_sas.h +++ b/drivers/scsi/hisi_sas/hisi_sas.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -199,17 +200,18 @@ struct hisi_sas_slot { int dlvry_queue_slot; int cmplt_queue; int cmplt_queue_slot; - int idx; int abort; int ready; - void *buf; - dma_addr_t buf_dma; void *cmd_hdr; 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 *tmf; + /* Do not reorder/change members after here */ + void *buf; + dma_addr_t buf_dma; + int idx; }; struct hisi_sas_hw { @@ -299,7 +301,6 @@ struct hisi_hba { int queue_count; - struct dma_pool *buffer_pool; struct hisi_sas_device devices[HISI_SAS_MAX_DEVICES]; struct hisi_sas_cmd_hdr *cmd_hdr[HISI_SAS_MAX_QUEUES]; dma_addr_t cmd_hdr_dma[HISI_SAS_MAX_QUEUES]; diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index da1d5fe..20aab10 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -242,20 +242,16 @@ void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task, task->data_dir); } - 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; + + memset(slot, 0, offsetof(struct hisi_sas_slot, buf)); + 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 */ } EXPORT_SYMBOL_GPL(hisi_sas_slot_task_free); @@ -430,21 +426,13 @@ static int hisi_sas_task_prep(struct sas_task *task, goto err_out_dma_unmap; slot = &hisi_hba->slot_info[slot_idx]; - memset(slot, 0, sizeof(struct hisi_sas_slot)); - - slot->buf = dma_pool_alloc(hisi_hba->buffer_pool, - GFP_ATOMIC, &slot->buf_dma); - if (!slot->buf) { - rc = -ENOMEM; - goto err_out_tag; - } spin_lock_irqsave(&dq->lock, flags_dq); wr_q_index = hisi_hba->hw->get_free_slot(hisi_hba, dq); if (wr_q_index < 0) { spin_unlock_irqrestore(&dq->lock, flags_dq); rc = -EAGAIN; - goto err_out_buf; + goto err_out_tag; } list_add_tail(&slot->delivery, &dq->list); @@ -453,7 +441,6 @@ static int hisi_sas_task_prep(struct sas_task *task, dlvry_queue = dq->id; dlvry_queue_slot = wr_q_index; - slot->idx = slot_idx; slot->n_elem = n_elem; slot->dlvry_queue = dlvry_queue; slot->dlvry_queue_slot = dlvry_queue_slot; @@ -500,9 +487,6 @@ static int hisi_sas_task_prep(struct sas_task *task, return 0; -err_out_buf: - dma_pool_free(hisi_hba->buffer_pool, slot->buf, - slot->buf_dma); err_out_tag: spin_lock_irqsave(&hisi_hba->lock, flags); hisi_sas_slot_index_free(hisi_hba, slot_idx); @@ -1749,21 +1733,13 @@ static int hisi_sas_query_task(struct sas_task *task) spin_unlock_irqrestore(&hisi_hba->lock, flags); slot = &hisi_hba->slot_info[slot_idx]; - memset(slot, 0, sizeof(struct hisi_sas_slot)); - - slot->buf = dma_pool_alloc(hisi_hba->buffer_pool, - GFP_ATOMIC, &slot->buf_dma); - if (!slot->buf) { - rc = -ENOMEM; - goto err_out_tag; - } spin_lock_irqsave(&dq->lock, flags_dq); wr_q_index = hisi_hba->hw->get_free_slot(hisi_hba, dq); if (wr_q_index < 0) { spin_unlock_irqrestore(&dq->lock, flags_dq); rc = -EAGAIN; - goto err_out_buf; + goto err_out_tag; } list_add_tail(&slot->delivery, &dq->list); spin_unlock_irqrestore(&dq->lock, flags_dq); @@ -1771,7 +1747,6 @@ static int hisi_sas_query_task(struct sas_task *task) dlvry_queue = dq->id; dlvry_queue_slot = wr_q_index; - slot->idx = slot_idx; slot->n_elem = n_elem; slot->dlvry_queue = dlvry_queue; slot->dlvry_queue_slot = dlvry_queue_slot; @@ -1802,9 +1777,6 @@ static int hisi_sas_query_task(struct sas_task *task) return 0; -err_out_buf: - dma_pool_free(hisi_hba->buffer_pool, slot->buf, - slot->buf_dma); err_out_tag: spin_lock_irqsave(&hisi_hba->lock, flags); hisi_sas_slot_index_free(hisi_hba, slot_idx); @@ -2041,7 +2013,9 @@ void hisi_sas_init_mem(struct hisi_hba *hisi_hba) int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) { struct device *dev = hisi_hba->dev; - int i, s, max_command_entries = hisi_hba->hw->max_command_entries; + int i, j, s, max_command_entries = hisi_hba->hw->max_command_entries; + int max_command_entries_ru, sz_slot_buf_ru; + int blk_cnt, slots_per_blk; sema_init(&hisi_hba->sem, 1); spin_lock_init(&hisi_hba->lock); @@ -2088,11 +2062,6 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) goto err_out; } - s = sizeof(struct hisi_sas_slot_buf_table); - hisi_hba->buffer_pool = dma_pool_create("dma_buffer", dev, s, 16, 0); - if (!hisi_hba->buffer_pool) - goto err_out; - s = HISI_SAS_MAX_ITCT_ENTRIES * sizeof(struct hisi_sas_itct); hisi_hba->itct = dmam_alloc_coherent(dev, s, &hisi_hba->itct_dma, GFP_KERNEL); @@ -2106,6 +2075,35 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) if (!hisi_hba->slot_info) goto err_out; + /* roundup to avoid overly large block size */ + max_command_entries_ru = roundup(max_command_entries, 64); + sz_slot_buf_ru = roundup(sizeof(struct hisi_sas_slot_buf_table), 64); + s = lcm(max_command_entries_ru, sz_slot_buf_ru); + blk_cnt = (max_command_entries_ru * sz_slot_buf_ru) / s; + slots_per_blk = s / sz_slot_buf_ru; + for (i = 0; i < blk_cnt; i++) { + struct hisi_sas_slot_buf_table *buf; + dma_addr_t buf_dma; + int slot_index = i * slots_per_blk; + + buf = dmam_alloc_coherent(dev, s, &buf_dma, GFP_KERNEL); + if (!buf) + goto err_out; + memset(buf, 0, s); + + for (j = 0; j < slots_per_blk; j++, slot_index++) { + struct hisi_sas_slot *slot; + + slot = &hisi_hba->slot_info[slot_index]; + slot->buf = buf; + slot->buf_dma = buf_dma; + slot->idx = slot_index; + + buf++; + buf_dma += sizeof(*buf); + } + } + s = max_command_entries * sizeof(struct hisi_sas_iost); hisi_hba->iost = dmam_alloc_coherent(dev, s, &hisi_hba->iost_dma, GFP_KERNEL); @@ -2156,8 +2154,6 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba, struct Scsi_Host *shost) void hisi_sas_free(struct hisi_hba *hisi_hba) { - dma_pool_destroy(hisi_hba->buffer_pool); - if (hisi_hba->wq) destroy_workqueue(hisi_hba->wq); } From patchwork Thu May 31 12:50:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 137383 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp6562470lji; Thu, 31 May 2018 05:53:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIugBx3JFo0ljW58KreFk8EFZ2iLGEYxfT0VOjfsBUwQjZ9IaQQFlXxBA6RNg4CJ2DTM+J2 X-Received: by 2002:a17:902:8a95:: with SMTP id p21-v6mr6985583plo.325.1527771206616; Thu, 31 May 2018 05:53:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527771206; cv=none; d=google.com; s=arc-20160816; b=JaGGQDEjKy1HWGrbwdkeKUzN4miTURA9xoao9ByEcLRrwkpaVxA3+6etEZTxfHcDz+ sPMbFlIn5XsTRt2bUEetk0smyqQhpWkeoFYPzHp9pXxbHjuBqc9i7iYtu9Nhn2H6ldZi wfKXk38dC2I+bUKvAGraXaa41NEtYzHOLSfWe8M8S/HEURr/PtpNUXjEWxSVK+JTb3C/ NE6afhi3LkvjdUgTkL94D3XbmkRyTuQ0gRd/iqXEffrmi8N8wG9vOMCREGkUpzo0nPIZ CepDxwWdft+boWL8sBCaiHmNdER9CRHTAmuKAU7MYgn8IqIN+Bwtx6oCLfOWxt+tggyq OQCA== 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=QmugDvfCSbUnl1/K043WLbeDebkfxIt1PRAhRW8KMOc=; b=Xhx+9xpzJ/it9/BpudlNFpP7swDqh0DEvUCaJOnKSK8LkQHK09gDcbtVwe5sVIFssp 76Nsn2m1lGpHg2LRlkxktHpVpxEj7KH/ps301oMypB6sG2/guD/wjdrDM4T4OFY8fFir I9MTeE7fQAvrzBCfi6xrF0o9EbHyJckODz3dUP5UZMoFgxTHsn/LAb2Xc5Mb89ZwTkTp tXmclon/mrVWPkNCnlR9P27R5A7XPJTJaFonyNtqrx03BNMQCp2WqOoWy+iJQoVlIF5u 7qc7LfJ7zlfuwqlh5BC4+jIDP4Sipeh6AMvnUL4Gxhm2BedQOzgOcFqBYadIkH3bcn7o B/2g== 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 d18-v6si25058272pgp.280.2018.05.31.05.53.26; Thu, 31 May 2018 05:53:26 -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 S1755277AbeEaMxY (ORCPT + 30 others); Thu, 31 May 2018 08:53:24 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8235 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755174AbeEaMwf (ORCPT ); Thu, 31 May 2018 08:52:35 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 2011273A8F758; Thu, 31 May 2018 20:52:20 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 20:52:13 +0800 From: John Garry To: , CC: , , , John Garry Subject: [PATCH 9/9] scsi: hisi_sas: Update a couple of register settings for v3 hw Date: Thu, 31 May 2018 20:50:50 +0800 Message-ID: <1527771050-200916-10-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527771050-200916-1-git-send-email-john.garry@huawei.com> References: <1527771050-200916-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 Update CFG_1US_TIMER_TRSH and CON_CFG_DRIVER settings. Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 3 +-- 1 file changed, 1 insertion(+), 2 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 e43881d..4b7688a 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -51,7 +51,6 @@ #define CFG_ABT_SET_IPTT_DONE 0xd8 #define CFG_ABT_SET_IPTT_DONE_OFF 0 #define HGC_IOMB_PROC1_STATUS 0x104 -#define CFG_1US_TIMER_TRSH 0xcc #define CHNL_INT_STATUS 0x148 #define HGC_AXI_FIFO_ERR_INFO 0x154 #define AXI_ERR_INFO_OFF 0 @@ -428,7 +427,6 @@ static void init_reg_v3_hw(struct hisi_hba *hisi_hba) (u32)((1ULL << hisi_hba->queue_count) - 1)); hisi_sas_write32(hisi_hba, CFG_MAX_TAG, 0xfff0400); hisi_sas_write32(hisi_hba, HGC_SAS_TXFAIL_RETRY_CTRL, 0x108); - hisi_sas_write32(hisi_hba, CFG_1US_TIMER_TRSH, 0xd); hisi_sas_write32(hisi_hba, INT_COAL_EN, 0x1); hisi_sas_write32(hisi_hba, OQ_INT_COAL_TIME, 0x1); hisi_sas_write32(hisi_hba, OQ_INT_COAL_CNT, 0x1); @@ -489,6 +487,7 @@ static void init_reg_v3_hw(struct hisi_hba *hisi_hba) hisi_sas_phy_write32(hisi_hba, i, SL_RX_BCAST_CHK_MSK, 0x0); hisi_sas_phy_write32(hisi_hba, i, PHYCTRL_OOB_RESTART_MSK, 0x1); hisi_sas_phy_write32(hisi_hba, i, STP_LINK_TIMER, 0x7f7a120); + hisi_sas_phy_write32(hisi_hba, i, CON_CFG_DRIVER, 0x2a0a01); /* used for 12G negotiate */ hisi_sas_phy_write32(hisi_hba, i, COARSETUNE_TIME, 0x1e);