Commit 5accfd57 authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

rte_virtio: added virtio_dev_deinit



virtio_dev can now be freed via virtio_dev_deinit.

While here, also rename virtio_init_device to
virtio_dev_init for name consistency.

This patch also adds some error-checking.

Change-Id: Ic1222756b8686fbd8a14d8631f25525249529e1d
Signed-off-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/379335


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent fad291df
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -632,9 +632,15 @@ bdev_virtio_initialize(void)
			goto out;
		}

		/* TODO check rc, add virtio_dev_deinit() */
		virtio_init_device(vdev, VIRTIO_SCSI_DEV_SUPPORTED_FEATURES);
		virtio_dev_start(vdev);
		rc = virtio_dev_init(vdev, VIRTIO_SCSI_DEV_SUPPORTED_FEATURES);
		if (rc != 0) {
			goto out;
		}

		rc = virtio_dev_start(vdev);
		if (rc != 0) {
			goto out;
		}

		base->vdev = vdev;
		TAILQ_INIT(&base->found_disks);
@@ -648,6 +654,10 @@ bdev_virtio_initialize(void)
	return 0;

out:
	if (vdev) {
		virtio_dev_free(vdev);
	}

	spdk_bdev_module_init_done(SPDK_GET_BDEV_MODULE(virtio_scsi));
	return rc;
}
+9 −1
Original line number Diff line number Diff line
@@ -285,7 +285,7 @@ virtio_negotiate_features(struct virtio_dev *dev, uint64_t req_features)

/* reset device and renegotiate features if needed */
int
virtio_init_device(struct virtio_dev *dev, uint64_t req_features)
virtio_dev_init(struct virtio_dev *dev, uint64_t req_features)
{
	int ret;

@@ -315,6 +315,14 @@ virtio_init_device(struct virtio_dev *dev, uint64_t req_features)
	return 0;
}

void
virtio_dev_free(struct virtio_dev *dev)
{
	virtio_free_queues(dev);
	VTPCI_OPS(dev)->free_vdev(dev);
	/* FIXME clear VTPCI_OPS(dev) */
}

int
virtio_dev_start(struct virtio_dev *vdev)
{
+2 −1
Original line number Diff line number Diff line
@@ -80,7 +80,8 @@ uint16_t virtio_recv_pkts(struct virtqueue *vq, struct virtio_req **reqs,

uint16_t virtio_xmit_pkts(struct virtqueue *vq, struct virtio_req *req);

int virtio_init_device(struct virtio_dev *hw, uint64_t req_features);
int virtio_dev_init(struct virtio_dev *hw, uint64_t req_features);
void virtio_dev_free(struct virtio_dev *dev);
int virtio_dev_start(struct virtio_dev *hw);
struct virtio_dev *get_pci_virtio_hw(void);

+29 −2
Original line number Diff line number Diff line
@@ -83,6 +83,23 @@ check_vq_phys_addr_ok(struct virtqueue *vq)
	return 1;
}

static void
free_virtio_hw(struct virtio_dev *dev)
{
	struct virtio_hw *hw = virtio_dev_get_hw(dev);
	unsigned i;

	for (i = 0; i < 6; ++i) {
		if (hw->pci_bar[i].vaddr == NULL) {
			continue;
		}

		spdk_pci_device_unmap_bar(hw->pci_dev, i, hw->pci_bar[i].vaddr);
	}

	free(hw);
}

/*
 * Since we are in legacy mode:
 * http://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf
@@ -295,6 +312,7 @@ const struct virtio_pci_ops legacy_ops = {
	.set_features	= legacy_set_features,
	.get_isr	= legacy_get_isr,
	.set_config_irq	= legacy_set_config_irq,
	.free_vdev	= free_virtio_hw,
	.set_queue_irq  = legacy_set_queue_irq,
	.get_queue_num	= legacy_get_queue_num,
	.setup_queue	= legacy_setup_queue,
@@ -503,6 +521,7 @@ const struct virtio_pci_ops modern_ops = {
	.set_features	= modern_set_features,
	.get_isr	= modern_get_isr,
	.set_config_irq	= modern_set_config_irq,
	.free_vdev	= free_virtio_hw,
	.set_queue_irq  = modern_set_queue_irq,
	.get_queue_num	= modern_get_queue_num,
	.setup_queue	= modern_setup_queue,
@@ -692,6 +711,11 @@ pci_enum_virtio_probe_cb(void *ctx, struct spdk_pci_device *pci_dev)
	unsigned i;

	hw = calloc(1, sizeof(*hw));
	if (hw == NULL) {
		PMD_DRV_LOG(ERR, "calloc failed");
		return -1;
	}

	vdev = &hw->vdev;
	vdev->is_hw = 1;
	hw->pci_dev = pci_dev;
@@ -701,8 +725,7 @@ pci_enum_virtio_probe_cb(void *ctx, struct spdk_pci_device *pci_dev)
					     &bar_len);
		if (rc != 0) {
			PMD_DRV_LOG(ERR, "failed to memmap PCI BAR %d", i);
			free(hw);
			return -1;
			goto err;
		}

		hw->pci_bar[i].vaddr = bar_vaddr;
@@ -745,6 +768,10 @@ pci_enum_virtio_probe_cb(void *ctx, struct spdk_pci_device *pci_dev)

	TAILQ_INSERT_TAIL(&g_virtio_driver.init_ctrlrs, vdev, tailq);
	return 0;

err:
	free_virtio_hw(vdev);
	return -1;
}

int
+2 −0
Original line number Diff line number Diff line
@@ -203,6 +203,8 @@ struct virtio_pci_ops {

	uint16_t (*set_config_irq)(struct virtio_dev *hw, uint16_t vec);

	/** Deinit and free virtio device */
	void (*free_vdev)(struct virtio_dev *vdev);
	uint16_t (*set_queue_irq)(struct virtio_dev *hw, struct virtqueue *vq,
			uint16_t vec);

Loading