char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
Subsystems (3)
cover char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
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/[email protected]/
[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(-)
Signature · 1 line
2.30.2
PATCH 1/4 char: xillybus: Remove usage of the deprecated 'pci-dma-compat.h' API
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/[email protected]/
[2]: https://lore.kernel.org/kernel-janitors/alpine.DEB.2.22.394.2007120902170.2424@hadrien/
--- drivers/char/xillybus/xillybus_pcie.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/char/xillybus/xillybus_pcie.c +4 -5
@@ -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" );
Signature · 1 line
2.30.2
PATCH 2/4 char: xillybus: Remove usage of 'pci_unmap_single()'
In reply to 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.devSo 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.
--- drivers/char/xillybus/xillybus.h | 6 +----- drivers/char/xillybus/xillybus_pcie.c | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-)
drivers/char/xillybus/xillybus.h +1 -5
@@ -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;
drivers/char/xillybus/xillybus_pcie.c +3 -3
@@ -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;
Signature · 1 line
2.30.2
PATCH 3/4 char: xillybus: Remove usage of remaining deprecated pci_ API
In reply to 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.devSo 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.
--- 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(-)
drivers/char/xillybus/xillybus.h +0 -1
@@ -87,7 +87,6 @@ struct xilly_channel { };struct xilly_endpoint { -struct pci_dev *pdev;struct device *dev;struct xilly_endpoint_hardware *ephw;
drivers/char/xillybus/xillybus_core.c +1 -1
@@ -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 ;
drivers/char/xillybus/xillybus_pcie.c +6 -10
@@ -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 ; }
Signature · 1 line
2.30.2
Re: [PATCH v1 3/4] char: xillybus: Remove usage of remaining deprecated pci_ API
Quoted 17 lines · Christophe JAILLET
drivers/char/xillybus/xillybus.h +0
-1@@ -87,7 +87,6 @@ struct xilly_channel { };struct xilly_endpoint { -struct pci_dev *pdev;struct device *dev;struct xilly_endpoint_hardware *ephw;drivers/char/xillybus/xillybus_core.c +0
-0
drivers/char/xillybus/xillybus_core.c struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev, · line 1786
Quoted 5 lines
drivers/char/xillybus/xillybus_core.c +1
-1@@ -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.
drivers/char/xillybus/xillybus_core.c struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev, · line 1789
Quoted 3 lines
drivers/char/xillybus/xillybus_core.c +0
-0endpoint->dev = dev; endpoint->ephw = ephw; endpoint->msg_counter =0x0b ;
regards,
dan carpenter
Re: [PATCH v1 3/4] char: xillybus: Remove usage of remaining deprecated pci_ API
Le 30/08/2021 à 11:48, Dan Carpenter a écrit :
Quoted 28 lines · Christophe JAILLET
Quoted 17 lines
drivers/char/xillybus/xillybus.h +0
-1@@ -87,7 +87,6 @@ struct xilly_channel { };struct xilly_endpoint { -struct pci_dev *pdev;struct device *dev;struct xilly_endpoint_hardware *ephw;drivers/char/xillybus/xillybus_core.c +0
-0drivers/char/xillybus/xillybus_core.c struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev, · line 1786
Quoted 5 lines
drivers/char/xillybus/xillybus_core.c +1
-1@@ -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.
Quoted 8 lines
drivers/char/xillybus/xillybus_core.c struct xilly_endpoint *xillybus_init_endpoint(struct pci_dev *pdev, · line 1789
Quoted 3 lines
drivers/char/xillybus/xillybus_core.c +0
-0endpoint->dev = dev; endpoint->ephw = ephw; endpoint->msg_counter =0x0b ;regards,
dan carpenter
Well, I first did something like:
Review
Quoted 2 lines
(quoted diff) +1
-1- 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
PATCH 4/4 char: xillybus: Simplify 'xillybus_init_endpoint()'
In reply to Christophe JAILLETThs first argument of 'xillybus_init_endpoint()' is now useless. Remove it.
--- 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(-)
drivers/char/xillybus/xillybus.h +1 -2
@@ -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);
drivers/char/xillybus/xillybus_core.c +1 -3
@@ -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 ;
drivers/char/xillybus/xillybus_of.c +1 -1
@@ -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 ;
drivers/char/xillybus/xillybus_pcie.c +1 -1
@@ -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 ;
Signature · 1 line
2.30.2
Eli Billauer
maintainerQuoted 3 lines · Christophe JAILLET
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
Arnd Bergmann
maintainerQuoted 9 lines · Eli Billauer
Quoted 3 lines · Christophe JAILLET
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.
Quoted 1 line
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").
Quoted 4 lines
I think the best way is to put a comment at the top of
pci-dma-compat.hsaying 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
Eli Billauer
maintainerQuoted 6 lines · Arnd Bergmann
The documentation was updated 11 years ago to only describe the modern
linux/dma-mapping.hinterfaces and mark the old bus-specific ones as no longer recommended, see216bf58f4092("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