Thread (14 messages) 14 messages, 2 authors, 2021-02-23

RE: [PATCH V4 net 3/5] net: stmmac: fix dma physical address of descriptor when display ring

flat view

From: Joakim Zhang <hidden>
Date: 2021-02-20 07:58:05

-----Original Message-----
From: Jakub Kicinski <kuba@kernel.org>
Sent: 2021年2月7日 4:29
To: Joakim Zhang <redacted>
Cc: peppe.cavallaro@st.com; alexandre.torgue@st.com;
joabreu@synopsys.com; davem@davemloft.net; netdev@vger.kernel.org;
dl-linux-imx [off-list ref]
Subject: Re: [PATCH V4 net 3/5] net: stmmac: fix dma physical address of
descriptor when display ring

On Thu,  4 Feb 2021 19:21:42 +0800 Joakim Zhang wrote:
quoted
Driver uses dma_alloc_coherent to allocate dma memory for descriptors,
dma_alloc_coherent will return both the virtual address and physical
address. AFAIK, virt_to_phys could not convert virtual address to
physical address, for which memory is allocated by dma_alloc_coherent.

Signed-off-by: Joakim Zhang <redacted>
What does this patch fix? Theoretically incorrect value in a debug dump or are
you actually observing incorrect behavior?
Hi Jakub,

Sorry for late response since I am on holiday. 
It is incorrect value in a debug dump. When I debug DMA issue, I found the descriptor address is incorrect, which could be indicated by hardware register.
Correct descriptor address could help use locate that which is the issue descriptor, and then could further debug.
quoted
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
index c6540b003b43..6f951adc5f90 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
@@ -402,7 +402,8 @@ static void dwmac4_rd_set_tx_ic(struct dma_desc
*p)
quoted
 	p->des2 |= cpu_to_le32(TDES2_INTERRUPT_ON_COMPLETION);
 }

-static void dwmac4_display_ring(void *head, unsigned int size, bool
rx)
+static void dwmac4_display_ring(void *head, unsigned int size, bool rx,
+				dma_addr_t dma_rx_phy, unsigned int desc_size)
 {
 	struct dma_desc *p = (struct dma_desc *)head;
 	int i;
@@ -410,8 +411,8 @@ static void dwmac4_display_ring(void *head,
unsigned int size, bool rx)
quoted
 	pr_info("%s descriptor ring:\n", rx ? "RX" : "TX");

 	for (i = 0; i < size; i++) {
-		pr_info("%03d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
-			i, (unsigned int)virt_to_phys(p),
+		pr_info("%03d [0x%llx]: 0x%x 0x%x 0x%x 0x%x\n",
+			i, (unsigned long long)(dma_rx_phy + i * desc_size),
 			le32_to_cpu(p->des0), le32_to_cpu(p->des1),
 			le32_to_cpu(p->des2), le32_to_cpu(p->des3));
 		p++;
Why do you pass the desc_size in? The virt memory pointer is incremented by
sizeof(*p) surely

	dma_addr + i * sizeof(*p)
I think we can't use sizeof(*p), as when display descriptor, only do " struct dma_desc *p = (struct dma_desc *)head;", but driver can pass "struct dma_desc", " struct dma_edesc" or " struct dma_extended_desc",
so it's necessary to pass desc_size to compatible all cases.
 
would work correctly? Also please use the correct print format for dma_addr_t,
you shouldn't have to cast.
OK, I will change to use "%pad" for dma_addr_t.


Best Regards,
Joakim Zhang
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help