xref: /linux/drivers/crypto/intel/qat/qat_common/adf_dbgfs.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
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_cnv_dbgfs.h"
9 #include "adf_dbgfs.h"
10 #include "adf_fw_counters.h"
11 #include "adf_heartbeat_dbgfs.h"
12 #include "adf_pm_dbgfs.h"
13 #include "adf_tl_debugfs.h"
14 
15 /**
16  * adf_dbgfs_init() - add persistent debugfs entries
17  * @accel_dev:  Pointer to acceleration device.
18  *
19  * This function creates debugfs entries that are persistent through a device
20  * state change (from up to down or vice versa).
21  */
22 void adf_dbgfs_init(struct adf_accel_dev *accel_dev)
23 {
24 	char name[ADF_DEVICE_NAME_LENGTH];
25 	void *ret;
26 
27 	/* Create dev top level debugfs entry */
28 	snprintf(name, sizeof(name), "%s%s_%s", ADF_DEVICE_NAME_PREFIX,
29 		 accel_dev->hw_device->dev_class->name,
30 		 pci_name(accel_dev->accel_pci_dev.pci_dev));
31 
32 	ret = debugfs_create_dir(name, NULL);
33 	if (IS_ERR_OR_NULL(ret))
34 		return;
35 
36 	accel_dev->debugfs_dir = ret;
37 
38 	adf_cfg_dev_dbgfs_add(accel_dev);
39 }
40 EXPORT_SYMBOL_GPL(adf_dbgfs_init);
41 
42 /**
43  * adf_dbgfs_exit() - remove persistent debugfs entries
44  * @accel_dev:  Pointer to acceleration device.
45  */
46 void adf_dbgfs_exit(struct adf_accel_dev *accel_dev)
47 {
48 	adf_cfg_dev_dbgfs_rm(accel_dev);
49 	debugfs_remove(accel_dev->debugfs_dir);
50 }
51 EXPORT_SYMBOL_GPL(adf_dbgfs_exit);
52 
53 /**
54  * adf_dbgfs_add() - add non-persistent debugfs entries
55  * @accel_dev:  Pointer to acceleration device.
56  *
57  * This function creates debugfs entries that are not persistent through
58  * a device state change (from up to down or vice versa).
59  */
60 void adf_dbgfs_add(struct adf_accel_dev *accel_dev)
61 {
62 	if (!accel_dev->debugfs_dir)
63 		return;
64 
65 	if (!accel_dev->is_vf) {
66 		adf_fw_counters_dbgfs_add(accel_dev);
67 		adf_heartbeat_dbgfs_add(accel_dev);
68 		adf_pm_dbgfs_add(accel_dev);
69 		adf_cnv_dbgfs_add(accel_dev);
70 		adf_tl_dbgfs_add(accel_dev);
71 	}
72 }
73 
74 /**
75  * adf_dbgfs_rm() - remove non-persistent debugfs entries
76  * @accel_dev:  Pointer to acceleration device.
77  */
78 void adf_dbgfs_rm(struct adf_accel_dev *accel_dev)
79 {
80 	if (!accel_dev->debugfs_dir)
81 		return;
82 
83 	if (!accel_dev->is_vf) {
84 		adf_tl_dbgfs_rm(accel_dev);
85 		adf_cnv_dbgfs_rm(accel_dev);
86 		adf_pm_dbgfs_rm(accel_dev);
87 		adf_heartbeat_dbgfs_rm(accel_dev);
88 		adf_fw_counters_dbgfs_rm(accel_dev);
89 	}
90 }
91