From: Denis Kirjanov <kirjanov@gmail.com>
To: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Francois Romieu <romieu@fr.zoreil.com>, netdev@vger.kernel.org
Subject: Re: [PATCH 2/2 -next] r8169: use device model DMA API
Date: Thu, 23 Sep 2010 18:59:10 +0400 [thread overview]
Message-ID: <AANLkTin-GPjkpp3gmS=1u5wxmxFMy_B6GL1MuDR79fDQ@mail.gmail.com> (raw)
In-Reply-To: <1285243291-4520-2-git-send-email-sgruszka@redhat.com>
On Thu, Sep 23, 2010 at 4:01 PM, Stanislaw Gruszka <sgruszka@redhat.com> wrote:
> Use DMA API as PCI equivalents will be deprecated. This change also
> allow to allocate with GFP_KERNEL where possible.
>
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
dma_map_single and friend can fail. Thus, we should check for a return value.
Yes, this is not directly related to current patch, but it would be
great to fix this.
> drivers/net/r8169.c | 53 +++++++++++++++++++++++++++-----------------------
> 1 files changed, 29 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
> index 4f94073..51dd9ac 100644
> --- a/drivers/net/r8169.c
> +++ b/drivers/net/r8169.c
> @@ -1217,7 +1217,8 @@ static void rtl8169_update_counters(struct net_device *dev)
> if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0)
> 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)
> return;
>
> @@ -1238,7 +1239,8 @@ static void rtl8169_update_counters(struct net_device *dev)
> RTL_W32(CounterAddrLow, 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,
> @@ -3298,15 +3300,15 @@ static int rtl8169_open(struct net_device *dev)
>
> /*
> * 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->TxPhyAddr);
> + tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES,
> + &tp->TxPhyAddr, GFP_KERNEL);
> if (!tp->TxDescArray)
> goto err_pm_runtime_put;
>
> - tp->RxDescArray = pci_alloc_consistent(pdev, R8169_RX_RING_BYTES,
> - &tp->RxPhyAddr);
> + tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES,
> + &tp->RxPhyAddr, GFP_KERNEL);
> if (!tp->RxDescArray)
> goto err_free_tx_0;
>
> @@ -3340,12 +3342,12 @@ out:
> err_release_ring_2:
> rtl8169_rx_clear(tp);
> err_free_rx_1:
> - pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray,
> - tp->RxPhyAddr);
> + dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
> + tp->RxPhyAddr);
> tp->RxDescArray = NULL;
> err_free_tx_0:
> - pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray,
> - tp->TxPhyAddr);
> + dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
> + tp->TxPhyAddr);
> tp->TxDescArray = NULL;
> err_pm_runtime_put:
> pm_runtime_put_noidle(&pdev->dev);
> @@ -3981,7 +3983,7 @@ static void rtl8169_free_rx_skb(struct rtl8169_private *tp,
> {
> 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);
> dev_kfree_skb(*sk_buff);
> *sk_buff = NULL;
> @@ -4020,7 +4022,7 @@ static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev,
>
> 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);
>
> rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
> @@ -4105,7 +4107,8 @@ static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb,
> {
> 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->opts2 = 0x00;
> desc->addr = 0x00;
> @@ -4249,7 +4252,8 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
> txd = tp->TxDescArray + entry;
> len = frag->size;
> 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) */
> status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
> @@ -4319,7 +4323,8 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *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;
> txd->addr = cpu_to_le64(mapping);
> @@ -4482,8 +4487,8 @@ static inline bool rtl8169_try_rx_copy(struct sk_buff **sk_buff,
> if (!skb)
> goto out;
>
> - pci_dma_sync_single_for_cpu(tp->pci_dev, addr, pkt_size,
> - PCI_DMA_FROMDEVICE);
> + dma_sync_single_for_cpu(&tp->pci_dev->dev, addr, pkt_size,
> + PCI_DMA_FROMDEVICE);
> skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size);
> *sk_buff = skb;
> done = true;
> @@ -4552,11 +4557,11 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
> }
>
> 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);
> rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
> } else {
> - pci_unmap_single(pdev, addr, tp->rx_buf_sz,
> + dma_unmap_single(&pdev->dev, addr, tp->rx_buf_sz,
> PCI_DMA_FROMDEVICE);
> tp->Rx_skbuff[entry] = NULL;
> }
> @@ -4774,10 +4779,10 @@ static int rtl8169_close(struct net_device *dev)
>
> free_irq(dev->irq, dev);
>
> - pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray,
> - tp->RxPhyAddr);
> - pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray,
> - tp->TxPhyAddr);
> + dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
> + tp->RxPhyAddr);
> + dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
> + tp->TxPhyAddr);
> tp->TxDescArray = NULL;
> tp->RxDescArray = NULL;
>
> --
> 1.7.0.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
Regards,
Denis
next prev parent reply other threads:[~2010-09-23 14:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-23 12:01 [PATCH 1/2 -next] r8169: allocate with GFP_KERNEL flag when able to sleep Stanislaw Gruszka
2010-09-23 12:01 ` [PATCH 2/2 -next] r8169: use device model DMA API Stanislaw Gruszka
2010-09-23 14:59 ` Denis Kirjanov [this message]
2010-09-23 15:23 ` Stanislaw Gruszka
2010-09-23 21:20 ` [PATCH 1/2 -next] r8169: allocate with GFP_KERNEL flag when able to sleep Francois Romieu
2010-09-24 11:18 ` Stanislaw Gruszka
2010-09-24 22:24 ` Francois Romieu
2010-09-25 5:37 ` David Miller
2010-09-25 6:06 ` Eric Dumazet
2010-09-25 7:13 ` David Miller
2010-09-25 9:12 ` Eric Dumazet
2010-09-25 23:33 ` Ben Hutchings
2010-09-26 6:09 ` Eric Dumazet
2010-09-26 12:46 ` Ben Hutchings
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTin-GPjkpp3gmS=1u5wxmxFMy_B6GL1MuDR79fDQ@mail.gmail.com' \
--to=kirjanov@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=romieu@fr.zoreil.com \
--cc=sgruszka@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).