ATH11K Archive mirror
 help / color / mirror / Atom feed
From: Jeff Johnson <quic_jjohnson@quicinc.com>
To: Zhenghao Gu <imguzh@gmail.com>, <ath11k@lists.infradead.org>
Cc: <linux-wireless@vger.kernel.org>
Subject: Re: [PATCH] wifi: ath11k: fix IOMMU errors on buffer rings
Date: Mon, 11 Dec 2023 06:54:36 -0800	[thread overview]
Message-ID: <6e09aeb2-4811-47ff-aa4b-beb1a30ba00d@quicinc.com> (raw)
In-Reply-To: <20231206024325.27283-1-imguzh@gmail.com>

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 <imguzh@gmail.com>
> ---
>  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);
> 



      reply	other threads:[~2023-12-11 14:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-06  2:43 [PATCH] wifi: ath11k: fix IOMMU errors on buffer rings Zhenghao Gu
2023-12-11 14:54 ` Jeff Johnson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e09aeb2-4811-47ff-aa4b-beb1a30ba00d@quicinc.com \
    --to=quic_jjohnson@quicinc.com \
    --cc=ath11k@lists.infradead.org \
    --cc=imguzh@gmail.com \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).