This source file includes following definitions.
- qat_dev_cfg_start
- qat_dev_cfg_show
- qat_dev_cfg_next
- qat_dev_cfg_stop
- qat_dev_cfg_open
- adf_cfg_dev_add
- adf_cfg_del_all
- adf_cfg_dev_remove
- adf_cfg_keyval_add
- adf_cfg_keyval_del_all
- adf_cfg_section_del_all
- adf_cfg_key_value_find
- adf_cfg_sec_find
- adf_cfg_key_val_get
- adf_cfg_add_key_value_param
- adf_cfg_section_add
- adf_cfg_get_param_value
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 #include <linux/mutex.h>
48 #include <linux/slab.h>
49 #include <linux/list.h>
50 #include <linux/seq_file.h>
51 #include "adf_accel_devices.h"
52 #include "adf_cfg.h"
53 #include "adf_common_drv.h"
54
55 static DEFINE_MUTEX(qat_cfg_read_lock);
56
57 static void *qat_dev_cfg_start(struct seq_file *sfile, loff_t *pos)
58 {
59 struct adf_cfg_device_data *dev_cfg = sfile->private;
60
61 mutex_lock(&qat_cfg_read_lock);
62 return seq_list_start(&dev_cfg->sec_list, *pos);
63 }
64
65 static int qat_dev_cfg_show(struct seq_file *sfile, void *v)
66 {
67 struct list_head *list;
68 struct adf_cfg_section *sec =
69 list_entry(v, struct adf_cfg_section, list);
70
71 seq_printf(sfile, "[%s]\n", sec->name);
72 list_for_each(list, &sec->param_head) {
73 struct adf_cfg_key_val *ptr =
74 list_entry(list, struct adf_cfg_key_val, list);
75 seq_printf(sfile, "%s = %s\n", ptr->key, ptr->val);
76 }
77 return 0;
78 }
79
80 static void *qat_dev_cfg_next(struct seq_file *sfile, void *v, loff_t *pos)
81 {
82 struct adf_cfg_device_data *dev_cfg = sfile->private;
83
84 return seq_list_next(v, &dev_cfg->sec_list, pos);
85 }
86
87 static void qat_dev_cfg_stop(struct seq_file *sfile, void *v)
88 {
89 mutex_unlock(&qat_cfg_read_lock);
90 }
91
92 static const struct seq_operations qat_dev_cfg_sops = {
93 .start = qat_dev_cfg_start,
94 .next = qat_dev_cfg_next,
95 .stop = qat_dev_cfg_stop,
96 .show = qat_dev_cfg_show
97 };
98
99 static int qat_dev_cfg_open(struct inode *inode, struct file *file)
100 {
101 int ret = seq_open(file, &qat_dev_cfg_sops);
102
103 if (!ret) {
104 struct seq_file *seq_f = file->private_data;
105
106 seq_f->private = inode->i_private;
107 }
108 return ret;
109 }
110
111 static const struct file_operations qat_dev_cfg_fops = {
112 .open = qat_dev_cfg_open,
113 .read = seq_read,
114 .llseek = seq_lseek,
115 .release = seq_release
116 };
117
118
119
120
121
122
123
124
125
126
127
128 int adf_cfg_dev_add(struct adf_accel_dev *accel_dev)
129 {
130 struct adf_cfg_device_data *dev_cfg_data;
131
132 dev_cfg_data = kzalloc(sizeof(*dev_cfg_data), GFP_KERNEL);
133 if (!dev_cfg_data)
134 return -ENOMEM;
135 INIT_LIST_HEAD(&dev_cfg_data->sec_list);
136 init_rwsem(&dev_cfg_data->lock);
137 accel_dev->cfg = dev_cfg_data;
138
139
140 dev_cfg_data->debug = debugfs_create_file("dev_cfg", S_IRUSR,
141 accel_dev->debugfs_dir,
142 dev_cfg_data,
143 &qat_dev_cfg_fops);
144 return 0;
145 }
146 EXPORT_SYMBOL_GPL(adf_cfg_dev_add);
147
148 static void adf_cfg_section_del_all(struct list_head *head);
149
150 void adf_cfg_del_all(struct adf_accel_dev *accel_dev)
151 {
152 struct adf_cfg_device_data *dev_cfg_data = accel_dev->cfg;
153
154 down_write(&dev_cfg_data->lock);
155 adf_cfg_section_del_all(&dev_cfg_data->sec_list);
156 up_write(&dev_cfg_data->lock);
157 clear_bit(ADF_STATUS_CONFIGURED, &accel_dev->status);
158 }
159
160
161
162
163
164
165
166
167
168
169
170 void adf_cfg_dev_remove(struct adf_accel_dev *accel_dev)
171 {
172 struct adf_cfg_device_data *dev_cfg_data = accel_dev->cfg;
173
174 if (!dev_cfg_data)
175 return;
176
177 down_write(&dev_cfg_data->lock);
178 adf_cfg_section_del_all(&dev_cfg_data->sec_list);
179 up_write(&dev_cfg_data->lock);
180 debugfs_remove(dev_cfg_data->debug);
181 kfree(dev_cfg_data);
182 accel_dev->cfg = NULL;
183 }
184 EXPORT_SYMBOL_GPL(adf_cfg_dev_remove);
185
186 static void adf_cfg_keyval_add(struct adf_cfg_key_val *new,
187 struct adf_cfg_section *sec)
188 {
189 list_add_tail(&new->list, &sec->param_head);
190 }
191
192 static void adf_cfg_keyval_del_all(struct list_head *head)
193 {
194 struct list_head *list_ptr, *tmp;
195
196 list_for_each_prev_safe(list_ptr, tmp, head) {
197 struct adf_cfg_key_val *ptr =
198 list_entry(list_ptr, struct adf_cfg_key_val, list);
199 list_del(list_ptr);
200 kfree(ptr);
201 }
202 }
203
204 static void adf_cfg_section_del_all(struct list_head *head)
205 {
206 struct adf_cfg_section *ptr;
207 struct list_head *list, *tmp;
208
209 list_for_each_prev_safe(list, tmp, head) {
210 ptr = list_entry(list, struct adf_cfg_section, list);
211 adf_cfg_keyval_del_all(&ptr->param_head);
212 list_del(list);
213 kfree(ptr);
214 }
215 }
216
217 static struct adf_cfg_key_val *adf_cfg_key_value_find(struct adf_cfg_section *s,
218 const char *key)
219 {
220 struct list_head *list;
221
222 list_for_each(list, &s->param_head) {
223 struct adf_cfg_key_val *ptr =
224 list_entry(list, struct adf_cfg_key_val, list);
225 if (!strcmp(ptr->key, key))
226 return ptr;
227 }
228 return NULL;
229 }
230
231 static struct adf_cfg_section *adf_cfg_sec_find(struct adf_accel_dev *accel_dev,
232 const char *sec_name)
233 {
234 struct adf_cfg_device_data *cfg = accel_dev->cfg;
235 struct list_head *list;
236
237 list_for_each(list, &cfg->sec_list) {
238 struct adf_cfg_section *ptr =
239 list_entry(list, struct adf_cfg_section, list);
240 if (!strcmp(ptr->name, sec_name))
241 return ptr;
242 }
243 return NULL;
244 }
245
246 static int adf_cfg_key_val_get(struct adf_accel_dev *accel_dev,
247 const char *sec_name,
248 const char *key_name,
249 char *val)
250 {
251 struct adf_cfg_section *sec = adf_cfg_sec_find(accel_dev, sec_name);
252 struct adf_cfg_key_val *keyval = NULL;
253
254 if (sec)
255 keyval = adf_cfg_key_value_find(sec, key_name);
256 if (keyval) {
257 memcpy(val, keyval->val, ADF_CFG_MAX_VAL_LEN_IN_BYTES);
258 return 0;
259 }
260 return -1;
261 }
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277 int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
278 const char *section_name,
279 const char *key, const void *val,
280 enum adf_cfg_val_type type)
281 {
282 struct adf_cfg_device_data *cfg = accel_dev->cfg;
283 struct adf_cfg_key_val *key_val;
284 struct adf_cfg_section *section = adf_cfg_sec_find(accel_dev,
285 section_name);
286 if (!section)
287 return -EFAULT;
288
289 key_val = kzalloc(sizeof(*key_val), GFP_KERNEL);
290 if (!key_val)
291 return -ENOMEM;
292
293 INIT_LIST_HEAD(&key_val->list);
294 strlcpy(key_val->key, key, sizeof(key_val->key));
295
296 if (type == ADF_DEC) {
297 snprintf(key_val->val, ADF_CFG_MAX_VAL_LEN_IN_BYTES,
298 "%ld", (*((long *)val)));
299 } else if (type == ADF_STR) {
300 strlcpy(key_val->val, (char *)val, sizeof(key_val->val));
301 } else if (type == ADF_HEX) {
302 snprintf(key_val->val, ADF_CFG_MAX_VAL_LEN_IN_BYTES,
303 "0x%lx", (unsigned long)val);
304 } else {
305 dev_err(&GET_DEV(accel_dev), "Unknown type given.\n");
306 kfree(key_val);
307 return -1;
308 }
309 key_val->type = type;
310 down_write(&cfg->lock);
311 adf_cfg_keyval_add(key_val, section);
312 up_write(&cfg->lock);
313 return 0;
314 }
315 EXPORT_SYMBOL_GPL(adf_cfg_add_key_value_param);
316
317
318
319
320
321
322
323
324
325
326
327
328 int adf_cfg_section_add(struct adf_accel_dev *accel_dev, const char *name)
329 {
330 struct adf_cfg_device_data *cfg = accel_dev->cfg;
331 struct adf_cfg_section *sec = adf_cfg_sec_find(accel_dev, name);
332
333 if (sec)
334 return 0;
335
336 sec = kzalloc(sizeof(*sec), GFP_KERNEL);
337 if (!sec)
338 return -ENOMEM;
339
340 strlcpy(sec->name, name, sizeof(sec->name));
341 INIT_LIST_HEAD(&sec->param_head);
342 down_write(&cfg->lock);
343 list_add_tail(&sec->list, &cfg->sec_list);
344 up_write(&cfg->lock);
345 return 0;
346 }
347 EXPORT_SYMBOL_GPL(adf_cfg_section_add);
348
349 int adf_cfg_get_param_value(struct adf_accel_dev *accel_dev,
350 const char *section, const char *name,
351 char *value)
352 {
353 struct adf_cfg_device_data *cfg = accel_dev->cfg;
354 int ret;
355
356 down_read(&cfg->lock);
357 ret = adf_cfg_key_val_get(accel_dev, section, name, value);
358 up_read(&cfg->lock);
359 return ret;
360 }