Skip to content

Commit b97bf44

Browse files
niklas88hcahca
authored andcommitted
s390/pci: fix PF/VF linking on hot plug
Currently there are four places in which a PCI function is scanned and made available to drivers: 1. In pci_scan_root_bus() as part of the initial zbus creation. 2. In zpci_bus_add_devices() when registering a device in configured state on a zbus that has already been scanned. 3. When a function is already known to zPCI (in reserved/standby state) and configuration is triggered through firmware by PEC 0x301. 4. When a device is already known to zPCI (in standby/reserved state) and configuration is triggered from within Linux using enable_slot(). The PF/VF linking step and setting of pdev->is_virtfn introduced with commit e5794cf ("s390/pci: create links between PFs and VFs") was only triggered for the second case, which is where VFs created through sriov_numvfs usually land. However unlike some other platforms but like POWER VFs can be individually enabled/disabled through /sys/bus/pci/slots. Fix this by doing VF setup as part of pcibios_bus_add_device() which is called in all of the above cases. Finally to remove the PF/VF links call the common code pci_iov_remove_virtfn() function to remove linked VFs. This takes care of the necessary sysfs cleanup. Fixes: e5794cf ("s390/pci: create links between PFs and VFs") Cc: <[email protected]> # 5.8: 2f0230b: s390/pci: re-introduce zpci_remove_device() Cc: <[email protected]> # 5.8 Acked-by: Pierre Morel <[email protected]> Signed-off-by: Niklas Schnelle <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent 2f0230b commit b97bf44

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

arch/s390/pci/pci.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,11 @@ void zpci_remove_device(struct zpci_dev *zdev)
678678
struct pci_dev *pdev;
679679

680680
pdev = pci_get_slot(zbus->bus, zdev->devfn);
681-
if (pdev)
681+
if (pdev) {
682+
if (pdev->is_virtfn)
683+
return zpci_remove_virtfn(pdev, zdev->vfn);
682684
pci_stop_and_remove_bus_device_locked(pdev);
685+
}
683686
}
684687

685688
int zpci_create_device(struct zpci_dev *zdev)

arch/s390/pci/pci_bus.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ static inline int zpci_bus_setup_virtfn(struct zpci_bus *zbus,
189189
}
190190
#endif
191191

192+
void pcibios_bus_add_device(struct pci_dev *pdev)
193+
{
194+
struct zpci_dev *zdev = to_zpci(pdev);
195+
196+
/*
197+
* With pdev->no_vf_scan the common PCI probing code does not
198+
* perform PF/VF linking.
199+
*/
200+
if (zdev->vfn)
201+
zpci_bus_setup_virtfn(zdev->zbus, pdev, zdev->vfn);
202+
203+
}
204+
192205
static int zpci_bus_add_device(struct zpci_bus *zbus, struct zpci_dev *zdev)
193206
{
194207
struct pci_bus *bus;
@@ -219,20 +232,10 @@ static int zpci_bus_add_device(struct zpci_bus *zbus, struct zpci_dev *zdev)
219232
}
220233

221234
pdev = pci_scan_single_device(bus, zdev->devfn);
222-
if (pdev) {
223-
if (!zdev->is_physfn) {
224-
rc = zpci_bus_setup_virtfn(zbus, pdev, zdev->vfn);
225-
if (rc)
226-
goto failed_with_pdev;
227-
}
235+
if (pdev)
228236
pci_bus_add_device(pdev);
229-
}
230-
return 0;
231237

232-
failed_with_pdev:
233-
pci_stop_and_remove_bus_device(pdev);
234-
pci_dev_put(pdev);
235-
return rc;
238+
return 0;
236239
}
237240

238241
static void zpci_bus_add_devices(struct zpci_bus *zbus)

arch/s390/pci/pci_bus.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,16 @@ static inline struct zpci_dev *get_zdev_by_bus(struct pci_bus *bus,
2929

3030
return (devfn >= ZPCI_FUNCTIONS_PER_BUS) ? NULL : zbus->function[devfn];
3131
}
32+
33+
#ifdef CONFIG_PCI_IOV
34+
static inline void zpci_remove_virtfn(struct pci_dev *pdev, int vfn)
35+
{
36+
37+
pci_lock_rescan_remove();
38+
/* Linux' vfid's start at 0 vfn at 1 */
39+
pci_iov_remove_virtfn(pdev->physfn, vfn - 1);
40+
pci_unlock_rescan_remove();
41+
}
42+
#else /* CONFIG_PCI_IOV */
43+
static inline void zpci_remove_virtfn(struct pci_dev *pdev, int vfn) {}
44+
#endif /* CONFIG_PCI_IOV */

0 commit comments

Comments
 (0)