Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5988614ybc; Wed, 27 Nov 2019 12:59:54 -0800 (PST) X-Google-Smtp-Source: APXvYqyMg0Q9m7qvz2Zrg4S9lRd3EtK5u1/wxdxjz3NicFNZmadTnMRYtSTL/Kf3+w94tO6Gkq0r X-Received: by 2002:a50:fb14:: with SMTP id d20mr33244277edq.190.1574888393906; Wed, 27 Nov 2019 12:59:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888393; cv=none; d=google.com; s=arc-20160816; b=IAjqxEEMrzrxoRQdnAiF9SSowvNYY+7BB7iiXJ9yPiv2g2G/wOpXkXyptPf7jMwpU7 02NVkS81WpMX8EH1Ma/EOJNS1NiR9xDtoDsqtlQOcumxvdXwnlWHCLnleoVY+iiZT06U pg0+cYpBFUy/jJ5v1cVbkG08hyzotDdoIV2XJqiLHIqFylYv39Ado9WCPBF6iybpYjRF WK8tVQDXGgaijXHJVdmLR2LVXj6Xn8U6Rmawkk5cAWaFem5LSISJeGiPKJyh696gkdJV mxd04rCHX61It6/s+H3QySPy7x4gJiBjIroviQp5ybnAiGYF2uGYODS+rJU7/THGct9V 1JVQ== 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=HTmRW9Y+yo9vDVXh3mHFY027irq5jk64/5K/wDmDwbY=; b=r+1Z5GaxcnrMy9RNZCeuOPz/4sLgeDMWnv2ENOGk3InlcqV64JGyjyk/RnsvTlR01H VFVW8gpYdmdo1ZBny8ZFQYn5Nk29LXe0TuiPI8i+UtiFnGTAAior6MLERboFZZyghAuf sx4YC/Q1C9/HuM8dNKAWMR0TenziYkNCq81oScNFbKes34Wzpimv1sIWhm3mq1LCCmog 8TM+QKvTgD/rEQXS66KKWDv90nZB2wY4wfCRJtBg7Z4hGWDjD/kXjLL5rtTOzONYOfH4 3FAilbXMuvk3uUbSKJfdVXtL79pYoKUs5nbPXX5Gwfqncj/Y2i2ayww+tkgeFlffmEI2 zPJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e1z5ua9m; 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 g17si11094119edh.379.2019.11.27.12.59.30; Wed, 27 Nov 2019 12:59:53 -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=e1z5ua9m; 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 S1731097AbfK0U4k (ORCPT + 99 others); Wed, 27 Nov 2019 15:56:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:47480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731090AbfK0U4j (ORCPT ); Wed, 27 Nov 2019 15:56:39 -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 D4A092068E; Wed, 27 Nov 2019 20:56:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888198; bh=NCveOPv2W5RThA3yaETDgr6El8ZxljBwoh0xzoAt/9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e1z5ua9m14ExpDJdOxUvlPEpeFqH8floXgUCCh4sBB0ugy/qvn7Swy/RkxieL/rHi UEyBF3fop+MCj88lt+94CvV1zmP4zhVp9oy8MLTtcOH95s8vq5COL3rfrYc7oJN2EP u0bpMNCBu+M2FK/wG9u7ps9h9MNOHI75xYFn37A4= 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.19 041/306] ath10k: allocate small size dma memory in ath10k_pci_diag_write_mem Date: Wed, 27 Nov 2019 21:28:11 +0100 Message-Id: <20191127203117.846562794@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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 97fa5c74f2fe7..50a801a5d4f15 100644 --- a/drivers/net/wireless/ath/ath10k/pci.c +++ b/drivers/net/wireless/ath/ath10k/pci.c @@ -1054,10 +1054,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; @@ -1071,9 +1070,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) { @@ -1081,9 +1081,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. @@ -1096,12 +1093,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 = ce_diag->ops->ce_rx_post_buf(ce_diag, &address, address); if (ret != 0) @@ -1111,7 +1110,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; @@ -1152,12 +1151,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