diff --git a/lib/vmd/vmd.c b/lib/vmd/vmd.c index e4b90f2cf..5fc38ddbe 100644 --- a/lib/vmd/vmd.c +++ b/lib/vmd/vmd.c @@ -516,64 +516,6 @@ vmd_alloc_dev(struct vmd_pci_bus *bus, uint32_t devfn) return dev; } -static void -vmd_add_bus_to_list(struct vmd_adapter *vmd, struct vmd_pci_bus *bus) -{ - struct vmd_pci_bus *blist; - - blist = vmd->bus_list; - bus->next = NULL; - if (blist == NULL) { - vmd->bus_list = bus; - return; - } - - while (blist->next != NULL) { - blist = blist->next; - } - - blist->next = bus; -} - -static void -vmd_pcibus_remove_device(struct vmd_pci_bus *bus, struct vmd_pci_device *device) -{ - struct vmd_pci_device *list = bus->dev_list; - - if (list == device) { - bus->dev_list = NULL; - } - - while (list->next != NULL) { - if (list->next == device) { - assert(list->next->next); - list->next = list->next->next; - } - list = list->next; - } -} - - -static bool -vmd_bus_add_device(struct vmd_pci_bus *bus, struct vmd_pci_device *device) -{ - struct vmd_pci_device *next_dev = bus->dev_list; - - device->next = NULL; - if (next_dev == NULL) { - bus->dev_list = device; - return 1; - } - - while (next_dev->next != NULL) { - next_dev = next_dev->next; - } - - next_dev->next = device; - - return 1; -} - static struct vmd_pci_bus * vmd_create_new_bus(struct vmd_pci_bus *parent, struct vmd_pci_device *bridge, uint8_t bus_number) { @@ -590,6 +532,8 @@ vmd_create_new_bus(struct vmd_pci_bus *parent, struct vmd_pci_device *bridge, ui new_bus->secondary_bus = new_bus->subordinate_bus = bus_number; new_bus->self = bridge; new_bus->vmd = parent->vmd; + TAILQ_INIT(&new_bus->dev_list); + bridge->subordinate = new_bus; bridge->pci.addr.bus = new_bus->bus_number; @@ -880,7 +824,7 @@ vmd_scan_single_bus(struct vmd_pci_bus *bus, struct vmd_pci_device *parent_bridg new_dev->header->one.subordinate = new_bus->subordinate_bus; vmd_bus_update_bridge_info(new_dev); - vmd_add_bus_to_list(bus->vmd, new_bus); + TAILQ_INSERT_TAIL(&bus->vmd->bus_list, new_bus, tailq); /* Attach hot plug instance if HP is supported */ /* Hot inserted SSDs can be assigned port bus of sub-ordinate + 1 */ @@ -903,7 +847,7 @@ 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 */ - vmd_bus_add_device(bus, new_dev); + 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]); @@ -915,7 +859,7 @@ vmd_scan_single_bus(struct vmd_pci_bus *bus, struct vmd_pci_device *parent_bridg } } else { SPDK_DEBUGLOG(SPDK_LOG_VMD, "Removing failed device:%p\n", new_dev); - vmd_pcibus_remove_device(bus, new_dev); + TAILQ_REMOVE(&bus->dev_list, new_dev, tailq); if (dev_cnt) { dev_cnt--; } @@ -1003,31 +947,26 @@ vmd_scan_pcibus(struct vmd_pci_bus *bus) uint8_t dev_cnt; g_end_device_count = 0; - vmd_add_bus_to_list(bus->vmd, bus); + TAILQ_INSERT_TAIL(&bus->vmd->bus_list, bus, tailq); bus->vmd->next_bus_number = bus->bus_number + 1; dev_cnt = vmd_scan_single_bus(bus, NULL); - bus_entry = bus->vmd->bus_list; SPDK_DEBUGLOG(SPDK_LOG_VMD, "VMD scan found %u devices\n", dev_cnt); SPDK_DEBUGLOG(SPDK_LOG_VMD, "VMD scan found %u END DEVICES\n", g_end_device_count); SPDK_INFOLOG(SPDK_LOG_VMD, "PCIe devices attached to VMD %04x:%02x:%02x:%x...\n", - bus_entry->vmd->pci.addr.domain, bus_entry->vmd->pci.addr.bus, - bus_entry->vmd->pci.addr.dev, bus_entry->vmd->pci.addr.func); + bus->vmd->pci.addr.domain, bus->vmd->pci.addr.bus, + bus->vmd->pci.addr.dev, bus->vmd->pci.addr.func); - while (bus_entry != NULL) { + TAILQ_FOREACH(bus_entry, &bus->vmd->bus_list, tailq) { if (bus_entry->self != NULL) { vmd_print_pci_info(bus_entry->self); vmd_cache_scan_info(bus_entry->self); } - dev = bus_entry->dev_list; - while (dev != NULL) { + TAILQ_FOREACH(dev, &bus_entry->dev_list, tailq) { vmd_print_pci_info(dev); - dev = dev->next; } - - bus_entry = bus_entry->next; } return dev_cnt; @@ -1075,14 +1014,14 @@ vmd_find_device(const struct spdk_pci_addr *addr) int i; for (i = 0; i < MAX_VMD_TARGET; ++i) { - for (bus = g_vmd_container.vmd[i].bus_list; bus != NULL; bus = bus->next) { + TAILQ_FOREACH(bus, &g_vmd_container.vmd[i].bus_list, tailq) { if (bus->self) { if (spdk_pci_addr_compare(&bus->self->pci.addr, addr) == 0) { return bus->self; } } - for (dev = bus->dev_list; dev != NULL; dev = dev->next) { + TAILQ_FOREACH(dev, &bus->dev_list, tailq) { if (spdk_pci_addr_compare(&dev->pci.addr, addr) == 0) { return dev; } @@ -1115,6 +1054,8 @@ vmd_enum_cb(void *ctx, struct spdk_pci_device *pci_dev) vmd_c->vmd[i].domain = (pci_dev->addr.bus << 16) | (pci_dev->addr.dev << 8) | pci_dev->addr.func; vmd_c->vmd[i].max_pci_bus = PCI_MAX_BUS_NUMBER; + TAILQ_INIT(&vmd_c->vmd[i].bus_list); + if (vmd_map_bars(&vmd_c->vmd[i], pci_dev) == -1) { return -1; } @@ -1149,18 +1090,14 @@ spdk_vmd_pci_device_list(struct spdk_pci_addr vmd_addr, struct spdk_pci_device * for (int i = 0; i < MAX_VMD_TARGET; ++i) { if (spdk_pci_addr_compare(&vmd_addr, &g_vmd_container.vmd[i].pci.addr) == 0) { - bus = g_vmd_container.vmd[i].bus_list; - while (bus != NULL) { - dev = bus->dev_list; - while (dev != NULL) { + TAILQ_FOREACH(bus, &g_vmd_container.vmd[i].bus_list, tailq) { + TAILQ_FOREACH(dev, &bus->dev_list, tailq) { nvme_list[cnt++] = dev->pci; if (!dev->is_hooked) { vmd_dev_init(dev); dev->is_hooked = 1; } - dev = dev->next; } - bus = bus->next; } } } diff --git a/lib/vmd/vmd.h b/lib/vmd/vmd.h index bb0645752..904ab1fa0 100644 --- a/lib/vmd/vmd.h +++ b/lib/vmd/vmd.h @@ -67,8 +67,8 @@ struct vmd_pci_bus { uint32_t secondary_bus : 8; uint32_t subordinate_bus : 8; - struct vmd_pci_device *dev_list; /* list of pci end device attached to this bus */ - struct vmd_pci_bus *next; /* link for all buses found during scan */ + TAILQ_HEAD(, vmd_pci_device) dev_list; /* list of pci end device attached to this bus */ + TAILQ_ENTRY(vmd_pci_bus) tailq; /* link for all buses found during scan */ }; /* @@ -97,7 +97,7 @@ struct vmd_pci_device { struct spdk_pci_device pci; struct pci_bars bar[6]; - struct vmd_pci_device *parent_bridge, *next; + struct vmd_pci_device *parent_bridge; struct vmd_pci_bus *bus, *parent; struct vmd_pci_bus *bus_object; /* bus tracks pci bus associated with this dev if type 1 dev. */ struct vmd_pci_bus *subordinate; @@ -108,6 +108,8 @@ struct vmd_pci_device { volatile struct serial_number_capability *sn_cap; volatile struct pci_msix_table_entry *msix_table; + TAILQ_ENTRY(vmd_pci_device) tailq; + uint32_t class; uint16_t vid; uint16_t did; @@ -163,7 +165,9 @@ struct vmd_adapter { uint32_t nvme_count : 8; uint32_t vmd_index : 8; - struct vmd_pci_bus vmd_bus, *bus_list; + struct vmd_pci_bus vmd_bus; + + TAILQ_HEAD(, vmd_pci_bus) bus_list; struct event_fifo *hp_queue; };