From patchwork Tue Sep 20 15:49:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuval Mintz X-Patchwork-Id: 9341957 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E0F146077A for ; Tue, 20 Sep 2016 15:52:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D32112869A for ; Tue, 20 Sep 2016 15:52:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C77D6297B6; Tue, 20 Sep 2016 15:52:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FA06296D6 for ; Tue, 20 Sep 2016 15:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933105AbcITPwB (ORCPT ); Tue, 20 Sep 2016 11:52:01 -0400 Received: from mx0a-0016ce01.pphosted.com ([67.231.148.157]:43045 "EHLO mx0b-0016ce01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755212AbcITPwA (ORCPT ); Tue, 20 Sep 2016 11:52:00 -0400 Received: from pps.filterd (m0095336.ppops.net [127.0.0.1]) by mx0a-0016ce01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8KFp6Ju023437; Tue, 20 Sep 2016 08:51:57 -0700 Received: from avcashub1.qlogic.com ([198.186.0.115]) by mx0a-0016ce01.pphosted.com with ESMTP id 25h3x30dpv-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 20 Sep 2016 08:51:56 -0700 Received: from localhost.qlogic.org (10.185.6.94) by qlc.com (10.1.4.190) with Microsoft SMTP Server id 14.3.235.1; Tue, 20 Sep 2016 08:51:55 -0700 From: Yuval Mintz To: CC: , , Yuval Mintz , Yuval Mintz Subject: [RFC] PCI: Allow sysfs control over totalvfs Date: Tue, 20 Sep 2016 18:49:48 +0300 Message-ID: <1474386588-16337-1-git-send-email-Yuval.Mintz@qlogic.com> X-Mailer: git-send-email 1.9.3 MIME-Version: 1.0 disclaimer: bypass X-Proofpoint-Virus-Version: vendor=nai engine=5800 definitions=8294 signatures=670698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609020000 definitions=main-1609200201 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP [Sorry in advance if this was already discussed in the past] Some of the HW capable of SRIOV has resource limitations, where the PF and VFs resources are drawn from a common pool. In some cases, these limitations have to be considered early during chip initialization and can only be changed by tearing down the configuration and re-initializing. As a result, drivers for such HWs sometimes have to make unfavorable compromises where they reserve sufficient resources to accomadate the maximal number of VFs that can be created - at the expanse of resources that could have been used by the PF. If users were able to provide 'hints' regarding the required number of VFs *prior* to driver attachment, then such compromises could be avoided. As we already have sysfs nodes that can be queried for the number of totalvfs, it makes sense to let the user reduce the number of said totalvfs using same infrastrucure. Then, we can have drivers supporting SRIOV take that value into account when deciding how much resources to reserve, allowing the PF to benefit from the difference between the configuration space value and the actual number needed by user. Signed-off-by: Yuval Mintz --- drivers/pci/pci-sysfs.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index bcd10c7..c1546f8 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -449,6 +449,30 @@ static ssize_t sriov_totalvfs_show(struct device *dev, return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev)); } +static ssize_t sriov_totalvfs_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + u16 max_vfs; + int ret; + + ret = kstrtou16(buf, 0, &max_vfs); + if (ret < 0) + return ret; + + if (pdev->driver) { + dev_info(&pdev->dev, + "Can't change totalvfs while driver is attached\n"); + return -EUSERS; + } + + ret = pci_sriov_set_totalvfs(pdev, max_vfs); + if (ret) + return ret; + + return count; +} static ssize_t sriov_numvfs_show(struct device *dev, struct device_attribute *attr, @@ -516,7 +540,9 @@ static ssize_t sriov_numvfs_store(struct device *dev, return count; } -static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs); +static struct device_attribute sriov_totalvfs_attr = + __ATTR(sriov_totalvfs, (S_IRUGO|S_IWUSR|S_IWGRP), + sriov_totalvfs_show, sriov_totalvfs_store); static struct device_attribute sriov_numvfs_attr = __ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP), sriov_numvfs_show, sriov_numvfs_store);