Skip to content

Commit 1789935

Browse files
committed
drm/xe/pf: Add sysfs device symlinks to enabled VFs
For convenience, for every enabled VF add 'device' symlink from our SR-IOV admin VF folder to enabled sysfs PCI VF device entry. Remove all those links when disabling PCI VFs. For completeness, add static 'device' symlink for the PF itself. /sys/bus/pci/drivers/xe/BDF/sriov_admin/ ├── pf │   └── device -> ../../../BDF # PF BDF ├── vf1 │   └── device -> ../../../BDF' # VF1 BDF ├── vf2 │   └── device -> ../../../BDF" # VF2 BDF Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Cc: Lucas De Marchi <lucas.demarchi@intel.com> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Link: https://patch.msgid.link/20251030222348.186658-16-michal.wajdeczko@intel.com
1 parent ae16f18 commit 1789935

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

drivers/gpu/drm/xe/xe_pci_sriov.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "xe_sriov_pf_control.h"
2121
#include "xe_sriov_pf_helpers.h"
2222
#include "xe_sriov_pf_provision.h"
23+
#include "xe_sriov_pf_sysfs.h"
2324
#include "xe_sriov_printk.h"
2425

2526
static void pf_reset_vfs(struct xe_device *xe, unsigned int num_vfs)
@@ -138,6 +139,8 @@ static int pf_enable_vfs(struct xe_device *xe, int num_vfs)
138139
xe_sriov_info(xe, "Enabled %u of %u VF%s\n",
139140
num_vfs, total_vfs, str_plural(total_vfs));
140141

142+
xe_sriov_pf_sysfs_link_vfs(xe, num_vfs);
143+
141144
pf_engine_activity_stats(xe, num_vfs, true);
142145

143146
return num_vfs;
@@ -165,6 +168,8 @@ static int pf_disable_vfs(struct xe_device *xe)
165168

166169
pf_engine_activity_stats(xe, num_vfs, false);
167170

171+
xe_sriov_pf_sysfs_unlink_vfs(xe, num_vfs);
172+
168173
pci_disable_sriov(pdev);
169174

170175
pf_reset_vfs(xe, num_vfs);

drivers/gpu/drm/xe/xe_sriov_pf_sysfs.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <drm/drm_managed.h>
1010

1111
#include "xe_assert.h"
12+
#include "xe_pci_sriov.h"
1213
#include "xe_pm.h"
1314
#include "xe_sriov.h"
1415
#include "xe_sriov_pf.h"
@@ -45,12 +46,14 @@ static int emit_choice(char *buf, int choice, const char * const *array, size_t
4546
* │ └── sched_priority
4647
* ├── pf/
4748
* │ ├── ...
49+
* │ ├── device -> ../../../BDF
4850
* │ └── profile
4951
* │ ├── exec_quantum_ms
5052
* │ ├── preempt_timeout_us
5153
* │ └── sched_priority
5254
* ├── vf1/
5355
* │ ├── ...
56+
* │ ├── device -> ../../../BDF.1
5457
* │ └── profile
5558
* │ ├── exec_quantum_ms
5659
* │ ├── preempt_timeout_us
@@ -414,6 +417,11 @@ static int pf_sysfs_error(struct xe_device *xe, int err, const char *what)
414417
return err;
415418
}
416419

420+
static void pf_sysfs_note(struct xe_device *xe, int err, const char *what)
421+
{
422+
xe_sriov_dbg(xe, "Failed to setup sysfs %s (%pe)\n", what, ERR_PTR(err));
423+
}
424+
417425
static void action_put_kobject(void *arg)
418426
{
419427
struct kobject *kobj = arg;
@@ -480,6 +488,29 @@ static int pf_setup_tree(struct xe_device *xe)
480488
return 0;
481489
}
482490

491+
static void action_rm_device_link(void *arg)
492+
{
493+
struct kobject *kobj = arg;
494+
495+
sysfs_remove_link(kobj, "device");
496+
}
497+
498+
static int pf_link_pf_device(struct xe_device *xe)
499+
{
500+
struct kobject *kobj = xe->sriov.pf.vfs[PFID].kobj;
501+
int err;
502+
503+
err = sysfs_create_link(kobj, &xe->drm.dev->kobj, "device");
504+
if (err)
505+
return pf_sysfs_error(xe, err, "PF device link");
506+
507+
err = devm_add_action_or_reset(xe->drm.dev, action_rm_device_link, kobj);
508+
if (err)
509+
return pf_sysfs_error(xe, err, "PF unlink action");
510+
511+
return 0;
512+
}
513+
483514
/**
484515
* xe_sriov_pf_sysfs_init() - Setup PF's SR-IOV sysfs tree.
485516
* @xe: the PF &xe_device to setup sysfs
@@ -501,5 +532,67 @@ int xe_sriov_pf_sysfs_init(struct xe_device *xe)
501532
if (err)
502533
return err;
503534

535+
err = pf_link_pf_device(xe);
536+
if (err)
537+
return err;
538+
504539
return 0;
505540
}
541+
542+
/**
543+
* xe_sriov_pf_sysfs_link_vfs() - Add VF's links in SR-IOV sysfs tree.
544+
* @xe: the &xe_device where to update sysfs
545+
* @num_vfs: number of enabled VFs to link
546+
*
547+
* This function is specific for the PF driver.
548+
*
549+
* This function will add symbolic links between VFs represented in the SR-IOV
550+
* sysfs tree maintained by the PF and enabled VF PCI devices.
551+
*
552+
* The @xe_sriov_pf_sysfs_unlink_vfs() shall be used to remove those links.
553+
*/
554+
void xe_sriov_pf_sysfs_link_vfs(struct xe_device *xe, unsigned int num_vfs)
555+
{
556+
unsigned int totalvfs = xe_sriov_pf_get_totalvfs(xe);
557+
struct pci_dev *pf_pdev = to_pci_dev(xe->drm.dev);
558+
struct pci_dev *vf_pdev = NULL;
559+
unsigned int n;
560+
int err;
561+
562+
xe_assert(xe, IS_SRIOV_PF(xe));
563+
xe_assert(xe, num_vfs <= totalvfs);
564+
565+
for (n = 1; n <= num_vfs; n++) {
566+
vf_pdev = xe_pci_sriov_get_vf_pdev(pf_pdev, VFID(n));
567+
if (!vf_pdev)
568+
return pf_sysfs_note(xe, -ENOENT, "VF link");
569+
570+
err = sysfs_create_link(xe->sriov.pf.vfs[VFID(n)].kobj,
571+
&vf_pdev->dev.kobj, "device");
572+
573+
/* must balance xe_pci_sriov_get_vf_pdev() */
574+
pci_dev_put(vf_pdev);
575+
576+
if (err)
577+
return pf_sysfs_note(xe, err, "VF link");
578+
}
579+
}
580+
581+
/**
582+
* xe_sriov_pf_sysfs_unlink_vfs() - Remove VF's links from SR-IOV sysfs tree.
583+
* @xe: the &xe_device where to update sysfs
584+
* @num_vfs: number of VFs to unlink
585+
*
586+
* This function shall be called only on the PF.
587+
* This function will remove "device" links added by @xe_sriov_sysfs_link_vfs().
588+
*/
589+
void xe_sriov_pf_sysfs_unlink_vfs(struct xe_device *xe, unsigned int num_vfs)
590+
{
591+
unsigned int n;
592+
593+
xe_assert(xe, IS_SRIOV_PF(xe));
594+
xe_assert(xe, num_vfs <= xe_sriov_pf_get_totalvfs(xe));
595+
596+
for (n = 1; n <= num_vfs; n++)
597+
sysfs_remove_link(xe->sriov.pf.vfs[VFID(n)].kobj, "device");
598+
}

drivers/gpu/drm/xe/xe_sriov_pf_sysfs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ struct xe_device;
1010

1111
int xe_sriov_pf_sysfs_init(struct xe_device *xe);
1212

13+
void xe_sriov_pf_sysfs_link_vfs(struct xe_device *xe, unsigned int num_vfs);
14+
void xe_sriov_pf_sysfs_unlink_vfs(struct xe_device *xe, unsigned int num_vfs);
15+
1316
#endif

0 commit comments

Comments
 (0)