Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5980538ybc; Wed, 27 Nov 2019 12:49:43 -0800 (PST) X-Google-Smtp-Source: APXvYqzkkEwzN7IiQ+9jXK0sF5h3N9Q+Tb8uzGRlzFnP5eYFVqaISpc6fpFJi9qHcdbgP91+u2F8 X-Received: by 2002:a05:6402:324:: with SMTP id q4mr34457325edw.108.1574887783005; Wed, 27 Nov 2019 12:49:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574887782; cv=none; d=google.com; s=arc-20160816; b=UYbEWJ+szNVow7ssla3CUeggH3rV9X2cpZMSPST8BnH2TC+K6H8MSXxgLJSOAwrPbV t/PUsLj/msbRXBB+BqK7LGZTAVF2GLCXcJ3mzGnL6LCIQKvh+03VOtTrwNOk0W3EU2Zv lEsZMsrlEE1ApE36CZu8o2zZS0zzPLYx3pFdyjkO4ofE5lldoN2m258vyWQKWyXd3HAf jvfSkm5OX5zgidSFF/hbXfOwg8+BckNDN4XOjPWYrxUjDUe3UNCQQyc/50RiuYvOOl/d EWg1uoypsewtEFMe0qiVkgq+RS0G9Du55AleRt1VSJ8sYsyn7dCAtBnYPZ1UNeTFcWJJ cFBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L+8/3YKodNpuU6xW8/7lIe4/hTmUppNN5a3H/IhhFgU=; b=zux69wMWeIWviDBETI/omuOQ0w1+MMg4zLljF99QR0+SKmdspFA0MAhUHROelMtF31 VF7+4Qmbam0Ven3Y3DNLV7LRMYcBcLRnZCYDCrXLA/fK8MmnbVPU98LNk2cv3jEdS5Uh KG72VCp7XgiwjjKZQK+t0tUFb5F9MkCVhvehrWttn0viuG3NfUK1UG7VWgHNcP2Ot6Y/ H70kpjX3Dl2xcRXrtXQvY3loJQ1wPG9cQB4p+vXHSgLhRvQTB7CgqONYVCa0klb1y0uZ 2bgFPxpqzU6A+Y7B10S03NnQokQSrpZe1NGmLm9U8SZvIY5DIidaYomRsg2QNLNMiG8h 2GjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x3N69S6+; 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 j21si10288476ejd.265.2019.11.27.12.49.19; Wed, 27 Nov 2019 12:49:42 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=x3N69S6+; 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 S1729952AbfK0UrH (ORCPT + 99 others); Wed, 27 Nov 2019 15:47:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:59382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729945AbfK0Uq6 (ORCPT ); Wed, 27 Nov 2019 15:46:58 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C01082182A; Wed, 27 Nov 2019 20:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887617; bh=QcODrW0g2h0eVNaS81B9LTAQCEmFSlUp4VTfBNQ8rU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x3N69S6+wL02fwYnvhaP9W2vJgE/R9c4FCm1gABNXY7krMCV2/uXOY9xhF1gFJAyd UTCH2UU/RnFnM3JCV6CC/pYlVUzhqawDOB5LbuSR3YZttlRHhZWI4LWx4xJwJmTqi+ p6BbqJjPOx3LG6i/rC7kz3yPn22lQBv/t528L5fQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Carl Huang , Brian Norris , Kalle Valo , Sasha Levin Subject: [PATCH 4.14 028/211] ath10k: allocate small size dma memory in ath10k_pci_diag_write_mem Date: Wed, 27 Nov 2019 21:29:21 +0100 Message-Id: <20191127203053.892519794@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203049.431810767@linuxfoundation.org> References: <20191127203049.431810767@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Carl Huang [ Upstream commit 0738b4998c6d1caf9ca2447b946709a7278c70f1 ] ath10k_pci_diag_write_mem may allocate big size of the dma memory based on the parameter nbytes. Take firmware diag download as example, the biggest size is about 500K. In some systems, the allocation is likely to fail because it can't acquire such a large contiguous dma memory. The fix is to allocate a small size dma memory. In the loop, driver copies the data to the allocated dma memory and writes to the destination until all the data is written. Tested with QCA6174 PCI with firmware-6.bin_WLAN.RM.4.4.1-00119-QCARMSWP-1, this also affects QCA9377 PCI. Signed-off-by: Carl Huang Reviewed-by: Brian Norris Signed-off-by: Kalle Valo Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath10k/pci.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c index 27ab3eb47534f..0298ddc1ff060 100644 --- a/drivers/net/wireless/ath/ath10k/pci.c +++ b/drivers/net/wireless/ath/ath10k/pci.c @@ -1039,10 +1039,9 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, struct ath10k_ce *ce = ath10k_ce_priv(ar); int ret = 0; u32 *buf; - unsigned int completed_nbytes, orig_nbytes, remaining_bytes; + unsigned int completed_nbytes, alloc_nbytes, remaining_bytes; struct ath10k_ce_pipe *ce_diag; void *data_buf = NULL; - u32 ce_data; /* Host buffer address in CE space */ dma_addr_t ce_data_base = 0; int i; @@ -1056,9 +1055,10 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, * 1) 4-byte alignment * 2) Buffer in DMA-able space */ - orig_nbytes = nbytes; + alloc_nbytes = min_t(unsigned int, nbytes, DIAG_TRANSFER_LIMIT); + data_buf = (unsigned char *)dma_alloc_coherent(ar->dev, - orig_nbytes, + alloc_nbytes, &ce_data_base, GFP_ATOMIC); if (!data_buf) { @@ -1066,9 +1066,6 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, goto done; } - /* Copy caller's data to allocated DMA buf */ - memcpy(data_buf, data, orig_nbytes); - /* * The address supplied by the caller is in the * Target CPU virtual address space. @@ -1081,12 +1078,14 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, */ address = ath10k_pci_targ_cpu_to_ce_addr(ar, address); - remaining_bytes = orig_nbytes; - ce_data = ce_data_base; + remaining_bytes = nbytes; while (remaining_bytes) { /* FIXME: check cast */ nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT); + /* Copy caller's data to allocated DMA buf */ + memcpy(data_buf, data, nbytes); + /* Set up to receive directly into Target(!) address */ ret = __ath10k_ce_rx_post_buf(ce_diag, &address, address); if (ret != 0) @@ -1096,7 +1095,7 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, * Request CE to send caller-supplied data that * was copied to bounce buffer to Target(!) address. */ - ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data, + ret = ath10k_ce_send_nolock(ce_diag, NULL, ce_data_base, nbytes, 0, 0); if (ret != 0) goto done; @@ -1137,12 +1136,12 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, remaining_bytes -= nbytes; address += nbytes; - ce_data += nbytes; + data += nbytes; } done: if (data_buf) { - dma_free_coherent(ar->dev, orig_nbytes, data_buf, + dma_free_coherent(ar->dev, alloc_nbytes, data_buf, ce_data_base); } -- 2.20.1