/* If the irq is shared by all vqs and the config interrupt, * it is already freed in ifcvf_free_vq_irq, so here only * need to free config irq when msix_vector_status != MSIX_VECTOR_DEV_SHARED
*/ if (vf->msix_vector_status != MSIX_VECTOR_DEV_SHARED) {
devm_free_irq(&pdev->dev, vf->config_irq, vf);
vf->config_irq = -EINVAL;
}
}
/* ifcvf MSIX vectors allocator, this helper tries to allocate * vectors for all virtqueues and the config interrupt. * It returns the number of allocated vectors, negative * return value when fails.
*/ staticint ifcvf_alloc_vectors(struct ifcvf_hw *vf)
{ struct pci_dev *pdev = vf->pdev; int max_intr, ret;
/* all queues and config interrupt */
max_intr = vf->nr_vring + 1;
ret = pci_alloc_irq_vectors(pdev, 1, max_intr, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
if (ret < 0) {
IFCVF_ERR(pdev, "Failed to alloc IRQ vectors\n"); return ret;
}
if (ret < max_intr)
IFCVF_INFO(pdev, "Requested %u vectors, however only %u allocated, lower performance\n",
max_intr, ret);
return ret;
}
staticint ifcvf_request_per_vq_irq(struct ifcvf_hw *vf)
{ struct pci_dev *pdev = vf->pdev; int i, vector, ret, irq;
vf->vqs_reused_irq = -EINVAL; for (i = 0; i < vf->nr_vring; i++) {
snprintf(vf->vring[i].msix_name, 256, "ifcvf[%s]-%d\n", pci_name(pdev), i);
vector = i;
irq = pci_irq_vector(pdev, vector);
ret = devm_request_irq(&pdev->dev, irq,
ifcvf_vq_intr_handler, 0,
vf->vring[i].msix_name,
&vf->vring[i]); if (ret) {
IFCVF_ERR(pdev, "Failed to request irq for vq %d\n", i); goto err;
}
vf->vring[i].irq = irq;
ret = ifcvf_set_vq_vector(vf, i, vector); if (ret == VIRTIO_MSI_NO_VECTOR) {
IFCVF_ERR(pdev, "No msix vector for vq %u\n", i); goto err;
}
}
return 0;
err:
ifcvf_free_irq(vf);
return -EFAULT;
}
staticint ifcvf_request_vqs_reused_irq(struct ifcvf_hw *vf)
{ struct pci_dev *pdev = vf->pdev; int i, vector, ret, irq;
vector = 0;
snprintf(vf->vring[0].msix_name, 256, "ifcvf[%s]-vqs-reused-irq\n", pci_name(pdev));
irq = pci_irq_vector(pdev, vector);
ret = devm_request_irq(&pdev->dev, irq,
ifcvf_vqs_reused_intr_handler, 0,
vf->vring[0].msix_name, vf); if (ret) {
IFCVF_ERR(pdev, "Failed to request reused irq for the device\n"); goto err;
}
vf->vqs_reused_irq = irq; for (i = 0; i < vf->nr_vring; i++) {
vf->vring[i].irq = -EINVAL;
ret = ifcvf_set_vq_vector(vf, i, vector); if (ret == VIRTIO_MSI_NO_VECTOR) {
IFCVF_ERR(pdev, "No msix vector for vq %u\n", i); goto err;
}
}
return 0;
err:
ifcvf_free_irq(vf);
return -EFAULT;
}
staticint ifcvf_request_dev_irq(struct ifcvf_hw *vf)
{ struct pci_dev *pdev = vf->pdev; int i, vector, ret, irq;
vector = 0;
snprintf(vf->vring[0].msix_name, 256, "ifcvf[%s]-dev-irq\n", pci_name(pdev));
irq = pci_irq_vector(pdev, vector);
ret = devm_request_irq(&pdev->dev, irq,
ifcvf_dev_intr_handler, 0,
vf->vring[0].msix_name, vf); if (ret) {
IFCVF_ERR(pdev, "Failed to request irq for the device\n"); goto err;
}
vf->vqs_reused_irq = irq; for (i = 0; i < vf->nr_vring; i++) {
vf->vring[i].irq = -EINVAL;
ret = ifcvf_set_vq_vector(vf, i, vector); if (ret == VIRTIO_MSI_NO_VECTOR) {
IFCVF_ERR(pdev, "No msix vector for vq %u\n", i); goto err;
}
}
vf->config_irq = irq;
ret = ifcvf_set_config_vector(vf, vector); if (ret == VIRTIO_MSI_NO_VECTOR) {
IFCVF_ERR(pdev, "No msix vector for device config\n"); goto err;
}
return 0;
err:
ifcvf_free_irq(vf);
return -EFAULT;
}
staticint ifcvf_request_vq_irq(struct ifcvf_hw *vf)
{ int ret;
if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG)
ret = ifcvf_request_per_vq_irq(vf); else
ret = ifcvf_request_vqs_reused_irq(vf);
if (vf->msix_vector_status == MSIX_VECTOR_PER_VQ_AND_CONFIG)
config_vector = vf->nr_vring; elseif (vf->msix_vector_status == MSIX_VECTOR_SHARED_VQ_AND_CONFIG) /* vector 0 for vqs and 1 for config interrupt */
config_vector = 1; elseif (vf->msix_vector_status == MSIX_VECTOR_DEV_SHARED) /* re-use the vqs vector */ return 0; else return -EINVAL;
snprintf(vf->config_msix_name, 256, "ifcvf[%s]-config\n",
pci_name(pdev));
vf->config_irq = pci_irq_vector(pdev, config_vector);
ret = devm_request_irq(&pdev->dev, vf->config_irq,
ifcvf_config_changed, 0,
vf->config_msix_name, vf); if (ret) {
IFCVF_ERR(pdev, "Failed to request config irq\n"); goto err;
}
ret = ifcvf_set_config_vector(vf, config_vector); if (ret == VIRTIO_MSI_NO_VECTOR) {
IFCVF_ERR(pdev, "No msix vector for device config\n"); goto err;
}
return 0;
err:
ifcvf_free_irq(vf);
return -EFAULT;
}
staticint ifcvf_request_irq(struct ifcvf_hw *vf)
{ int nvectors, ret, max_intr;
nvectors = ifcvf_alloc_vectors(vf); if (nvectors <= 0) return -EFAULT;
if (type == VIRTIO_ID_NET || type == VIRTIO_ID_BLOCK)
features = ifcvf_get_dev_features(vf); else {
features = 0;
IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", vf->dev_type);
}
/* This drirver drives both modern virtio devices and transitional * devices in modern mode. * vDPA requires feature bit VIRTIO_F_ACCESS_PLATFORM, * so legacy devices and transitional devices in legacy * mode will not work for vDPA, this driver will not * drive devices with legacy interface.
*/
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
ret = dev_set_name(&vdpa_dev->dev, "vdpa%u", vdpa_dev->index);
ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring); if (ret) {
put_device(&adapter->vdpa.dev);
IFCVF_ERR(pdev, "Failed to register to vDPA bus"); return ret;
}
ret = pcim_enable_device(pdev); if (ret) {
IFCVF_ERR(pdev, "Failed to enable device\n"); return ret;
}
ret = pcim_iomap_regions(pdev, BIT(0) | BIT(2) | BIT(4),
IFCVF_DRIVER_NAME); if (ret) {
IFCVF_ERR(pdev, "Failed to request MMIO region\n"); return ret;
}
ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); if (ret) {
IFCVF_ERR(pdev, "No usable DMA configuration\n"); return ret;
}
ret = devm_add_action_or_reset(dev, ifcvf_free_irq_vectors, pdev); if (ret) {
IFCVF_ERR(pdev, "Failed for adding devres for freeing irq vectors\n"); return ret;
}
pci_set_master(pdev);
ifcvf_mgmt_dev = kzalloc(sizeof(struct ifcvf_vdpa_mgmt_dev), GFP_KERNEL); if (!ifcvf_mgmt_dev) {
IFCVF_ERR(pdev, "Failed to alloc memory for the vDPA management device\n"); return -ENOMEM;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.