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