Linux PCI subsystem development
 help / color / mirror / Atom feed
From: "Longpeng(Mike)" <longpeng2@huawei.com>
To: <bhelgaas@google.com>
Cc: <linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<jianjay.zhou@huawei.com>, <zhuangshengen@huawei.com>,
	<arei.gonglei@huawei.com>, <yechuan@huawei.com>,
	<huangzhichao@huawei.com>, <xiehong@huawei.com>,
	Longpeng <longpeng2@huawei.com>
Subject: [RFC 4/4] pci/sriov: add sriov_scan_vf_id interface
Date: Fri, 11 Nov 2022 22:27:22 +0800	[thread overview]
Message-ID: <20221111142722.1172-5-longpeng2@huawei.com> (raw)
In-Reply-To: <20221111142722.1172-1-longpeng2@huawei.com>

From: Longpeng <longpeng2@huawei.com>

The users can add a specific VF through the sriov_scan_vf_id interface.

For example:
 echo 4 > /sys/bus/pci/devices/0000\:65\:00.0/sriov_scan_vf_id
 ( Add VF4 into the system. )

Signed-off-by: Longpeng <longpeng2@huawei.com>
---
 drivers/pci/iov.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index cb24d4b60e0d..2b585b3a9ad8 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -553,6 +553,51 @@ static ssize_t sriov_numvfs_no_scan_show(struct device *dev,
 	return sriov_numvfs_show(dev, attr, buf);
 }
 
+static ssize_t sriov_scan_vf_id_store(struct device *dev,
+				      struct device_attribute *attr,
+				      const char *buf, size_t count)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	u16 vf_id;
+	ssize_t ret;
+
+	if (kstrtou16(buf, 0, &vf_id) < 0)
+		return -EINVAL;
+
+	device_lock(&pdev->dev);
+
+	if (!pdev->sriov->num_VFs) {
+		ret = -ENOENT;
+		goto exit;
+	}
+
+	if (vf_id >= pdev->sriov->num_VFs) {
+		ret = -ENODEV;
+		goto exit;
+	}
+
+	if (test_bit(vf_id, pdev->sriov->vf_bitmap)) {
+		ret = -EEXIST;
+		goto exit;
+	}
+
+	device_unlock(&pdev->dev);
+
+	/* Already scanned VF0 when enabling VFs */
+	if (vf_id == 0)
+		return count;
+
+	ret = pci_iov_add_virtfn(pdev, vf_id);
+	if (ret < 0)
+		return ret;
+
+	return count;
+
+exit:
+	device_unlock(&pdev->dev);
+	return ret;
+}
+
 static ssize_t sriov_offset_show(struct device *dev,
 				 struct device_attribute *attr,
 				 char *buf)
@@ -607,6 +652,7 @@ static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
 static DEVICE_ATTR_RO(sriov_totalvfs);
 static DEVICE_ATTR_RW(sriov_numvfs);
 static DEVICE_ATTR_RW(sriov_numvfs_no_scan);
+static DEVICE_ATTR_WO(sriov_scan_vf_id);
 static DEVICE_ATTR_RO(sriov_offset);
 static DEVICE_ATTR_RO(sriov_stride);
 static DEVICE_ATTR_RO(sriov_vf_device);
@@ -616,6 +662,7 @@ static struct attribute *sriov_pf_dev_attrs[] = {
 	&dev_attr_sriov_totalvfs.attr,
 	&dev_attr_sriov_numvfs.attr,
 	&dev_attr_sriov_numvfs_no_scan.attr,
+	&dev_attr_sriov_scan_vf_id.attr,
 	&dev_attr_sriov_offset.attr,
 	&dev_attr_sriov_stride.attr,
 	&dev_attr_sriov_vf_device.attr,
-- 
2.23.0


  parent reply	other threads:[~2022-11-11 14:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 14:27 [RFC 0/4] pci/sriov: support VFs dynamic addition Longpeng(Mike)
2022-11-11 14:27 ` [RFC 1/4] pci/sriov: extract sriov_numvfs common helper Longpeng(Mike)
2022-11-11 14:27 ` [RFC 2/4] pci/sriov: add vf_bitmap to mark the vf id allocation Longpeng(Mike)
2022-11-11 14:27 ` [RFC 3/4] pci/sriov: add sriov_numfs_no_scan interface Longpeng(Mike)
2022-11-11 14:27 ` Longpeng(Mike) [this message]
2022-11-11 16:39 ` [RFC 0/4] pci/sriov: support VFs dynamic addition Leon Romanovsky
2022-11-13 13:47   ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2022-11-14  7:04     ` Leon Romanovsky
2022-11-14 12:38       ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2022-11-14 13:09         ` Leon Romanovsky
2022-11-14 14:06           ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2022-11-14 14:20             ` Leon Romanovsky
2022-11-15  1:38               ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2022-11-15  1:50               ` Oliver O'Halloran
2022-11-15  8:32                 ` Leon Romanovsky
2022-11-15  9:36                   ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2022-11-15 10:02                     ` Leon Romanovsky
2022-11-15 10:27                       ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2022-11-15 12:49                   ` Oliver O'Halloran
2022-11-15  2:06             ` Oliver O'Halloran
2022-11-16  0:52               ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2022-11-11 23:07 ` Bjorn Helgaas
2022-11-13 13:49   ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221111142722.1172-5-longpeng2@huawei.com \
    --to=longpeng2@huawei.com \
    --cc=arei.gonglei@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=huangzhichao@huawei.com \
    --cc=jianjay.zhou@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=xiehong@huawei.com \
    --cc=yechuan@huawei.com \
    --cc=zhuangshengen@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox