From patchwork Fri Nov 3 22:23:37 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: 10041265 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 345CB600C5 for ; Fri, 3 Nov 2017 22:23:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26802299C6 for ; Fri, 3 Nov 2017 22:23:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B527299C5; Fri, 3 Nov 2017 22:23:53 +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 A1A5D299B3 for ; Fri, 3 Nov 2017 22:23:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755519AbdKCWXv (ORCPT ); Fri, 3 Nov 2017 18:23:51 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:46889 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752425AbdKCWXo (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=TVURgnlF+YE0iQ4iOI7pS3sWowJAlafoxImU1YpLgd0=; b=IImwdq/o3YARsAgj4sAPO4cSceiEl5mBIy/Cfcdya7zMFSIBSzr20Pba pSBYgV9Hgqoy5zmhXJ3Aa6qHTENutVPzEdxnFEUVgf74AKXO3nHufRL+l n4INsSF2WhSJ1msUuTKAEPRcLX4lQqGI6vAF1VS54gsx9qbZHZSY4MiU5 ufdFydoz8qW8IlvHF8exQ5n1IPH7+MWGdCEJBRsN3pTm1YJskHpJSp9qn ehkJjI3Iofkcp1QK8rFIj2admyjjBM+bc99kl664vJhuW8yWMBnsg7C6r jUqL3e3iZqsoOeCg3kpgPA9Uj8anNn+kS236YPzSK703TZQE9iHa3ijrh A==; X-IronPort-AV: E=Sophos;i="5.44,339,1505750400"; d="scan'208";a="163704793" 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:41 +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.8.100) 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:40 -0700 X-AuditID: 0ab1095a-d99e3980000146e4-7d-59fcec6c7730 Received: from thinkpad-bart.int.fusionio.com ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id B8.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" , Subject: [PATCH v3 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order() Date: Fri, 3 Nov 2017 15:23:37 -0700 Message-ID: <20171103222339.26540-7-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+NgFtrFJMWRmVeSWpSXmKPExsXCtZEjRTfnzZ9IgxObjC3+f9jNaLH6bj+b xaU/XxgtVq4+ymTR/UrGYu8tbYvu6zvYLJYf/8fkwOGx7YCqx+WzpR53ru1h89h9s4HN4+PT WywenzfJebQf6GYKYI/isklJzcksSy3St0vgyph9soWl4Kxsxc9jZg2M/8S7GDk5JARMJL5/ nMDYxcjFISSwmlHi//PFLCAJNgE9iVPz9jGB2CICChI9v1eygRQxC8xmkpj8bDsjSEJYwEfi 8ItrYDaLgKrElnVXgIo4OHgFrCWWv2eHWCAvsfbtPbASTgEbiSsLmsBmCgGV9HauYJ/AyL2A kWEVo1huZk5xbnpmgaGRXnFiXkpmcbZecn7uJkZw6HBG7WC8PtH8ECMTB6dUA6MxJ1+VomRW 6IFHm+YKPY4rFJF3Nsk5lPVjW/OMrUu3nCgs21R2yuuRbZD7DK1VrkyFSjd4j8gV3g/W2bvb 6uEy25+Zsqq++2YyN915dc+BTXm6UuxBOY8vU9dEy89hEKxd9FEy9N6eHzPLOU2UXz40fKwc FPzK711ZeqPhu62RHcts9xxeUKvEUpyRaKjFXFScCAARzt1kzQEAAA== MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 Acked-by: Brian King Reviewed-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Cc: Martin K. Petersen Cc: linux-scsi@vger.kernel.org --- drivers/scsi/Kconfig | 1 + drivers/scsi/ipr.c | 49 ++++++++----------------------------------------- drivers/scsi/ipr.h | 2 +- 3 files changed, 10 insertions(+), 42 deletions(-) diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index 766955318005..d918115afdca 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig @@ -1059,6 +1059,7 @@ config SCSI_IPR depends on PCI && SCSI && ATA select FW_LOADER select IRQ_POLL + select SGL_ALLOC ---help--- This driver supports the IBM Power Linux family RAID adapters. This includes IBM pSeries 5712, 5703, 5709, and 570A, as well diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c index f838bd73befa..6fed5db6255e 100644 --- a/drivers/scsi/ipr.c +++ b/drivers/scsi/ipr.c @@ -3815,10 +3815,8 @@ static struct device_attribute ipr_iopoll_weight_attr = { **/ static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len) { - int sg_size, order, bsize_elem, num_elem, i, j; + int sg_size, order; struct ipr_sglist *sglist; - struct scatterlist *scatterlist; - struct page *page; /* Get the minimum size per scatter/gather element */ sg_size = buf_len / (IPR_MAX_SGLIST - 1); @@ -3826,45 +3824,18 @@ static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len) /* Get the actual size per element */ order = get_order(sg_size); - /* Determine the actual number of bytes per element */ - bsize_elem = PAGE_SIZE * (1 << order); - - /* Determine the actual number of sg entries needed */ - if (buf_len % bsize_elem) - num_elem = (buf_len / bsize_elem) + 1; - else - num_elem = buf_len / bsize_elem; - /* Allocate a scatter/gather list for the DMA */ - sglist = kzalloc(sizeof(struct ipr_sglist) + - (sizeof(struct scatterlist) * (num_elem - 1)), - GFP_KERNEL); - + sglist = kzalloc(sizeof(struct ipr_sglist), GFP_KERNEL); if (sglist == NULL) { ipr_trace; return NULL; } - - scatterlist = sglist->scatterlist; - sg_init_table(scatterlist, num_elem); - sglist->order = order; - sglist->num_sg = num_elem; - - /* Allocate a bunch of sg elements */ - for (i = 0; i < num_elem; i++) { - page = alloc_pages(GFP_KERNEL, order); - if (!page) { - ipr_trace; - - /* Free up what we already allocated */ - for (j = i - 1; j >= 0; j--) - __free_pages(sg_page(&scatterlist[j]), order); - kfree(sglist); - return NULL; - } - - sg_set_page(&scatterlist[i], page, 0, 0); + sglist->scatterlist = sgl_alloc_order(buf_len, order, false, GFP_KERNEL, + &sglist->num_sg); + if (!sglist->scatterlist) { + kfree(sglist); + return NULL; } return sglist; @@ -3882,11 +3853,7 @@ static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len) **/ static void ipr_free_ucode_buffer(struct ipr_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); } diff --git a/drivers/scsi/ipr.h b/drivers/scsi/ipr.h index c7f0e9e3cd7d..93570734cbfb 100644 --- a/drivers/scsi/ipr.h +++ b/drivers/scsi/ipr.h @@ -1454,7 +1454,7 @@ struct ipr_sglist { u32 num_sg; u32 num_dma_sg; u32 buffer_len; - struct scatterlist scatterlist[1]; + struct scatterlist *scatterlist; }; enum ipr_sdt_state {