From patchwork Tue May 15 18:20:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salil Mehta X-Patchwork-Id: 135918 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1371708lji; Tue, 15 May 2018 11:21:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr6cK8oU8JHuyMtQN/+BZQeS5Hv+7EW5DDMIA/+RnF4bMkofwJFCO7PNw//YgIBiJlbpc+q X-Received: by 2002:a17:902:bb83:: with SMTP id m3-v6mr15549011pls.236.1526408496300; Tue, 15 May 2018 11:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526408496; cv=none; d=google.com; s=arc-20160816; b=LRqLNXeCdLqZ6Ldz7q6P8OWib5xoWafMoZqHj+UHFPBqdoSwDD80WALI0rHjfA4Q7F rNr8T9jxiKzUU1lA5GAd3zWvt2pQ3nqaW7Z6TShg9bqdihsFwXsuti5BLIlmrQMN0Hna +oq5GpOTXLKX8x8RTmoyQSt4SAlwA/Ry4f5gEuuxW+D2fHHnihQy49t/iKBX2F9xWC3X Y18din4hY4D2TgbKDAzdUHRVyHhlkqvE0WzsKbzWp2tox/YmGTWUlkBL1Pih5YT9kAUo FKIuQldJWsBkwM1fahVjJik4vSvjbR+sA7VCRaz8aY3J9mzD/aTKUdCMLQ3XFQRTkVU1 Nt2Q== 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=t+JZbugqxwT3h4Q18jAZg+ymLtM+E4GWP2trQVyQyu8=; b=VY3m0VdlVJZDMLi6cEw4dPCx1kmPu4RalQ07l1F8zxo9gMxiP76No3kMTkEa3atOo+ AWwEpk26gtPayWoTTAQncgeEEvkv/YjSv6RFlf4PD+of7fA0mKdDJDmfIkRut4PUufis bcAW5P2Rdu0Mz9BNUT+SMQfok/Wjkb+Vu+xdqnUjQpoI65PomKOPYV6rBWdk0VXu3mcg A3qQDVAz35IKSHo8tNgkLk8QdGx0Tk7kqVt5ZG1rTFLN1+HlXjrmfQrJW+MPksdh/Pnl tR1qekxoHMQ3pKy1PehQjH24+yELR4FWYEzuPlD+eAAgDMUq19bZxdbeCir57j9B+g0E oW4g== 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 x4-v6si446329pgc.411.2018.05.15.11.21.36; Tue, 15 May 2018 11:21:36 -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 S1753677AbeEOSVe (ORCPT + 29 others); Tue, 15 May 2018 14:21:34 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:59564 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751859AbeEOSVb (ORCPT ); Tue, 15 May 2018 14:21:31 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id C8A69EA251E04; Wed, 16 May 2018 02:21:26 +0800 (CST) Received: from S00293818-DELL1.china.huawei.com (10.202.227.234) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.382.0; Wed, 16 May 2018 02:21:21 +0800 From: Salil Mehta To: CC: , , , , , , Subject: [PATCH net-next 09/10] net: hns3: Add support of .sriov_configure in HNS3 driver Date: Tue, 15 May 2018 19:20:13 +0100 Message-ID: <20180515182014.42196-10-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20180515182014.42196-1-salil.mehta@huawei.com> References: <20180515182014.42196-1-salil.mehta@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.234] 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 As HNS3 driver will enable SRIOV default and enable all VFs the HW support, if PF and VF driver compiled to kernel, VF driver will work on host default, it is not right. This patch adds support for hns3_driver.sriov_configure to support user configs the VF_num, and do not enable sriov default. Signed-off-by: Peng Li Suggested-by: Zhou Wang Signed-off-by: Salil Mehta --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 58 ++++++++++++++----------- 1 file changed, 32 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index ac75b5d..e85ff38 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -1511,29 +1511,6 @@ static bool hns3_is_phys_func(struct pci_dev *pdev) return false; } -static int get_num_req_vfs(struct pci_dev *pdev) -{ - /* a variable vf num will be supported later */ - return pci_sriov_get_totalvfs(pdev); -} - -static void hns3_enable_sriov(struct pci_dev *pdev) -{ - int num_req_vfs = get_num_req_vfs(pdev); - int ret; - - /* Enable SRIOV */ - if (!num_req_vfs) - return; - - dev_info(&pdev->dev, "active VFs(%d) found, enabling SRIOV\n", - num_req_vfs); - - ret = pci_enable_sriov(pdev, num_req_vfs); - if (ret) - dev_err(&pdev->dev, "SRIOV enable failed %d\n", ret); -} - static void hns3_disable_sriov(struct pci_dev *pdev) { /* If our VFs are assigned we cannot shut down SR-IOV @@ -1578,9 +1555,6 @@ static int hns3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) hnae3_register_ae_dev(ae_dev); - if (hns3_is_phys_func(pdev) && IS_ENABLED(CONFIG_PCI_IOV)) - hns3_enable_sriov(pdev); - return 0; } @@ -1597,11 +1571,43 @@ static void hns3_remove(struct pci_dev *pdev) hnae3_unregister_ae_dev(ae_dev); } +/** + * hns3_pci_sriov_configure + * @pdev: pointer to a pci_dev structure + * @num_vfs: number of VFs to allocate + * + * Enable or change the number of VFs. Called when the user updates the number + * of VFs in sysfs. + **/ +int hns3_pci_sriov_configure(struct pci_dev *pdev, int num_vfs) +{ + int ret; + + if (!(hns3_is_phys_func(pdev) && IS_ENABLED(CONFIG_PCI_IOV))) { + dev_warn(&pdev->dev, "Can not config SRIOV\n"); + return -EINVAL; + } + + if (num_vfs) { + ret = pci_enable_sriov(pdev, num_vfs); + if (ret) + dev_err(&pdev->dev, "SRIOV enable failed %d\n", ret); + } else if (!pci_vfs_assigned(pdev)) { + pci_disable_sriov(pdev); + } else { + dev_warn(&pdev->dev, + "Unable to free VFs because some are assigned to VMs.\n"); + } + + return 0; +} + static struct pci_driver hns3_driver = { .name = hns3_driver_name, .id_table = hns3_pci_tbl, .probe = hns3_probe, .remove = hns3_remove, + .sriov_configure = hns3_pci_sriov_configure, }; /* set default feature to hns3 */