Received: by 10.223.185.116 with SMTP id b49csp5784395wrg; Wed, 7 Mar 2018 18:37:07 -0800 (PST) X-Google-Smtp-Source: AG47ELs2k51K4zd6sxBAjGNtL7ZmPJ1EDslJ/1uPeoplJZ8rirUAj+gEVxCvbBnLUToeg/JIfphp X-Received: by 10.98.232.6 with SMTP id c6mr24496426pfi.242.1520476627153; Wed, 07 Mar 2018 18:37:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520476627; cv=none; d=google.com; s=arc-20160816; b=VAFUyN5lXaQob0PEi7kbLD1SCCpTXoVkGm7BK0HkXkxh7vlz0QyOwP0GlNWsPAg5Ql wE6IOsmlHz/l8Xr2p99SG5GI/onKi/qiQJ8xXHVEBsFeEXTiFSO1RtT1uS/IM8M0mTXM 0k3abMu8u0ZTN8GK8Et5w50vm1BitnPIgvemN4VxDDbVV9RTQX1I+8I/MbXdBlzhHaUp Xlw3O1MLoPnkkuL8TTiFODI9Yx60XSDvSy8an09RXNnKi1v129ILrAsPFlwiuLGMIh/B D0aU7DqHbjnBjDuKQ0wvPBWTIo93ddOHau2hQAss1J84DN1qk5yTyLkciGCiFZhfSPnc bpzQ== 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:arc-authentication-results; bh=q/L88506sfUJ2oZ6lTwd4bTzHKKKRa25KvhZv2Jpbvo=; b=Ks2kAtPi+TeWerhpB12bjR97UaxhlaZlKJ5s0k408XUueID8y5ZU8H7keVAdLwrBJN BPUNDJ3LQecmnBxBPPCB+U2vdFw6vBDio4cd3e+70p5kDAB9tPhavbeVrpKOWuLb8Ihi XLRIrVTjwa9JWJ2vrM2Q1HO9KiiGIBQyoUa9b0a/zTz0IJ31Jk1Q+2gWI+sTqITjGfiX Ipx9W1Pw/Eo9h8ke+HE/AaJxBMygsFQIx1QAGFlIMYY/BBr7iIl9JmkqOAvLkxr1YyiI r0z38RpxYFd73R5IOJVaWIMNrRai6mbvp9B7i/IR5Du62MDfHmjQmJdkgQ0v/YpXZmv0 WmZw== 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 bj11-v6si1863765plb.286.2018.03.07.18.36.52; Wed, 07 Mar 2018 18:37:07 -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 S964863AbeCHCfU (ORCPT + 99 others); Wed, 7 Mar 2018 21:35:20 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:5759 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934902AbeCHCfD (ORCPT ); Wed, 7 Mar 2018 21:35:03 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D7F6A5D6EC02D; Thu, 8 Mar 2018 10:34:48 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.361.1; Thu, 8 Mar 2018 10:34:42 +0800 From: Peng Li To: CC: , , , , Subject: [PATCH net-next 22/23] {topost} net: hns3: set the max ring num when alloc netdev Date: Thu, 8 Mar 2018 11:06:47 +0800 Message-ID: <1520478408-116992-23-git-send-email-lipeng321@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1520478408-116992-1-git-send-email-lipeng321@huawei.com> References: <1520478408-116992-1-git-send-email-lipeng321@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.71.200.31] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org HNS3 driver should alloc netdev with max support ring num, as driver support change netdev count by ethtool -L. Signed-off-by: Peng Li --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index b02f3ff..94f0b92 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -255,6 +255,16 @@ static int hns3_nic_set_real_num_queue(struct net_device *netdev) return 0; } +static u16 hns3_get_max_available_channels(struct hnae3_handle *h) +{ + u16 free_tqps, max_rss_size, max_tqps; + + h->ae_algo->ops->get_tqps_and_rss_info(h, &free_tqps, &max_rss_size); + max_tqps = h->kinfo.num_tc * max_rss_size; + + return min_t(u16, max_tqps, (free_tqps + h->kinfo.num_tqps)); +} + static int hns3_nic_net_up(struct net_device *netdev) { struct hns3_nic_priv *priv = netdev_priv(netdev); @@ -3062,7 +3072,7 @@ static int hns3_client_init(struct hnae3_handle *handle) int ret; netdev = alloc_etherdev_mq(sizeof(struct hns3_nic_priv), - handle->kinfo.num_tqps); + hns3_get_max_available_channels(handle)); if (!netdev) return -ENOMEM; @@ -3401,17 +3411,6 @@ static int hns3_reset_notify(struct hnae3_handle *handle, return ret; } -static u16 hns3_get_max_available_channels(struct net_device *netdev) -{ - struct hnae3_handle *h = hns3_get_handle(netdev); - u16 free_tqps, max_rss_size, max_tqps; - - h->ae_algo->ops->get_tqps_and_rss_info(h, &free_tqps, &max_rss_size); - max_tqps = h->kinfo.num_tc * max_rss_size; - - return min_t(u16, max_tqps, (free_tqps + h->kinfo.num_tqps)); -} - static void hns3_restore_coal(struct hns3_nic_priv *priv, struct hns3_enet_coalesce *tx, struct hns3_enet_coalesce *rx) @@ -3488,12 +3487,12 @@ int hns3_set_channels(struct net_device *netdev, if (ch->rx_count || ch->tx_count) return -EINVAL; - if (new_tqp_num > hns3_get_max_available_channels(netdev) || + if (new_tqp_num > hns3_get_max_available_channels(h) || new_tqp_num < kinfo->num_tc) { dev_err(&netdev->dev, "Change tqps fail, the tqp range is from %d to %d", kinfo->num_tc, - hns3_get_max_available_channels(netdev)); + hns3_get_max_available_channels(h)); return -EINVAL; } -- 2.9.3