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