Index: sys/dev/pci/pci.c =================================================================== --- sys/dev/pci/pci.c +++ sys/dev/pci/pci.c @@ -5643,6 +5643,10 @@ pci_resume_msi(dev); if (dinfo->cfg.msix.msix_location != 0) pci_resume_msix(dev); + + if (dinfo->cfg.iov != NULL) + pci_iov_cfg_restore(dev, dinfo); + } static void @@ -5755,6 +5759,9 @@ if (dinfo->cfg.pcix.pcix_location != 0) pci_cfg_save_pcix(dev, dinfo); + if (dinfo->cfg.iov != NULL) + pci_iov_cfg_save(dev, dinfo); + /* * don't set the state for display devices, base peripherals and * memory devices since bad things happen when they are powered down. Index: sys/dev/pci/pci_iov.c =================================================================== --- sys/dev/pci/pci_iov.c +++ sys/dev/pci/pci_iov.c @@ -442,6 +442,7 @@ } } } + free(devlist, M_TEMP); /* * If we called this function some device must have the SR-IOV @@ -451,10 +452,14 @@ ("Could not find child of %s with SR-IOV capability", device_get_nameunit(bus))); - iov_ctl = pci_read_config(lowest, iov_pos + PCIR_SRIOV_CTL, 2); + iov_ctl = pci_read_config(lowest, lowest_pos + PCIR_SRIOV_CTL, 2); iov_ctl |= PCIM_SRIOV_ARI_EN; - pci_write_config(lowest, iov_pos + PCIR_SRIOV_CTL, iov_ctl, 2); - free(devlist, M_TEMP); + pci_write_config(lowest, lowest_pos + PCIR_SRIOV_CTL, iov_ctl, 2); + if ((pci_read_config(lowest, lowest_pos + PCIR_SRIOV_CTL, 2) & + PCIM_SRIOV_ARI_EN) == 0) { + device_printf(lowest, "failed to enable ARI\n"); + return (ENXIO); + } return (0); } @@ -765,6 +770,29 @@ return (error); } +void +pci_iov_cfg_restore(device_t dev, struct pci_devinfo *dinfo) +{ + struct pcicfg_iov *iov; + + iov = dinfo->cfg.iov; + + IOV_WRITE(dinfo, PCIR_SRIOV_PAGE_SIZE, iov->iov_page_size, 4); + IOV_WRITE(dinfo, PCIR_SRIOV_NUM_VFS, iov->iov_num_vfs, 2); + IOV_WRITE(dinfo, PCIR_SRIOV_CTL, iov->iov_ctl, 2); +} + +void +pci_iov_cfg_save(device_t dev, struct pci_devinfo *dinfo) +{ + struct pcicfg_iov *iov; + + iov = dinfo->cfg.iov; + + iov->iov_page_size = IOV_READ(dinfo, PCIR_SRIOV_PAGE_SIZE, 4); + iov->iov_ctl = IOV_READ(dinfo, PCIR_SRIOV_CTL, 2); +} + /* Return true if child is a VF of the given PF. */ static int pci_iov_is_child_vf(struct pcicfg_iov *pf, device_t child) Index: sys/dev/pci/pci_iov_private.h =================================================================== --- sys/dev/pci/pci_iov_private.h +++ sys/dev/pci/pci_iov_private.h @@ -47,10 +47,16 @@ int iov_pos; int iov_num_vfs; uint32_t iov_flags; + + uint16_t iov_ctl; + uint32_t iov_page_size; }; #define IOV_RMAN_INITED 0x0001 #define IOV_BUSY 0x0002 +void pci_iov_cfg_restore(device_t dev, struct pci_devinfo *dinfo); +void pci_iov_cfg_save(device_t dev, struct pci_devinfo *dinfo); + #endif