1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 #include "adf_c4xxx_hw_data.h"
4 #include <linux/kernel.h>
5 #include <linux/types.h>
6 #include <linux/fs.h>
7 #include <linux/errno.h>
8 #include <linux/device.h>
9 #include <linux/io.h>
10 #include <sys/sbuf.h>
11 #include <sys/sysctl.h>
12 #include <adf_accel_devices.h>
13 #include <adf_common_drv.h>
14 #include <adf_cfg.h>
15
16 /* String buffer size */
17 #define AE_INFO_BUFFER_SIZE 50
18
19 #define AE_CONFIG_DBG_FILE "ae_config"
20
21 static u8
find_first_me_index(const u32 au_mask)22 find_first_me_index(const u32 au_mask)
23 {
24 u8 i;
25 u32 mask = au_mask;
26
27 /* Retrieve the index of the first ME of an accel unit */
28 for (i = 0; i < ADF_C4XXX_MAX_ACCELENGINES; i++) {
29 if (mask & BIT(i))
30 return i;
31 }
32
33 return 0;
34 }
35
36 static u8
get_au_index(u8 au_mask)37 get_au_index(u8 au_mask)
38 {
39 u8 au_index = 0;
40
41 while (au_mask) {
42 if (au_mask == BIT(0))
43 return au_index;
44 au_index++;
45 au_mask = au_mask >> 1;
46 }
47
48 return 0;
49 }
50
adf_ae_config_show(SYSCTL_HANDLER_ARGS)51 static int adf_ae_config_show(SYSCTL_HANDLER_ARGS)
52 {
53 struct sbuf sb;
54 struct adf_accel_dev *accel_dev = arg1;
55 struct adf_hw_device_data *hw_data = accel_dev->hw_device;
56 struct adf_accel_unit *accel_unit = accel_dev->au_info->au;
57 u8 i, j;
58 u8 au_index;
59 u8 ae_index;
60 u8 num_aes;
61 int ret = 0;
62 u32 num_au = hw_data->get_num_accel_units(hw_data);
63
64 sbuf_new_for_sysctl(&sb, NULL, 2048, req);
65
66 sbuf_printf(&sb, "\n");
67 for (i = 0; i < num_au; i++) {
68 /* Retrieve accel unit index */
69 au_index = get_au_index(accel_unit[i].au_mask);
70
71 /* Retrieve index of fist ME in current accel unit */
72 ae_index = find_first_me_index(accel_unit[i].ae_mask);
73 num_aes = accel_unit[i].num_ae;
74
75 /* Retrieve accel unit type */
76 switch (accel_unit[i].services) {
77 case ADF_ACCEL_CRYPTO:
78 sbuf_printf(&sb,
79 "\tAccel unit %d - CRYPTO\n",
80 au_index);
81 /* Display ME assignment for a particular accel unit */
82 for (j = ae_index; j < (num_aes + ae_index); j++)
83 sbuf_printf(&sb, "\t\tAE[%d]: crypto\n", j);
84 break;
85 case ADF_ACCEL_COMPRESSION:
86 sbuf_printf(&sb,
87 "\tAccel unit %d - COMPRESSION\n",
88 au_index);
89 /* Display ME assignment for a particular accel unit */
90 for (j = ae_index; j < (num_aes + ae_index); j++)
91 sbuf_printf(&sb,
92 "\t\tAE[%d]: compression\n",
93 j);
94 break;
95 case ADF_ACCEL_SERVICE_NULL:
96 default:
97 break;
98 }
99 }
100
101 sbuf_finish(&sb);
102 ret = SYSCTL_OUT(req, sbuf_data(&sb), sbuf_len(&sb));
103 sbuf_delete(&sb);
104
105 return ret;
106 }
107
108 static int
c4xxx_add_debugfs_ae_config(struct adf_accel_dev * accel_dev)109 c4xxx_add_debugfs_ae_config(struct adf_accel_dev *accel_dev)
110 {
111 struct sysctl_ctx_list *qat_sysctl_ctx = NULL;
112 struct sysctl_oid *qat_sysctl_tree = NULL;
113 struct sysctl_oid *ae_conf_ctl = NULL;
114
115 qat_sysctl_ctx =
116 device_get_sysctl_ctx(accel_dev->accel_pci_dev.pci_dev);
117 qat_sysctl_tree =
118 device_get_sysctl_tree(accel_dev->accel_pci_dev.pci_dev);
119
120 ae_conf_ctl = SYSCTL_ADD_PROC(qat_sysctl_ctx,
121 SYSCTL_CHILDREN(qat_sysctl_tree),
122 OID_AUTO,
123 AE_CONFIG_DBG_FILE,
124 CTLTYPE_STRING | CTLFLAG_RD,
125 accel_dev,
126 0,
127 adf_ae_config_show,
128 "A",
129 "AE config");
130 accel_dev->debugfs_ae_config = ae_conf_ctl;
131 if (!accel_dev->debugfs_ae_config) {
132 device_printf(GET_DEV(accel_dev),
133 "Could not create debug ae config entry.\n");
134 return EFAULT;
135 }
136 return 0;
137 }
138
139 int
c4xxx_init_ae_config(struct adf_accel_dev * accel_dev)140 c4xxx_init_ae_config(struct adf_accel_dev *accel_dev)
141 {
142 int ret = 0;
143
144 /* Add a new file in debug file system with h/w version. */
145 ret = c4xxx_add_debugfs_ae_config(accel_dev);
146 if (ret) {
147 c4xxx_exit_ae_config(accel_dev);
148 device_printf(GET_DEV(accel_dev),
149 "Could not create debugfs ae config file\n");
150 return EINVAL;
151 }
152
153 return 0;
154 }
155
156 void
c4xxx_exit_ae_config(struct adf_accel_dev * accel_dev)157 c4xxx_exit_ae_config(struct adf_accel_dev *accel_dev)
158 {
159 if (!accel_dev->debugfs_ae_config)
160 return;
161
162 /* Delete ae configuration file */
163 remove_oid(accel_dev, accel_dev->debugfs_ae_config);
164
165 accel_dev->debugfs_ae_config = NULL;
166 }
167