All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: moxa: inherit DMA masks to make dma_map_single() work
@ 2022-08-12 15:48 Sergei Antonov
  2022-08-12 16:13 ` Andrew Lunn
  0 siblings, 1 reply; 5+ messages in thread
From: Sergei Antonov @ 2022-08-12 15:48 UTC (permalink / raw)
  To: netdev
  Cc: Sergei Antonov, Jakub Kicinski, Pavel Skripkin, David S . Miller,
	Guobin Huang, Paolo Abeni

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.

Signed-off-by: Sergei Antonov <saproj@gmail.com>
CC: Jakub Kicinski <kuba@kernel.org>
CC: Pavel Skripkin <paskripkin@gmail.com>
CC: David S. Miller <davem@davemloft.net>
CC: Guobin Huang <huangguobin4@huawei.com>
CC: Paolo Abeni <pabeni@redhat.com>
---
 drivers/net/ethernet/moxa/moxart_ether.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c
index a3214a762e4b..de99211d85c2 100644
--- a/drivers/net/ethernet/moxa/moxart_ether.c
+++ b/drivers/net/ethernet/moxa/moxart_ether.c
@@ -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);
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: moxa: inherit DMA masks to make dma_map_single() work
  2022-08-12 15:48 [PATCH] net: moxa: inherit DMA masks to make dma_map_single() work Sergei Antonov
@ 2022-08-12 16:13 ` Andrew Lunn
  2022-08-12 16:35   ` Sergei Antonov
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2022-08-12 16:13 UTC (permalink / raw)
  To: Sergei Antonov
  Cc: netdev, Jakub Kicinski, Pavel Skripkin, David S . Miller,
	Guobin Huang, Paolo Abeni

On Fri, Aug 12, 2022 at 06:48:20PM +0300, Sergei Antonov wrote:
> 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.
> 
> Signed-off-by: Sergei Antonov <saproj@gmail.com>
> CC: Jakub Kicinski <kuba@kernel.org>
> CC: Pavel Skripkin <paskripkin@gmail.com>
> CC: David S. Miller <davem@davemloft.net>
> CC: Guobin Huang <huangguobin4@huawei.com>
> CC: Paolo Abeni <pabeni@redhat.com>
> ---
>  drivers/net/ethernet/moxa/moxart_ether.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c
> index a3214a762e4b..de99211d85c2 100644
> --- a/drivers/net/ethernet/moxa/moxart_ether.c
> +++ b/drivers/net/ethernet/moxa/moxart_ether.c
> @@ -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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: moxa: inherit DMA masks to make dma_map_single() work
  2022-08-12 16:13 ` Andrew Lunn
@ 2022-08-12 16:35   ` Sergei Antonov
  2022-08-12 16:38     ` Andrew Lunn
  0 siblings, 1 reply; 5+ messages in thread
From: Sergei Antonov @ 2022-08-12 16:35 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: netdev, Jakub Kicinski, Pavel Skripkin, David S . Miller,
	Guobin Huang, Paolo Abeni

On Fri, 12 Aug 2022 at 19:13, Andrew Lunn <andrew@lunn.ch> wrote:
> > +     /* 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?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: moxa: inherit DMA masks to make dma_map_single() work
  2022-08-12 16:35   ` Sergei Antonov
@ 2022-08-12 16:38     ` Andrew Lunn
  2022-08-12 16:58       ` Florian Fainelli
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2022-08-12 16:38 UTC (permalink / raw)
  To: Sergei Antonov
  Cc: netdev, Jakub Kicinski, Pavel Skripkin, David S . Miller,
	Guobin Huang, Paolo Abeni

On Fri, Aug 12, 2022 at 07:35:43PM +0300, Sergei Antonov wrote:
> On Fri, 12 Aug 2022 at 19:13, Andrew Lunn <andrew@lunn.ch> wrote:
> > > +     /* 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?

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

    Andrew

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: moxa: inherit DMA masks to make dma_map_single() work
  2022-08-12 16:38     ` Andrew Lunn
@ 2022-08-12 16:58       ` Florian Fainelli
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Fainelli @ 2022-08-12 16:58 UTC (permalink / raw)
  To: Andrew Lunn, Sergei Antonov
  Cc: netdev, Jakub Kicinski, Pavel Skripkin, David S . Miller,
	Guobin Huang, Paolo Abeni

On 8/12/22 09:38, Andrew Lunn wrote:
> On Fri, Aug 12, 2022 at 07:35:43PM +0300, Sergei Antonov wrote:
>> On Fri, 12 Aug 2022 at 19:13, Andrew Lunn <andrew@lunn.ch> wrote:
>>>> +     /* 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?
> 
> 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?
-- 
Florian

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-12 16:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-12 15:48 [PATCH] net: moxa: inherit DMA masks to make dma_map_single() work Sergei Antonov
2022-08-12 16:13 ` Andrew Lunn
2022-08-12 16:35   ` Sergei Antonov
2022-08-12 16:38     ` Andrew Lunn
2022-08-12 16:58       ` Florian Fainelli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.