Re: [PATCH] net: sky2: switch from 'pci_' to 'dma_' API

2020-07-12 Thread David Miller
From: Christophe JAILLET 
Date: Sat, 11 Jul 2020 22:49:44 +0200

> The wrappers in include/linux/pci-dma-compat.h should go away.
> 
> The patch has been generated with the coccinelle script below and has been
> hand modified to replace GPF_ with a correct flag.
> It has been compile tested.
> 
> When memory is allocated in 'sky2_alloc_buffers()', GFP_KERNEL can be used
> because some other memory allocations in the same function already use this
> flag.
> 
> When memory is allocated in 'sky2_probe()', GFP_KERNEL can be used
> because another memory allocations in the same function already uses this
> flag.
 ...
> Signed-off-by: Christophe JAILLET 

Applied.


Re: [PATCH] net: sky2: switch from 'pci_' to 'dma_' API

2020-07-12 Thread Julia Lawall


On Sun, 12 Jul 2020, Christophe JAILLET wrote:

> Le 12/07/2020 à 08:32, Joe Perches a écrit :
> > On Sun, 2020-07-12 at 08:29 +0200, Christophe JAILLET wrote:
> > > Le 11/07/2020 à 23:20, Joe Perches a écrit :
> > > > On Sat, 2020-07-11 at 22:49 +0200, Christophe JAILLET wrote:
> > > > > The wrappers in include/linux/pci-dma-compat.h should go away.
> > > > why?
> > > >
> > > >
> > >   From Christoph Hellwig
> > > https://marc.info/?l=kernel-janitors=158745678307186=4
> > There's no why there.
> > There's just an assertion a wrapper should "go away".
> >
> > "the wrappers in include/linux/pci-dma-compat.h should go away"
> >
> > wrappers aren't all bad.
> >
> >
> Adding Christoph Hellwig to shed some light.

Neither the wrapped name nor the unwrapped name is higher or lower level.
Nothing much happens to the arguments.  The wrappers and the wrapped
functions are not used entirely consistently, eg some files, and perhaps
even some functions, use a mixture of the two.  There a set of confusingly
named constants associated with the two sets of functions, and these
constants are also not always used consistently.

julia

Re: [PATCH] net: sky2: switch from 'pci_' to 'dma_' API

2020-07-12 Thread Christophe JAILLET

Le 12/07/2020 à 08:32, Joe Perches a écrit :

On Sun, 2020-07-12 at 08:29 +0200, Christophe JAILLET wrote:

Le 11/07/2020 à 23:20, Joe Perches a écrit :

On Sat, 2020-07-11 at 22:49 +0200, Christophe JAILLET wrote:

The wrappers in include/linux/pci-dma-compat.h should go away.

why?



  From Christoph Hellwig
https://marc.info/?l=kernel-janitors=158745678307186=4

There's no why there.
There's just an assertion a wrapper should "go away".

"the wrappers in include/linux/pci-dma-compat.h should go away"

wrappers aren't all bad.



Adding Christoph Hellwig to shed some light.

CJ



Re: [PATCH] net: sky2: switch from 'pci_' to 'dma_' API

2020-07-12 Thread Joe Perches
On Sun, 2020-07-12 at 08:29 +0200, Christophe JAILLET wrote:
> Le 11/07/2020 à 23:20, Joe Perches a écrit :
> > On Sat, 2020-07-11 at 22:49 +0200, Christophe JAILLET wrote:
> > > The wrappers in include/linux/pci-dma-compat.h should go away.
> > why?
> > 
> > 
>  From Christoph Hellwig 
> https://marc.info/?l=kernel-janitors=158745678307186=4

There's no why there.
There's just an assertion a wrapper should "go away".

"the wrappers in include/linux/pci-dma-compat.h should go away"

wrappers aren't all bad.



Re: [PATCH] net: sky2: switch from 'pci_' to 'dma_' API

2020-07-11 Thread Joe Perches
On Sat, 2020-07-11 at 22:49 +0200, Christophe JAILLET wrote:
> The wrappers in include/linux/pci-dma-compat.h should go away.

why?




[PATCH] net: sky2: switch from 'pci_' to 'dma_' API

2020-07-11 Thread Christophe JAILLET
The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GPF_ with a correct flag.
It has been compile tested.

When memory is allocated in 'sky2_alloc_buffers()', GFP_KERNEL can be used
because some other memory allocations in the same function already use this
flag.

When memory is allocated in 'sky2_probe()', GFP_KERNEL can be used
because another memory allocations in the same function already uses this
flag.


@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
   https://marc.info/?l=kernel-janitors=158745678307186=4
---
 drivers/net/ethernet/marvell/sky2.c | 89 +++--
 1 file changed, 46 insertions(+), 43 deletions(-)

diff --git a/drivers/net/ethernet/marvell/sky2.c 
b/drivers/net/ethernet/marvell/sky2.c
index fe54764caea9..adb1a9c19505 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -1209,8 +1209,9 @@ static int sky2_rx_map_skb(struct pci_dev *pdev, struct 
rx_ring_info *re,
struct sk_buff *skb = re->skb;
int i;
 
-   re->data_addr = pci_map_single(pdev, skb->data, size, 
PCI_DMA_FROMDEVICE);
-   if (pci_dma_mapping_error(pdev, re->data_addr))
+   re->data_addr = dma_map_single(>dev, skb->data, size,
+  DMA_FROM_DEVICE);
+   if (dma_mapping_error(>dev, re->data_addr))
goto mapping_error;
 
dma_unmap_len_set(re, data_size, size);
@@ -1229,13 +1230,13 @@ static int sky2_rx_map_skb(struct pci_dev *pdev, struct 
rx_ring_info *re,
 
 map_page_error:
while (--i >= 0) {
-   pci_unmap_page(pdev, re->frag_addr[i],
+   dma_unmap_page(>dev, re->frag_addr[i],
   skb_frag_size(_shinfo(skb)->frags[i]),
-  PCI_DMA_FROMDEVICE);
+  DMA_FROM_DEVICE);
}
 
-   pci_unmap_single(pdev, re->data_addr, dma_unmap_len(re, data_size),
-PCI_DMA_FROMDEVICE);
+   dma_unmap_single(>dev, re->data_addr,
+dma_unmap_len(re, data_size), DMA_FROM_DEVICE);
 
 mapping_error:
if (net_ratelimit())
@@ -1249,13 +1250,13 @@ static void sky2_rx_unmap_skb(struct pci_dev *pdev, 
struct rx_ring_info *re)
struct sk_buff *skb = re->skb;
int i;
 
-   pci_unmap_single(pdev, re->data_addr, dma_unmap_len(re, data_size),
-PCI_DMA_FROMDEVICE);
+   dma_unmap_single(>dev, re->data_addr,
+dma_unmap_len(re, data_size), DMA_FROM_DEVICE);
 
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
-   pci_unmap_page(pdev, re->frag_addr[i],
-  skb_frag_size(_shinfo(skb)->frags[i]),
-  PCI_DMA_FROMDEVICE);
+   dma_unmap_page(>dev, re->frag_addr[i],
+