From patchwork Thu Mar 18 09:11:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suganath Prabu S X-Patchwork-Id: 405200 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90ABFC4332B for ; Thu, 18 Mar 2021 09:13:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30FD664F33 for ; Thu, 18 Mar 2021 09:13:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbhCRJM1 (ORCPT ); Thu, 18 Mar 2021 05:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbhCRJMY (ORCPT ); Thu, 18 Mar 2021 05:12:24 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90CA0C06174A for ; Thu, 18 Mar 2021 02:12:24 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id 11so3048691pfn.9 for ; Thu, 18 Mar 2021 02:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=Rqiz40Vaj+6KpcrE4vC8n3rmaDvW5XLRMr6QPWhrjmY=; b=FoA9kxqb1LXs0rX7EZb61W/DZy3fmFinv4mzYH0slRwLnCs+IJcs0ZOX0OoC5ajozZ a1zUdp7PTfliKsea/gdS3epm7mkaCWkOzzxb5CdPzn4oU+jtoX6XWCop3Jzi1UDx6Fx1 eAz7KE9aeLrs9IWZuU2eT1HoeQwCf7MpSZ2g8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=Rqiz40Vaj+6KpcrE4vC8n3rmaDvW5XLRMr6QPWhrjmY=; b=NkgmJGw3uiSdJGu79S8a8oRUnCCob/7D5DmUkucQnIlJu3JvOv96ru3yXridg1f1zK ZbemqjsLyRbklD1VPeq0wAjMQOoLvYnnBM39hrMbRnZymz+SKNefGmHHeRmFWOaWeD4Y +H3slJbSC7SOK27NtXBMOLTRg+kO0unqyGBvNSSb4Uq2ZSoDDMfJ0wUyqg55edd2/HUn uazMfQ/8hGUXfHbd//8MO7EDz6y71uqUjvB/ZYfZd9iq7EqgN7FIx8Q4FtBcq7auZS+3 KhRWjy6lz36JFIq1wb9VBUhE9FH9V8AAOjvL+hY4vJTSeNJX9Sky8pE8Y502RXsUomcZ aUKQ== X-Gm-Message-State: AOAM531qvVlO9QgMGPuRO/PkpPv/dA6+G/G//O1pqkkKwLeBNRwwuhpS BzKjeUR8uHi9jtG5mUGJ3IdZAMOt4Nl6NKp5XlejAfdLZgCLOw2FWXLKVT20dlDNpvlrAo377Pq 2MB/7ma3QsuzB11LuJP0nf/m95TxLTqM2kXenhNyMSmykvfir3A33fcAQzK7OxdbJI+vFf57oij 4G4eXl/bGqAn6K4K1Xyqhy X-Google-Smtp-Source: ABdhPJx5n9C500cAtBuqvgJfiY2rOtRZLl6mayFcweQoQivTnPDS00m2Wp1dJBjNXIyCc1omFtFkwg== X-Received: by 2002:a62:5e02:0:b029:1ed:8bee:6132 with SMTP id s2-20020a625e020000b02901ed8bee6132mr3222288pfb.48.1616058743153; Thu, 18 Mar 2021 02:12:23 -0700 (PDT) Received: from dhcp-10-123-20-76.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id 11sm1413350pgt.83.2021.03.18.02.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 02:12:22 -0700 (PDT) From: Suganath Prabu S To: linux-scsi@vger.kernel.org, martin.petersen@oracle.com Cc: Sathya.Prakash@broadcom.com, sreekanth.reddy@broadcom.com, Suganath Prabu S Subject: [PATCH V2 6/7] mpt3sas: Handle reply post array DMA allocations in same 4G region Date: Thu, 18 Mar 2021 14:41:50 +0530 Message-Id: <20210318091151.39349-7-suganath-prabu.subramani@broadcom.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210318091151.39349-1-suganath-prabu.subramani@broadcom.com> References: <20210318091151.39349-1-suganath-prabu.subramani@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org According to MPI Specification Reply post Array buffer should not cross 4GB boundary. So while allocating Reply Post Array buffer, if it crosses the 4GB boundary then, * Release the already allocated memory pools and * Reallocate them by changing the DMA coherent mask to 32 bit. Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_base.c | 55 ++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 9e717b3..2b59902 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -5630,6 +5630,39 @@ _base_allocate_reply_free_dma_pool(struct MPT3SAS_ADAPTER *ioc, u32 sz) return 0; } +/** + * _base_allocate_reply_post_free_array - Allocating DMA'able memory + * for reply post free array. + * @ioc: Adapter object + * @reply_post_free_array_sz: DMA Pool size + * Return: 0 for success, non-zero for failure. + */ + +static int +_base_allocate_reply_post_free_array(struct MPT3SAS_ADAPTER *ioc, + u32 reply_post_free_array_sz) +{ + ioc->reply_post_free_array_dma_pool = + dma_pool_create("reply_post_free_array pool", + &ioc->pdev->dev, reply_post_free_array_sz, 16, 0); + if (!ioc->reply_post_free_array_dma_pool) + return -ENOMEM; + ioc->reply_post_free_array = + dma_pool_alloc(ioc->reply_post_free_array_dma_pool, + GFP_KERNEL, &ioc->reply_post_free_array_dma); + if (!ioc->reply_post_free_array) + return -EAGAIN; + if (!mpt3sas_check_same_4gb_region((long)ioc->reply_post_free_array, + reply_post_free_array_sz)) { + dinitprintk(ioc, pr_err( + "Bad Reply Free Pool! Reply Free (0x%p) Reply Free dma = (0x%llx)\n", + ioc->reply_free, + (unsigned long long) ioc->reply_free_dma)); + ioc->use_32bit_dma = true; + return -EAGAIN; + } + return 0; +} /** * base_alloc_rdpq_dma_pool - Allocating DMA'able memory * for reply queues. @@ -6102,22 +6135,12 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc) if (ioc->rdpq_array_enable) { reply_post_free_array_sz = ioc->reply_queue_count * sizeof(Mpi2IOCInitRDPQArrayEntry); - ioc->reply_post_free_array_dma_pool = - dma_pool_create("reply_post_free_array pool", - &ioc->pdev->dev, reply_post_free_array_sz, 16, 0); - if (!ioc->reply_post_free_array_dma_pool) { - dinitprintk(ioc, - ioc_info(ioc, "reply_post_free_array pool: dma_pool_create failed\n")); - goto out; - } - ioc->reply_post_free_array = - dma_pool_alloc(ioc->reply_post_free_array_dma_pool, - GFP_KERNEL, &ioc->reply_post_free_array_dma); - if (!ioc->reply_post_free_array) { - dinitprintk(ioc, - ioc_info(ioc, "reply_post_free_array pool: dma_pool_alloc failed\n")); - goto out; - } + rc = _base_allocate_reply_post_free_array(ioc, + reply_post_free_array_sz); + if (rc == -ENOMEM) + return -ENOMEM; + else if (rc == -EAGAIN) + goto try_32bit_dma; } ioc->config_page_sz = 512; ioc->config_page = dma_alloc_coherent(&ioc->pdev->dev,