diff mbox series

[03/16] fpga: dfl: pci: Remove usage of the deprecated "pci-dma-compat.h" API

Message ID 4a0a48fb682d13e6861f604d3cad3424672bee1f.1641500561.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State New
Headers show
Series Remove usage of the deprecated "pci-dma-compat.h" API | expand

Commit Message

Christophe JAILLET Jan. 6, 2022, 9:49 p.m. UTC
In [1], Christoph Hellwig has proposed to remove the wrappers in
include/linux/pci-dma-compat.h.

Some reasons why this API should be removed have been given by Julia
Lawall in [2].

A coccinelle script has been used to perform the needed transformation.
It can be found in [3].


It has been hand modified to use 'dma_set_mask_and_coherent()' instead of
'pci_set_dma_mask()/pci_set_consistent_dma_mask()' when applicable.
This is less verbose.

The explicit 'ret = -EIO;' has been removed because
'dma_set_mask_and_coherent()' returns 0 or -EIO, so its return code can be
used directly.


[1]: https://lore.kernel.org/kernel-janitors/20200421081257.GA131897@infradead.org/
[2]: https://lore.kernel.org/kernel-janitors/alpine.DEB.2.22.394.2007120902170.2424@hadrien/
[3]: https://lore.kernel.org/kernel-janitors/20200716192821.321233-1-christophe.jaillet@wanadoo.fr/

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Xu Yilun <yilun.xu@intel.com>
---
Reviewed in: https://lore.kernel.org/kernel-janitors/20210823025635.GA620145@yilunxu-OptiPlex-7050/
---
 drivers/fpga/dfl-pci.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Comments

Arnd Bergmann Jan. 6, 2022, 11:06 p.m. UTC | #1
On Thu, Jan 6, 2022 at 4:49 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> In [1], Christoph Hellwig has proposed to remove the wrappers in
> include/linux/pci-dma-compat.h.
>
> Some reasons why this API should be removed have been given by Julia
> Lawall in [2].
>
> A coccinelle script has been used to perform the needed transformation.
> It can be found in [3].
>
>
> It has been hand modified to use 'dma_set_mask_and_coherent()' instead of
> 'pci_set_dma_mask()/pci_set_consistent_dma_mask()' when applicable.
> This is less verbose.
>
> The explicit 'ret = -EIO;' has been removed because
> 'dma_set_mask_and_coherent()' returns 0 or -EIO, so its return code can be
> used directly.
>
>
> [1]: https://lore.kernel.org/kernel-janitors/20200421081257.GA131897@infradead.org/
> [2]: https://lore.kernel.org/kernel-janitors/alpine.DEB.2.22.394.2007120902170.2424@hadrien/
> [3]: https://lore.kernel.org/kernel-janitors/20200716192821.321233-1-christophe.jaillet@wanadoo.fr/
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Reviewed-by: Xu Yilun <yilun.xu@intel.com>

This is a correct conversion of the driver, but I'd prefer to keep this separate
from the pci-dma-compat series.

> +       ret = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(64));
> +       if (ret)
> +               ret = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32));
> +       if (ret) {
>                 dev_err(&pcidev->dev, "No suitable DMA support available.\n");
>                 goto disable_error_report_exit;

The code looks a bit suspicous, both the old and the new version. If the device
ends up on a bus that can only do 32-bit DMA, shouldn't it remember this and
make sure it only does GFP_DMA32 allocations for buffers that are passed to
the device?

        Arnd
Arnd Bergmann Jan. 7, 2022, 12:58 a.m. UTC | #2
On Thu, Jan 6, 2022 at 6:06 PM Arnd Bergmann <arnd@arndb.de> wrote:
>

> > [1]: https://lore.kernel.org/kernel-janitors/20200421081257.GA131897@infradead.org/
> > [2]: https://lore.kernel.org/kernel-janitors/alpine.DEB.2.22.394.2007120902170.2424@hadrien/
> > [3]: https://lore.kernel.org/kernel-janitors/20200716192821.321233-1-christophe.jaillet@wanadoo.fr/
> >
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > Reviewed-by: Xu Yilun <yilun.xu@intel.com>
>
> This is a correct conversion of the driver, but I'd prefer to keep this separate
> from the pci-dma-compat series.

Nevermind, I just misread the patch, and it is required after all to get
rid of pci_set_dma_mask()

Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Christophe JAILLET Jan. 7, 2022, 6:34 a.m. UTC | #3
Le 07/01/2022 à 01:58, Arnd Bergmann a écrit :
> On Thu, Jan 6, 2022 at 6:06 PM Arnd Bergmann <arnd@arndb.de> wrote:
>>
> 
>>> [1]: https://lore.kernel.org/kernel-janitors/20200421081257.GA131897@infradead.org/
>>> [2]: https://lore.kernel.org/kernel-janitors/alpine.DEB.2.22.394.2007120902170.2424@hadrien/
>>> [3]: https://lore.kernel.org/kernel-janitors/20200716192821.321233-1-christophe.jaillet@wanadoo.fr/
>>>
>>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>>> Reviewed-by: Xu Yilun <yilun.xu@intel.com>
>>
>> This is a correct conversion of the driver, but I'd prefer to keep this separate
>> from the pci-dma-compat series.
> 
> Nevermind, I just misread the patch, and it is required after all to get
> rid of pci_set_dma_mask()
> 
> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
> 

Hi,

I also have another WIP which removes these DMA(32) fallbacks.
It will be clean-up later-on.

CJ
Christoph Hellwig Jan. 10, 2022, 8:44 a.m. UTC | #4
Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/drivers/fpga/dfl-pci.c b/drivers/fpga/dfl-pci.c
index 4d68719e608f..96a11084bef4 100644
--- a/drivers/fpga/dfl-pci.c
+++ b/drivers/fpga/dfl-pci.c
@@ -15,6 +15,7 @@ 
  */
 
 #include <linux/pci.h>
+#include <linux/dma-mapping.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -354,16 +355,10 @@  int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid)
 
 	pci_set_master(pcidev);
 
-	if (!pci_set_dma_mask(pcidev, DMA_BIT_MASK(64))) {
-		ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
-		if (ret)
-			goto disable_error_report_exit;
-	} else if (!pci_set_dma_mask(pcidev, DMA_BIT_MASK(32))) {
-		ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
-		if (ret)
-			goto disable_error_report_exit;
-	} else {
-		ret = -EIO;
+	ret = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(64));
+	if (ret)
+		ret = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32));
+	if (ret) {
 		dev_err(&pcidev->dev, "No suitable DMA support available.\n");
 		goto disable_error_report_exit;
 	}