xref: /freebsd/sys/dev/qat/qat_common/adf_freebsd_ver_dbg.c (revision 3a3af6b2a160bea72509a9d5ef84e25906b0478a)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 #include "qat_freebsd.h"
5 #include "adf_cfg.h"
6 #include "adf_common_drv.h"
7 #include "adf_accel_devices.h"
8 #include "adf_ver_dbg.h"
9 
10 static int adf_sysctl_read_fw_versions(SYSCTL_HANDLER_ARGS)
11 {
12 	struct adf_accel_dev *accel_dev = arg1;
13 	char fw_version[ADF_CFG_MAX_VAL_LEN_IN_BYTES];
14 
15 	if (!accel_dev)
16 		return -EINVAL;
17 
18 	if (adf_dev_started(accel_dev))
19 		snprintf(fw_version,
20 			 ADF_CFG_MAX_VAL_LEN_IN_BYTES,
21 			 "%d.%d.%d",
22 			 accel_dev->fw_versions.fw_version_major,
23 			 accel_dev->fw_versions.fw_version_minor,
24 			 accel_dev->fw_versions.fw_version_patch);
25 	else
26 		snprintf(fw_version, ADF_CFG_MAX_VAL_LEN_IN_BYTES, "");
27 
28 	return SYSCTL_OUT(req,
29 			  fw_version,
30 			  strnlen(fw_version, ADF_CFG_MAX_VAL_LEN_IN_BYTES));
31 }
32 
33 static int adf_sysctl_read_hw_versions(SYSCTL_HANDLER_ARGS)
34 {
35 	struct adf_accel_dev *accel_dev = arg1;
36 	char hw_version[ADF_CFG_MAX_VAL_LEN_IN_BYTES];
37 
38 	if (!accel_dev)
39 		return -EINVAL;
40 
41 	if (adf_dev_started(accel_dev))
42 		snprintf(hw_version,
43 			 ADF_CFG_MAX_VAL_LEN_IN_BYTES,
44 			 "%d",
45 			 accel_dev->accel_pci_dev.revid);
46 	else
47 		snprintf(hw_version, ADF_CFG_MAX_VAL_LEN_IN_BYTES, "");
48 
49 	return SYSCTL_OUT(req,
50 			  hw_version,
51 			  strnlen(hw_version, ADF_CFG_MAX_VAL_LEN_IN_BYTES));
52 }
53 
54 static int adf_sysctl_read_mmp_versions(SYSCTL_HANDLER_ARGS)
55 {
56 	struct adf_accel_dev *accel_dev = arg1;
57 	char mmp_version[ADF_CFG_MAX_VAL_LEN_IN_BYTES];
58 
59 	if (!accel_dev)
60 		return -EINVAL;
61 
62 	if (adf_dev_started(accel_dev))
63 		snprintf(mmp_version,
64 			 ADF_CFG_MAX_VAL_LEN_IN_BYTES,
65 			 "%d.%d.%d",
66 			 accel_dev->fw_versions.mmp_version_major,
67 			 accel_dev->fw_versions.mmp_version_minor,
68 			 accel_dev->fw_versions.mmp_version_patch);
69 
70 	if (adf_dev_started(accel_dev))
71 		snprintf(mmp_version,
72 			 ADF_CFG_MAX_VAL_LEN_IN_BYTES,
73 			 "%d.%d.%d",
74 			 accel_dev->fw_versions.mmp_version_major,
75 			 accel_dev->fw_versions.mmp_version_minor,
76 			 accel_dev->fw_versions.mmp_version_patch);
77 	else
78 		snprintf(mmp_version, ADF_CFG_MAX_VAL_LEN_IN_BYTES, "");
79 
80 	return SYSCTL_OUT(req,
81 			  mmp_version,
82 			  strnlen(mmp_version, ADF_CFG_MAX_VAL_LEN_IN_BYTES));
83 }
84 
85 int
86 adf_ver_dbg_add(struct adf_accel_dev *accel_dev)
87 {
88 	struct sysctl_ctx_list *qat_sysctl_ctx;
89 	struct sysctl_oid *qat_sysctl_tree;
90 	struct sysctl_oid *rc = 0;
91 
92 	if (!accel_dev)
93 		return -EINVAL;
94 
95 	qat_sysctl_ctx =
96 	    device_get_sysctl_ctx(accel_dev->accel_pci_dev.pci_dev);
97 	qat_sysctl_tree =
98 	    device_get_sysctl_tree(accel_dev->accel_pci_dev.pci_dev);
99 
100 	rc = SYSCTL_ADD_OID(qat_sysctl_ctx,
101 			    SYSCTL_CHILDREN(qat_sysctl_tree),
102 			    OID_AUTO,
103 			    "fw_version",
104 			    CTLTYPE_STRING | CTLFLAG_RD,
105 			    accel_dev,
106 			    0,
107 			    adf_sysctl_read_fw_versions,
108 			    "A",
109 			    "QAT FW version");
110 	if (!rc)
111 		goto err;
112 
113 	rc = SYSCTL_ADD_OID(qat_sysctl_ctx,
114 			    SYSCTL_CHILDREN(qat_sysctl_tree),
115 			    OID_AUTO,
116 			    "hw_version",
117 			    CTLTYPE_STRING | CTLFLAG_RD,
118 			    accel_dev,
119 			    0,
120 			    adf_sysctl_read_hw_versions,
121 			    "A",
122 			    "QAT HW version");
123 	if (!rc)
124 		goto err;
125 
126 	rc = SYSCTL_ADD_OID(qat_sysctl_ctx,
127 			    SYSCTL_CHILDREN(qat_sysctl_tree),
128 			    OID_AUTO,
129 			    "mmp_version",
130 			    CTLTYPE_STRING | CTLFLAG_RD,
131 			    accel_dev,
132 			    0,
133 			    adf_sysctl_read_mmp_versions,
134 			    "A",
135 			    "QAT MMP version");
136 	if (!rc)
137 		goto err;
138 
139 	return 0;
140 err:
141 	device_printf(GET_DEV(accel_dev),
142 		      "Failed to add firmware versions to sysctl\n");
143 	return -EINVAL;
144 }
145 
146 void
147 adf_ver_dbg_del(struct adf_accel_dev *accel_dev)
148 {
149 }
150