Commit 84d47961 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Kalle Valo

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: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20200722104534.30760-1-christophe.jaillet@wanadoo.fr
parent 81cf72b7
...@@ -636,10 +636,10 @@ islpci_alloc_memory(islpci_private *priv) ...@@ -636,10 +636,10 @@ islpci_alloc_memory(islpci_private *priv)
*/ */
/* perform the allocation */ /* perform the allocation */
priv->driver_mem_address = pci_alloc_consistent(priv->pdev, priv->driver_mem_address = dma_alloc_coherent(&priv->pdev->dev,
HOST_MEM_BLOCK, HOST_MEM_BLOCK,
&priv-> &priv->device_host_address,
device_host_address); GFP_KERNEL);
if (!priv->driver_mem_address) { if (!priv->driver_mem_address) {
/* error allocating the block of PCI memory */ /* error allocating the block of PCI memory */
...@@ -692,11 +692,9 @@ islpci_alloc_memory(islpci_private *priv) ...@@ -692,11 +692,9 @@ islpci_alloc_memory(islpci_private *priv)
/* map the allocated skb data area to pci */ /* map the allocated skb data area to pci */
priv->pci_map_rx_address[counter] = priv->pci_map_rx_address[counter] =
pci_map_single(priv->pdev, (void *) skb->data, dma_map_single(&priv->pdev->dev, (void *)skb->data,
MAX_FRAGMENT_SIZE_RX + 2, MAX_FRAGMENT_SIZE_RX + 2, DMA_FROM_DEVICE);
PCI_DMA_FROMDEVICE); if (dma_mapping_error(&priv->pdev->dev, priv->pci_map_rx_address[counter])) {
if (pci_dma_mapping_error(priv->pdev,
priv->pci_map_rx_address[counter])) {
priv->pci_map_rx_address[counter] = 0; priv->pci_map_rx_address[counter] = 0;
/* error mapping the buffer to device /* error mapping the buffer to device
accessible memory address */ accessible memory address */
...@@ -727,9 +725,9 @@ islpci_free_memory(islpci_private *priv) ...@@ -727,9 +725,9 @@ islpci_free_memory(islpci_private *priv)
/* free consistent DMA area... */ /* free consistent DMA area... */
if (priv->driver_mem_address) if (priv->driver_mem_address)
pci_free_consistent(priv->pdev, HOST_MEM_BLOCK, dma_free_coherent(&priv->pdev->dev, HOST_MEM_BLOCK,
priv->driver_mem_address, priv->driver_mem_address,
priv->device_host_address); priv->device_host_address);
/* clear some dangling pointers */ /* clear some dangling pointers */
priv->driver_mem_address = NULL; priv->driver_mem_address = NULL;
...@@ -741,8 +739,8 @@ islpci_free_memory(islpci_private *priv) ...@@ -741,8 +739,8 @@ islpci_free_memory(islpci_private *priv)
for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) { for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
struct islpci_membuf *buf = &priv->mgmt_rx[counter]; struct islpci_membuf *buf = &priv->mgmt_rx[counter];
if (buf->pci_addr) if (buf->pci_addr)
pci_unmap_single(priv->pdev, buf->pci_addr, dma_unmap_single(&priv->pdev->dev, buf->pci_addr,
buf->size, PCI_DMA_FROMDEVICE); buf->size, DMA_FROM_DEVICE);
buf->pci_addr = 0; buf->pci_addr = 0;
kfree(buf->mem); kfree(buf->mem);
buf->size = 0; buf->size = 0;
...@@ -752,10 +750,10 @@ islpci_free_memory(islpci_private *priv) ...@@ -752,10 +750,10 @@ islpci_free_memory(islpci_private *priv)
/* clean up data rx buffers */ /* clean up data rx buffers */
for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) { for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
if (priv->pci_map_rx_address[counter]) if (priv->pci_map_rx_address[counter])
pci_unmap_single(priv->pdev, dma_unmap_single(&priv->pdev->dev,
priv->pci_map_rx_address[counter], priv->pci_map_rx_address[counter],
MAX_FRAGMENT_SIZE_RX + 2, MAX_FRAGMENT_SIZE_RX + 2,
PCI_DMA_FROMDEVICE); DMA_FROM_DEVICE);
priv->pci_map_rx_address[counter] = 0; priv->pci_map_rx_address[counter] = 0;
if (priv->data_low_rx[counter]) if (priv->data_low_rx[counter])
......
...@@ -50,9 +50,9 @@ islpci_eth_cleanup_transmit(islpci_private *priv, ...@@ -50,9 +50,9 @@ islpci_eth_cleanup_transmit(islpci_private *priv,
skb, skb->data, skb->len, skb->truesize); skb, skb->data, skb->len, skb->truesize);
#endif #endif
pci_unmap_single(priv->pdev, dma_unmap_single(&priv->pdev->dev,
priv->pci_map_tx_address[index], priv->pci_map_tx_address[index],
skb->len, PCI_DMA_TODEVICE); skb->len, DMA_TO_DEVICE);
dev_kfree_skb_irq(skb); dev_kfree_skb_irq(skb);
skb = NULL; skb = NULL;
} }
...@@ -176,10 +176,9 @@ islpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev) ...@@ -176,10 +176,9 @@ islpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev)
#endif #endif
/* map the skb buffer to pci memory for DMA operation */ /* map the skb buffer to pci memory for DMA operation */
pci_map_address = pci_map_single(priv->pdev, pci_map_address = dma_map_single(&priv->pdev->dev, (void *)skb->data,
(void *) skb->data, skb->len, skb->len, DMA_TO_DEVICE);
PCI_DMA_TODEVICE); if (dma_mapping_error(&priv->pdev->dev, pci_map_address)) {
if (pci_dma_mapping_error(priv->pdev, pci_map_address)) {
printk(KERN_WARNING "%s: cannot map buffer to PCI\n", printk(KERN_WARNING "%s: cannot map buffer to PCI\n",
ndev->name); ndev->name);
goto drop_free; goto drop_free;
...@@ -323,9 +322,8 @@ islpci_eth_receive(islpci_private *priv) ...@@ -323,9 +322,8 @@ islpci_eth_receive(islpci_private *priv)
#endif #endif
/* delete the streaming DMA mapping before processing the skb */ /* delete the streaming DMA mapping before processing the skb */
pci_unmap_single(priv->pdev, dma_unmap_single(&priv->pdev->dev, priv->pci_map_rx_address[index],
priv->pci_map_rx_address[index], MAX_FRAGMENT_SIZE_RX + 2, DMA_FROM_DEVICE);
MAX_FRAGMENT_SIZE_RX + 2, PCI_DMA_FROMDEVICE);
/* update the skb structure and align the buffer */ /* update the skb structure and align the buffer */
skb_put(skb, size); skb_put(skb, size);
...@@ -431,11 +429,9 @@ islpci_eth_receive(islpci_private *priv) ...@@ -431,11 +429,9 @@ islpci_eth_receive(islpci_private *priv)
/* set the streaming DMA mapping for proper PCI bus operation */ /* set the streaming DMA mapping for proper PCI bus operation */
priv->pci_map_rx_address[index] = priv->pci_map_rx_address[index] =
pci_map_single(priv->pdev, (void *) skb->data, dma_map_single(&priv->pdev->dev, (void *)skb->data,
MAX_FRAGMENT_SIZE_RX + 2, MAX_FRAGMENT_SIZE_RX + 2, DMA_FROM_DEVICE);
PCI_DMA_FROMDEVICE); if (dma_mapping_error(&priv->pdev->dev, priv->pci_map_rx_address[index])) {
if (pci_dma_mapping_error(priv->pdev,
priv->pci_map_rx_address[index])) {
/* error mapping the buffer to device accessible memory address */ /* error mapping the buffer to device accessible memory address */
DEBUG(SHOW_ERROR_MESSAGES, DEBUG(SHOW_ERROR_MESSAGES,
"Error mapping DMA address\n"); "Error mapping DMA address\n");
......
...@@ -107,7 +107,7 @@ prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -107,7 +107,7 @@ prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
} }
/* enable PCI DMA */ /* enable PCI DMA */
if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME); printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
goto do_pci_disable_device; goto do_pci_disable_device;
} }
......
...@@ -115,10 +115,11 @@ islpci_mgmt_rx_fill(struct net_device *ndev) ...@@ -115,10 +115,11 @@ islpci_mgmt_rx_fill(struct net_device *ndev)
buf->size = MGMT_FRAME_SIZE; buf->size = MGMT_FRAME_SIZE;
} }
if (buf->pci_addr == 0) { if (buf->pci_addr == 0) {
buf->pci_addr = pci_map_single(priv->pdev, buf->mem, buf->pci_addr = dma_map_single(&priv->pdev->dev,
buf->mem,
MGMT_FRAME_SIZE, MGMT_FRAME_SIZE,
PCI_DMA_FROMDEVICE); DMA_FROM_DEVICE);
if (pci_dma_mapping_error(priv->pdev, buf->pci_addr)) { if (dma_mapping_error(&priv->pdev->dev, buf->pci_addr)) {
printk(KERN_WARNING printk(KERN_WARNING
"Failed to make memory DMA'able.\n"); "Failed to make memory DMA'able.\n");
return -ENOMEM; return -ENOMEM;
...@@ -203,9 +204,9 @@ islpci_mgt_transmit(struct net_device *ndev, int operation, unsigned long oid, ...@@ -203,9 +204,9 @@ islpci_mgt_transmit(struct net_device *ndev, int operation, unsigned long oid,
#endif #endif
err = -ENOMEM; err = -ENOMEM;
buf.pci_addr = pci_map_single(priv->pdev, buf.mem, frag_len, buf.pci_addr = dma_map_single(&priv->pdev->dev, buf.mem, frag_len,
PCI_DMA_TODEVICE); DMA_TO_DEVICE);
if (pci_dma_mapping_error(priv->pdev, buf.pci_addr)) { if (dma_mapping_error(&priv->pdev->dev, buf.pci_addr)) {
printk(KERN_WARNING "%s: cannot map PCI memory for mgmt\n", printk(KERN_WARNING "%s: cannot map PCI memory for mgmt\n",
ndev->name); ndev->name);
goto error_free; goto error_free;
...@@ -302,8 +303,8 @@ islpci_mgt_receive(struct net_device *ndev) ...@@ -302,8 +303,8 @@ islpci_mgt_receive(struct net_device *ndev)
} }
/* Ensure the results of device DMA are visible to the CPU. */ /* Ensure the results of device DMA are visible to the CPU. */
pci_dma_sync_single_for_cpu(priv->pdev, buf->pci_addr, dma_sync_single_for_cpu(&priv->pdev->dev, buf->pci_addr,
buf->size, PCI_DMA_FROMDEVICE); buf->size, DMA_FROM_DEVICE);
/* Perform endianess conversion for PIMFOR header in-place. */ /* Perform endianess conversion for PIMFOR header in-place. */
header = pimfor_decode_header(buf->mem, frag_len); header = pimfor_decode_header(buf->mem, frag_len);
...@@ -414,8 +415,8 @@ islpci_mgt_cleanup_transmit(struct net_device *ndev) ...@@ -414,8 +415,8 @@ islpci_mgt_cleanup_transmit(struct net_device *ndev)
for (; priv->index_mgmt_tx < curr_frag; priv->index_mgmt_tx++) { for (; priv->index_mgmt_tx < curr_frag; priv->index_mgmt_tx++) {
int index = priv->index_mgmt_tx % ISL38XX_CB_MGMT_QSIZE; int index = priv->index_mgmt_tx % ISL38XX_CB_MGMT_QSIZE;
struct islpci_membuf *buf = &priv->mgmt_tx[index]; struct islpci_membuf *buf = &priv->mgmt_tx[index];
pci_unmap_single(priv->pdev, buf->pci_addr, buf->size, dma_unmap_single(&priv->pdev->dev, buf->pci_addr, buf->size,
PCI_DMA_TODEVICE); DMA_TO_DEVICE);
buf->pci_addr = 0; buf->pci_addr = 0;
kfree(buf->mem); kfree(buf->mem);
buf->mem = NULL; buf->mem = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment