xref: /freebsd/sys/dev/qat/qat_common/adf_freebsd_cfg_dev_dbg.c (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 #include "qat_freebsd.h"
4 #include "adf_common_drv.h"
5 #include "adf_cfg_device.h"
6 #include "adf_cfg_dev_dbg.h"
7 #include <sys/bus.h>
8 #include <sys/libkern.h>
9 #include <sys/lock.h>
10 #include <sys/kernel.h>
11 #include <sys/sbuf.h>
12 #include <sys/sx.h>
13 #include <sys/systm.h>
14 #include <sys/malloc.h>
15 
qat_dev_cfg_show(SYSCTL_HANDLER_ARGS)16 static int qat_dev_cfg_show(SYSCTL_HANDLER_ARGS)
17 {
18 	struct adf_cfg_device_data *dev_cfg;
19 	struct adf_cfg_section *sec;
20 	struct adf_cfg_key_val *ptr;
21 	struct sbuf sb;
22 	int error;
23 
24 	sbuf_new_for_sysctl(&sb, NULL, 128, req);
25 	dev_cfg = arg1;
26 	sx_slock(&dev_cfg->lock);
27 	list_for_each_entry(sec, &dev_cfg->sec_list, list)
28 	{
29 		sbuf_printf(&sb, "[%s]\n", sec->name);
30 		list_for_each_entry(ptr, &sec->param_head, list)
31 		{
32 			sbuf_printf(&sb, "%s = %s\n", ptr->key, ptr->val);
33 		}
34 	}
35 	sx_sunlock(&dev_cfg->lock);
36 	error = sbuf_finish(&sb);
37 	sbuf_delete(&sb);
38 	return error;
39 }
40 
41 int
adf_cfg_dev_dbg_add(struct adf_accel_dev * accel_dev)42 adf_cfg_dev_dbg_add(struct adf_accel_dev *accel_dev)
43 {
44 	struct adf_cfg_device_data *dev_cfg_data = accel_dev->cfg;
45 	device_t dev;
46 
47 	dev = GET_DEV(accel_dev);
48 	dev_cfg_data->debug =
49 	    SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
50 			    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
51 			    OID_AUTO,
52 			    "dev_cfg",
53 			    CTLFLAG_RD | CTLTYPE_STRING,
54 			    dev_cfg_data,
55 			    0,
56 			    qat_dev_cfg_show,
57 			    "A",
58 			    "Device configuration");
59 
60 	if (!dev_cfg_data->debug) {
61 		device_printf(dev, "Failed to create qat cfg sysctl.\n");
62 		return ENXIO;
63 	}
64 	return 0;
65 }
66 
67 void
adf_cfg_dev_dbg_remove(struct adf_accel_dev * accel_dev)68 adf_cfg_dev_dbg_remove(struct adf_accel_dev *accel_dev)
69 {
70 	struct adf_cfg_device_data *dev_cfg_data = accel_dev->cfg;
71 
72 	if (dev_cfg_data->dev) {
73 		adf_cfg_device_clear(dev_cfg_data->dev, accel_dev);
74 		free(dev_cfg_data->dev, M_QAT);
75 		dev_cfg_data->dev = NULL;
76 	}
77 }
78