Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9030300ybi; Tue, 23 Jul 2019 20:23:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeFy8Fs0J7XIYiNo+80e94gmeYkJ0AUwXjnL0PdlRBj4lQUR4u9t+omZ7rd2YtyFgt+L8+ X-Received: by 2002:a63:24a:: with SMTP id 71mr1564683pgc.273.1563938584336; Tue, 23 Jul 2019 20:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563938584; cv=none; d=google.com; s=arc-20160816; b=vRIaMtjNtj+k3E0QVNawsJ/4z0C1RspJ94lPoJWhoflZHjJBYDFbcIOYlFb1XTku+8 SpZiLQYAERlVnMCOXo1IWLB/EPHxldc2wx1ypHtEGmwieB8gEQF/bw2y70ThJGr3WnXo pm37EEaCxjnlIePD+RCU9C0VSTCESY3a4fkgl/R28Kb+B/FzorAgC4CXoR/7NWFFdSMq WkAjTHI+Kigwm7O3sjnSr4jD8i65hLza+otQPv3Q4bBHNJ6pArGVv7Kfs26gcc9j9CuF 4C0GbdSAlcLVlLmt1hico5yen0gs0R0MpDwBSrMS0E1SsQy3Z23UgbEuCQhfGUtyEqYe AeUQ== 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=sw1bbZg7n8GnRCwE0caZ0hrdo0a5rULAw9GSjXFYCGA=; b=u7ruRn5tHQaXqux1IuBn+0mCI7nSbjit+DVgdPhaplydxT4qrzCrs+i6h4io5KtPed OCJLDd5CgmHtPEnqECd6C1BtWKn4V/WfZp5rGNuBrX8fHki321paiJ699AMtUh9gafyW rFbqBghS1x3LbaMF558QSYhigpnCu8FaRMGOeWXzZvUMwsSzMesNjVvH3y90zovn1gJT BquiPy9a0vMmxB0wOnBHdxgD2ha2HReTjAS0UGKw2aiW3gSWgA8TjW1+1GxeOY2dvu2d yQLVUBcmk6B1YF2xtPNoUOhFmcYVaaUWjCO1bRtAQM4NVJ9J0Uu4jMr+uItEkutrUxLT YOyA== 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 r8si12904800pls.372.2019.07.23.20.22.49; Tue, 23 Jul 2019 20:23:04 -0700 (PDT) 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 S1726451AbfGXDU7 (ORCPT + 99 others); Tue, 23 Jul 2019 23:20:59 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:50688 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725827AbfGXDU6 (ORCPT ); Tue, 23 Jul 2019 23:20:58 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 84E6B647C03281143F2B; Wed, 24 Jul 2019 11:20:52 +0800 (CST) Received: from localhost.localdomain (10.67.212.132) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Wed, 24 Jul 2019 11:20:45 +0800 From: Huazhong Tan To: CC: , , , , , Yunsheng Lin , Huazhong Tan Subject: [PATCH net-next 10/11] net: hns3: Add support for using order 1 pages with a 4K buffer Date: Wed, 24 Jul 2019 11:18:46 +0800 Message-ID: <1563938327-9865-11-git-send-email-tanhuazhong@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1563938327-9865-1-git-send-email-tanhuazhong@huawei.com> References: <1563938327-9865-1-git-send-email-tanhuazhong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.212.132] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yunsheng Lin Hardware supports 0.5K, 1K, 2K, 4K RX buffer size, the RX buffer can not be reused because the hns3_page_order return 0 when page size and RX buffer size are both 4096. So this patch changes the hns3_page_order to return 1 when RX buffer is greater than half of the page size and page size is less the 8192, and dev_alloc_pages has already been used to allocate the compound page for RX buffer. This patch also changes hnae3_* to hns3_* for page order and RX buffer size calculation because they are used in hns3 module. Signed-off-by: Yunsheng Lin Reviewed-by: Peng Li Signed-off-by: Huazhong Tan --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 10 +++++----- drivers/net/ethernet/hisilicon/hns3/hns3_enet.h | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index cff5d59..56af4be 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -2086,7 +2086,7 @@ static void hns3_set_default_feature(struct net_device *netdev) static int hns3_alloc_buffer(struct hns3_enet_ring *ring, struct hns3_desc_cb *cb) { - unsigned int order = hnae3_page_order(ring); + unsigned int order = hns3_page_order(ring); struct page *p; p = dev_alloc_pages(order); @@ -2097,7 +2097,7 @@ static int hns3_alloc_buffer(struct hns3_enet_ring *ring, cb->page_offset = 0; cb->reuse_flag = 0; cb->buf = page_address(p); - cb->length = hnae3_page_size(ring); + cb->length = hns3_page_size(ring); cb->type = DESC_TYPE_PAGE; return 0; @@ -2400,7 +2400,7 @@ static void hns3_nic_reuse_page(struct sk_buff *skb, int i, { struct hns3_desc *desc = &ring->desc[ring->next_to_clean]; int size = le16_to_cpu(desc->rx.size); - u32 truesize = hnae3_buf_size(ring); + u32 truesize = hns3_buf_size(ring); skb_add_rx_frag(skb, i, desc_cb->priv, desc_cb->page_offset + pull_len, size - pull_len, truesize); @@ -2415,7 +2415,7 @@ static void hns3_nic_reuse_page(struct sk_buff *skb, int i, /* Move offset up to the next cache line */ desc_cb->page_offset += truesize; - if (desc_cb->page_offset + truesize <= hnae3_page_size(ring)) { + if (desc_cb->page_offset + truesize <= hns3_page_size(ring)) { desc_cb->reuse_flag = 1; /* Bump ref count on page before it is given */ get_page(desc_cb->priv); @@ -2697,7 +2697,7 @@ static int hns3_add_frag(struct hns3_enet_ring *ring, struct hns3_desc *desc, } if (ring->tail_skb) { - head_skb->truesize += hnae3_buf_size(ring); + head_skb->truesize += hns3_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; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h index 848b866..1a17856 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h @@ -608,9 +608,18 @@ static inline bool hns3_nic_resetting(struct net_device *netdev) #define tx_ring_data(priv, idx) ((priv)->ring_data[idx]) -#define hnae3_buf_size(_ring) ((_ring)->buf_size) -#define hnae3_page_order(_ring) (get_order(hnae3_buf_size(_ring))) -#define hnae3_page_size(_ring) (PAGE_SIZE << (u32)hnae3_page_order(_ring)) +#define hns3_buf_size(_ring) ((_ring)->buf_size) + +static inline unsigned int hns3_page_order(struct hns3_enet_ring *ring) +{ +#if (PAGE_SIZE < 8192) + if (ring->buf_size > (PAGE_SIZE / 2)) + return 1; +#endif + return 0; +} + +#define hns3_page_size(_ring) (PAGE_SIZE << hns3_page_order(_ring)) /* iterator for handling rings in ring group */ #define hns3_for_each_ring(pos, head) \ -- 2.7.4