From patchwork Thu Mar 29 18:22:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 10315971 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 7B8146037E for ; Thu, 29 Mar 2018 18:22:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CB4028492 for ; Thu, 29 Mar 2018 18:22:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50DD8285DE; Thu, 29 Mar 2018 18:22:56 +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,DKIM_SIGNED, DKIM_VALID,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 BEFE928492 for ; Thu, 29 Mar 2018 18:22:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753579AbeC2SWu (ORCPT ); Thu, 29 Mar 2018 14:22:50 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:44042 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751210AbeC2SWs (ORCPT ); Thu, 29 Mar 2018 14:22:48 -0400 Received: by mail-pf0-f196.google.com with SMTP id m68so3792218pfm.11 for ; Thu, 29 Mar 2018 11:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=/Q17FFtyV+Yzu3dSYgMqr13CzjdO6ifrtK5iqbkg64o=; b=ADOjYeH5yVvqbVKTxLty3mxoob4A+PpY8uYtXF/53w0qEKNbVbZuCXPCf1/whC17OE TvSyugeEhx77yZF3wuwEXhCe2wtQ+F4yS7wDvpbbvo45e9fEUyItz5RZkXa8OMTW80iN lHlT3qMBdDNt5VYwRVbkSUk+PiDKbSsBWmIfRx7/iqn78ohdHOXpmTkYki2LRLyKHfnH mPZJRhZ267unKVuHA5U25zLVakrsm09VFrLUPePY2kvmx2Y1BsfCSj07wzNg1he836Ii 93OSpV4q+xJWGyEkXnRZl4St30D354hNYs+15x68O3pYX6dZhXVmhn1fag5I3BZBuSvG sCzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/Q17FFtyV+Yzu3dSYgMqr13CzjdO6ifrtK5iqbkg64o=; b=Vaf/uqMNcuEDC0r0IBqHHE+K5Zj6XsIcPnZwOL+CE63KxR09X7ihN3G2+qjKcmtpvl ZINMwMP2zbpSRLsi3F1TY1jeYICpG2TZFc3EIR1DFed+84Tvb24FOWk4s7rEMGTpZP+/ Z89xAXV8jTNSjaNrrgPfbgY3FeXet8NBnnBrpWS0KQLToIAaOM1js5XVDpNdMp0Exyqc f/VaTFzppE3jxTWMhy5fzlRdm/sPF6g4IniGW3j0Sxg1t6wkYJWN73b++8yGOcTGsHxK tQgMmIA3c2VFimE/M2PEQyk7+yJXRUcQEcJs13aAx1IYTVloY3J1M+0eO+j1cScB6K94 ZJ3g== X-Gm-Message-State: AElRT7G7Fqvhah+B9vIJEC0DW0vrPiurrjJttGL/TpnzlMTPBksoc6mE lIKXKIplH4yh9kMcLzSm6ZEK2yLv X-Google-Smtp-Source: AIpwx48/JddqUbOJmbmW5bYUQzxtnsuW2tLnTq+/mpd5CuPRwz9rzamziQ66tMq4d0MYHUFLBnVgpw== X-Received: by 2002:a17:902:6a85:: with SMTP id n5-v6mr3962647plk.165.1522347768229; Thu, 29 Mar 2018 11:22:48 -0700 (PDT) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id l19sm12227573pgc.92.2018.03.29.11.22.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Mar 2018 11:22:47 -0700 (PDT) From: Jakub Kicinski To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, netdev@vger.kernel.org, Sathya Perla , Felix Manlunas , alexander.duyck@gmail.com, john.fastabend@gmail.com, Jacob Keller , Donald Dutile , oss-drivers@netronome.com, Jakub Kicinski Subject: [PATCH] PCI: allow drivers to limit the number of VFs to 0 Date: Thu, 29 Mar 2018 11:22:31 -0700 Message-Id: <20180329182231.32151-1-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.16.2 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 Some user space depends on driver allowing sriov_totalvfs to be enabled. For devices which VF support depends on loaded FW we have the pci_sriov_{g,s}et_totalvfs() API. However, this API uses 0 as a special "unset" value, meaning drivers can't limit sriov_totalvfs to 0. Change the special value to be U16_MAX. Use simple min() to determine actual totalvfs. Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/netronome/nfp/nfp_main.c | 6 +++--- drivers/pci/iov.c | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_main.c b/drivers/net/ethernet/netronome/nfp/nfp_main.c index c4b1f344b4da..dcd6e208a155 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_main.c @@ -123,7 +123,7 @@ static int nfp_pcie_sriov_read_nfd_limit(struct nfp_pf *pf) return pci_sriov_set_totalvfs(pf->pdev, pf->limit_vfs); pf->limit_vfs = ~0; - pci_sriov_set_totalvfs(pf->pdev, 0); /* 0 is unset */ + pci_sriov_set_totalvfs(pf->pdev, ~0); /* Allow any setting for backwards compatibility if symbol not found */ if (err == -ENOENT) return 0; @@ -537,7 +537,7 @@ static int nfp_pci_probe(struct pci_dev *pdev, err_net_remove: nfp_net_pci_remove(pf); err_sriov_unlimit: - pci_sriov_set_totalvfs(pf->pdev, 0); + pci_sriov_set_totalvfs(pf->pdev, ~0); err_fw_unload: kfree(pf->rtbl); nfp_mip_close(pf->mip); @@ -570,7 +570,7 @@ static void nfp_pci_remove(struct pci_dev *pdev) nfp_hwmon_unregister(pf); nfp_pcie_sriov_disable(pdev); - pci_sriov_set_totalvfs(pf->pdev, 0); + pci_sriov_set_totalvfs(pf->pdev, ~0); nfp_net_pci_remove(pf); diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 677924ae0350..aa3dfe3ecd68 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -446,6 +446,7 @@ static int sriov_init(struct pci_dev *dev, int pos) pci_read_config_word(dev, pos + PCI_SRIOV_VF_DID, &iov->vf_device); iov->pgsz = pgsz; iov->self = dev; + iov->driver_max_VFs = U16_MAX; iov->drivers_autoprobe = true; pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap); pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link); @@ -801,9 +802,6 @@ int pci_sriov_get_totalvfs(struct pci_dev *dev) if (!dev->is_physfn) return 0; - if (dev->sriov->driver_max_VFs) - return dev->sriov->driver_max_VFs; - - return dev->sriov->total_VFs; + return min(dev->sriov->total_VFs, dev->sriov->driver_max_VFs); } EXPORT_SYMBOL_GPL(pci_sriov_get_totalvfs);