Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4021737rdb; Mon, 11 Dec 2023 06:55:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeDuuR1QfQ40EgPSW9GkXlTK41cDuzSXR/GErfAQ4TH3BLZIxq+xZyrtvWm9HnA0p0qOSU X-Received: by 2002:a50:c943:0:b0:54c:dff9:98ce with SMTP id p3-20020a50c943000000b0054cdff998cemr31614edh.14.1702306505765; Mon, 11 Dec 2023 06:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702306505; cv=none; d=google.com; s=arc-20160816; b=KNFeii0xR8sI1IGlEk0pk+Dl+d4qYajOIQkbHkrj/flD2SX/+dtUBsE7KzqFhGRkSW eCyFqgIfaSzfspuENhH9DSwxdvbD1gVtyNQm4ogKgQJMxSdh+EQ1jEdi6tNA8MYyFAuG q4FQMxEJC6hvqznFjJ6zyo8A3JfHLC39YXNeoXYcemnWu1pbU7sc4+HeUnrQT6NcC7YV jlYdeIh06ZlpkhsV4JkINmF5EVTPNnlBEPFvaeFXwuYwhTsFNmKc9nW8nBYDAOuAPN65 nfFIbIOWdm2eW5tpE9VxhuwOHq2+gPzQlJC6gYHPtXcyZ6QLbQ8UQEJ7jHAyFd1wEBC7 CM+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=DXqbcW2/yfevKNDzFduXfzs6j0etXw4ujAd+Te43fK4=; fh=TQdU2P/AkCbipLLidffWKHptwlCDCageBvd1EwLi/Ww=; b=e+S1N8iPDYVFjJH07CQx5HAPT4zExtdek3thiG28ZwVMpRIGVJjtK7VVRmAKHciny8 H2Tyoa3ODvGfPa9AAMXD7B+UDbf8kx7N4/0vTvHDYVjTuK1vJmjpT2r9QDlgRG9u/9+z VDzuo5m0AxMMoqqadZFVvc/tsBP/axe7/oaJkk7pQOtuj3jA8o6aKBqr/OBBQLb8cCT7 gyzXjKzcB38b81rJwWcSRK35PMF/qvIOMl9zdumG2sJJOoJIExbYrGWohB8vxaodcr2n Na4M8g5Np3RxtK6blC3UjXJ3hBNly05ApPaGTCcKUPFsxn6SnDjCXQrj+IdBW33XRNGQ ezFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dAx3NDT7; spf=pass (google.com: domain of linux-wireless+bounces-665-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-wireless+bounces-665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z8-20020a056402274800b0054bf7e0937dsi3818656edd.455.2023.12.11.06.55.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 06:55:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-665-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=dAx3NDT7; spf=pass (google.com: domain of linux-wireless+bounces-665-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-wireless+bounces-665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5584B1F21644 for ; Mon, 11 Dec 2023 14:55:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53770495EA; Mon, 11 Dec 2023 14:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="dAx3NDT7" X-Original-To: linux-wireless@vger.kernel.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8A9EAB for ; Mon, 11 Dec 2023 06:54:59 -0800 (PST) Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BBC9kZm010067; Mon, 11 Dec 2023 14:54:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=DXqbcW2/yfevKNDzFduXfzs6j0etXw4ujAd+Te43fK4=; b=dA x3NDT7Ww/VxrYNp7+v3LdFuB7OSbkrWwxHSffZygN4VlUGCyYHdORPpniiha2IjO zQin4X7vXDlRBcnMtel9H6ViwRtEZC31mqk/AU+C+GUyPFxarlAWo9HhHJIHt8JZ AdFrvGt1jx0mFhe/tHkI92oI/M2d6ABEDUqbSQ+t6XwINIoJgWvzTw9F/sTbqLI5 17cWJYBHpKNQ5ocwgnO28vDkF2GaDfvirm6mKOcFqr+vzgC60KLsKAnWuZjl6Ytz xNFLzXN245QRD2J/UafE+C8sxioYYrgOb6bS99ctxELCOwItUvVoq/9Zpi+i9/iq ASNM3HAy0i407r+H1vdg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ux25xgbb1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Dec 2023 14:54:38 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BBEscjW021479 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Dec 2023 14:54:38 GMT Received: from [10.110.106.103] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 11 Dec 2023 06:54:37 -0800 Message-ID: <6e09aeb2-4811-47ff-aa4b-beb1a30ba00d@quicinc.com> Date: Mon, 11 Dec 2023 06:54:36 -0800 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] wifi: ath11k: fix IOMMU errors on buffer rings Content-Language: en-US To: Zhenghao Gu , CC: References: <20231206024325.27283-1-imguzh@gmail.com> From: Jeff Johnson In-Reply-To: <20231206024325.27283-1-imguzh@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: dgkxoVU3qJQi5SczLJM7wcF_N5AY0Hh3 X-Proofpoint-GUID: dgkxoVU3qJQi5SczLJM7wcF_N5AY0Hh3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1011 spamscore=0 lowpriorityscore=0 mlxlogscore=445 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312110122 On 12/5/2023 6:43 PM, Zhenghao Gu wrote: > virt_to_phys doesn't work on systems with IOMMU enabled, > which have non-identity physical-to-IOVA mappings. > It leads to IO_PAGE_FAULTs like this: > [IO_PAGE_FAULT domain=0x0023 address=0x1cce00000 flags=0x0020] > and no link can be established. > > This patch changes that to dma_map_single(), which works correctly. > > Tested-on: QCN9074 hw1.0 PCI WLAN.HK.2.7.0.1-01744-QCAHKSWPL_SILICONZ-1 > Signed-off-by: Zhenghao Gu > --- > drivers/net/wireless/ath/ath11k/dp.c | 19 ++++++++++++++++--- > drivers/net/wireless/ath/ath11k/hal.c | 20 ++++++++++++++++++-- > drivers/net/wireless/ath/ath11k/hal.h | 2 ++ > 3 files changed, 36 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/wireless/ath/ath11k/dp.c b/drivers/net/wireless/ath/ath11k/dp.c > index d070bcb3f..c74230e4c 100644 > --- a/drivers/net/wireless/ath/ath11k/dp.c > +++ b/drivers/net/wireless/ath/ath11k/dp.c > @@ -104,11 +104,14 @@ void ath11k_dp_srng_cleanup(struct ath11k_base *ab, struct dp_srng *ring) > if (!ring->vaddr_unaligned) > return; > > - if (ring->cached) > + if (ring->cached) { > + dma_unmap_single(ab->dev, ring->paddr_unaligned, ring->size, > + DMA_FROM_DEVICE); > kfree(ring->vaddr_unaligned); > - else > + } else { > dma_free_coherent(ab->dev, ring->size, ring->vaddr_unaligned, > ring->paddr_unaligned); > + } > > ring->vaddr_unaligned = NULL; > } > @@ -249,7 +252,17 @@ int ath11k_dp_srng_setup(struct ath11k_base *ab, struct dp_srng *ring, > > if (cached) { > ring->vaddr_unaligned = kzalloc(ring->size, GFP_KERNEL); > - ring->paddr_unaligned = virt_to_phys(ring->vaddr_unaligned); > + if (!ring->vaddr_unaligned) > + return -ENOMEM; > + > + ring->paddr_unaligned = > + dma_map_single(ab->dev, ring->vaddr_unaligned, > + ring->size, DMA_FROM_DEVICE); > + if (dma_mapping_error(ab->dev, ring->paddr_unaligned)) { > + kfree(ring->vaddr_unaligned); > + ring->vaddr_unaligned = NULL; > + return -ENOMEM; > + } > } > } > > diff --git a/drivers/net/wireless/ath/ath11k/hal.c b/drivers/net/wireless/ath/ath11k/hal.c > index 0a99aa7dd..bd4cccdba 100644 > --- a/drivers/net/wireless/ath/ath11k/hal.c > +++ b/drivers/net/wireless/ath/ath11k/hal.c > @@ -628,15 +628,31 @@ u32 *ath11k_hal_srng_dst_peek(struct ath11k_base *ab, struct hal_srng *srng) > return NULL; > } > > +u32 *ath11k_hal_srng_dst_peek_with_dma(struct ath11k_base *ab, > + struct hal_srng *srng, dma_addr_t *paddr) since this is only used from within hal.c make it static > +{ > + lockdep_assert_held(&srng->lock); > + > + if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp) { > + *paddr = (srng->ring_base_paddr + > + sizeof(*srng->ring_base_vaddr) * srng->u.dst_ring.tp); > + return (srng->ring_base_vaddr + srng->u.dst_ring.tp); > + } > + > + return NULL; > +} > + > static void ath11k_hal_srng_prefetch_desc(struct ath11k_base *ab, > struct hal_srng *srng) > { > u32 *desc; > + dma_addr_t desc_paddr; > + > > /* prefetch only if desc is available */ > - desc = ath11k_hal_srng_dst_peek(ab, srng); > + desc = ath11k_hal_srng_dst_peek_with_dma(ab, srng, &desc_paddr); > if (likely(desc)) { > - dma_sync_single_for_cpu(ab->dev, virt_to_phys(desc), > + dma_sync_single_for_cpu(ab->dev, desc_paddr, > (srng->entry_size * sizeof(u32)), > DMA_FROM_DEVICE); > prefetch(desc); > diff --git a/drivers/net/wireless/ath/ath11k/hal.h b/drivers/net/wireless/ath/ath11k/hal.h > index 1942d41d6..facaf8fe0 100644 > --- a/drivers/net/wireless/ath/ath11k/hal.h > +++ b/drivers/net/wireless/ath/ath11k/hal.h > @@ -943,6 +943,8 @@ void ath11k_hal_srng_get_params(struct ath11k_base *ab, struct hal_srng *srng, > u32 *ath11k_hal_srng_dst_get_next_entry(struct ath11k_base *ab, > struct hal_srng *srng); > u32 *ath11k_hal_srng_dst_peek(struct ath11k_base *ab, struct hal_srng *srng); > +u32 *ath11k_hal_srng_dst_peek_with_dma(struct ath11k_base *ab, > + struct hal_srng *srng, dma_addr_t *paddr); should be static so remove this > int ath11k_hal_srng_dst_num_free(struct ath11k_base *ab, struct hal_srng *srng, > bool sync_hw_ptr); > u32 *ath11k_hal_srng_src_peek(struct ath11k_base *ab, struct hal_srng *srng); >