Lines Matching +full:num +full:- +full:vectors

1 // SPDX-License-Identifier: GPL-2.0-only
3 * vDPA bridge driver for modern virtio-pci device
43 int vectors; member
61 return vp_vdpa->mdev; in vdpa_to_mdev()
66 return vp_vdpa->mdev; in vp_vdpa_to_mdev()
73 return vp_vdpa->device_features; in vp_vdpa_get_device_features()
102 int irq = vp_vdpa->vring[idx].irq; in vp_vdpa_get_vq_irq()
105 return -EINVAL; in vp_vdpa_get_vq_irq()
113 struct pci_dev *pdev = mdev->pci_dev; in vp_vdpa_free_irq()
116 for (i = 0; i < vp_vdpa->queues; i++) { in vp_vdpa_free_irq()
117 if (vp_vdpa->vring[i].irq != VIRTIO_MSI_NO_VECTOR) { in vp_vdpa_free_irq()
119 devm_free_irq(&pdev->dev, vp_vdpa->vring[i].irq, in vp_vdpa_free_irq()
120 &vp_vdpa->vring[i]); in vp_vdpa_free_irq()
121 vp_vdpa->vring[i].irq = VIRTIO_MSI_NO_VECTOR; in vp_vdpa_free_irq()
125 if (vp_vdpa->config_irq != VIRTIO_MSI_NO_VECTOR) { in vp_vdpa_free_irq()
127 devm_free_irq(&pdev->dev, vp_vdpa->config_irq, vp_vdpa); in vp_vdpa_free_irq()
128 vp_vdpa->config_irq = VIRTIO_MSI_NO_VECTOR; in vp_vdpa_free_irq()
131 if (vp_vdpa->vectors) { in vp_vdpa_free_irq()
133 vp_vdpa->vectors = 0; in vp_vdpa_free_irq()
141 if (vring->cb.callback) in vp_vdpa_vq_handler()
142 return vring->cb.callback(vring->cb.private); in vp_vdpa_vq_handler()
151 if (vp_vdpa->config_cb.callback) in vp_vdpa_config_handler()
152 return vp_vdpa->config_cb.callback(vp_vdpa->config_cb.private); in vp_vdpa_config_handler()
160 struct pci_dev *pdev = mdev->pci_dev; in vp_vdpa_request_irq()
162 int queues = vp_vdpa->queues; in vp_vdpa_request_irq()
163 int vectors = 1; in vp_vdpa_request_irq() local
167 if (vp_vdpa->vring[i].cb.callback) in vp_vdpa_request_irq()
168 vectors++; in vp_vdpa_request_irq()
171 ret = pci_alloc_irq_vectors(pdev, vectors, vectors, PCI_IRQ_MSIX); in vp_vdpa_request_irq()
172 if (ret != vectors) { in vp_vdpa_request_irq()
173 dev_err(&pdev->dev, in vp_vdpa_request_irq()
174 "vp_vdpa: fail to allocate irq vectors want %d but %d\n", in vp_vdpa_request_irq()
175 vectors, ret); in vp_vdpa_request_irq()
179 vp_vdpa->vectors = vectors; in vp_vdpa_request_irq()
182 if (!vp_vdpa->vring[i].cb.callback) in vp_vdpa_request_irq()
185 snprintf(vp_vdpa->vring[i].msix_name, VP_VDPA_NAME_SIZE, in vp_vdpa_request_irq()
186 "vp-vdpa[%s]-%d\n", pci_name(pdev), i); in vp_vdpa_request_irq()
188 ret = devm_request_irq(&pdev->dev, irq, in vp_vdpa_request_irq()
190 0, vp_vdpa->vring[i].msix_name, in vp_vdpa_request_irq()
191 &vp_vdpa->vring[i]); in vp_vdpa_request_irq()
193 dev_err(&pdev->dev, in vp_vdpa_request_irq()
198 vp_vdpa->vring[i].irq = irq; in vp_vdpa_request_irq()
202 snprintf(vp_vdpa->msix_name, VP_VDPA_NAME_SIZE, "vp-vdpa[%s]-config\n", in vp_vdpa_request_irq()
205 ret = devm_request_irq(&pdev->dev, irq, vp_vdpa_config_handler, 0, in vp_vdpa_request_irq()
206 vp_vdpa->msix_name, vp_vdpa); in vp_vdpa_request_irq()
208 dev_err(&pdev->dev, in vp_vdpa_request_irq()
213 vp_vdpa->config_irq = irq; in vp_vdpa_request_irq()
261 * we return -EOPNOTSUPP here. This means we can't support live in vp_vdpa_get_vq_state()
264 return -EOPNOTSUPP; in vp_vdpa_get_vq_state()
270 const struct vdpa_vq_state_split *split = &state->split; in vp_vdpa_set_vq_state_split()
272 if (split->avail_index == 0) in vp_vdpa_set_vq_state_split()
275 return -EOPNOTSUPP; in vp_vdpa_set_vq_state_split()
281 const struct vdpa_vq_state_packed *packed = &state->packed; in vp_vdpa_set_vq_state_packed()
283 if (packed->last_avail_counter == 1 && in vp_vdpa_set_vq_state_packed()
284 packed->last_avail_idx == 0 && in vp_vdpa_set_vq_state_packed()
285 packed->last_used_counter == 1 && in vp_vdpa_set_vq_state_packed()
286 packed->last_used_idx == 0) in vp_vdpa_set_vq_state_packed()
289 return -EOPNOTSUPP; in vp_vdpa_set_vq_state_packed()
310 return -EOPNOTSUPP; in vp_vdpa_set_vq_state()
318 vp_vdpa->vring[qid].cb = *cb; in vp_vdpa_set_vq_cb()
337 u32 num) in vp_vdpa_set_vq_num() argument
341 vp_modern_set_queue_size(mdev, qid, num); in vp_vdpa_set_vq_num()
367 vp_iowrite16(qid, vp_vdpa->vring[qid].notify); in vp_vdpa_kick_vq()
381 return mdev->id.device; in vp_vdpa_get_device_id()
388 return mdev->id.vendor; in vp_vdpa_get_vendor_id()
400 return mdev->device_len; in vp_vdpa_get_config_size()
414 old = vp_ioread8(&mdev->common->config_generation); in vp_vdpa_get_config()
417 *p++ = vp_ioread8(mdev->device + offset + i); in vp_vdpa_get_config()
419 new = vp_ioread8(&mdev->common->config_generation); in vp_vdpa_get_config()
433 vp_iowrite8(*p++, mdev->device + offset + i); in vp_vdpa_set_config()
441 vp_vdpa->config_cb = *cb; in vp_vdpa_set_config_cb()
451 notify.addr = vp_vdpa->vring[qid].notify_pa; in vp_vdpa_get_vq_notification()
452 notify.size = mdev->notify_offset_multiplier; in vp_vdpa_get_vq_notification()
497 struct virtio_pci_modern_device *mdev = vp_vdpa_mgtdev->mdev; in vp_vdpa_dev_add()
498 struct pci_dev *pdev = mdev->pci_dev; in vp_vdpa_dev_add()
499 struct device *dev = &pdev->dev; in vp_vdpa_dev_add()
512 vp_vdpa_mgtdev->vp_vdpa = vp_vdpa; in vp_vdpa_dev_add()
514 vp_vdpa->vdpa.dma_dev = &pdev->dev; in vp_vdpa_dev_add()
515 vp_vdpa->queues = vp_modern_get_num_queues(mdev); in vp_vdpa_dev_add()
516 vp_vdpa->mdev = mdev; in vp_vdpa_dev_add()
519 if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) { in vp_vdpa_dev_add()
520 if (add_config->device_features & ~device_features) { in vp_vdpa_dev_add()
521 ret = -EINVAL; in vp_vdpa_dev_add()
522 dev_err(&pdev->dev, "Try to provision features " in vp_vdpa_dev_add()
525 device_features, add_config->device_features); in vp_vdpa_dev_add()
528 device_features = add_config->device_features; in vp_vdpa_dev_add()
530 vp_vdpa->device_features = device_features; in vp_vdpa_dev_add()
534 dev_err(&pdev->dev, in vp_vdpa_dev_add()
535 "Failed for adding devres for freeing irq vectors\n"); in vp_vdpa_dev_add()
539 vp_vdpa->vring = devm_kcalloc(&pdev->dev, vp_vdpa->queues, in vp_vdpa_dev_add()
540 sizeof(*vp_vdpa->vring), in vp_vdpa_dev_add()
542 if (!vp_vdpa->vring) { in vp_vdpa_dev_add()
543 ret = -ENOMEM; in vp_vdpa_dev_add()
544 dev_err(&pdev->dev, "Fail to allocate virtqueues\n"); in vp_vdpa_dev_add()
548 for (i = 0; i < vp_vdpa->queues; i++) { in vp_vdpa_dev_add()
549 vp_vdpa->vring[i].irq = VIRTIO_MSI_NO_VECTOR; in vp_vdpa_dev_add()
550 vp_vdpa->vring[i].notify = in vp_vdpa_dev_add()
552 &vp_vdpa->vring[i].notify_pa); in vp_vdpa_dev_add()
553 if (!vp_vdpa->vring[i].notify) { in vp_vdpa_dev_add()
554 ret = -EINVAL; in vp_vdpa_dev_add()
555 dev_warn(&pdev->dev, "Fail to map vq notify %d\n", i); in vp_vdpa_dev_add()
559 vp_vdpa->config_irq = VIRTIO_MSI_NO_VECTOR; in vp_vdpa_dev_add()
561 vp_vdpa->vdpa.mdev = &vp_vdpa_mgtdev->mgtdev; in vp_vdpa_dev_add()
562 ret = _vdpa_register_device(&vp_vdpa->vdpa, vp_vdpa->queues); in vp_vdpa_dev_add()
564 dev_err(&pdev->dev, "Failed to register to vdpa bus\n"); in vp_vdpa_dev_add()
571 put_device(&vp_vdpa->vdpa.dev); in vp_vdpa_dev_add()
581 struct vp_vdpa *vp_vdpa = vp_vdpa_mgtdev->vp_vdpa; in vp_vdpa_dev_del()
583 _vdpa_unregister_device(&vp_vdpa->vdpa); in vp_vdpa_dev_del()
584 vp_vdpa_mgtdev->vp_vdpa = NULL; in vp_vdpa_dev_del()
596 struct device *dev = &pdev->dev; in vp_vdpa_probe()
603 return -ENOMEM; in vp_vdpa_probe()
605 mgtdev = &vp_vdpa_mgtdev->mgtdev; in vp_vdpa_probe()
606 mgtdev->ops = &vp_vdpa_mdev_ops; in vp_vdpa_probe()
607 mgtdev->device = dev; in vp_vdpa_probe()
611 err = -ENOMEM; in vp_vdpa_probe()
621 err = -ENOMEM; in vp_vdpa_probe()
625 vp_vdpa_mgtdev->mdev = mdev; in vp_vdpa_probe()
626 mdev->pci_dev = pdev; in vp_vdpa_probe()
635 dev_err(&pdev->dev, "Failed to probe modern PCI device\n"); in vp_vdpa_probe()
639 mdev_id[0].device = mdev->id.device; in vp_vdpa_probe()
640 mdev_id[0].vendor = mdev->id.vendor; in vp_vdpa_probe()
641 mgtdev->id_table = mdev_id; in vp_vdpa_probe()
642 mgtdev->max_supported_vqs = vp_modern_get_num_queues(mdev); in vp_vdpa_probe()
643 mgtdev->supported_features = vp_modern_get_features(mdev); in vp_vdpa_probe()
644 mgtdev->config_attr_mask = (1 << VDPA_ATTR_DEV_FEATURES); in vp_vdpa_probe()
650 dev_err(&pdev->dev, "Failed to register vdpa mgmtdev device\n"); in vp_vdpa_probe()
657 vp_modern_remove(vp_vdpa_mgtdev->mdev); in vp_vdpa_probe()
672 mdev = vp_vdpa_mgtdev->mdev; in vp_vdpa_remove()
673 vdpa_mgmtdev_unregister(&vp_vdpa_mgtdev->mgtdev); in vp_vdpa_remove()
675 kfree(vp_vdpa_mgtdev->mgtdev.id_table); in vp_vdpa_remove()
681 .name = "vp-vdpa",
690 MODULE_DESCRIPTION("vp-vdpa");