r8169: use device model DMA API

Use DMA API as PCI equivalents will be deprecated. This change also
allow to allocate with GFP_KERNEL where possible.

Tested-by: Neal Becker <ndbecker2@gmail.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Stanislaw Gruszka 2010-10-08 04:25:01 +00:00 committed by David S. Miller
parent aeb19f6052
commit 82553bb621
1 changed files with 29 additions and 24 deletions

View File

@ -1212,7 +1212,8 @@ static void rtl8169_update_counters(struct net_device *dev)
if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0)
return; return;
counters = pci_alloc_consistent(tp->pci_dev, sizeof(*counters), &paddr); counters = dma_alloc_coherent(&tp->pci_dev->dev, sizeof(*counters),
&paddr, GFP_KERNEL);
if (!counters) if (!counters)
return; return;
@ -1233,7 +1234,8 @@ static void rtl8169_update_counters(struct net_device *dev)
RTL_W32(CounterAddrLow, 0); RTL_W32(CounterAddrLow, 0);
RTL_W32(CounterAddrHigh, 0); RTL_W32(CounterAddrHigh, 0);
pci_free_consistent(tp->pci_dev, sizeof(*counters), counters, paddr); dma_free_coherent(&tp->pci_dev->dev, sizeof(*counters), counters,
paddr);
} }
static void rtl8169_get_ethtool_stats(struct net_device *dev, static void rtl8169_get_ethtool_stats(struct net_device *dev,
@ -3292,15 +3294,15 @@ static int rtl8169_open(struct net_device *dev)
/* /*
* Rx and Tx desscriptors needs 256 bytes alignment. * Rx and Tx desscriptors needs 256 bytes alignment.
* pci_alloc_consistent provides more. * dma_alloc_coherent provides more.
*/ */
tp->TxDescArray = pci_alloc_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES,
&tp->TxPhyAddr); &tp->TxPhyAddr, GFP_KERNEL);
if (!tp->TxDescArray) if (!tp->TxDescArray)
goto err_pm_runtime_put; goto err_pm_runtime_put;
tp->RxDescArray = pci_alloc_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES,
&tp->RxPhyAddr); &tp->RxPhyAddr, GFP_KERNEL);
if (!tp->RxDescArray) if (!tp->RxDescArray)
goto err_free_tx_0; goto err_free_tx_0;
@ -3334,12 +3336,12 @@ out:
err_release_ring_2: err_release_ring_2:
rtl8169_rx_clear(tp); rtl8169_rx_clear(tp);
err_free_rx_1: err_free_rx_1:
pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray, dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
tp->RxPhyAddr); tp->RxPhyAddr);
tp->RxDescArray = NULL; tp->RxDescArray = NULL;
err_free_tx_0: err_free_tx_0:
pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray, dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
tp->TxPhyAddr); tp->TxPhyAddr);
tp->TxDescArray = NULL; tp->TxDescArray = NULL;
err_pm_runtime_put: err_pm_runtime_put:
pm_runtime_put_noidle(&pdev->dev); pm_runtime_put_noidle(&pdev->dev);
@ -3975,7 +3977,7 @@ static void rtl8169_free_rx_skb(struct rtl8169_private *tp,
{ {
struct pci_dev *pdev = tp->pci_dev; struct pci_dev *pdev = tp->pci_dev;
pci_unmap_single(pdev, le64_to_cpu(desc->addr), tp->rx_buf_sz, dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), tp->rx_buf_sz,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
dev_kfree_skb(*sk_buff); dev_kfree_skb(*sk_buff);
*sk_buff = NULL; *sk_buff = NULL;
@ -4014,7 +4016,7 @@ static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev,
skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad); skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad);
mapping = pci_map_single(pdev, skb->data, rx_buf_sz, mapping = dma_map_single(&pdev->dev, skb->data, rx_buf_sz,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
rtl8169_map_to_asic(desc, mapping, rx_buf_sz); rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
@ -4099,7 +4101,8 @@ static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb,
{ {
unsigned int len = tx_skb->len; unsigned int len = tx_skb->len;
pci_unmap_single(pdev, le64_to_cpu(desc->addr), len, PCI_DMA_TODEVICE); dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), len,
PCI_DMA_TODEVICE);
desc->opts1 = 0x00; desc->opts1 = 0x00;
desc->opts2 = 0x00; desc->opts2 = 0x00;
desc->addr = 0x00; desc->addr = 0x00;
@ -4243,7 +4246,8 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
txd = tp->TxDescArray + entry; txd = tp->TxDescArray + entry;
len = frag->size; len = frag->size;
addr = ((void *) page_address(frag->page)) + frag->page_offset; addr = ((void *) page_address(frag->page)) + frag->page_offset;
mapping = pci_map_single(tp->pci_dev, addr, len, PCI_DMA_TODEVICE); mapping = dma_map_single(&tp->pci_dev->dev, addr, len,
PCI_DMA_TODEVICE);
/* anti gcc 2.95.3 bugware (sic) */ /* anti gcc 2.95.3 bugware (sic) */
status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
@ -4313,7 +4317,8 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
tp->tx_skb[entry].skb = skb; tp->tx_skb[entry].skb = skb;
} }
mapping = pci_map_single(tp->pci_dev, skb->data, len, PCI_DMA_TODEVICE); mapping = dma_map_single(&tp->pci_dev->dev, skb->data, len,
PCI_DMA_TODEVICE);
tp->tx_skb[entry].len = len; tp->tx_skb[entry].len = len;
txd->addr = cpu_to_le64(mapping); txd->addr = cpu_to_le64(mapping);
@ -4477,8 +4482,8 @@ static inline bool rtl8169_try_rx_copy(struct sk_buff **sk_buff,
if (!skb) if (!skb)
goto out; goto out;
pci_dma_sync_single_for_cpu(tp->pci_dev, addr, pkt_size, dma_sync_single_for_cpu(&tp->pci_dev->dev, addr, pkt_size,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size); skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size);
*sk_buff = skb; *sk_buff = skb;
done = true; done = true;
@ -4549,11 +4554,11 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
rtl8169_rx_csum(skb, desc); rtl8169_rx_csum(skb, desc);
if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) { if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) {
pci_dma_sync_single_for_device(pdev, addr, dma_sync_single_for_device(&pdev->dev, addr,
pkt_size, PCI_DMA_FROMDEVICE); pkt_size, PCI_DMA_FROMDEVICE);
rtl8169_mark_to_asic(desc, tp->rx_buf_sz); rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
} else { } else {
pci_unmap_single(pdev, addr, tp->rx_buf_sz, dma_unmap_single(&pdev->dev, addr, tp->rx_buf_sz,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
tp->Rx_skbuff[entry] = NULL; tp->Rx_skbuff[entry] = NULL;
} }
@ -4769,10 +4774,10 @@ static int rtl8169_close(struct net_device *dev)
free_irq(dev->irq, dev); free_irq(dev->irq, dev);
pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray, dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
tp->RxPhyAddr); tp->RxPhyAddr);
pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray, dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
tp->TxPhyAddr); tp->TxPhyAddr);
tp->TxDescArray = NULL; tp->TxDescArray = NULL;
tp->RxDescArray = NULL; tp->RxDescArray = NULL;