]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
drm/xe/configfs: Allow adding configurations for future VFs
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Thu, 31 Jul 2025 21:21:45 +0000 (23:21 +0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Tue, 5 Aug 2025 19:30:48 +0000 (12:30 -0700)
Since we are expecting that all configuration directory names
will match some of the existing devices, we can't provide any
configuration for the VFs until they are actually enabled.

But we can relax that restriction by just checking if there
is a PF device that could create given VF. This is easy since
all our PF devices are always present at function 0 and we can
query PF device for number of VFs it could support.

Then for some system with PF device at 0000:00:02.0 we can add
configs for all VFs:

  /sys/kernel/config/xe/
  ├── 0000:00:02.0
  │   └── ...
  ├── 0000:00:02.1
  │   └── ...
  ├── 0000:00:02.2
  │   └── ...
  :
  └── 0000:00:02.7
      └── ...

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: John Harrison <John.C.Harrison@Intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/20250731212145.179898-1-michal.wajdeczko@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/xe/xe_configfs.c

index 5c13749733af0500dde9102c4153ccc0d6f72e66..853da2ee837ac2e87a66292fea4fc38a6e7d1db2 100644 (file)
@@ -12,9 +12,9 @@
 #include <linux/string.h>
 
 #include "xe_configfs.h"
-#include "xe_module.h"
-
 #include "xe_hw_engine_types.h"
+#include "xe_module.h"
+#include "xe_pci_types.h"
 
 /**
  * DOC: Xe Configfs
@@ -280,6 +280,15 @@ static const struct xe_device_desc *xe_match_desc(struct pci_dev *pdev)
        return found ? (const void *)found->driver_data : NULL;
 }
 
+static struct pci_dev *get_physfn_instead(struct pci_dev *virtfn)
+{
+       struct pci_dev *physfn = pci_physfn(virtfn);
+
+       pci_dev_get(physfn);
+       pci_dev_put(virtfn);
+       return physfn;
+}
+
 static struct config_group *xe_config_make_device_group(struct config_group *group,
                                                        const char *name)
 {
@@ -288,6 +297,7 @@ static struct config_group *xe_config_make_device_group(struct config_group *gro
        const struct xe_device_desc *match;
        struct pci_dev *pdev;
        char canonical[16];
+       int vfnumber = 0;
        int ret;
 
        ret = sscanf(name, "%x:%x:%x.%x", &domain, &bus, &slot, &function);
@@ -301,12 +311,29 @@ static struct config_group *xe_config_make_device_group(struct config_group *gro
                return ERR_PTR(-EINVAL);
 
        pdev = pci_get_domain_bus_and_slot(domain, bus, PCI_DEVFN(slot, function));
+       if (!pdev && function)
+               pdev = pci_get_domain_bus_and_slot(domain, bus, PCI_DEVFN(slot, 0));
+       if (!pdev && slot)
+               pdev = pci_get_domain_bus_and_slot(domain, bus, PCI_DEVFN(0, 0));
        if (!pdev)
                return ERR_PTR(-ENODEV);
 
+       if (PCI_DEVFN(slot, function) != pdev->devfn) {
+               pdev = get_physfn_instead(pdev);
+               vfnumber = PCI_DEVFN(slot, function) - pdev->devfn;
+               if (!dev_is_pf(&pdev->dev) || vfnumber > pci_sriov_get_totalvfs(pdev)) {
+                       pci_dev_put(pdev);
+                       return ERR_PTR(-ENODEV);
+               }
+       }
+
        match = xe_match_desc(pdev);
-       if (!match)
+       if (match && vfnumber && !match->has_sriov) {
+               pci_info(pdev, "xe driver does not support VFs on this device\n");
+               match = NULL;
+       } else if (!match) {
                pci_info(pdev, "xe driver does not support configuration of this device\n");
+       }
 
        pci_dev_put(pdev);