From patchwork Tue Nov 13 10:13:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salil Mehta X-Patchwork-Id: 150956 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4213784ljp; Tue, 13 Nov 2018 02:14:42 -0800 (PST) X-Google-Smtp-Source: AJdET5fZDnmyAULWCqsk6N5uYQ6FihOD1viSHj8NnAN1aYEvFZC/3qKoqAUVBbJVO5k8pcWIjkq8 X-Received: by 2002:aa7:880d:: with SMTP id c13-v6mr2064135pfo.20.1542104082108; Tue, 13 Nov 2018 02:14:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542104082; cv=none; d=google.com; s=arc-20160816; b=VZJ7ISmoQ6xcpOkMth6OVSDt2anTfI7bcuZovoPdFxTpgjWtP70kFiX97KJQlm+z+B Bvg1Rh8BU7DewqtWs3S0iV43jOT15H00/sIVT+TapUqUyFdGfztPhnyexiuBNUF8C/zx neeI1SPm9epzk44Vnr5CQXiyriE+R3tr5NS7qZcyRIgK1LxwGA325nQCLOaC2WYBn6BW G/PqbZ7ytcFdVKfifCECBUoAewcqWMHCkg/b8+x8Crb+g5sd2XO5Ud1/zmvJpIKPAEJf 0vpYty4yrrmjMLJu8lkk4Z+dwEIladSBm4JbjlRsllPf7Wrs8mLwCs1ilbWfs49Lnhtu zYuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=BoYAsJfylJLLtobC3FOTNzyB90FMkhxOxdJyIm/l4a4=; b=KUEdA5jCTdKt60sU5/9dhPblTkFF2iTgx+qLwdndoHWhEm8d2yZhv+26gP+3HWFMOd UL2YyIAod4t5/uf571qYP0aELljj2Jjl6L12cS+5jFCIP6Vbt85sTOD9f6RY0MINJOK1 YDfgJaoWmUtglAExSiD5lBEZHcNkOWRxUbBoEcFRBG2aQkVLUWypyQWUmuPbnM3YjrYk CP9qv6gFVPZJTD0nd9IW36HcgMfqo9+4MywNzY2ZKyvOKyEXaJYtDPKu+78DJT1DOjnN Z1mdNt2e45D22KrueagtI1fX1HxX503KedQJo6bNf1FptLsb9K9FU5Fe/eh8a4pqLwrB G2gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11-v6si18712509pgj.195.2018.11.13.02.14.41; Tue, 13 Nov 2018 02:14:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732230AbeKMUMD (ORCPT + 32 others); Tue, 13 Nov 2018 15:12:03 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:54100 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732205AbeKMUMC (ORCPT ); Tue, 13 Nov 2018 15:12:02 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 15299268A1EF5; Tue, 13 Nov 2018 18:14:36 +0800 (CST) Received: from S00293818-DELL1.china.huawei.com (10.47.86.21) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.408.0; Tue, 13 Nov 2018 18:14:27 +0800 From: Salil Mehta To: CC: , , , , , , , Subject: [PATCH net-next 4/5] net: hns3: Add skb chain when num of RX buf exceeds MAX_SKB_FRAGS Date: Tue, 13 Nov 2018 10:13:06 +0000 Message-ID: <20181113101307.6020-5-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20181113101307.6020-1-salil.mehta@huawei.com> References: <20181113101307.6020-1-salil.mehta@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.86.21] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peng Li 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 Signed-off-by: Salil Mehta --- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 37 ++++++++++++++++++- .../net/ethernet/hisilicon/hns3/hns3_enet.h | 2 + 2 files changed, 37 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 860067898471..7776089b6bc2 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -2361,6 +2361,9 @@ static void hns3_rx_checksum(struct hns3_enet_ring *ring, struct sk_buff *skb, static void hns3_rx_skb(struct hns3_enet_ring *ring, struct sk_buff *skb) { + if (skb_has_frag_list(skb)) + napi_gro_flush(&ring->tqp_vector->napi, false); + napi_gro_receive(&ring->tqp_vector->napi, skb); } @@ -2417,6 +2420,8 @@ static int hns3_alloc_skb(struct hns3_enet_ring *ring, int length, prefetchw(skb->data); ring->pending_buf = 1; + ring->frag_num = 0; + ring->tail_skb = NULL; if (length <= HNS3_RX_HEAD_SIZE) { memcpy(__skb_put(skb, length), va, ALIGN(length, sizeof(long))); @@ -2435,7 +2440,7 @@ static int hns3_alloc_skb(struct hns3_enet_ring *ring, int length, ring->pull_len = eth_get_headlen(va, HNS3_RX_HEAD_SIZE); __skb_put(skb, ring->pull_len); - hns3_nic_reuse_page(skb, 0, ring, ring->pull_len, + hns3_nic_reuse_page(skb, ring->frag_num++, ring, ring->pull_len, desc_cb); ring_ptr_move_fw(ring, next_to_clean); @@ -2446,6 +2451,8 @@ static int hns3_add_frag(struct hns3_enet_ring *ring, struct hns3_desc *desc, struct sk_buff **out_skb, bool pending) { struct sk_buff *skb = *out_skb; + struct sk_buff *head_skb = *out_skb; + struct sk_buff *new_skb; struct hns3_desc_cb *desc_cb; struct hns3_desc *pre_desc; u32 bd_base_info; @@ -2470,7 +2477,33 @@ static int hns3_add_frag(struct hns3_enet_ring *ring, struct hns3_desc *desc, if (!hnae3_get_bit(bd_base_info, HNS3_RXD_VLD_B)) return -ENXIO; - hns3_nic_reuse_page(skb, ring->pending_buf, ring, 0, desc_cb); + if (unlikely(ring->frag_num >= MAX_SKB_FRAGS)) { + new_skb = napi_alloc_skb(&ring->tqp_vector->napi, + HNS3_RX_HEAD_SIZE); + if (unlikely(!new_skb)) { + netdev_err(ring->tqp->handle->kinfo.netdev, + "alloc rx skb frag fail\n"); + return -ENXIO; + } + ring->frag_num = 0; + + if (ring->tail_skb) { + ring->tail_skb->next = new_skb; + ring->tail_skb = new_skb; + } else { + skb_shinfo(skb)->frag_list = new_skb; + ring->tail_skb = new_skb; + } + } + + if (ring->tail_skb) { + head_skb->truesize += hnae3_buf_size(ring); + head_skb->data_len += le16_to_cpu(desc->rx.size); + head_skb->len += le16_to_cpu(desc->rx.size); + skb = ring->tail_skb; + } + + hns3_nic_reuse_page(skb, ring->frag_num++, ring, 0, desc_cb); ring_ptr_move_fw(ring, next_to_clean); ring->pending_buf++; } diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h index d8c0998127be..8e56b7e44978 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h @@ -402,6 +402,7 @@ struct hns3_enet_ring { int next_to_clean; int pull_len; /* head length for current packet */ + u32 frag_num; unsigned char *va; /* first buffer address for current packet */ u32 flag; /* ring attribute */ @@ -412,6 +413,7 @@ struct hns3_enet_ring { int pending_buf; struct sk_buff *skb; + struct sk_buff *tail_skb; }; struct hns_queue;