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); }