Commit 46fc0917 authored by Zhu Lingshan's avatar Zhu Lingshan Committed by Michael S. Tsirkin
Browse files

vDPA/ifcvf: implement features provisioning



This commit implements features provisioning for ifcvf, that means:
1)checkk whether the provisioned features are supported by
the management device
2)vDPA device only presents selected feature bits

Examples:
a)The management device supported features:
$ vdpa mgmtdev show pci/0000:01:00.5
pci/0000:01:00.5:
  supported_classes net
  max_supported_vqs 9
  dev_features MTU MAC MRG_RXBUF CTRL_VQ MQ ANY_LAYOUT VERSION_1 ACCESS_PLATFORM

b)Provision a vDPA device with all supported features:
$ vdpa dev add name vdpa0 mgmtdev pci/0000:01:00.5
$ vdpa/vdpa dev config show vdpa0
vdpa0: mac 00:e8:ca:11:be:05 link up link_announce false max_vq_pairs 4 mtu 1500
  negotiated_features MRG_RXBUF CTRL_VQ MQ VERSION_1 ACCESS_PLATFORM

c)Provision a vDPA device with a subset of the supported features:
$ vdpa dev add name vdpa0 mgmtdev pci/0000:01:00.5 device_features 0x300020020
$ vdpa dev config show vdpa0
mac 00:e8:ca:11:be:05 link up link_announce false
  negotiated_features CTRL_VQ VERSION_1 ACCESS_PLATFORM

Signed-off-by: default avatarZhu Lingshan <lingshan.zhu@intel.com>
Message-Id: <20221125145724.1129962-13-lingshan.zhu@intel.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 267000e9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ u64 ifcvf_get_hw_features(struct ifcvf_hw *hw)

u64 ifcvf_get_features(struct ifcvf_hw *hw)
{
	return hw->hw_features;
	return hw->dev_features;
}

int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features)
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <uapi/linux/virtio_blk.h>
#include <uapi/linux/virtio_config.h>
#include <uapi/linux/virtio_pci.h>
#include <uapi/linux/vdpa.h>

#define N3000_DEVICE_ID		0x1041
#define N3000_SUBSYS_DEVICE_ID	0x001A
@@ -75,6 +76,8 @@ struct ifcvf_hw {
	u32 dev_type;
	u64 req_features;
	u64 hw_features;
	/* provisioned device features */
	u64 dev_features;
	struct virtio_pci_common_cfg __iomem *common_cfg;
	void __iomem *dev_cfg;
	struct vring_info vring[IFCVF_MAX_QUEUES];
+13 −0
Original line number Diff line number Diff line
@@ -743,6 +743,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
	struct vdpa_device *vdpa_dev;
	struct pci_dev *pdev;
	struct ifcvf_hw *vf;
	u64 device_features;
	int ret;

	ifcvf_mgmt_dev = container_of(mdev, struct ifcvf_vdpa_mgmt_dev, mdev);
@@ -762,6 +763,17 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
	adapter->vf = vf;
	vdpa_dev = &adapter->vdpa;

	device_features = vf->hw_features;
	if (config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) {
		if (config->device_features & ~device_features) {
			IFCVF_ERR(pdev, "The provisioned features 0x%llx are not supported by this device with features 0x%llx\n",
				  config->device_features, device_features);
			return -EINVAL;
		}
		device_features &= config->device_features;
	}
	vf->dev_features = device_features;

	if (name)
		ret = dev_set_name(&vdpa_dev->dev, "%s", name);
	else
@@ -866,6 +878,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	ifcvf_mgmt_dev->mdev.device = dev;
	ifcvf_mgmt_dev->mdev.max_supported_vqs = vf->nr_vring;
	ifcvf_mgmt_dev->mdev.supported_features = vf->hw_features;
	ifcvf_mgmt_dev->mdev.config_attr_mask = (1 << VDPA_ATTR_DEV_FEATURES);

	ret = vdpa_mgmtdev_register(&ifcvf_mgmt_dev->mdev);
	if (ret) {