chelsio: switch from 'pci_' to 'dma_' API
Subsystems (3)
PATCH 1/1 chelsio: switch from 'pci_' to 'dma_' API
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 GFP_ with a correct flag.
It has been compile tested.
When memory is allocated in 'free_rx_resources()' and 'alloc_tx_resources()' (sge.c) GFP_KERNEL can be used because it is already used in these functions.
Moreover, they can only be called from a .ndo_open function. So it is
guarded by the 'rtnl_lock()', which is a mutex.
While at it, a pr_err message in 'init_one()' has been updated accordingly (s/consistent/coherent).
@@
@@
- 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(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3;
@@
- pci_zalloc_consistent(e1, e2, e3)
+ dma_alloc_coherent(&e1->dev, e2, e3, GFP_)
@@
expression e1, e2, e3, e4;
@@
- pci_free_consistent(e1, e2, e3, e4)
+ dma_free_coherent(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_single(e1, e2, e3, e4)
+ dma_map_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_single(e1, e2, e3, e4)
+ dma_unmap_single(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4, e5;
@@
- pci_map_page(e1, e2, e3, e4, e5)
+ dma_map_page(&e1->dev, e2, e3, e4, e5)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_page(e1, e2, e3, e4)
+ dma_unmap_page(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_map_sg(e1, e2, e3, e4)
+ dma_map_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_unmap_sg(e1, e2, e3, e4)
+ dma_unmap_sg(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+ dma_sync_single_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_single_for_device(e1, e2, e3, e4)
+ dma_sync_single_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+ dma_sync_sg_for_cpu(&e1->dev, e2, e3, e4)
@@
expression e1, e2, e3, e4;
@@
- pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+ dma_sync_sg_for_device(&e1->dev, e2, e3, e4)
@@
expression e1, e2;
@@
- pci_dma_mapping_error(e1, e2)
+ dma_mapping_error(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_dma_mask(e1, e2)
+ dma_set_mask(&e1->dev, e2)
@@
expression e1, e2;
@@
- pci_set_consistent_dma_mask(e1, e2)
+ dma_set_coherent_mask(&e1->dev, e2)
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
https://marc.info/?l=kernel-janitors&m8745678307186&w=4
--- drivers/net/ethernet/chelsio/cxgb/cxgb2.c | 10 ++-- drivers/net/ethernet/chelsio/cxgb/sge.c | 64 ++++++++++++----------- 2 files changed, 39 insertions(+), 35 deletions(-)
drivers/net/ethernet/chelsio/cxgb/cxgb2.c +5 -5
@@ -997,17 +997,17 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent) goto out_disable_pdev; } -if (!pci_set_dma_mask (pdev,DMA_BIT_MASK (64 ))) { +if (!dma_set_mask (&pdev->dev,DMA_BIT_MASK (64 ))) { pci_using_dac =1 ; -if (pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 ))) { -pr_err ("%s: unable to obtain 64-bit DMA for " -"consistent allocations\n" ,pci_name (pdev)); +if (dma_set_coherent_mask (&pdev->dev,DMA_BIT_MASK (64 ))) { +pr_err ("%s: unable to obtain 64-bit DMA for coherent allocations\n" , +pci_name (pdev)); err = -ENODEV ; goto out_disable_pdev; } - }else if ((err =pci_set_dma_mask (pdev,DMA_BIT_MASK (32 ))) !=0 ) { + }else if ((err =dma_set_mask (&pdev->dev,DMA_BIT_MASK (32 ))) !=0 ) {pr_err ("%s: no usable DMA configuration\n" ,pci_name (pdev)); goto out_disable_pdev; }
drivers/net/ethernet/chelsio/cxgb/sge.c +34 -29
143 lines not on this page · raw message
Signature · 1 line
2.25.1
From: Christophe JAILLET <[email protected]>
Date: Sun, 23 Aug 2020 10:36:48 +0200
Quoted 15 lines
The wrappers in
include/linux/pci-dma-compat.hshould go away.The patch has been generated with the coccinelle script below and has been hand modified to replace
GFP_with a correct flag.
It has been compile tested.When memory is allocated in '
free_rx_resources()' and 'alloc_tx_resources()' (sge.c)GFP_KERNELcan be used because it is already used in these functions.Moreover, they can only be called from a .ndo_open function. So it is
guarded by the 'rtnl_lock()', which is a mutex.While at it, a
pr_errmessage in 'init_one()' has been updated accordingly (s/consistent/coherent).
...
Quoted 1 line
Signed-off-by Christophe JAILLET <[email protected]>
Applied, thanks.