sysfs.c (4a95857a875e887cc958c92fe9d2cde6184d2ec0) | sysfs.c (8e50d392652f20616a136165dff516b86baf5e49) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright(c) 2019 Intel Corporation. All rights rsvd. */ 3#include <linux/init.h> 4#include <linux/kernel.h> 5#include <linux/module.h> 6#include <linux/pci.h> 7#include <linux/device.h> 8#include <linux/io-64-nonatomic-lo-hi.h> --- 161 unchanged lines hidden (view full) --- 170 } 171 172 if (strlen(wq->name) == 0) { 173 mutex_unlock(&wq->wq_lock); 174 dev_warn(dev, "WQ name not set.\n"); 175 return -EINVAL; 176 } 177 | 1// SPDX-License-Identifier: GPL-2.0 2/* Copyright(c) 2019 Intel Corporation. All rights rsvd. */ 3#include <linux/init.h> 4#include <linux/kernel.h> 5#include <linux/module.h> 6#include <linux/pci.h> 7#include <linux/device.h> 8#include <linux/io-64-nonatomic-lo-hi.h> --- 161 unchanged lines hidden (view full) --- 170 } 171 172 if (strlen(wq->name) == 0) { 173 mutex_unlock(&wq->wq_lock); 174 dev_warn(dev, "WQ name not set.\n"); 175 return -EINVAL; 176 } 177 |
178 /* Shared WQ checks */ 179 if (wq_shared(wq)) { 180 if (!device_swq_supported(idxd)) { 181 dev_warn(dev, 182 "PASID not enabled and shared WQ.\n"); 183 mutex_unlock(&wq->wq_lock); 184 return -ENXIO; 185 } 186 /* 187 * Shared wq with the threshold set to 0 means the user 188 * did not set the threshold or transitioned from a 189 * dedicated wq but did not set threshold. A value 190 * of 0 would effectively disable the shared wq. The 191 * driver does not allow a value of 0 to be set for 192 * threshold via sysfs. 193 */ 194 if (wq->threshold == 0) { 195 dev_warn(dev, 196 "Shared WQ and threshold 0.\n"); 197 mutex_unlock(&wq->wq_lock); 198 return -EINVAL; 199 } 200 } 201 |
|
178 rc = idxd_wq_alloc_resources(wq); 179 if (rc < 0) { 180 mutex_unlock(&wq->wq_lock); 181 dev_warn(dev, "WQ resource alloc failed\n"); 182 return rc; 183 } 184 185 spin_lock_irqsave(&idxd->dev_lock, flags); --- 684 unchanged lines hidden (view full) --- 870 return -EPERM; 871 872 if (wq->state != IDXD_WQ_DISABLED) 873 return -EPERM; 874 875 if (sysfs_streq(buf, "dedicated")) { 876 set_bit(WQ_FLAG_DEDICATED, &wq->flags); 877 wq->threshold = 0; | 202 rc = idxd_wq_alloc_resources(wq); 203 if (rc < 0) { 204 mutex_unlock(&wq->wq_lock); 205 dev_warn(dev, "WQ resource alloc failed\n"); 206 return rc; 207 } 208 209 spin_lock_irqsave(&idxd->dev_lock, flags); --- 684 unchanged lines hidden (view full) --- 894 return -EPERM; 895 896 if (wq->state != IDXD_WQ_DISABLED) 897 return -EPERM; 898 899 if (sysfs_streq(buf, "dedicated")) { 900 set_bit(WQ_FLAG_DEDICATED, &wq->flags); 901 wq->threshold = 0; |
902 } else if (sysfs_streq(buf, "shared") && device_swq_supported(idxd)) { 903 clear_bit(WQ_FLAG_DEDICATED, &wq->flags); |
|
878 } else { 879 return -EINVAL; 880 } 881 882 return count; 883} 884 885static struct device_attribute dev_attr_wq_mode = --- 82 unchanged lines hidden (view full) --- 968 969 wq->priority = prio; 970 return count; 971} 972 973static struct device_attribute dev_attr_wq_priority = 974 __ATTR(priority, 0644, wq_priority_show, wq_priority_store); 975 | 904 } else { 905 return -EINVAL; 906 } 907 908 return count; 909} 910 911static struct device_attribute dev_attr_wq_mode = --- 82 unchanged lines hidden (view full) --- 994 995 wq->priority = prio; 996 return count; 997} 998 999static struct device_attribute dev_attr_wq_priority = 1000 __ATTR(priority, 0644, wq_priority_show, wq_priority_store); 1001 |
1002static ssize_t wq_block_on_fault_show(struct device *dev, 1003 struct device_attribute *attr, char *buf) 1004{ 1005 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 1006 1007 return sprintf(buf, "%u\n", 1008 test_bit(WQ_FLAG_BLOCK_ON_FAULT, &wq->flags)); 1009} 1010 1011static ssize_t wq_block_on_fault_store(struct device *dev, 1012 struct device_attribute *attr, 1013 const char *buf, size_t count) 1014{ 1015 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 1016 struct idxd_device *idxd = wq->idxd; 1017 bool bof; 1018 int rc; 1019 1020 if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) 1021 return -EPERM; 1022 1023 if (wq->state != IDXD_WQ_DISABLED) 1024 return -ENXIO; 1025 1026 rc = kstrtobool(buf, &bof); 1027 if (rc < 0) 1028 return rc; 1029 1030 if (bof) 1031 set_bit(WQ_FLAG_BLOCK_ON_FAULT, &wq->flags); 1032 else 1033 clear_bit(WQ_FLAG_BLOCK_ON_FAULT, &wq->flags); 1034 1035 return count; 1036} 1037 1038static struct device_attribute dev_attr_wq_block_on_fault = 1039 __ATTR(block_on_fault, 0644, wq_block_on_fault_show, 1040 wq_block_on_fault_store); 1041 1042static ssize_t wq_threshold_show(struct device *dev, 1043 struct device_attribute *attr, char *buf) 1044{ 1045 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 1046 1047 return sprintf(buf, "%u\n", wq->threshold); 1048} 1049 1050static ssize_t wq_threshold_store(struct device *dev, 1051 struct device_attribute *attr, 1052 const char *buf, size_t count) 1053{ 1054 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 1055 struct idxd_device *idxd = wq->idxd; 1056 unsigned int val; 1057 int rc; 1058 1059 rc = kstrtouint(buf, 0, &val); 1060 if (rc < 0) 1061 return -EINVAL; 1062 1063 if (val > wq->size || val <= 0) 1064 return -EINVAL; 1065 1066 if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) 1067 return -EPERM; 1068 1069 if (wq->state != IDXD_WQ_DISABLED) 1070 return -ENXIO; 1071 1072 if (test_bit(WQ_FLAG_DEDICATED, &wq->flags)) 1073 return -EINVAL; 1074 1075 wq->threshold = val; 1076 1077 return count; 1078} 1079 1080static struct device_attribute dev_attr_wq_threshold = 1081 __ATTR(threshold, 0644, wq_threshold_show, wq_threshold_store); 1082 |
|
976static ssize_t wq_type_show(struct device *dev, 977 struct device_attribute *attr, char *buf) 978{ 979 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 980 981 switch (wq->type) { 982 case IDXD_WQT_KERNEL: 983 return sprintf(buf, "%s\n", --- 55 unchanged lines hidden (view full) --- 1039 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 1040 1041 if (wq->state != IDXD_WQ_DISABLED) 1042 return -EPERM; 1043 1044 if (strlen(buf) > WQ_NAME_SIZE || strlen(buf) == 0) 1045 return -EINVAL; 1046 | 1083static ssize_t wq_type_show(struct device *dev, 1084 struct device_attribute *attr, char *buf) 1085{ 1086 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 1087 1088 switch (wq->type) { 1089 case IDXD_WQT_KERNEL: 1090 return sprintf(buf, "%s\n", --- 55 unchanged lines hidden (view full) --- 1146 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 1147 1148 if (wq->state != IDXD_WQ_DISABLED) 1149 return -EPERM; 1150 1151 if (strlen(buf) > WQ_NAME_SIZE || strlen(buf) == 0) 1152 return -EINVAL; 1153 |
1154 /* 1155 * This is temporarily placed here until we have SVM support for 1156 * dmaengine. 1157 */ 1158 if (wq->type == IDXD_WQT_KERNEL && device_pasid_enabled(wq->idxd)) 1159 return -EOPNOTSUPP; 1160 |
|
1047 memset(wq->name, 0, WQ_NAME_SIZE + 1); 1048 strncpy(wq->name, buf, WQ_NAME_SIZE); 1049 strreplace(wq->name, '\n', '\0'); 1050 return count; 1051} 1052 1053static struct device_attribute dev_attr_wq_name = 1054 __ATTR(name, 0644, wq_name_show, wq_name_store); --- 94 unchanged lines hidden (view full) --- 1149 1150static struct attribute *idxd_wq_attributes[] = { 1151 &dev_attr_wq_clients.attr, 1152 &dev_attr_wq_state.attr, 1153 &dev_attr_wq_group_id.attr, 1154 &dev_attr_wq_mode.attr, 1155 &dev_attr_wq_size.attr, 1156 &dev_attr_wq_priority.attr, | 1161 memset(wq->name, 0, WQ_NAME_SIZE + 1); 1162 strncpy(wq->name, buf, WQ_NAME_SIZE); 1163 strreplace(wq->name, '\n', '\0'); 1164 return count; 1165} 1166 1167static struct device_attribute dev_attr_wq_name = 1168 __ATTR(name, 0644, wq_name_show, wq_name_store); --- 94 unchanged lines hidden (view full) --- 1263 1264static struct attribute *idxd_wq_attributes[] = { 1265 &dev_attr_wq_clients.attr, 1266 &dev_attr_wq_state.attr, 1267 &dev_attr_wq_group_id.attr, 1268 &dev_attr_wq_mode.attr, 1269 &dev_attr_wq_size.attr, 1270 &dev_attr_wq_priority.attr, |
1271 &dev_attr_wq_block_on_fault.attr, 1272 &dev_attr_wq_threshold.attr, |
|
1157 &dev_attr_wq_type.attr, 1158 &dev_attr_wq_name.attr, 1159 &dev_attr_wq_cdev_minor.attr, 1160 &dev_attr_wq_max_transfer_size.attr, 1161 &dev_attr_wq_max_batch_size.attr, 1162 NULL, 1163}; 1164 --- 135 unchanged lines hidden (view full) --- 1300 count += wq->client_count; 1301 } 1302 spin_unlock_irqrestore(&idxd->dev_lock, flags); 1303 1304 return sprintf(buf, "%d\n", count); 1305} 1306static DEVICE_ATTR_RO(clients); 1307 | 1273 &dev_attr_wq_type.attr, 1274 &dev_attr_wq_name.attr, 1275 &dev_attr_wq_cdev_minor.attr, 1276 &dev_attr_wq_max_transfer_size.attr, 1277 &dev_attr_wq_max_batch_size.attr, 1278 NULL, 1279}; 1280 --- 135 unchanged lines hidden (view full) --- 1416 count += wq->client_count; 1417 } 1418 spin_unlock_irqrestore(&idxd->dev_lock, flags); 1419 1420 return sprintf(buf, "%d\n", count); 1421} 1422static DEVICE_ATTR_RO(clients); 1423 |
1424static ssize_t pasid_enabled_show(struct device *dev, 1425 struct device_attribute *attr, char *buf) 1426{ 1427 struct idxd_device *idxd = 1428 container_of(dev, struct idxd_device, conf_dev); 1429 1430 return sprintf(buf, "%u\n", device_pasid_enabled(idxd)); 1431} 1432static DEVICE_ATTR_RO(pasid_enabled); 1433 |
|
1308static ssize_t state_show(struct device *dev, 1309 struct device_attribute *attr, char *buf) 1310{ 1311 struct idxd_device *idxd = 1312 container_of(dev, struct idxd_device, conf_dev); 1313 1314 switch (idxd->state) { 1315 case IDXD_DEV_DISABLED: --- 103 unchanged lines hidden (view full) --- 1419 &dev_attr_max_engines.attr, 1420 &dev_attr_numa_node.attr, 1421 &dev_attr_max_batch_size.attr, 1422 &dev_attr_max_transfer_size.attr, 1423 &dev_attr_op_cap.attr, 1424 &dev_attr_gen_cap.attr, 1425 &dev_attr_configurable.attr, 1426 &dev_attr_clients.attr, | 1434static ssize_t state_show(struct device *dev, 1435 struct device_attribute *attr, char *buf) 1436{ 1437 struct idxd_device *idxd = 1438 container_of(dev, struct idxd_device, conf_dev); 1439 1440 switch (idxd->state) { 1441 case IDXD_DEV_DISABLED: --- 103 unchanged lines hidden (view full) --- 1545 &dev_attr_max_engines.attr, 1546 &dev_attr_numa_node.attr, 1547 &dev_attr_max_batch_size.attr, 1548 &dev_attr_max_transfer_size.attr, 1549 &dev_attr_op_cap.attr, 1550 &dev_attr_gen_cap.attr, 1551 &dev_attr_configurable.attr, 1552 &dev_attr_clients.attr, |
1553 &dev_attr_pasid_enabled.attr, |
|
1427 &dev_attr_state.attr, 1428 &dev_attr_errors.attr, 1429 &dev_attr_max_tokens.attr, 1430 &dev_attr_token_limit.attr, 1431 &dev_attr_cdev_major.attr, 1432 &dev_attr_cmd_status.attr, 1433 NULL, 1434}; --- 219 unchanged lines hidden --- | 1554 &dev_attr_state.attr, 1555 &dev_attr_errors.attr, 1556 &dev_attr_max_tokens.attr, 1557 &dev_attr_token_limit.attr, 1558 &dev_attr_cdev_major.attr, 1559 &dev_attr_cmd_status.attr, 1560 NULL, 1561}; --- 219 unchanged lines hidden --- |