sysfs.c (8f47d1a5e545f903cd049c42da31a3be36178447) | sysfs.c (42d279f9137ab7d5503836baec2739284b278d8f) |
---|---|
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> 9#include <uapi/linux/idxd.h> 10#include "registers.h" 11#include "idxd.h" 12 13static char *idxd_wq_type_names[] = { 14 [IDXD_WQT_NONE] = "none", 15 [IDXD_WQT_KERNEL] = "kernel", | 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> 9#include <uapi/linux/idxd.h> 10#include "registers.h" 11#include "idxd.h" 12 13static char *idxd_wq_type_names[] = { 14 [IDXD_WQT_NONE] = "none", 15 [IDXD_WQT_KERNEL] = "kernel", |
16 [IDXD_WQT_USER] = "user", |
|
16}; 17 18static void idxd_conf_device_release(struct device *dev) 19{ 20 dev_dbg(dev, "%s for %s\n", __func__, dev_name(dev)); 21} 22 23static struct device_type idxd_group_device_type = { --- 34 unchanged lines hidden (view full) --- 58static inline bool is_idxd_wq_dmaengine(struct idxd_wq *wq) 59{ 60 if (wq->type == IDXD_WQT_KERNEL && 61 strcmp(wq->name, "dmaengine") == 0) 62 return true; 63 return false; 64} 65 | 17}; 18 19static void idxd_conf_device_release(struct device *dev) 20{ 21 dev_dbg(dev, "%s for %s\n", __func__, dev_name(dev)); 22} 23 24static struct device_type idxd_group_device_type = { --- 34 unchanged lines hidden (view full) --- 59static inline bool is_idxd_wq_dmaengine(struct idxd_wq *wq) 60{ 61 if (wq->type == IDXD_WQT_KERNEL && 62 strcmp(wq->name, "dmaengine") == 0) 63 return true; 64 return false; 65} 66 |
67static inline bool is_idxd_wq_cdev(struct idxd_wq *wq) 68{ 69 return wq->type == IDXD_WQT_USER ? true : false; 70} 71 |
|
66static int idxd_config_bus_match(struct device *dev, 67 struct device_driver *drv) 68{ 69 int matched = 0; 70 71 if (is_idxd_dev(dev)) { 72 struct idxd_device *idxd = confdev_to_idxd(dev); 73 --- 30 unchanged lines hidden (view full) --- 104 if (is_idxd_dev(dev)) { 105 struct idxd_device *idxd = confdev_to_idxd(dev); 106 107 if (idxd->state != IDXD_DEV_CONF_READY) { 108 dev_warn(dev, "Device not ready for config\n"); 109 return -EBUSY; 110 } 111 | 72static int idxd_config_bus_match(struct device *dev, 73 struct device_driver *drv) 74{ 75 int matched = 0; 76 77 if (is_idxd_dev(dev)) { 78 struct idxd_device *idxd = confdev_to_idxd(dev); 79 --- 30 unchanged lines hidden (view full) --- 110 if (is_idxd_dev(dev)) { 111 struct idxd_device *idxd = confdev_to_idxd(dev); 112 113 if (idxd->state != IDXD_DEV_CONF_READY) { 114 dev_warn(dev, "Device not ready for config\n"); 115 return -EBUSY; 116 } 117 |
118 if (!try_module_get(THIS_MODULE)) 119 return -ENXIO; 120 |
|
112 spin_lock_irqsave(&idxd->dev_lock, flags); 113 114 /* Perform IDXD configuration and enabling */ 115 rc = idxd_device_config(idxd); 116 if (rc < 0) { 117 spin_unlock_irqrestore(&idxd->dev_lock, flags); 118 dev_warn(dev, "Device config failed: %d\n", rc); 119 return rc; --- 91 unchanged lines hidden (view full) --- 211 212 if (is_idxd_wq_dmaengine(wq)) { 213 rc = idxd_register_dma_channel(wq); 214 if (rc < 0) { 215 dev_dbg(dev, "DMA channel register failed\n"); 216 mutex_unlock(&wq->wq_lock); 217 return rc; 218 } | 121 spin_lock_irqsave(&idxd->dev_lock, flags); 122 123 /* Perform IDXD configuration and enabling */ 124 rc = idxd_device_config(idxd); 125 if (rc < 0) { 126 spin_unlock_irqrestore(&idxd->dev_lock, flags); 127 dev_warn(dev, "Device config failed: %d\n", rc); 128 return rc; --- 91 unchanged lines hidden (view full) --- 220 221 if (is_idxd_wq_dmaengine(wq)) { 222 rc = idxd_register_dma_channel(wq); 223 if (rc < 0) { 224 dev_dbg(dev, "DMA channel register failed\n"); 225 mutex_unlock(&wq->wq_lock); 226 return rc; 227 } |
228 } else if (is_idxd_wq_cdev(wq)) { 229 rc = idxd_wq_add_cdev(wq); 230 if (rc < 0) { 231 dev_dbg(dev, "Cdev creation failed\n"); 232 mutex_unlock(&wq->wq_lock); 233 return rc; 234 } |
|
219 } 220 221 mutex_unlock(&wq->wq_lock); 222 return 0; 223 } 224 225 return -ENODEV; 226} --- 9 unchanged lines hidden (view full) --- 236 dev_dbg(dev, "%s removing WQ %s\n", __func__, dev_name(&wq->conf_dev)); 237 if (wq->state == IDXD_WQ_DISABLED) { 238 mutex_unlock(&wq->wq_lock); 239 return; 240 } 241 242 if (is_idxd_wq_dmaengine(wq)) 243 idxd_unregister_dma_channel(wq); | 235 } 236 237 mutex_unlock(&wq->wq_lock); 238 return 0; 239 } 240 241 return -ENODEV; 242} --- 9 unchanged lines hidden (view full) --- 252 dev_dbg(dev, "%s removing WQ %s\n", __func__, dev_name(&wq->conf_dev)); 253 if (wq->state == IDXD_WQ_DISABLED) { 254 mutex_unlock(&wq->wq_lock); 255 return; 256 } 257 258 if (is_idxd_wq_dmaengine(wq)) 259 idxd_unregister_dma_channel(wq); |
260 else if (is_idxd_wq_cdev(wq)) 261 idxd_wq_del_cdev(wq); |
|
244 245 if (idxd_wq_refcount(wq)) 246 dev_warn(dev, "Clients has claim on wq %d: %d\n", 247 wq->id, idxd_wq_refcount(wq)); 248 249 idxd_wq_unmap_portal(wq); 250 251 spin_lock_irqsave(&idxd->dev_lock, flags); --- 38 unchanged lines hidden (view full) --- 290 dev_name(&idxd->conf_dev)); 291 device_release_driver(&wq->conf_dev); 292 } 293 294 idxd_unregister_dma_device(idxd); 295 spin_lock_irqsave(&idxd->dev_lock, flags); 296 rc = idxd_device_disable(idxd); 297 spin_unlock_irqrestore(&idxd->dev_lock, flags); | 262 263 if (idxd_wq_refcount(wq)) 264 dev_warn(dev, "Clients has claim on wq %d: %d\n", 265 wq->id, idxd_wq_refcount(wq)); 266 267 idxd_wq_unmap_portal(wq); 268 269 spin_lock_irqsave(&idxd->dev_lock, flags); --- 38 unchanged lines hidden (view full) --- 308 dev_name(&idxd->conf_dev)); 309 device_release_driver(&wq->conf_dev); 310 } 311 312 idxd_unregister_dma_device(idxd); 313 spin_lock_irqsave(&idxd->dev_lock, flags); 314 rc = idxd_device_disable(idxd); 315 spin_unlock_irqrestore(&idxd->dev_lock, flags); |
316 module_put(THIS_MODULE); |
|
298 if (rc < 0) 299 dev_warn(dev, "Device disable failed\n"); 300 else 301 dev_info(dev, "Device %s disabled\n", dev_name(dev)); | 317 if (rc < 0) 318 dev_warn(dev, "Device disable failed\n"); 319 else 320 dev_info(dev, "Device %s disabled\n", dev_name(dev)); |
321 |
|
302 } 303 304 return 0; 305} 306 307static void idxd_config_bus_shutdown(struct device *dev) 308{ 309 dev_dbg(dev, "%s called\n", __func__); 310} 311 | 322 } 323 324 return 0; 325} 326 327static void idxd_config_bus_shutdown(struct device *dev) 328{ 329 dev_dbg(dev, "%s called\n", __func__); 330} 331 |
312static struct bus_type dsa_bus_type = { | 332struct bus_type dsa_bus_type = { |
313 .name = "dsa", 314 .match = idxd_config_bus_match, 315 .probe = idxd_config_bus_probe, 316 .remove = idxd_config_bus_remove, 317 .shutdown = idxd_config_bus_shutdown, 318}; 319 320static struct bus_type *idxd_bus_types[] = { --- 8 unchanged lines hidden (view full) --- 329 .mod_name = KBUILD_MODNAME, 330 }, 331}; 332 333static struct idxd_device_driver *idxd_drvs[] = { 334 &dsa_drv 335}; 336 | 333 .name = "dsa", 334 .match = idxd_config_bus_match, 335 .probe = idxd_config_bus_probe, 336 .remove = idxd_config_bus_remove, 337 .shutdown = idxd_config_bus_shutdown, 338}; 339 340static struct bus_type *idxd_bus_types[] = { --- 8 unchanged lines hidden (view full) --- 349 .mod_name = KBUILD_MODNAME, 350 }, 351}; 352 353static struct idxd_device_driver *idxd_drvs[] = { 354 &dsa_drv 355}; 356 |
337static struct bus_type *idxd_get_bus_type(struct idxd_device *idxd) | 357struct bus_type *idxd_get_bus_type(struct idxd_device *idxd) |
338{ 339 return idxd_bus_types[idxd->type]; 340} 341 342static struct device_type *idxd_get_device_type(struct idxd_device *idxd) 343{ 344 if (idxd->type == IDXD_TYPE_DSA) 345 return &dsa_device_type; --- 605 unchanged lines hidden (view full) --- 951 struct device_attribute *attr, char *buf) 952{ 953 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 954 955 switch (wq->type) { 956 case IDXD_WQT_KERNEL: 957 return sprintf(buf, "%s\n", 958 idxd_wq_type_names[IDXD_WQT_KERNEL]); | 358{ 359 return idxd_bus_types[idxd->type]; 360} 361 362static struct device_type *idxd_get_device_type(struct idxd_device *idxd) 363{ 364 if (idxd->type == IDXD_TYPE_DSA) 365 return &dsa_device_type; --- 605 unchanged lines hidden (view full) --- 971 struct device_attribute *attr, char *buf) 972{ 973 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 974 975 switch (wq->type) { 976 case IDXD_WQT_KERNEL: 977 return sprintf(buf, "%s\n", 978 idxd_wq_type_names[IDXD_WQT_KERNEL]); |
979 case IDXD_WQT_USER: 980 return sprintf(buf, "%s\n", 981 idxd_wq_type_names[IDXD_WQT_USER]); |
|
959 case IDXD_WQT_NONE: 960 default: 961 return sprintf(buf, "%s\n", 962 idxd_wq_type_names[IDXD_WQT_NONE]); 963 } 964 965 return -EINVAL; 966} --- 6 unchanged lines hidden (view full) --- 973 enum idxd_wq_type old_type; 974 975 if (wq->state != IDXD_WQ_DISABLED) 976 return -EPERM; 977 978 old_type = wq->type; 979 if (sysfs_streq(buf, idxd_wq_type_names[IDXD_WQT_KERNEL])) 980 wq->type = IDXD_WQT_KERNEL; | 982 case IDXD_WQT_NONE: 983 default: 984 return sprintf(buf, "%s\n", 985 idxd_wq_type_names[IDXD_WQT_NONE]); 986 } 987 988 return -EINVAL; 989} --- 6 unchanged lines hidden (view full) --- 996 enum idxd_wq_type old_type; 997 998 if (wq->state != IDXD_WQ_DISABLED) 999 return -EPERM; 1000 1001 old_type = wq->type; 1002 if (sysfs_streq(buf, idxd_wq_type_names[IDXD_WQT_KERNEL])) 1003 wq->type = IDXD_WQT_KERNEL; |
1004 else if (sysfs_streq(buf, idxd_wq_type_names[IDXD_WQT_USER])) 1005 wq->type = IDXD_WQT_USER; |
|
981 else 982 wq->type = IDXD_WQT_NONE; 983 984 /* If we are changing queue type, clear the name */ 985 if (wq->type != old_type) 986 memset(wq->name, 0, WQ_NAME_SIZE + 1); 987 988 return count; --- 26 unchanged lines hidden (view full) --- 1015 strncpy(wq->name, buf, WQ_NAME_SIZE); 1016 strreplace(wq->name, '\n', '\0'); 1017 return count; 1018} 1019 1020static struct device_attribute dev_attr_wq_name = 1021 __ATTR(name, 0644, wq_name_show, wq_name_store); 1022 | 1006 else 1007 wq->type = IDXD_WQT_NONE; 1008 1009 /* If we are changing queue type, clear the name */ 1010 if (wq->type != old_type) 1011 memset(wq->name, 0, WQ_NAME_SIZE + 1); 1012 1013 return count; --- 26 unchanged lines hidden (view full) --- 1040 strncpy(wq->name, buf, WQ_NAME_SIZE); 1041 strreplace(wq->name, '\n', '\0'); 1042 return count; 1043} 1044 1045static struct device_attribute dev_attr_wq_name = 1046 __ATTR(name, 0644, wq_name_show, wq_name_store); 1047 |
1048static ssize_t wq_cdev_minor_show(struct device *dev, 1049 struct device_attribute *attr, char *buf) 1050{ 1051 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev); 1052 1053 return sprintf(buf, "%d\n", wq->idxd_cdev.minor); 1054} 1055 1056static struct device_attribute dev_attr_wq_cdev_minor = 1057 __ATTR(cdev_minor, 0444, wq_cdev_minor_show, NULL); 1058 |
|
1023static struct attribute *idxd_wq_attributes[] = { 1024 &dev_attr_wq_clients.attr, 1025 &dev_attr_wq_state.attr, 1026 &dev_attr_wq_group_id.attr, 1027 &dev_attr_wq_mode.attr, 1028 &dev_attr_wq_size.attr, 1029 &dev_attr_wq_priority.attr, 1030 &dev_attr_wq_type.attr, 1031 &dev_attr_wq_name.attr, | 1059static struct attribute *idxd_wq_attributes[] = { 1060 &dev_attr_wq_clients.attr, 1061 &dev_attr_wq_state.attr, 1062 &dev_attr_wq_group_id.attr, 1063 &dev_attr_wq_mode.attr, 1064 &dev_attr_wq_size.attr, 1065 &dev_attr_wq_priority.attr, 1066 &dev_attr_wq_type.attr, 1067 &dev_attr_wq_name.attr, |
1068 &dev_attr_wq_cdev_minor.attr, |
|
1032 NULL, 1033}; 1034 1035static const struct attribute_group idxd_wq_attribute_group = { 1036 .attrs = idxd_wq_attributes, 1037}; 1038 1039static const struct attribute_group *idxd_wq_attribute_groups[] = { --- 197 unchanged lines hidden (view full) --- 1237 if (val > idxd->hw.group_cap.total_tokens) 1238 return -EINVAL; 1239 1240 idxd->token_limit = val; 1241 return count; 1242} 1243static DEVICE_ATTR_RW(token_limit); 1244 | 1069 NULL, 1070}; 1071 1072static const struct attribute_group idxd_wq_attribute_group = { 1073 .attrs = idxd_wq_attributes, 1074}; 1075 1076static const struct attribute_group *idxd_wq_attribute_groups[] = { --- 197 unchanged lines hidden (view full) --- 1274 if (val > idxd->hw.group_cap.total_tokens) 1275 return -EINVAL; 1276 1277 idxd->token_limit = val; 1278 return count; 1279} 1280static DEVICE_ATTR_RW(token_limit); 1281 |
1282static ssize_t cdev_major_show(struct device *dev, 1283 struct device_attribute *attr, char *buf) 1284{ 1285 struct idxd_device *idxd = 1286 container_of(dev, struct idxd_device, conf_dev); 1287 1288 return sprintf(buf, "%u\n", idxd->major); 1289} 1290static DEVICE_ATTR_RO(cdev_major); 1291 |
|
1245static struct attribute *idxd_device_attributes[] = { 1246 &dev_attr_max_groups.attr, 1247 &dev_attr_max_work_queues.attr, 1248 &dev_attr_max_work_queues_size.attr, 1249 &dev_attr_max_engines.attr, 1250 &dev_attr_numa_node.attr, 1251 &dev_attr_max_batch_size.attr, 1252 &dev_attr_max_transfer_size.attr, 1253 &dev_attr_op_cap.attr, 1254 &dev_attr_configurable.attr, 1255 &dev_attr_clients.attr, 1256 &dev_attr_state.attr, 1257 &dev_attr_errors.attr, 1258 &dev_attr_max_tokens.attr, 1259 &dev_attr_token_limit.attr, | 1292static struct attribute *idxd_device_attributes[] = { 1293 &dev_attr_max_groups.attr, 1294 &dev_attr_max_work_queues.attr, 1295 &dev_attr_max_work_queues_size.attr, 1296 &dev_attr_max_engines.attr, 1297 &dev_attr_numa_node.attr, 1298 &dev_attr_max_batch_size.attr, 1299 &dev_attr_max_transfer_size.attr, 1300 &dev_attr_op_cap.attr, 1301 &dev_attr_configurable.attr, 1302 &dev_attr_clients.attr, 1303 &dev_attr_state.attr, 1304 &dev_attr_errors.attr, 1305 &dev_attr_max_tokens.attr, 1306 &dev_attr_token_limit.attr, |
1307 &dev_attr_cdev_major.attr, |
|
1260 NULL, 1261}; 1262 1263static const struct attribute_group idxd_device_attribute_group = { 1264 .attrs = idxd_device_attributes, 1265}; 1266 1267static const struct attribute_group *idxd_attribute_groups[] = { --- 213 unchanged lines hidden --- | 1308 NULL, 1309}; 1310 1311static const struct attribute_group idxd_device_attribute_group = { 1312 .attrs = idxd_device_attributes, 1313}; 1314 1315static const struct attribute_group *idxd_attribute_groups[] = { --- 213 unchanged lines hidden --- |