Skip to content

Commit

Permalink
net: ena: separate skb allocation to dedicated function
Browse files Browse the repository at this point in the history
Signed-off-by: Netanel Belgazal <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
NetanelBelgazal authored and davem330 committed Jun 23, 2017
1 parent e745daf commit 4265114
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions drivers/net/ethernet/amazon/ena/ena_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,28 @@ static int ena_clean_tx_irq(struct ena_ring *tx_ring, u32 budget)
return tx_pkts;
}

static struct sk_buff *ena_alloc_skb(struct ena_ring *rx_ring, bool frags)
{
struct sk_buff *skb;

if (frags)
skb = napi_get_frags(rx_ring->napi);
else
skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
rx_ring->rx_copybreak);

if (unlikely(!skb)) {
u64_stats_update_begin(&rx_ring->syncp);
rx_ring->rx_stats.skb_alloc_fail++;
u64_stats_update_end(&rx_ring->syncp);
netif_dbg(rx_ring->adapter, rx_err, rx_ring->netdev,
"Failed to allocate skb. frags: %d\n", frags);
return NULL;
}

return skb;
}

static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
struct ena_com_rx_buf_info *ena_bufs,
u32 descs,
Expand Down Expand Up @@ -854,16 +876,9 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
prefetch(va + NET_IP_ALIGN);

if (len <= rx_ring->rx_copybreak) {
skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
rx_ring->rx_copybreak);
if (unlikely(!skb)) {
u64_stats_update_begin(&rx_ring->syncp);
rx_ring->rx_stats.skb_alloc_fail++;
u64_stats_update_end(&rx_ring->syncp);
netif_err(rx_ring->adapter, rx_err, rx_ring->netdev,
"Failed to allocate skb\n");
skb = ena_alloc_skb(rx_ring, false);
if (unlikely(!skb))
return NULL;
}

netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
"rx allocated small packet. len %d. data_len %d\n",
Expand All @@ -882,20 +897,15 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,

skb_put(skb, len);
skb->protocol = eth_type_trans(skb, rx_ring->netdev);
rx_ring->free_rx_ids[*next_to_clean] = req_id;
*next_to_clean = ENA_RX_RING_IDX_ADD(*next_to_clean, descs,
rx_ring->ring_size);
return skb;
}

skb = napi_get_frags(rx_ring->napi);
if (unlikely(!skb)) {
netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
"Failed allocating skb\n");
u64_stats_update_begin(&rx_ring->syncp);
rx_ring->rx_stats.skb_alloc_fail++;
u64_stats_update_end(&rx_ring->syncp);
skb = ena_alloc_skb(rx_ring, true);
if (unlikely(!skb))
return NULL;
}

do {
dma_unmap_page(rx_ring->dev,
Expand Down

0 comments on commit 4265114

Please sign in to comment.