LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
@ 2021-08-27 17:17 Christophe JAILLET
  2021-08-27 17:17 ` [PATCH v1 1/4] " Christophe JAILLET
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Christophe JAILLET @ 2021-08-27 17:17 UTC (permalink / raw)
  To: eli.billauer, arnd, gregkh
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET

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].

However, updating 'drivers/char/xillybus' is a bit tricky because of its use of
'struct xilly_mapping' and 'struct xilly_endpoint'.

The first patch is just the easy part of the pci_  --> dma_ conversion. This is
mostly done with a coccinelle script.

The second updates 'struct xilly_mapping' (and code using it) to explicitly use
the dma_ API.

The third takes care of 'struct xilly_endpoint' (and code using it).

Finally, the 4th patch is a clean-up to remove a now useless parameter from
'xillybus_init_endpoint()'


These changes also offert the opportunity to merge some code from
'xillybus_pcie.c' and 'xillybus_of.c' into 'xillybus_core.c'.
See 'xilly_dma_sync_single_for_cpu_of()' and
'xilly_dma_sync_single_for_cpu_pci()' for example.

This goes beyond the scope of removing the usage of the deprecated
'pci-dma-compat.h' API. The need of 'xilly_pci_direction()' should then be
discussed.
It could be included afterwards it required.


All these patches have been compile tested only.


[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/

Christophe JAILLET (4):
  char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
  char: xillybus: Remove usage of 'pci_unmap_single()'
  char: xillybus: Remove usage of remaining deprecated pci_ API
  char: xillybus: Simplify 'xillybus_init_endpoint()'

 drivers/char/xillybus/xillybus.h      | 10 ++------
 drivers/char/xillybus/xillybus_core.c |  4 +---
 drivers/char/xillybus/xillybus_of.c   |  2 +-
 drivers/char/xillybus/xillybus_pcie.c | 33 ++++++++++++---------------
 4 files changed, 18 insertions(+), 31 deletions(-)

-- 
2.30.2


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

* [PATCH v1 1/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
  2021-08-27 17:17 [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Christophe JAILLET
@ 2021-08-27 17:17 ` Christophe JAILLET
  2021-11-03 18:38   ` Christophe JAILLET
  2021-08-27 17:17 ` [PATCH v1 2/4] char: xillybus: Remove usage of 'pci_unmap_single()' Christophe JAILLET
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Christophe JAILLET @ 2021-08-27 17:17 UTC (permalink / raw)
  To: eli.billauer, arnd, gregkh
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET

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
Only relevant part are given below.

'xilly_pci_direction()' has been hand modified to simplify it slightly.

It has been compile tested.


@@ @@
-    PCI_DMA_BIDIRECTIONAL
+    DMA_BIDIRECTIONAL

@@ @@
-    PCI_DMA_TODEVICE
+    DMA_TO_DEVICE

@@ @@
-    PCI_DMA_FROMDEVICE
+    DMA_FROM_DEVICE

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

[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/

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/char/xillybus/xillybus_pcie.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/char/xillybus/xillybus_pcie.c b/drivers/char/xillybus/xillybus_pcie.c
index bdf1c366b4fc..be25bfdb0d9a 100644
--- a/drivers/char/xillybus/xillybus_pcie.c
+++ b/drivers/char/xillybus/xillybus_pcie.c
@@ -36,11 +36,10 @@ static int xilly_pci_direction(int direction)
 {
 	switch (direction) {
 	case DMA_TO_DEVICE:
-		return PCI_DMA_TODEVICE;
 	case DMA_FROM_DEVICE:
-		return PCI_DMA_FROMDEVICE;
+		return direction;
 	default:
-		return PCI_DMA_BIDIRECTIONAL;
+		return DMA_BIDIRECTIONAL;
 	}
 }
 
@@ -185,9 +184,9 @@ static int xilly_probe(struct pci_dev *pdev,
 	 * So go for the 64-bit mask only when failing is the other option.
 	 */
 
-	if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
+	if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
 		endpoint->dma_using_dac = 0;
-	} else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
+	} else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
 		endpoint->dma_using_dac = 1;
 	} else {
 		dev_err(endpoint->dev, "Failed to set DMA mask. Aborting.\n");
-- 
2.30.2


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

* [PATCH v1 2/4] char: xillybus: Remove usage of 'pci_unmap_single()'
  2021-08-27 17:17 [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Christophe JAILLET
  2021-08-27 17:17 ` [PATCH v1 1/4] " Christophe JAILLET
@ 2021-08-27 17:17 ` Christophe JAILLET
  2021-08-27 17:17 ` [PATCH v1 3/4] char: xillybus: Remove usage of remaining deprecated pci_ API Christophe JAILLET
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Christophe JAILLET @ 2021-08-27 17:17 UTC (permalink / raw)
  To: eli.billauer, arnd, gregkh
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET

'struct xilly_mapping' includes a 'void *device' field which holds,
depending of the context, a 'struct device *' or a 'struct pci_dev *'.

This field is then used with 'pci_umap_single()' in 'xillybus_pcie.c' and
with 'dma_umap_single()' in 'xillybus_of.c'.

In order to remove usage of the deprecated 'pci_unmap_single()' API, turn
the 'void *device' field from 'struct xilly_mapping', into an explicit
'struct device *device' and use 'dma_umap_single()' everywhere.

In order to update 'xillybus_pcie.c', use the 'dev' field instead of the
'pdev' field from the 'struct xilly_endpoint'.
Both fields are initialized by 'xillybus_init_endpoint()' and in
'xillybus_pcie.c', we have:
	xillybus_init_endpoint(pdev, &pdev->dev, &pci_hw);
                                 ^       ^
        xilly_endpoint.pdev = ___|       |___ = xilly_endpoint.dev
So the modification from pci_ to dma_ function is straightforward.

While at it, remove a comment that is wrong, because in the case above,
both 'dev' and 'pdev' are not NULL.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/char/xillybus/xillybus.h      | 6 +-----
 drivers/char/xillybus/xillybus_pcie.c | 6 +++---
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/char/xillybus/xillybus.h b/drivers/char/xillybus/xillybus.h
index c63ffc56637c..7c71bdef7ccb 100644
--- a/drivers/char/xillybus/xillybus.h
+++ b/drivers/char/xillybus/xillybus.h
@@ -87,10 +87,6 @@ struct xilly_channel {
 };
 
 struct xilly_endpoint {
-	/*
-	 * One of pdev and dev is always NULL, and the other is a valid
-	 * pointer, depending on the type of device
-	 */
 	struct pci_dev *pdev;
 	struct device *dev;
 	struct xilly_endpoint_hardware *ephw;
@@ -131,7 +127,7 @@ struct xilly_endpoint_hardware {
 };
 
 struct xilly_mapping {
-	void *device;
+	struct device *device;
 	dma_addr_t dma_addr;
 	size_t size;
 	int direction;
diff --git a/drivers/char/xillybus/xillybus_pcie.c b/drivers/char/xillybus/xillybus_pcie.c
index be25bfdb0d9a..8360427e4226 100644
--- a/drivers/char/xillybus/xillybus_pcie.c
+++ b/drivers/char/xillybus/xillybus_pcie.c
@@ -69,8 +69,8 @@ static void xilly_pci_unmap(void *ptr)
 {
 	struct xilly_mapping *data = ptr;
 
-	pci_unmap_single(data->device, data->dma_addr,
-			 data->size, data->direction);
+	dma_unmap_single(data->device, data->dma_addr, data->size,
+			 data->direction);
 
 	kfree(ptr);
 }
@@ -105,7 +105,7 @@ static int xilly_map_single_pci(struct xilly_endpoint *ep,
 		return -ENODEV;
 	}
 
-	this->device = ep->pdev;
+	this->device = ep->dev;
 	this->dma_addr = addr;
 	this->size = size;
 	this->direction = pci_direction;
-- 
2.30.2


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

* [PATCH v1 3/4] char: xillybus: Remove usage of remaining deprecated pci_ API
  2021-08-27 17:17 [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Christophe JAILLET
  2021-08-27 17:17 ` [PATCH v1 1/4] " Christophe JAILLET
  2021-08-27 17:17 ` [PATCH v1 2/4] char: xillybus: Remove usage of 'pci_unmap_single()' Christophe JAILLET
@ 2021-08-27 17:17 ` Christophe JAILLET
  2021-08-30  9:48   ` Dan Carpenter
  2021-08-27 17:17 ` [PATCH v1 4/4] char: xillybus: Simplify 'xillybus_init_endpoint()' Christophe JAILLET
  2021-08-28 15:05 ` [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Eli Billauer
  4 siblings, 1 reply; 11+ messages in thread
From: Christophe JAILLET @ 2021-08-27 17:17 UTC (permalink / raw)
  To: eli.billauer, arnd, gregkh
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET

'struct xilly_endpoint' has a 'dev' field which is a 'struct device *' and
a 'pdev' field which is 'struct pci_dev *'.

Both fields are initialized by 'xillybus_init_endpoint()' and in
'xillybus_pcie.c', we have:
	xillybus_init_endpoint(pdev, &pdev->dev, &pci_hw);
                                 ^       ^
        xilly_endpoint.pdev = ___|       |___ = xilly_endpoint.dev
So the modification from pci_ to dma_ function is straightforward.

Update all remaining deprecated pci_ function calls to equivalent
dma_ API function.
Switching from 'ep->pdev' to 'ep->dev' makes the transformation
straightforward.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/char/xillybus/xillybus.h      |  1 -
 drivers/char/xillybus/xillybus_core.c |  2 +-
 drivers/char/xillybus/xillybus_pcie.c | 16 ++++++----------
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/char/xillybus/xillybus.h b/drivers/char/xillybus/xillybus.h
index 7c71bdef7ccb..55d47cb13a7b 100644
--- a/drivers/char/xillybus/xillybus.h
+++ b/drivers/char/xillybus/xillybus.h
@@ -87,7 +87,6 @@ struct xilly_channel {
 };
 
 struct xilly_endpoint {
-	struct pci_dev *pdev;
 	struct device *dev;
 	struct xilly_endpoint_hardware *ephw;
 
diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/xillybus_core.c
index 931d0bf4cec6..0ced9ec6977f 100644
--- a/drivers/char/xillybus/xillybus_core.c
+++ b/drivers/char/xillybus/xillybus_core.c
@@ -1783,7 +1783,7 @@ struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev,
 	if (!endpoint)
 		return NULL;
 
-	endpoint->pdev = pdev;
+	(void)pdev;	// silence a compiler warning, will be removed
 	endpoint->dev = dev;
 	endpoint->ephw = ephw;
 	endpoint->msg_counter = 0x0b;
diff --git a/drivers/char/xillybus/xillybus_pcie.c b/drivers/char/xillybus/xillybus_pcie.c
index 8360427e4226..f4be61349ca6 100644
--- a/drivers/char/xillybus/xillybus_pcie.c
+++ b/drivers/char/xillybus/xillybus_pcie.c
@@ -48,10 +48,8 @@ static void xilly_dma_sync_single_for_cpu_pci(struct xilly_endpoint *ep,
 					      size_t size,
 					      int direction)
 {
-	pci_dma_sync_single_for_cpu(ep->pdev,
-				    dma_handle,
-				    size,
-				    xilly_pci_direction(direction));
+	dma_sync_single_for_cpu(ep->dev, dma_handle, size,
+				xilly_pci_direction(direction));
 }
 
 static void xilly_dma_sync_single_for_device_pci(struct xilly_endpoint *ep,
@@ -59,10 +57,8 @@ static void xilly_dma_sync_single_for_device_pci(struct xilly_endpoint *ep,
 						 size_t size,
 						 int direction)
 {
-	pci_dma_sync_single_for_device(ep->pdev,
-				       dma_handle,
-				       size,
-				       xilly_pci_direction(direction));
+	dma_sync_single_for_device(ep->dev, dma_handle, size,
+				   xilly_pci_direction(direction));
 }
 
 static void xilly_pci_unmap(void *ptr)
@@ -98,9 +94,9 @@ static int xilly_map_single_pci(struct xilly_endpoint *ep,
 
 	pci_direction = xilly_pci_direction(direction);
 
-	addr = pci_map_single(ep->pdev, ptr, size, pci_direction);
+	addr = dma_map_single(ep->dev, ptr, size, pci_direction);
 
-	if (pci_dma_mapping_error(ep->pdev, addr)) {
+	if (dma_mapping_error(ep->dev, addr)) {
 		kfree(this);
 		return -ENODEV;
 	}
-- 
2.30.2


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

* [PATCH v1 4/4] char: xillybus: Simplify 'xillybus_init_endpoint()'
  2021-08-27 17:17 [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Christophe JAILLET
                   ` (2 preceding siblings ...)
  2021-08-27 17:17 ` [PATCH v1 3/4] char: xillybus: Remove usage of remaining deprecated pci_ API Christophe JAILLET
@ 2021-08-27 17:17 ` Christophe JAILLET
  2021-08-28 15:05 ` [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Eli Billauer
  4 siblings, 0 replies; 11+ messages in thread
From: Christophe JAILLET @ 2021-08-27 17:17 UTC (permalink / raw)
  To: eli.billauer, arnd, gregkh
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET

Ths first argument of 'xillybus_init_endpoint()' is now useless.
Remove it.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/char/xillybus/xillybus.h      | 3 +--
 drivers/char/xillybus/xillybus_core.c | 4 +---
 drivers/char/xillybus/xillybus_of.c   | 2 +-
 drivers/char/xillybus/xillybus_pcie.c | 2 +-
 4 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/char/xillybus/xillybus.h b/drivers/char/xillybus/xillybus.h
index 55d47cb13a7b..afce5bb4d127 100644
--- a/drivers/char/xillybus/xillybus.h
+++ b/drivers/char/xillybus/xillybus.h
@@ -134,8 +134,7 @@ struct xilly_mapping {
 
 irqreturn_t xillybus_isr(int irq, void *data);
 
-struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev,
-					      struct device *dev,
+struct xilly_endpoint *xillybus_init_endpoint(struct device *dev,
 					      struct xilly_endpoint_hardware
 					      *ephw);
 
diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/xillybus_core.c
index 0ced9ec6977f..02f30140c2d5 100644
--- a/drivers/char/xillybus/xillybus_core.c
+++ b/drivers/char/xillybus/xillybus_core.c
@@ -1772,8 +1772,7 @@ static const struct file_operations xillybus_fops = {
 	.poll       = xillybus_poll,
 };
 
-struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev,
-					      struct device *dev,
+struct xilly_endpoint *xillybus_init_endpoint(struct device *dev,
 					      struct xilly_endpoint_hardware
 					      *ephw)
 {
@@ -1783,7 +1782,6 @@ struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev,
 	if (!endpoint)
 		return NULL;
 
-	(void)pdev;	// silence a compiler warning, will be removed
 	endpoint->dev = dev;
 	endpoint->ephw = ephw;
 	endpoint->msg_counter = 0x0b;
diff --git a/drivers/char/xillybus/xillybus_of.c b/drivers/char/xillybus/xillybus_of.c
index 1a20b286fd1d..4e6e0c19d8c8 100644
--- a/drivers/char/xillybus/xillybus_of.c
+++ b/drivers/char/xillybus/xillybus_of.c
@@ -120,7 +120,7 @@ static int xilly_drv_probe(struct platform_device *op)
 	if (of_property_read_bool(dev->of_node, "dma-coherent"))
 		ephw = &of_hw_coherent;
 
-	endpoint = xillybus_init_endpoint(NULL, dev, ephw);
+	endpoint = xillybus_init_endpoint(dev, ephw);
 
 	if (!endpoint)
 		return -ENOMEM;
diff --git a/drivers/char/xillybus/xillybus_pcie.c b/drivers/char/xillybus/xillybus_pcie.c
index f4be61349ca6..a6ef4ce90649 100644
--- a/drivers/char/xillybus/xillybus_pcie.c
+++ b/drivers/char/xillybus/xillybus_pcie.c
@@ -124,7 +124,7 @@ static int xilly_probe(struct pci_dev *pdev,
 	struct xilly_endpoint *endpoint;
 	int rc;
 
-	endpoint = xillybus_init_endpoint(pdev, &pdev->dev, &pci_hw);
+	endpoint = xillybus_init_endpoint(&pdev->dev, &pci_hw);
 
 	if (!endpoint)
 		return -ENOMEM;
-- 
2.30.2


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

* Re: [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
  2021-08-27 17:17 [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Christophe JAILLET
                   ` (3 preceding siblings ...)
  2021-08-27 17:17 ` [PATCH v1 4/4] char: xillybus: Simplify 'xillybus_init_endpoint()' Christophe JAILLET
@ 2021-08-28 15:05 ` Eli Billauer
  2021-08-28 21:26   ` Arnd Bergmann
  4 siblings, 1 reply; 11+ messages in thread
From: Eli Billauer @ 2021-08-28 15:05 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: arnd, gregkh, linux-kernel, kernel-janitors, Christoph Hellwig

On 27/08/21 20:17, Christophe JAILLET wrote:
> In [1], Christoph Hellwig has proposed to remove the wrappers in
> include/linux/pci-dma-compat.h.
>    
Xillybus' driver is an example for why this is a good idea. But has this 
been decided upon? Are we sure that there isn't a single platform where 
the DMA mapping for PCI is different from non-PCI, and that such 
platform will never be?

If so, is there any reference to that decision?

I think the best way is to put a comment at the top of pci-dma-compat.h 
saying that the functions in that header file are deprecated and will go 
away soon. That would, more than anything else, convince people like me 
to get rid of those PCI-DMA function calls.

The bonus is that the discussion on the patch inserting that comment, 
along with the decision to apply or reject it, will become the 
authoritative word on this matter.

Thanks,
    Eli

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

* Re: [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
  2021-08-28 15:05 ` [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Eli Billauer
@ 2021-08-28 21:26   ` Arnd Bergmann
  2021-08-29  8:23     ` Eli Billauer
  0 siblings, 1 reply; 11+ messages in thread
From: Arnd Bergmann @ 2021-08-28 21:26 UTC (permalink / raw)
  To: Eli Billauer
  Cc: Christophe JAILLET, Arnd Bergmann, gregkh,
	Linux Kernel Mailing List, kernel-janitors, Christoph Hellwig

On Sat, Aug 28, 2021 at 5:07 PM Eli Billauer <eli.billauer@gmail.com> wrote:
>
> On 27/08/21 20:17, Christophe JAILLET wrote:
> > In [1], Christoph Hellwig has proposed to remove the wrappers in
> > include/linux/pci-dma-compat.h.
> >
> Xillybus' driver is an example for why this is a good idea. But has this
> been decided upon? Are we sure that there isn't a single platform where
> the DMA mapping for PCI is different from non-PCI, and that such
> platform will never be?

Yes.

> If so, is there any reference to that decision?

The documentation was updated 11 years ago to only describe the modern
linux/dma-mapping.h interfaces and mark the old bus-specific ones as
no longer recommended, see 216bf58f4092 ("Documentation: convert
PCI-DMA-mapping.txt to use the generic DMA API").

> I think the best way is to put a comment at the top of pci-dma-compat.h
> saying that the functions in that header file are deprecated and will go
> away soon. That would, more than anything else, convince people like me
> to get rid of those PCI-DMA function calls.

The only reason for keeping the old interface around any day longer would
be to identify drivers that have been unmaintained for the past decade
and ignored all the previous cleanup patches that got sent to them.

       Arnd

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

* Re: [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
  2021-08-28 21:26   ` Arnd Bergmann
@ 2021-08-29  8:23     ` Eli Billauer
  0 siblings, 0 replies; 11+ messages in thread
From: Eli Billauer @ 2021-08-29  8:23 UTC (permalink / raw)
  To: Arnd Bergmann, Christophe JAILLET
  Cc: gregkh, Linux Kernel Mailing List, kernel-janitors, Christoph Hellwig

On 29/08/21 00:26, Arnd Bergmann wrote:
>
> The documentation was updated 11 years ago to only describe the modern
> linux/dma-mapping.h interfaces and mark the old bus-specific ones as
> no longer recommended, see 216bf58f4092 ("Documentation: convert
> PCI-DMA-mapping.txt to use the generic DMA API").
>    
Thanks, Arnd. That's exactly the kind of reference I was asking about.

And of course, a thanks goes to Christophe as well for drawing my 
attention to this issue. A bit surprising it didn't happen back in 2013, 
when the driver was included in the kernel. Or possibly in 2014, when it 
went out of staging.

As for this patch set, three out of four patches make modifications in 
functions that should be deleted altogether. Their only purpose is to 
wrap DMA-related calls made by the core driver, so that the pci_* API is 
used for PCI devices, and the dma_* API otherwise. As it turns out, this 
was a lot of nonsense code from day one.

I'll prepare a patch that removes all this.

Thanks again,
    Eli

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

* Re: [PATCH v1 3/4] char: xillybus: Remove usage of remaining deprecated pci_ API
  2021-08-27 17:17 ` [PATCH v1 3/4] char: xillybus: Remove usage of remaining deprecated pci_ API Christophe JAILLET
@ 2021-08-30  9:48   ` Dan Carpenter
  2021-08-30 17:19     ` Christophe JAILLET
  0 siblings, 1 reply; 11+ messages in thread
From: Dan Carpenter @ 2021-08-30  9:48 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: eli.billauer, arnd, gregkh, linux-kernel, kernel-janitors

On Fri, Aug 27, 2021 at 07:17:47PM +0200, Christophe JAILLET wrote:
> diff --git a/drivers/char/xillybus/xillybus.h b/drivers/char/xillybus/xillybus.h
> index 7c71bdef7ccb..55d47cb13a7b 100644
> --- a/drivers/char/xillybus/xillybus.h
> +++ b/drivers/char/xillybus/xillybus.h
> @@ -87,7 +87,6 @@ struct xilly_channel {
>  };
>  
>  struct xilly_endpoint {
> -	struct pci_dev *pdev;
>  	struct device *dev;
>  	struct xilly_endpoint_hardware *ephw;
>  
> diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/xillybus_core.c
> index 931d0bf4cec6..0ced9ec6977f 100644
> --- a/drivers/char/xillybus/xillybus_core.c
> +++ b/drivers/char/xillybus/xillybus_core.c
> @@ -1783,7 +1783,7 @@ struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev,
>  	if (!endpoint)
>  		return NULL;
>  
> -	endpoint->pdev = pdev;
> +	(void)pdev;	// silence a compiler warning, will be removed

Just out of curiousity which compiler warning is this?  I don't think
GCC will complain.  I think there are other compilers which complain but
I don't know which.

>  	endpoint->dev = dev;
>  	endpoint->ephw = ephw;
>  	endpoint->msg_counter = 0x0b;

regards,
dan carpenter


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

* Re: [PATCH v1 3/4] char: xillybus: Remove usage of remaining deprecated pci_ API
  2021-08-30  9:48   ` Dan Carpenter
@ 2021-08-30 17:19     ` Christophe JAILLET
  0 siblings, 0 replies; 11+ messages in thread
From: Christophe JAILLET @ 2021-08-30 17:19 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: eli.billauer, arnd, gregkh, linux-kernel, kernel-janitors

Le 30/08/2021 à 11:48, Dan Carpenter a écrit :
> On Fri, Aug 27, 2021 at 07:17:47PM +0200, Christophe JAILLET wrote:
>> diff --git a/drivers/char/xillybus/xillybus.h b/drivers/char/xillybus/xillybus.h
>> index 7c71bdef7ccb..55d47cb13a7b 100644
>> --- a/drivers/char/xillybus/xillybus.h
>> +++ b/drivers/char/xillybus/xillybus.h
>> @@ -87,7 +87,6 @@ struct xilly_channel {
>>   };
>>   
>>   struct xilly_endpoint {
>> -	struct pci_dev *pdev;
>>   	struct device *dev;
>>   	struct xilly_endpoint_hardware *ephw;
>>   
>> diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/xillybus_core.c
>> index 931d0bf4cec6..0ced9ec6977f 100644
>> --- a/drivers/char/xillybus/xillybus_core.c
>> +++ b/drivers/char/xillybus/xillybus_core.c
>> @@ -1783,7 +1783,7 @@ struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev,
>>   	if (!endpoint)
>>   		return NULL;
>>   
>> -	endpoint->pdev = pdev;
>> +	(void)pdev;	// silence a compiler warning, will be removed
> 
> Just out of curiousity which compiler warning is this?  I don't think
> GCC will complain.  I think there are other compilers which complain but
> I don't know which.
> 
>>   	endpoint->dev = dev;
>>   	endpoint->ephw = ephw;
>>   	endpoint->msg_counter = 0x0b;
> 
> regards,
> dan carpenter
> 
> 

Well, I first did something like:
 > -	endpoint->pdev = pdev;
 > +	pdev;

in order to avoid a *potential* warning about unused parameter.
gcc (10.3.0) complains about it.
So I added the (void) to please gcc.

But, you are right, removing all uses of 'pdev' is just fine for gcc and 
the warning I wanted to avoid just does not exist :(

CJ

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

* [PATCH v1 1/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
  2021-08-27 17:17 ` [PATCH v1 1/4] " Christophe JAILLET
@ 2021-11-03 18:38   ` Christophe JAILLET
  0 siblings, 0 replies; 11+ messages in thread
From: Christophe JAILLET @ 2021-11-03 18:38 UTC (permalink / raw)
  To: mathieu.poirier, suzuki.poulose, mike.leach, leo.yan,
	alexander.shishkin, mcoquelin.stm32, alexandre.torgue
  Cc: coresight, linux-arm-kernel, linux-stm32, linux-kernel,
	kernel-janitors, Christophe JAILLET

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
Only relevant part are given below.

'xilly_pci_direction()' has been hand modified to simplify it slightly.

It has been compile tested.


@@ @@
-    PCI_DMA_BIDIRECTIONAL
+    DMA_BIDIRECTIONAL

@@ @@
-    PCI_DMA_TODEVICE
+    DMA_TO_DEVICE

@@ @@
-    PCI_DMA_FROMDEVICE
+    DMA_FROM_DEVICE

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

[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/

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/char/xillybus/xillybus_pcie.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/char/xillybus/xillybus_pcie.c b/drivers/char/xillybus/xillybus_pcie.c
index bdf1c366b4fc..be25bfdb0d9a 100644
--- a/drivers/char/xillybus/xillybus_pcie.c
+++ b/drivers/char/xillybus/xillybus_pcie.c
@@ -36,11 +36,10 @@ static int xilly_pci_direction(int direction)
 {
 	switch (direction) {
 	case DMA_TO_DEVICE:
-		return PCI_DMA_TODEVICE;
 	case DMA_FROM_DEVICE:
-		return PCI_DMA_FROMDEVICE;
+		return direction;
 	default:
-		return PCI_DMA_BIDIRECTIONAL;
+		return DMA_BIDIRECTIONAL;
 	}
 }
 
@@ -185,9 +184,9 @@ static int xilly_probe(struct pci_dev *pdev,
 	 * So go for the 64-bit mask only when failing is the other option.
 	 */
 
-	if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
+	if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
 		endpoint->dma_using_dac = 0;
-	} else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
+	} else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
 		endpoint->dma_using_dac = 1;
 	} else {
 		dev_err(endpoint->dev, "Failed to set DMA mask. Aborting.\n");
-- 
2.30.2


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

end of thread, other threads:[~2021-11-03 18:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 17:17 [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Christophe JAILLET
2021-08-27 17:17 ` [PATCH v1 1/4] " Christophe JAILLET
2021-11-03 18:38   ` Christophe JAILLET
2021-08-27 17:17 ` [PATCH v1 2/4] char: xillybus: Remove usage of 'pci_unmap_single()' Christophe JAILLET
2021-08-27 17:17 ` [PATCH v1 3/4] char: xillybus: Remove usage of remaining deprecated pci_ API Christophe JAILLET
2021-08-30  9:48   ` Dan Carpenter
2021-08-30 17:19     ` Christophe JAILLET
2021-08-27 17:17 ` [PATCH v1 4/4] char: xillybus: Simplify 'xillybus_init_endpoint()' Christophe JAILLET
2021-08-28 15:05 ` [PATCH v1 0/4] char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API Eli Billauer
2021-08-28 21:26   ` Arnd Bergmann
2021-08-29  8:23     ` Eli Billauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).