vmd: extract end device initialization

It'll make it easier to reuse this part of the code.

Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Id26f3f00abeeea6205df4f44689ffab1d367d777
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13885
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tom Nabarro <tom.nabarro@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
This commit is contained in:
Konrad Sztyber 2022-08-04 07:34:42 +02:00 committed by Tomasz Zawadzki
parent b20f3678dd
commit 2dfd36772f

View File

@ -892,6 +892,33 @@ vmd_dev_init(struct vmd_pci_device *dev)
}
}
static int
vmd_init_end_device(struct vmd_pci_device *dev)
{
struct vmd_pci_bus *bus = dev->bus;
struct vmd_adapter *vmd;
/* Attach the device to the current bus and assign base addresses */
TAILQ_INSERT_TAIL(&bus->dev_list, dev, tailq);
g_end_device_count++;
if (vmd_assign_base_addrs(dev)) {
vmd_setup_msix(dev, &bus->vmd->msix_table[0]);
vmd_dev_init(dev);
if (vmd_is_supported_device(dev)) {
vmd = bus->vmd;
vmd->target[vmd->nvme_count] = dev;
vmd->nvme_count++;
}
return 0;
} else {
SPDK_INFOLOG(vmd, "Removing failed device:%p\n", dev);
TAILQ_REMOVE(&bus->dev_list, dev, tailq);
return -1;
}
}
/*
* Scans a single bus for all devices attached and return a count of
* how many devices found. In the VMD topology, it is assume there are no multi-
@ -917,11 +944,11 @@ vmd_scan_single_bus(struct vmd_pci_bus *bus, struct vmd_pci_device *parent_bridg
{
/* assuming only single function devices are on the bus */
struct vmd_pci_device *new_dev;
struct vmd_adapter *vmd;
union express_slot_capabilities_register slot_cap;
struct vmd_pci_bus *new_bus;
uint8_t device_number, dev_cnt = 0;
uint8_t new_bus_num;
int rc;
for (device_number = 0; device_number < 32; device_number++) {
new_dev = vmd_alloc_dev(bus, device_number);
@ -984,20 +1011,8 @@ vmd_scan_single_bus(struct vmd_pci_bus *bus, struct vmd_pci_device *parent_bridg
}
}
} else {
/* Attach the device to the current bus and assign base addresses */
TAILQ_INSERT_TAIL(&bus->dev_list, new_dev, tailq);
g_end_device_count++;
if (vmd_assign_base_addrs(new_dev)) {
vmd_setup_msix(new_dev, &bus->vmd->msix_table[0]);
vmd_dev_init(new_dev);
if (vmd_is_supported_device(new_dev)) {
vmd = bus->vmd;
vmd->target[vmd->nvme_count] = new_dev;
vmd->nvme_count++;
}
} else {
SPDK_INFOLOG(vmd, "Removing failed device:%p\n", new_dev);
TAILQ_REMOVE(&bus->dev_list, new_dev, tailq);
rc = vmd_init_end_device(new_dev);
if (rc != 0) {
free(new_dev);
if (dev_cnt) {
dev_cnt--;