1 // SPDX-License-Identifier: GPL-2.0-only 2 /* Copyright(c) 2026 Intel Corporation */ 3 #include <linux/sysfs.h> 4 #include <linux/types.h> 5 6 #include "adf_anti_rb.h" 7 #include "adf_common_drv.h" 8 #include "adf_sysfs_anti_rb.h" 9 10 static ssize_t enforced_min_show(struct device *dev, struct device_attribute *attr, 11 char *buf) 12 { 13 struct adf_accel_dev *accel_dev; 14 int err; 15 u8 svn; 16 17 accel_dev = adf_devmgr_pci_to_accel_dev(to_pci_dev(dev)); 18 if (!accel_dev) 19 return -EINVAL; 20 21 err = adf_anti_rb_query(accel_dev, ARB_ENFORCED_MIN_SVN, &svn); 22 if (err) 23 return err; 24 25 return sysfs_emit(buf, "%u\n", svn); 26 } 27 static DEVICE_ATTR_RO(enforced_min); 28 29 static ssize_t active_show(struct device *dev, struct device_attribute *attr, 30 char *buf) 31 { 32 struct adf_accel_dev *accel_dev; 33 int err; 34 u8 svn; 35 36 accel_dev = adf_devmgr_pci_to_accel_dev(to_pci_dev(dev)); 37 if (!accel_dev) 38 return -EINVAL; 39 40 err = adf_anti_rb_query(accel_dev, ARB_ACTIVE_SVN, &svn); 41 if (err) 42 return err; 43 44 return sysfs_emit(buf, "%u\n", svn); 45 } 46 static DEVICE_ATTR_RO(active); 47 48 static ssize_t permanent_min_show(struct device *dev, struct device_attribute *attr, 49 char *buf) 50 { 51 struct adf_accel_dev *accel_dev; 52 int err; 53 u8 svn; 54 55 accel_dev = adf_devmgr_pci_to_accel_dev(to_pci_dev(dev)); 56 if (!accel_dev) 57 return -EINVAL; 58 59 err = adf_anti_rb_query(accel_dev, ARB_PERMANENT_MIN_SVN, &svn); 60 if (err) 61 return err; 62 63 return sysfs_emit(buf, "%u\n", svn); 64 } 65 static DEVICE_ATTR_RO(permanent_min); 66 67 static ssize_t commit_store(struct device *dev, struct device_attribute *attr, 68 const char *buf, size_t count) 69 { 70 struct adf_accel_dev *accel_dev; 71 bool val; 72 int err; 73 74 accel_dev = adf_devmgr_pci_to_accel_dev(to_pci_dev(dev)); 75 if (!accel_dev) 76 return -EINVAL; 77 78 err = kstrtobool(buf, &val); 79 if (err) 80 return err; 81 82 if (!val) 83 return -EINVAL; 84 85 err = adf_anti_rb_commit(accel_dev); 86 if (err) 87 return err; 88 89 return count; 90 } 91 static DEVICE_ATTR_WO(commit); 92 93 static struct attribute *qat_svn_attrs[] = { 94 &dev_attr_commit.attr, 95 &dev_attr_active.attr, 96 &dev_attr_enforced_min.attr, 97 &dev_attr_permanent_min.attr, 98 NULL 99 }; 100 101 static const struct attribute_group qat_svn_group = { 102 .attrs = qat_svn_attrs, 103 .name = "qat_svn", 104 }; 105 106 void adf_sysfs_start_arb(struct adf_accel_dev *accel_dev) 107 { 108 struct adf_anti_rb_hw_data *anti_rb = GET_ANTI_RB_DATA(accel_dev); 109 110 if (!anti_rb->anti_rb_enabled || !anti_rb->anti_rb_enabled(accel_dev)) 111 return; 112 113 if (device_add_group(&GET_DEV(accel_dev), &qat_svn_group)) { 114 dev_warn(&GET_DEV(accel_dev), 115 "Failed to create qat_svn attribute group\n"); 116 return; 117 } 118 119 anti_rb->sysfs_added = true; 120 } 121 122 void adf_sysfs_stop_arb(struct adf_accel_dev *accel_dev) 123 { 124 struct adf_anti_rb_hw_data *anti_rb = GET_ANTI_RB_DATA(accel_dev); 125 126 if (!anti_rb->sysfs_added) 127 return; 128 129 device_remove_group(&GET_DEV(accel_dev), &qat_svn_group); 130 131 anti_rb->sysfs_added = false; 132 anti_rb->svncheck_retry = 0; 133 } 134