Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

prism54: 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 'islpci_alloc_memory()' (islpci_dev.c),
GFP_KERNEL can be used because it is only called from a probe function
and no spin_lock is taken in the between.

The call chain is:
prism54_probe (probe function, in 'islpci_hotplug.c')
--> islpci_setup (in 'islpci_dev.c')
--> islpci_alloc_memory (in 'islpci_dev.c')

@@
@@
- 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)

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20200722104534.30760-1-christophe.jaillet@wanadoo.fr

authored by

Christophe JAILLET and committed by
Kalle Valo
84d47961 81cf72b7

+36 -41
+14 -16
drivers/net/wireless/intersil/prism54/islpci_dev.c
··· 636 636 */ 637 637 638 638 /* perform the allocation */ 639 - priv->driver_mem_address = pci_alloc_consistent(priv->pdev, 640 - HOST_MEM_BLOCK, 641 - &priv-> 642 - device_host_address); 639 + priv->driver_mem_address = dma_alloc_coherent(&priv->pdev->dev, 640 + HOST_MEM_BLOCK, 641 + &priv->device_host_address, 642 + GFP_KERNEL); 643 643 644 644 if (!priv->driver_mem_address) { 645 645 /* error allocating the block of PCI memory */ ··· 692 692 693 693 /* map the allocated skb data area to pci */ 694 694 priv->pci_map_rx_address[counter] = 695 - pci_map_single(priv->pdev, (void *) skb->data, 696 - MAX_FRAGMENT_SIZE_RX + 2, 697 - PCI_DMA_FROMDEVICE); 698 - if (pci_dma_mapping_error(priv->pdev, 699 - priv->pci_map_rx_address[counter])) { 695 + dma_map_single(&priv->pdev->dev, (void *)skb->data, 696 + MAX_FRAGMENT_SIZE_RX + 2, DMA_FROM_DEVICE); 697 + if (dma_mapping_error(&priv->pdev->dev, priv->pci_map_rx_address[counter])) { 700 698 priv->pci_map_rx_address[counter] = 0; 701 699 /* error mapping the buffer to device 702 700 accessible memory address */ ··· 725 727 726 728 /* free consistent DMA area... */ 727 729 if (priv->driver_mem_address) 728 - pci_free_consistent(priv->pdev, HOST_MEM_BLOCK, 729 - priv->driver_mem_address, 730 - priv->device_host_address); 730 + dma_free_coherent(&priv->pdev->dev, HOST_MEM_BLOCK, 731 + priv->driver_mem_address, 732 + priv->device_host_address); 731 733 732 734 /* clear some dangling pointers */ 733 735 priv->driver_mem_address = NULL; ··· 739 741 for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) { 740 742 struct islpci_membuf *buf = &priv->mgmt_rx[counter]; 741 743 if (buf->pci_addr) 742 - pci_unmap_single(priv->pdev, buf->pci_addr, 743 - buf->size, PCI_DMA_FROMDEVICE); 744 + dma_unmap_single(&priv->pdev->dev, buf->pci_addr, 745 + buf->size, DMA_FROM_DEVICE); 744 746 buf->pci_addr = 0; 745 747 kfree(buf->mem); 746 748 buf->size = 0; ··· 750 752 /* clean up data rx buffers */ 751 753 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) { 752 754 if (priv->pci_map_rx_address[counter]) 753 - pci_unmap_single(priv->pdev, 755 + dma_unmap_single(&priv->pdev->dev, 754 756 priv->pci_map_rx_address[counter], 755 757 MAX_FRAGMENT_SIZE_RX + 2, 756 - PCI_DMA_FROMDEVICE); 758 + DMA_FROM_DEVICE); 757 759 priv->pci_map_rx_address[counter] = 0; 758 760 759 761 if (priv->data_low_rx[counter])
+10 -14
drivers/net/wireless/intersil/prism54/islpci_eth.c
··· 50 50 skb, skb->data, skb->len, skb->truesize); 51 51 #endif 52 52 53 - pci_unmap_single(priv->pdev, 53 + dma_unmap_single(&priv->pdev->dev, 54 54 priv->pci_map_tx_address[index], 55 - skb->len, PCI_DMA_TODEVICE); 55 + skb->len, DMA_TO_DEVICE); 56 56 dev_kfree_skb_irq(skb); 57 57 skb = NULL; 58 58 } ··· 176 176 #endif 177 177 178 178 /* map the skb buffer to pci memory for DMA operation */ 179 - pci_map_address = pci_map_single(priv->pdev, 180 - (void *) skb->data, skb->len, 181 - PCI_DMA_TODEVICE); 182 - if (pci_dma_mapping_error(priv->pdev, pci_map_address)) { 179 + pci_map_address = dma_map_single(&priv->pdev->dev, (void *)skb->data, 180 + skb->len, DMA_TO_DEVICE); 181 + if (dma_mapping_error(&priv->pdev->dev, pci_map_address)) { 183 182 printk(KERN_WARNING "%s: cannot map buffer to PCI\n", 184 183 ndev->name); 185 184 goto drop_free; ··· 322 323 #endif 323 324 324 325 /* delete the streaming DMA mapping before processing the skb */ 325 - pci_unmap_single(priv->pdev, 326 - priv->pci_map_rx_address[index], 327 - MAX_FRAGMENT_SIZE_RX + 2, PCI_DMA_FROMDEVICE); 326 + dma_unmap_single(&priv->pdev->dev, priv->pci_map_rx_address[index], 327 + MAX_FRAGMENT_SIZE_RX + 2, DMA_FROM_DEVICE); 328 328 329 329 /* update the skb structure and align the buffer */ 330 330 skb_put(skb, size); ··· 429 431 430 432 /* set the streaming DMA mapping for proper PCI bus operation */ 431 433 priv->pci_map_rx_address[index] = 432 - pci_map_single(priv->pdev, (void *) skb->data, 433 - MAX_FRAGMENT_SIZE_RX + 2, 434 - PCI_DMA_FROMDEVICE); 435 - if (pci_dma_mapping_error(priv->pdev, 436 - priv->pci_map_rx_address[index])) { 434 + dma_map_single(&priv->pdev->dev, (void *)skb->data, 435 + MAX_FRAGMENT_SIZE_RX + 2, DMA_FROM_DEVICE); 436 + if (dma_mapping_error(&priv->pdev->dev, priv->pci_map_rx_address[index])) { 437 437 /* error mapping the buffer to device accessible memory address */ 438 438 DEBUG(SHOW_ERROR_MESSAGES, 439 439 "Error mapping DMA address\n");
+1 -1
drivers/net/wireless/intersil/prism54/islpci_hotplug.c
··· 107 107 } 108 108 109 109 /* enable PCI DMA */ 110 - if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { 110 + if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { 111 111 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME); 112 112 goto do_pci_disable_device; 113 113 }
+11 -10
drivers/net/wireless/intersil/prism54/islpci_mgt.c
··· 115 115 buf->size = MGMT_FRAME_SIZE; 116 116 } 117 117 if (buf->pci_addr == 0) { 118 - buf->pci_addr = pci_map_single(priv->pdev, buf->mem, 118 + buf->pci_addr = dma_map_single(&priv->pdev->dev, 119 + buf->mem, 119 120 MGMT_FRAME_SIZE, 120 - PCI_DMA_FROMDEVICE); 121 - if (pci_dma_mapping_error(priv->pdev, buf->pci_addr)) { 121 + DMA_FROM_DEVICE); 122 + if (dma_mapping_error(&priv->pdev->dev, buf->pci_addr)) { 122 123 printk(KERN_WARNING 123 124 "Failed to make memory DMA'able.\n"); 124 125 return -ENOMEM; ··· 204 203 #endif 205 204 206 205 err = -ENOMEM; 207 - buf.pci_addr = pci_map_single(priv->pdev, buf.mem, frag_len, 208 - PCI_DMA_TODEVICE); 209 - if (pci_dma_mapping_error(priv->pdev, buf.pci_addr)) { 206 + buf.pci_addr = dma_map_single(&priv->pdev->dev, buf.mem, frag_len, 207 + DMA_TO_DEVICE); 208 + if (dma_mapping_error(&priv->pdev->dev, buf.pci_addr)) { 210 209 printk(KERN_WARNING "%s: cannot map PCI memory for mgmt\n", 211 210 ndev->name); 212 211 goto error_free; ··· 303 302 } 304 303 305 304 /* Ensure the results of device DMA are visible to the CPU. */ 306 - pci_dma_sync_single_for_cpu(priv->pdev, buf->pci_addr, 307 - buf->size, PCI_DMA_FROMDEVICE); 305 + dma_sync_single_for_cpu(&priv->pdev->dev, buf->pci_addr, 306 + buf->size, DMA_FROM_DEVICE); 308 307 309 308 /* Perform endianess conversion for PIMFOR header in-place. */ 310 309 header = pimfor_decode_header(buf->mem, frag_len); ··· 415 414 for (; priv->index_mgmt_tx < curr_frag; priv->index_mgmt_tx++) { 416 415 int index = priv->index_mgmt_tx % ISL38XX_CB_MGMT_QSIZE; 417 416 struct islpci_membuf *buf = &priv->mgmt_tx[index]; 418 - pci_unmap_single(priv->pdev, buf->pci_addr, buf->size, 419 - PCI_DMA_TODEVICE); 417 + dma_unmap_single(&priv->pdev->dev, buf->pci_addr, buf->size, 418 + DMA_TO_DEVICE); 420 419 buf->pci_addr = 0; 421 420 kfree(buf->mem); 422 421 buf->mem = NULL;