Commit 9cfeeb57 authored by Yangchun Fu's avatar Yangchun Fu Committed by David S. Miller

gve: Fixes DMA synchronization.

Synces the DMA buffer properly in order for CPU and device to see
the most up-to-data data.
Signed-off-by: default avatarYangchun Fu <yangchun@google.com>
Reviewed-by: default avatarCatherine Sullivan <csully@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a904a069
...@@ -289,6 +289,8 @@ static bool gve_rx(struct gve_rx_ring *rx, struct gve_rx_desc *rx_desc, ...@@ -289,6 +289,8 @@ static bool gve_rx(struct gve_rx_ring *rx, struct gve_rx_desc *rx_desc,
len = be16_to_cpu(rx_desc->len) - GVE_RX_PAD; len = be16_to_cpu(rx_desc->len) - GVE_RX_PAD;
page_info = &rx->data.page_info[idx]; page_info = &rx->data.page_info[idx];
dma_sync_single_for_cpu(&priv->pdev->dev, rx->data.qpl->page_buses[idx],
PAGE_SIZE, DMA_FROM_DEVICE);
/* gvnic can only receive into registered segments. If the buffer /* gvnic can only receive into registered segments. If the buffer
* can't be recycled, our only choice is to copy the data out of * can't be recycled, our only choice is to copy the data out of
......
...@@ -390,7 +390,21 @@ static void gve_tx_fill_seg_desc(union gve_tx_desc *seg_desc, ...@@ -390,7 +390,21 @@ static void gve_tx_fill_seg_desc(union gve_tx_desc *seg_desc,
seg_desc->seg.seg_addr = cpu_to_be64(addr); seg_desc->seg.seg_addr = cpu_to_be64(addr);
} }
static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb) static void gve_dma_sync_for_device(struct device *dev, dma_addr_t *page_buses,
u64 iov_offset, u64 iov_len)
{
dma_addr_t dma;
u64 addr;
for (addr = iov_offset; addr < iov_offset + iov_len;
addr += PAGE_SIZE) {
dma = page_buses[addr / PAGE_SIZE];
dma_sync_single_for_device(dev, dma, PAGE_SIZE, DMA_TO_DEVICE);
}
}
static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb,
struct device *dev)
{ {
int pad_bytes, hlen, hdr_nfrags, payload_nfrags, l4_hdr_offset; int pad_bytes, hlen, hdr_nfrags, payload_nfrags, l4_hdr_offset;
union gve_tx_desc *pkt_desc, *seg_desc; union gve_tx_desc *pkt_desc, *seg_desc;
...@@ -432,6 +446,9 @@ static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb) ...@@ -432,6 +446,9 @@ static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb)
skb_copy_bits(skb, 0, skb_copy_bits(skb, 0,
tx->tx_fifo.base + info->iov[hdr_nfrags - 1].iov_offset, tx->tx_fifo.base + info->iov[hdr_nfrags - 1].iov_offset,
hlen); hlen);
gve_dma_sync_for_device(dev, tx->tx_fifo.qpl->page_buses,
info->iov[hdr_nfrags - 1].iov_offset,
info->iov[hdr_nfrags - 1].iov_len);
copy_offset = hlen; copy_offset = hlen;
for (i = payload_iov; i < payload_nfrags + payload_iov; i++) { for (i = payload_iov; i < payload_nfrags + payload_iov; i++) {
...@@ -445,6 +462,9 @@ static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb) ...@@ -445,6 +462,9 @@ static int gve_tx_add_skb(struct gve_tx_ring *tx, struct sk_buff *skb)
skb_copy_bits(skb, copy_offset, skb_copy_bits(skb, copy_offset,
tx->tx_fifo.base + info->iov[i].iov_offset, tx->tx_fifo.base + info->iov[i].iov_offset,
info->iov[i].iov_len); info->iov[i].iov_len);
gve_dma_sync_for_device(dev, tx->tx_fifo.qpl->page_buses,
info->iov[i].iov_offset,
info->iov[i].iov_len);
copy_offset += info->iov[i].iov_len; copy_offset += info->iov[i].iov_len;
} }
...@@ -473,7 +493,7 @@ netdev_tx_t gve_tx(struct sk_buff *skb, struct net_device *dev) ...@@ -473,7 +493,7 @@ netdev_tx_t gve_tx(struct sk_buff *skb, struct net_device *dev)
gve_tx_put_doorbell(priv, tx->q_resources, tx->req); gve_tx_put_doorbell(priv, tx->q_resources, tx->req);
return NETDEV_TX_BUSY; return NETDEV_TX_BUSY;
} }
nsegs = gve_tx_add_skb(tx, skb); nsegs = gve_tx_add_skb(tx, skb, &priv->pdev->dev);
netdev_tx_sent_queue(tx->netdev_txq, skb->len); netdev_tx_sent_queue(tx->netdev_txq, skb->len);
skb_tx_timestamp(skb); skb_tx_timestamp(skb);
......
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