1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2023 Intel Corporation */
3 
4 #include <linux/debugfs.h>
5 #include "adf_accel_devices.h"
6 #include "adf_cfg.h"
7 #include "adf_common_drv.h"
8 #include "adf_dbgfs.h"
9 #include "adf_fw_counters.h"
10 #include "adf_heartbeat_dbgfs.h"
11 
12 /**
13  * adf_dbgfs_init() - add persistent debugfs entries
14  * @accel_dev:  Pointer to acceleration device.
15  *
16  * This function creates debugfs entries that are persistent through a device
17  * state change (from up to down or vice versa).
18  */
19 void adf_dbgfs_init(struct adf_accel_dev *accel_dev)
20 {
21 	char name[ADF_DEVICE_NAME_LENGTH];
22 	void *ret;
23 
24 	/* Create dev top level debugfs entry */
25 	snprintf(name, sizeof(name), "%s%s_%s", ADF_DEVICE_NAME_PREFIX,
26 		 accel_dev->hw_device->dev_class->name,
27 		 pci_name(accel_dev->accel_pci_dev.pci_dev));
28 
29 	ret = debugfs_create_dir(name, NULL);
30 	if (IS_ERR_OR_NULL(ret))
31 		return;
32 
33 	accel_dev->debugfs_dir = ret;
34 
35 	adf_cfg_dev_dbgfs_add(accel_dev);
36 }
37 EXPORT_SYMBOL_GPL(adf_dbgfs_init);
38 
39 /**
40  * adf_dbgfs_exit() - remove persistent debugfs entries
41  * @accel_dev:  Pointer to acceleration device.
42  */
43 void adf_dbgfs_exit(struct adf_accel_dev *accel_dev)
44 {
45 	adf_cfg_dev_dbgfs_rm(accel_dev);
46 	debugfs_remove(accel_dev->debugfs_dir);
47 }
48 EXPORT_SYMBOL_GPL(adf_dbgfs_exit);
49 
50 /**
51  * adf_dbgfs_add() - add non-persistent debugfs entries
52  * @accel_dev:  Pointer to acceleration device.
53  *
54  * This function creates debugfs entries that are not persistent through
55  * a device state change (from up to down or vice versa).
56  */
57 void adf_dbgfs_add(struct adf_accel_dev *accel_dev)
58 {
59 	if (!accel_dev->debugfs_dir)
60 		return;
61 
62 	if (!accel_dev->is_vf) {
63 		adf_fw_counters_dbgfs_add(accel_dev);
64 		adf_heartbeat_dbgfs_add(accel_dev);
65 	}
66 }
67 
68 /**
69  * adf_dbgfs_rm() - remove non-persistent debugfs entries
70  * @accel_dev:  Pointer to acceleration device.
71  */
72 void adf_dbgfs_rm(struct adf_accel_dev *accel_dev)
73 {
74 	if (!accel_dev->debugfs_dir)
75 		return;
76 
77 	if (!accel_dev->is_vf) {
78 		adf_heartbeat_dbgfs_rm(accel_dev);
79 		adf_fw_counters_dbgfs_rm(accel_dev);
80 	}
81 }
82