Skip to content

Commit 1396d31

Browse files
ShayAgroskuba-moo
authored andcommitted
net: ena: fix packet's addresses for rx_offset feature
This patch fixes two lines in which the rx_offset received by the device wasn't taken into account: - prefetch function: In our driver the copied data would reside in rx_info->page + rx_headroom + rx_offset so the prefetch function is changed accordingly. - setting page_offset to zero for descriptors > 1: for every descriptor but the first, the rx_offset is zero. Hence the page_offset value should be set to rx_headroom. The previous implementation changed the value of rx_info after the descriptor was added to the SKB (essentially providing wrong page offset). Fixes: 68f236d ("net: ena: add support for the rx offset feature") Signed-off-by: Shay Agroskin <shayagr@amazon.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 09323b3 commit 1396d31

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

drivers/net/ethernet/amazon/ena/ena_netdev.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,14 @@ static void ena_free_all_io_rx_resources(struct ena_adapter *adapter)
908908
static int ena_alloc_rx_page(struct ena_ring *rx_ring,
909909
struct ena_rx_buffer *rx_info, gfp_t gfp)
910910
{
911+
int headroom = rx_ring->rx_headroom;
911912
struct ena_com_buf *ena_buf;
912913
struct page *page;
913914
dma_addr_t dma;
914915

916+
/* restore page offset value in case it has been changed by device */
917+
rx_info->page_offset = headroom;
918+
915919
/* if previous allocated page is not used */
916920
if (unlikely(rx_info->page))
917921
return 0;
@@ -941,10 +945,9 @@ static int ena_alloc_rx_page(struct ena_ring *rx_ring,
941945
"Allocate page %p, rx_info %p\n", page, rx_info);
942946

943947
rx_info->page = page;
944-
rx_info->page_offset = 0;
945948
ena_buf = &rx_info->ena_buf;
946-
ena_buf->paddr = dma + rx_ring->rx_headroom;
947-
ena_buf->len = ENA_PAGE_SIZE - rx_ring->rx_headroom;
949+
ena_buf->paddr = dma + headroom;
950+
ena_buf->len = ENA_PAGE_SIZE - headroom;
948951

949952
return 0;
950953
}
@@ -1356,7 +1359,8 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
13561359

13571360
/* save virt address of first buffer */
13581361
va = page_address(rx_info->page) + rx_info->page_offset;
1359-
prefetch(va + NET_IP_ALIGN);
1362+
1363+
prefetch(va);
13601364

13611365
if (len <= rx_ring->rx_copybreak) {
13621366
skb = ena_alloc_skb(rx_ring, false);
@@ -1397,8 +1401,6 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
13971401

13981402
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_info->page,
13991403
rx_info->page_offset, len, ENA_PAGE_SIZE);
1400-
/* The offset is non zero only for the first buffer */
1401-
rx_info->page_offset = 0;
14021404

14031405
netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
14041406
"RX skb updated. len %d. data_len %d\n",
@@ -1517,8 +1519,7 @@ static int ena_xdp_handle_buff(struct ena_ring *rx_ring, struct xdp_buff *xdp)
15171519
int ret;
15181520

15191521
rx_info = &rx_ring->rx_buffer_info[rx_ring->ena_bufs[0].req_id];
1520-
xdp->data = page_address(rx_info->page) +
1521-
rx_info->page_offset + rx_ring->rx_headroom;
1522+
xdp->data = page_address(rx_info->page) + rx_info->page_offset;
15221523
xdp_set_data_meta_invalid(xdp);
15231524
xdp->data_hard_start = page_address(rx_info->page);
15241525
xdp->data_end = xdp->data + rx_ring->ena_bufs[0].len;
@@ -1585,8 +1586,9 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi,
15851586
if (unlikely(ena_rx_ctx.descs == 0))
15861587
break;
15871588

1589+
/* First descriptor might have an offset set by the device */
15881590
rx_info = &rx_ring->rx_buffer_info[rx_ring->ena_bufs[0].req_id];
1589-
rx_info->page_offset = ena_rx_ctx.pkt_offset;
1591+
rx_info->page_offset += ena_rx_ctx.pkt_offset;
15901592

15911593
netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
15921594
"rx_poll: q %d got packet from ena. descs #: %d l3 proto %d l4 proto %d hash: %x\n",

0 commit comments

Comments
 (0)