From patchwork Fri Nov 3 22:23:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10041263 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8748F600C5 for ; Fri, 3 Nov 2017 22:23:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79A8F299B3 for ; Fri, 3 Nov 2017 22:23:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E030299C3; Fri, 3 Nov 2017 22:23:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03AFC299B3 for ; Fri, 3 Nov 2017 22:23:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754811AbdKCWXu (ORCPT ); Fri, 3 Nov 2017 18:23:50 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:54160 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752551AbdKCWXo (ORCPT ); Fri, 3 Nov 2017 18:23:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1509747824; x=1541283824; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=DgCcrGyJR2qBWPzSudPE43vAaR/ELokSZemnaGYEqsU=; b=rPH7y9ZhBSesvBg8UI5qha5UvrPdRQTG3ceio35lMtFbfwH6mlZJVpSp fGR1OtlRTT3xB97+PQyL0nc3Znfeon1QBbH92l6/8zqy4MfZJsRTpAyO7 C+O67mHbnI8RYoIcTwo8TTeW81csOLmKMAWpWDiXhDXQYK/sJnyY7nwZm BYQC0N3QerZh7OahUlfRT83+ysoLIGOMttFT2XEOxHLBsy3IzHZ+cAohF pefNz24lPzuVWsBcqttCQnzvrxk04YHA+Hdmg6hIo2wQp9PoFRLiltAnE 5Q8CQPHPyWamtPl9bF02IUF3vAT9VG01v01JTjON88FaKFCqLxrLQaaQ4 w==; X-IronPort-AV: E=Sophos;i="5.44,339,1505750400"; d="scan'208";a="163704795" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 04 Nov 2017 06:23:42 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 03 Nov 2017 15:21:44 -0700 Received: from unknown (HELO MILHUBIP03.sdcorp.global.sandisk.com) ([10.177.9.96]) by uls-op-cesaip02.wdc.com with ESMTP; 03 Nov 2017 15:23:43 -0700 Received: from milsmgip12.sandisk.com (10.177.9.6) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Fri, 3 Nov 2017 15:23:41 -0700 X-AuditID: 0ab1095a-d99e3980000146e4-7f-59fcec6c83f4 Received: from thinkpad-bart.int.fusionio.com ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id E9.92.18148.C6CECF95; Fri, 3 Nov 2017 15:23:40 -0700 (PDT) From: Bart Van Assche To: Jens Axboe CC: , Christoph Hellwig , "Ard Biesheuvel" , Herbert Xu , Bart Van Assche , , "Martin K . Petersen" , Anil Ravindranath Subject: [PATCH v3 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order() Date: Fri, 3 Nov 2017 15:23:39 -0700 Message-ID: <20171103222339.26540-9-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171103222339.26540-1-bart.vanassche@wdc.com> References: <20171103222339.26540-1-bart.vanassche@wdc.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMJMWRmVeSWpSXmKPExsXCtZEjRTfnzZ9Ig/NXLSxuH7vAZvH/w25G i9V3+9ksLv35wmixcvVRJovuVzIWe29pW3Rf38Fmsfz4PyYHTo9tB1Q9Lp8t9bhzbQ+bx+6b DWweH5/eYvF4sO4mq8fnTXIe7Qe6mQI4orhsUlJzMstSi/TtErgyrpz/xVzwS6riaXszYwPj H9EuRk4OCQETiZ0LFzB3MXJxCAmsZpT4tHcOM0iCTUBP4tS8fUwgtoiAgkTP75VsIDazwGUm iZfneEFsYYEAiVMznrB2MXJwsAioSvzujgExeQWsJeackoQYLy+x9u09RhCbU8BG4sqCJrCJ QkAlvZ0r2Ccwci9gZFjFKJabmVOcm55ZYGikV5yYl5JZnK2XnJ+7iREcTJxROxivTzQ/xMjE wSnVwLhULHlvx8fVl5683hPNV6+pwvCx2zygMTXfJdgjTCL8sCCz/S1Jg5lb8vlLrcr6p6jM rc3RsvzDLPqAPbXU0TnGRNzZ3CY9Oc19f27HypmXY+SOexuw3qrbOfu3khDnmqDiCSyzLh+X v/z3k91kn41Vk4XErpv+3/HlQ0Pe40UKO6YwapmfV2Ipzkg01GIuKk4EALFMp4fWAQAA MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the sgl_alloc_order() and sgl_free_order() functions instead of open coding these functions. Signed-off-by: Bart Van Assche Reviewed-by: Johannes Thumshirn Cc: linux-scsi@vger.kernel.org Cc: Martin K. Petersen Cc: Anil Ravindranath Reviewed-by: Hannes Reinecke --- drivers/scsi/Kconfig | 1 + drivers/scsi/pmcraid.c | 43 ++++--------------------------------------- drivers/scsi/pmcraid.h | 2 +- 3 files changed, 6 insertions(+), 40 deletions(-) diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index d918115afdca..04400bed39a1 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig @@ -1577,6 +1577,7 @@ config ZFCP config SCSI_PMCRAID tristate "PMC SIERRA Linux MaxRAID adapter support" depends on PCI && SCSI && NET + select SGL_ALLOC ---help--- This driver supports the PMC SIERRA MaxRAID adapters. diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c index b4d6cd8cd1ad..95fc0352f9bb 100644 --- a/drivers/scsi/pmcraid.c +++ b/drivers/scsi/pmcraid.c @@ -3232,12 +3232,7 @@ static int pmcraid_build_ioadl( */ static void pmcraid_free_sglist(struct pmcraid_sglist *sglist) { - int i; - - for (i = 0; i < sglist->num_sg; i++) - __free_pages(sg_page(&(sglist->scatterlist[i])), - sglist->order); - + sgl_free_order(sglist->scatterlist, sglist->order); kfree(sglist); } @@ -3254,50 +3249,20 @@ static void pmcraid_free_sglist(struct pmcraid_sglist *sglist) static struct pmcraid_sglist *pmcraid_alloc_sglist(int buflen) { struct pmcraid_sglist *sglist; - struct scatterlist *scatterlist; - struct page *page; - int num_elem, i, j; int sg_size; int order; - int bsize_elem; sg_size = buflen / (PMCRAID_MAX_IOADLS - 1); order = (sg_size > 0) ? get_order(sg_size) : 0; - bsize_elem = PAGE_SIZE * (1 << order); - - /* Determine the actual number of sg entries needed */ - if (buflen % bsize_elem) - num_elem = (buflen / bsize_elem) + 1; - else - num_elem = buflen / bsize_elem; /* Allocate a scatter/gather list for the DMA */ - sglist = kzalloc(sizeof(struct pmcraid_sglist) + - (sizeof(struct scatterlist) * (num_elem - 1)), - GFP_KERNEL); - + sglist = kzalloc(sizeof(struct pmcraid_sglist), GFP_KERNEL); if (sglist == NULL) return NULL; - scatterlist = sglist->scatterlist; - sg_init_table(scatterlist, num_elem); sglist->order = order; - sglist->num_sg = num_elem; - sg_size = buflen; - - for (i = 0; i < num_elem; i++) { - page = alloc_pages(GFP_KERNEL|GFP_DMA|__GFP_ZERO, order); - if (!page) { - for (j = i - 1; j >= 0; j--) - __free_pages(sg_page(&scatterlist[j]), order); - kfree(sglist); - return NULL; - } - - sg_set_page(&scatterlist[i], page, - sg_size < bsize_elem ? sg_size : bsize_elem, 0); - sg_size -= bsize_elem; - } + sgl_alloc_order(buflen, order, false, + GFP_KERNEL | GFP_DMA | __GFP_ZERO, &sglist->num_sg); return sglist; } diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h index 44da91712115..754ef30927e2 100644 --- a/drivers/scsi/pmcraid.h +++ b/drivers/scsi/pmcraid.h @@ -542,7 +542,7 @@ struct pmcraid_sglist { u32 order; u32 num_sg; u32 num_dma_sg; - struct scatterlist scatterlist[1]; + struct scatterlist *scatterlist; }; /* page D0 inquiry data of focal point resource */