Received: by 10.223.185.116 with SMTP id b49csp6178818wrg; Thu, 8 Mar 2018 03:12:52 -0800 (PST) X-Google-Smtp-Source: AG47ELsBUT870fXWAy0zPPTnKrH2c1MwNkxe/d2CH3pHGX0cHh13sKp1ZNKdMa9SI7U67tZ2t0Uz X-Received: by 10.98.73.89 with SMTP id w86mr25787110pfa.227.1520507572326; Thu, 08 Mar 2018 03:12:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520507572; cv=none; d=google.com; s=arc-20160816; b=rG5T2eb6W5QePYynsRI8S9niUwbvJFLSPCNCnvBRT5rEL/hpvZUg6RTT3Pt7QDt60Z /k3yGvhPbo2m0WFNnhf0Vx9zW/PqEGI59Pi7qlMyg2/gN8X63srTQimPpc/E0ymx7LGr yByGk5hGXLBdOeR2VjBbdiYitaFPvgnZ7e8Bag7HM62WQWskxKh/20Sd1Nqr8/oASJXy 1BdZ59kM8pkQBPVZyR0cPOu1T79oNbHBOkLiw3+HqnVA2FMrX+LQYKXO/jMpvueg3lwh cEIpaqOrSRvRx90ZB9zy2EkQcjOzfQAlMh679Lvfy0Alty/YVxQgkDKaGCTzxyUB9Dyb K9LA== 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=fkLGAXAGsKaYvweFp4VKkp/bf8WUcXagwzv8eLp4DFk=; b=ug96EjxaWgrn7yyCziXBC5JYDA43LvVcvTcNvJ+dQbCsz+W+xzdE1aVeGyoeOtMnYi EHk8qthmuvHJgA5JgpkGVWQLEV0lQBb9Yroof1GeyOAXRkQHgyKRT3xVe8PdPk/E92Q+ 9UuiVYLMbyOasE40QOXdYSxL0um8r53KwLb3kfL21g5EtOkNBiyBlJ1tiYloyfuovK0g 3c/09xrz4A7RLhcodYurFu4FctgRD6uWqmJ+ZfQZFNHfDmy3WA0AO51WUJLhng+0NxEd JNfS+RdKBS8y9lWcsUJWvaFYXHi7WahvNH8F1Qieyg8JSPMwvWCTbqDpE1+F5zBjoL1g 4wdg== 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 j12si12880997pgt.173.2018.03.08.03.12.37; Thu, 08 Mar 2018 03:12:52 -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 S1754558AbeCHLKZ (ORCPT + 99 others); Thu, 8 Mar 2018 06:10:25 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:5765 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755770AbeCHLKQ (ORCPT ); Thu, 8 Mar 2018 06:10:16 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A8385C9EBBEF2; Thu, 8 Mar 2018 19:10:02 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Thu, 8 Mar 2018 19:09:55 +0800 From: Peng Li To: CC: , , , , Subject: [Patch net-next 5/6] net: hns3: set the max ring num when alloc netdev Date: Thu, 8 Mar 2018 19:41:54 +0800 Message-ID: <1520509315-40895-6-git-send-email-lipeng321@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1520509315-40895-1-git-send-email-lipeng321@huawei.com> References: <1520509315-40895-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 601b629..c936945 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -249,6 +249,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); @@ -3013,7 +3023,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; @@ -3336,17 +3346,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 int hns3_modify_tqp_num(struct net_device *netdev, u16 new_tqp_num) { struct hns3_nic_priv *priv = netdev_priv(netdev); @@ -3397,12 +3396,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