Skip to content

Commit 81ae0e0

Browse files
321lipengdavem330
authored andcommitted
net: hns3: Add skb chain when num of RX buf exceeds MAX_SKB_FRAGS
MAX_SKB_FRAGS in protocol stack is defined as: MAX_SKB_FRAGS is 17 when PAGE_SIZE is 4K. If HW enable GRO, it may merge small packets and the rx buffer may be more than MAX_SKB_FRAGS. So driver will add skb chain when RX buffer num. more than MAX_SKB_FRAGS. Signed-off-by: Peng Li <[email protected]> Signed-off-by: Salil Mehta <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5c9f6b3 commit 81ae0e0

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,6 +2361,9 @@ static void hns3_rx_checksum(struct hns3_enet_ring *ring, struct sk_buff *skb,
23612361

23622362
static void hns3_rx_skb(struct hns3_enet_ring *ring, struct sk_buff *skb)
23632363
{
2364+
if (skb_has_frag_list(skb))
2365+
napi_gro_flush(&ring->tqp_vector->napi, false);
2366+
23642367
napi_gro_receive(&ring->tqp_vector->napi, skb);
23652368
}
23662369

@@ -2417,6 +2420,8 @@ static int hns3_alloc_skb(struct hns3_enet_ring *ring, int length,
24172420
prefetchw(skb->data);
24182421

24192422
ring->pending_buf = 1;
2423+
ring->frag_num = 0;
2424+
ring->tail_skb = NULL;
24202425
if (length <= HNS3_RX_HEAD_SIZE) {
24212426
memcpy(__skb_put(skb, length), va, ALIGN(length, sizeof(long)));
24222427

@@ -2435,7 +2440,7 @@ static int hns3_alloc_skb(struct hns3_enet_ring *ring, int length,
24352440

24362441
ring->pull_len = eth_get_headlen(va, HNS3_RX_HEAD_SIZE);
24372442
__skb_put(skb, ring->pull_len);
2438-
hns3_nic_reuse_page(skb, 0, ring, ring->pull_len,
2443+
hns3_nic_reuse_page(skb, ring->frag_num++, ring, ring->pull_len,
24392444
desc_cb);
24402445
ring_ptr_move_fw(ring, next_to_clean);
24412446

@@ -2446,6 +2451,8 @@ static int hns3_add_frag(struct hns3_enet_ring *ring, struct hns3_desc *desc,
24462451
struct sk_buff **out_skb, bool pending)
24472452
{
24482453
struct sk_buff *skb = *out_skb;
2454+
struct sk_buff *head_skb = *out_skb;
2455+
struct sk_buff *new_skb;
24492456
struct hns3_desc_cb *desc_cb;
24502457
struct hns3_desc *pre_desc;
24512458
u32 bd_base_info;
@@ -2470,7 +2477,33 @@ static int hns3_add_frag(struct hns3_enet_ring *ring, struct hns3_desc *desc,
24702477
if (!hnae3_get_bit(bd_base_info, HNS3_RXD_VLD_B))
24712478
return -ENXIO;
24722479

2473-
hns3_nic_reuse_page(skb, ring->pending_buf, ring, 0, desc_cb);
2480+
if (unlikely(ring->frag_num >= MAX_SKB_FRAGS)) {
2481+
new_skb = napi_alloc_skb(&ring->tqp_vector->napi,
2482+
HNS3_RX_HEAD_SIZE);
2483+
if (unlikely(!new_skb)) {
2484+
netdev_err(ring->tqp->handle->kinfo.netdev,
2485+
"alloc rx skb frag fail\n");
2486+
return -ENXIO;
2487+
}
2488+
ring->frag_num = 0;
2489+
2490+
if (ring->tail_skb) {
2491+
ring->tail_skb->next = new_skb;
2492+
ring->tail_skb = new_skb;
2493+
} else {
2494+
skb_shinfo(skb)->frag_list = new_skb;
2495+
ring->tail_skb = new_skb;
2496+
}
2497+
}
2498+
2499+
if (ring->tail_skb) {
2500+
head_skb->truesize += hnae3_buf_size(ring);
2501+
head_skb->data_len += le16_to_cpu(desc->rx.size);
2502+
head_skb->len += le16_to_cpu(desc->rx.size);
2503+
skb = ring->tail_skb;
2504+
}
2505+
2506+
hns3_nic_reuse_page(skb, ring->frag_num++, ring, 0, desc_cb);
24742507
ring_ptr_move_fw(ring, next_to_clean);
24752508
ring->pending_buf++;
24762509
}

drivers/net/ethernet/hisilicon/hns3/hns3_enet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ struct hns3_enet_ring {
402402
int next_to_clean;
403403

404404
int pull_len; /* head length for current packet */
405+
u32 frag_num;
405406
unsigned char *va; /* first buffer address for current packet */
406407

407408
u32 flag; /* ring attribute */
@@ -412,6 +413,7 @@ struct hns3_enet_ring {
412413

413414
int pending_buf;
414415
struct sk_buff *skb;
416+
struct sk_buff *tail_skb;
415417
};
416418

417419
struct hns_queue;

0 commit comments

Comments
 (0)