Skip to contentSkip to conversation

net: moxa: inherit DMA masks to make dma_map_single() work

PATCH In review Sergei Antonov 3 participants 5 messages Aug 12, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: moxa: inherit DMA masks to make dma_map_single() work

dma_map_single() calls fail in moxart_mac_setup_desc_ring() and moxart_mac_start_xmit() which leads to an incessant output of this:

[   16.043925] moxart-ethernet 92000000.mac eth0: DMA mapping error
[   16.050957] moxart-ethernet 92000000.mac eth0: DMA mapping error
[   16.058229] moxart-ethernet 92000000.mac eth0: DMA mapping error

To make dma_map_single() work, inherit DMA masks from the platform device.

CC Jakub Kicinski <[email protected]>
CC Pavel Skripkin <[email protected]>
CC David S. Miller <[email protected]>
CC Guobin Huang <[email protected]>
CC Paolo Abeni <[email protected]>
---
 drivers/net/ethernet/moxa/moxart_ether.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/moxa/moxart_ether.c +4 -0
index a3214a762e4b..de99211d85c2 100644
@@ -537,6 +537,10 @@ static int moxart_mac_probe(struct platform_device *pdev)
 	ndev->priv_flags |= IFF_UNICAST_FLT;
 	ndev->irq = irq;
 
+	/* Inherit the DMA masks from the platform device */
+	ndev->dev.dma_mask = p_dev->dma_mask;
+	ndev->dev.coherent_dma_mask = p_dev->coherent_dma_mask;
+
 	SET_NETDEV_DEV(ndev, &pdev->dev);
 
 	ret = register_netdev(ndev);
Signature · 1 line
2.32.0
#1 lore raw
Quoted 24 lines · Sergei Antonov

dma_map_single() calls fail in moxart_mac_setup_desc_ring() and moxart_mac_start_xmit() which leads to an incessant output of this:

[   16.043925] moxart-ethernet 92000000.mac eth0: DMA mapping error
[   16.050957] moxart-ethernet 92000000.mac eth0: DMA mapping error
[   16.058229] moxart-ethernet 92000000.mac eth0: DMA mapping error

To make dma_map_single() work, inherit DMA masks from the platform device.

CC Jakub Kicinski <[email protected]>
CC Pavel Skripkin <[email protected]>
CC David S. Miller <[email protected]>
CC Guobin Huang <[email protected]>
CC Paolo Abeni <[email protected]>
---
 drivers/net/ethernet/moxa/moxart_ether.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/moxa/moxart_ether.c +0 -0
index a3214a762e4b..de99211d85c2 100644

drivers/net/ethernet/moxa/moxart_ether.c static int moxart_mac_probe(struct platform_device *pdev) · line 542

Quoted 6 lines
drivers/net/ethernet/moxa/moxart_ether.c +3 -0
@@ -537,6 +537,10 @@ static int moxart_mac_probe(struct platform_device *pdev)
 	ndev->priv_flags |= IFF_UNICAST_FLT;
 	ndev->irq = irq;
 
+	/* Inherit the DMA masks from the platform device */
+	ndev->dev.dma_mask = p_dev->dma_mask;
+	ndev->dev.coherent_dma_mask = p_dev->coherent_dma_mask;

There is only one other ethernet driver which does this. What you see much more often is:

alacritech/slicoss.c: paddr = dma_map_single(&sdev->pdev->dev, skb->data, maplen,
neterion/s2io.c: dma_map_single(&sp->pdev->dev, ba->ba_1,
dlink/dl2k.c: cpu_to_le64(dma_map_single(&np->pdev->dev, skb->data,
micrel/ksz884x.c: dma_buf->dma = dma_map_single(&hw_priv->pdev->dev, skb->data,

Andrew

#2 lore raw
Quoted 11 lines · Andrew Lunn

drivers/net/ethernet/moxa/moxart_ether.c static int moxart_mac_probe(struct platform_device *pdev) · line 542

Quoted 3 lines
drivers/net/ethernet/moxa/moxart_ether.c +3 -0
+     /* Inherit the DMA masks from the platform device */
+     ndev->dev.dma_mask = p_dev->dma_mask;
+     ndev->dev.coherent_dma_mask = p_dev->coherent_dma_mask;

There is only one other ethernet driver which does this. What you see much more often is:

alacritech/slicoss.c:   paddr = dma_map_single(&sdev->pdev->dev, skb->data, maplen,
neterion/s2io.c:                                dma_map_single(&sp->pdev->dev, ba->ba_1,
dlink/dl2k.c:                       cpu_to_le64(dma_map_single(&np->pdev->dev, skb->data,
micrel/ksz884x.c:               dma_buf->dma = dma_map_single(&hw_priv->pdev->dev, skb->data,

Also works. Do you recommend to create a v2 of the patch?

#3 lore raw
Quoted 8 lines · Sergei Antonov
Quoted 7 lines · Andrew Lunn

drivers/net/ethernet/moxa/moxart_ether.c static int moxart_mac_probe(struct platform_device *pdev) · line 542

Quoted 3 lines
drivers/net/ethernet/moxa/moxart_ether.c +3 -0
+     /* Inherit the DMA masks from the platform device */
+     ndev->dev.dma_mask = p_dev->dma_mask;
+     ndev->dev.coherent_dma_mask = p_dev->coherent_dma_mask;

There is only one other ethernet driver which does this. What you see much more often is:

Quoted 6 lines
Quoted 4 lines
alacritech/slicoss.c:   paddr = dma_map_single(&sdev->pdev->dev, skb->data, maplen,
neterion/s2io.c:                                dma_map_single(&sp->pdev->dev, ba->ba_1,
dlink/dl2k.c:                       cpu_to_le64(dma_map_single(&np->pdev->dev, skb->data,
micrel/ksz884x.c:               dma_buf->dma = dma_map_single(&hw_priv->pdev->dev, skb->data,

Also works. Do you recommend to create a v2 of the patch?

Yes please. It makes things easier to maintain if every driver does the same thing.

Andrew

#4 lore raw
Quoted 14 lines · Andrew Lunn
Quoted 13 lines · Sergei Antonov
Quoted 11 lines · Andrew Lunn

drivers/net/ethernet/moxa/moxart_ether.c static int moxart_mac_probe(struct platform_device *pdev) · line 542

Quoted 3 lines
drivers/net/ethernet/moxa/moxart_ether.c +3 -0
+     /* Inherit the DMA masks from the platform device */
+     ndev->dev.dma_mask = p_dev->dma_mask;
+     ndev->dev.coherent_dma_mask = p_dev->coherent_dma_mask;

There is only one other ethernet driver which does this. What you see much more often is:

alacritech/slicoss.c:   paddr = dma_map_single(&sdev->pdev->dev, skb->data, maplen,
neterion/s2io.c:                                dma_map_single(&sp->pdev->dev, ba->ba_1,
dlink/dl2k.c:                       cpu_to_le64(dma_map_single(&np->pdev->dev, skb->data,
micrel/ksz884x.c:               dma_buf->dma = dma_map_single(&hw_priv->pdev->dev, skb->data,
Quoted 4 lines
Quoted 1 line

Also works. Do you recommend to create a v2 of the patch?

Yes please. It makes things easier to maintain if every driver does the same thing.

Yes this is a common pattern to store a device reference pointing to &pdev->dev into your network device private structure fetched via netdev_priv().

Alternatively, we could sort of try to settle on a common pattern where we utilize &dev->parent->dev thanks to having called SET_NETDEV_DEV(), that might be more universal?

Signature · 1 line
Florian