linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Barry Song <song.bao.hua@hisilicon.com>
To: <davem@davemloft.net>, <kuba@kernel.org>
Cc: <yisen.zhuang@huawei.com>, <salil.mehta@huawei.com>,
	<netdev@vger.kernel.org>, <linyunsheng@huawei.com>,
	<linux-kernel@vger.kernel.org>, <linuxarm@huawei.com>,
	Barry Song <song.bao.hua@hisilicon.com>
Subject: [PATCH 5/5] net: hns3: streaming dma buffer sync between cpu and device
Date: Thu, 18 Jun 2020 13:02:11 +1200	[thread overview]
Message-ID: <20200618010211.75840-6-song.bao.hua@hisilicon.com> (raw)
In-Reply-To: <20200618010211.75840-1-song.bao.hua@hisilicon.com>

Right now they are empty functions for our SoC since hardware can keep
cache coherent, but it is still good to align with streaming DMA APIs
as device drivers should not make an assumption of SoC.

Reviewed-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
---
 .../net/ethernet/hisilicon/hns3/hns3_enet.c    | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 1330820152fa..b319a766889f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2473,6 +2473,11 @@ static void hns3_reuse_buffer(struct hns3_enet_ring *ring, int i)
 	ring->desc[i].addr = cpu_to_le64(ring->desc_cb[i].dma +
 					 ring->desc_cb[i].page_offset);
 	ring->desc[i].rx.bd_base_info = 0;
+
+	dma_sync_single_for_device(ring_to_dev(ring),
+			ring->desc_cb[i].dma + ring->desc_cb[i].page_offset,
+			hns3_buf_size(ring),
+			DMA_FROM_DEVICE);
 }
 
 static void hns3_nic_reclaim_desc(struct hns3_enet_ring *ring, int head,
@@ -2918,6 +2923,11 @@ static int hns3_add_frag(struct hns3_enet_ring *ring)
 			skb = ring->tail_skb;
 		}
 
+		dma_sync_single_for_cpu(ring_to_dev(ring),
+				desc_cb->dma + desc_cb->page_offset,
+				hns3_buf_size(ring),
+				DMA_FROM_DEVICE);
+
 		hns3_nic_reuse_page(skb, ring->frag_num++, ring, 0, desc_cb);
 		trace_hns3_rx_desc(ring);
 		ring_ptr_move_fw(ring, next_to_clean);
@@ -3069,9 +3079,15 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring)
 	if (unlikely(!(bd_base_info & BIT(HNS3_RXD_VLD_B))))
 		return -ENXIO;
 
-	if (!skb)
+	if (!skb) {
 		ring->va = desc_cb->buf + desc_cb->page_offset;
 
+		dma_sync_single_for_cpu(ring_to_dev(ring),
+				desc_cb->dma + desc_cb->page_offset,
+				hns3_buf_size(ring),
+				DMA_FROM_DEVICE);
+	}
+
 	/* Prefetch first cache line of first page
 	 * Idea is to cache few bytes of the header of the packet. Our L1 Cache
 	 * line size is 64B so need to prefetch twice to make it 128B. But in
-- 
2.23.0



  parent reply	other threads:[~2020-06-18  1:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-18  1:02 [PATCH 0/5] net: hns3: a bundle of minor cleanup and fixes Barry Song
2020-06-18  1:02 ` [PATCH 1/5] net: hns3: remove unnecessary devm_kfree Barry Song
2020-06-18  1:02 ` [PATCH 2/5] net: hns3: pointer type of buffer should be void Barry Song
2020-06-18 23:35   ` Jakub Kicinski
2020-06-18  1:02 ` [PATCH 3/5] net: hns3: rename buffer-related functions Barry Song
2020-06-18  1:02 ` [PATCH 4/5] net: hns3: replace disable_irq by IRQ_NOAUTOEN flag Barry Song
2020-06-18  1:02 ` Barry Song [this message]
2020-06-19  3:43 ` [PATCH 0/5] net: hns3: a bundle of minor cleanup and fixes David Miller

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=20200618010211.75840-6-song.bao.hua@hisilicon.com \
    --to=song.bao.hua@hisilicon.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=linyunsheng@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=salil.mehta@huawei.com \
    --cc=yisen.zhuang@huawei.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).