sysfs.c (47c16ac27d4cb664cee53ee0b9b7e2f907923fb3) sysfs.c (7c5dd23e57c14cf7177b8a5e0fd08916e0c60005)
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>

--- 12 unchanged lines hidden (view full) ---

21 dev_dbg(dev, "%s for %s\n", __func__, dev_name(dev));
22}
23
24static struct device_type idxd_group_device_type = {
25 .name = "group",
26 .release = idxd_conf_sub_device_release,
27};
28
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>

--- 12 unchanged lines hidden (view full) ---

21 dev_dbg(dev, "%s for %s\n", __func__, dev_name(dev));
22}
23
24static struct device_type idxd_group_device_type = {
25 .name = "group",
26 .release = idxd_conf_sub_device_release,
27};
28
29static struct device_type idxd_wq_device_type = {
30 .name = "wq",
31 .release = idxd_conf_sub_device_release,
32};
33
34static struct device_type idxd_engine_device_type = {
35 .name = "engine",
36 .release = idxd_conf_sub_device_release,
37};
38
29static struct device_type idxd_engine_device_type = {
30 .name = "engine",
31 .release = idxd_conf_sub_device_release,
32};
33
39static inline bool is_idxd_wq_dev(struct device *dev)
40{
41 return dev ? dev->type == &idxd_wq_device_type : false;
42}
43
44static inline bool is_idxd_wq_dmaengine(struct idxd_wq *wq)
45{
46 if (wq->type == IDXD_WQT_KERNEL &&
47 strcmp(wq->name, "dmaengine") == 0)
48 return true;
49 return false;
50}
51
52static inline bool is_idxd_wq_cdev(struct idxd_wq *wq)
53{
54 return wq->type == IDXD_WQT_USER;
55}
56
57static int idxd_config_bus_match(struct device *dev,
58 struct device_driver *drv)
59{
60 int matched = 0;
61
62 if (is_idxd_dev(dev)) {
63 struct idxd_device *idxd = confdev_to_idxd(dev);
64

--- 227 unchanged lines hidden (view full) ---

292 disable_wq(wq);
293 } else if (is_idxd_dev(dev)) {
294 struct idxd_device *idxd = confdev_to_idxd(dev);
295 int i;
296
297 dev_dbg(dev, "%s removing dev %s\n", __func__,
298 dev_name(&idxd->conf_dev));
299 for (i = 0; i < idxd->max_wqs; i++) {
34static int idxd_config_bus_match(struct device *dev,
35 struct device_driver *drv)
36{
37 int matched = 0;
38
39 if (is_idxd_dev(dev)) {
40 struct idxd_device *idxd = confdev_to_idxd(dev);
41

--- 227 unchanged lines hidden (view full) ---

269 disable_wq(wq);
270 } else if (is_idxd_dev(dev)) {
271 struct idxd_device *idxd = confdev_to_idxd(dev);
272 int i;
273
274 dev_dbg(dev, "%s removing dev %s\n", __func__,
275 dev_name(&idxd->conf_dev));
276 for (i = 0; i < idxd->max_wqs; i++) {
300 struct idxd_wq *wq = &idxd->wqs[i];
277 struct idxd_wq *wq = idxd->wqs[i];
301
302 if (wq->state == IDXD_WQ_DISABLED)
303 continue;
304 dev_warn(dev, "Active wq %d on disable %s.\n", i,
305 dev_name(&idxd->conf_dev));
306 device_release_driver(&wq->conf_dev);
307 }
308
309 idxd_unregister_dma_device(idxd);
310 rc = idxd_device_disable(idxd);
311 for (i = 0; i < idxd->max_wqs; i++) {
278
279 if (wq->state == IDXD_WQ_DISABLED)
280 continue;
281 dev_warn(dev, "Active wq %d on disable %s.\n", i,
282 dev_name(&idxd->conf_dev));
283 device_release_driver(&wq->conf_dev);
284 }
285
286 idxd_unregister_dma_device(idxd);
287 rc = idxd_device_disable(idxd);
288 for (i = 0; i < idxd->max_wqs; i++) {
312 struct idxd_wq *wq = &idxd->wqs[i];
289 struct idxd_wq *wq = idxd->wqs[i];
313
314 mutex_lock(&wq->wq_lock);
315 idxd_wq_disable_cleanup(wq);
316 mutex_unlock(&wq->wq_lock);
317 }
318 module_put(THIS_MODULE);
319 if (rc < 0)
320 dev_warn(dev, "Device disable failed\n");

--- 352 unchanged lines hidden (view full) ---

673{
674 struct idxd_group *group =
675 container_of(dev, struct idxd_group, conf_dev);
676 int i, rc = 0;
677 char *tmp = buf;
678 struct idxd_device *idxd = group->idxd;
679
680 for (i = 0; i < idxd->max_wqs; i++) {
290
291 mutex_lock(&wq->wq_lock);
292 idxd_wq_disable_cleanup(wq);
293 mutex_unlock(&wq->wq_lock);
294 }
295 module_put(THIS_MODULE);
296 if (rc < 0)
297 dev_warn(dev, "Device disable failed\n");

--- 352 unchanged lines hidden (view full) ---

650{
651 struct idxd_group *group =
652 container_of(dev, struct idxd_group, conf_dev);
653 int i, rc = 0;
654 char *tmp = buf;
655 struct idxd_device *idxd = group->idxd;
656
657 for (i = 0; i < idxd->max_wqs; i++) {
681 struct idxd_wq *wq = &idxd->wqs[i];
658 struct idxd_wq *wq = idxd->wqs[i];
682
683 if (!wq->group)
684 continue;
685
686 if (wq->group->id == group->id)
687 rc += sprintf(tmp + rc, "wq%d.%d ",
688 idxd->id, wq->id);
689 }

--- 240 unchanged lines hidden (view full) ---

930}
931
932static int total_claimed_wq_size(struct idxd_device *idxd)
933{
934 int i;
935 int wq_size = 0;
936
937 for (i = 0; i < idxd->max_wqs; i++) {
659
660 if (!wq->group)
661 continue;
662
663 if (wq->group->id == group->id)
664 rc += sprintf(tmp + rc, "wq%d.%d ",
665 idxd->id, wq->id);
666 }

--- 240 unchanged lines hidden (view full) ---

907}
908
909static int total_claimed_wq_size(struct idxd_device *idxd)
910{
911 int i;
912 int wq_size = 0;
913
914 for (i = 0; i < idxd->max_wqs; i++) {
938 struct idxd_wq *wq = &idxd->wqs[i];
915 struct idxd_wq *wq = idxd->wqs[i];
939
940 wq_size += wq->size;
941 }
942
943 return wq_size;
944}
945
946static ssize_t wq_size_store(struct device *dev,

--- 379 unchanged lines hidden (view full) ---

1326 .attrs = idxd_wq_attributes,
1327};
1328
1329static const struct attribute_group *idxd_wq_attribute_groups[] = {
1330 &idxd_wq_attribute_group,
1331 NULL,
1332};
1333
916
917 wq_size += wq->size;
918 }
919
920 return wq_size;
921}
922
923static ssize_t wq_size_store(struct device *dev,

--- 379 unchanged lines hidden (view full) ---

1303 .attrs = idxd_wq_attributes,
1304};
1305
1306static const struct attribute_group *idxd_wq_attribute_groups[] = {
1307 &idxd_wq_attribute_group,
1308 NULL,
1309};
1310
1311static void idxd_conf_wq_release(struct device *dev)
1312{
1313 struct idxd_wq *wq = container_of(dev, struct idxd_wq, conf_dev);
1314
1315 kfree(wq->wqcfg);
1316 kfree(wq);
1317}
1318
1319struct device_type idxd_wq_device_type = {
1320 .name = "wq",
1321 .release = idxd_conf_wq_release,
1322 .groups = idxd_wq_attribute_groups,
1323};
1324
1334/* IDXD device attribs */
1335static ssize_t version_show(struct device *dev, struct device_attribute *attr,
1336 char *buf)
1337{
1338 struct idxd_device *idxd =
1339 container_of(dev, struct idxd_device, conf_dev);
1340
1341 return sprintf(buf, "%#x\n", idxd->hw.version);

--- 114 unchanged lines hidden (view full) ---

1456{
1457 struct idxd_device *idxd =
1458 container_of(dev, struct idxd_device, conf_dev);
1459 unsigned long flags;
1460 int count = 0, i;
1461
1462 spin_lock_irqsave(&idxd->dev_lock, flags);
1463 for (i = 0; i < idxd->max_wqs; i++) {
1325/* IDXD device attribs */
1326static ssize_t version_show(struct device *dev, struct device_attribute *attr,
1327 char *buf)
1328{
1329 struct idxd_device *idxd =
1330 container_of(dev, struct idxd_device, conf_dev);
1331
1332 return sprintf(buf, "%#x\n", idxd->hw.version);

--- 114 unchanged lines hidden (view full) ---

1447{
1448 struct idxd_device *idxd =
1449 container_of(dev, struct idxd_device, conf_dev);
1450 unsigned long flags;
1451 int count = 0, i;
1452
1453 spin_lock_irqsave(&idxd->dev_lock, flags);
1454 for (i = 0; i < idxd->max_wqs; i++) {
1464 struct idxd_wq *wq = &idxd->wqs[i];
1455 struct idxd_wq *wq = idxd->wqs[i];
1465
1466 count += wq->client_count;
1467 }
1468 spin_unlock_irqrestore(&idxd->dev_lock, flags);
1469
1470 return sprintf(buf, "%d\n", count);
1471}
1472static DEVICE_ATTR_RO(clients);

--- 233 unchanged lines hidden (view full) ---

1706 while (i--) {
1707 struct idxd_group *group = &idxd->groups[i];
1708
1709 device_unregister(&group->conf_dev);
1710 }
1711 return rc;
1712}
1713
1456
1457 count += wq->client_count;
1458 }
1459 spin_unlock_irqrestore(&idxd->dev_lock, flags);
1460
1461 return sprintf(buf, "%d\n", count);
1462}
1463static DEVICE_ATTR_RO(clients);

--- 233 unchanged lines hidden (view full) ---

1697 while (i--) {
1698 struct idxd_group *group = &idxd->groups[i];
1699
1700 device_unregister(&group->conf_dev);
1701 }
1702 return rc;
1703}
1704
1714static int idxd_setup_wq_sysfs(struct idxd_device *idxd)
1705static int idxd_register_wq_devices(struct idxd_device *idxd)
1715{
1706{
1716 struct device *dev = &idxd->pdev->dev;
1717 int i, rc;
1707 int i, rc, j;
1718
1719 for (i = 0; i < idxd->max_wqs; i++) {
1708
1709 for (i = 0; i < idxd->max_wqs; i++) {
1720 struct idxd_wq *wq = &idxd->wqs[i];
1710 struct idxd_wq *wq = idxd->wqs[i];
1721
1711
1722 wq->conf_dev.parent = &idxd->conf_dev;
1723 dev_set_name(&wq->conf_dev, "wq%d.%d", idxd->id, wq->id);
1724 wq->conf_dev.bus = idxd_get_bus_type(idxd);
1725 wq->conf_dev.groups = idxd_wq_attribute_groups;
1726 wq->conf_dev.type = &idxd_wq_device_type;
1727 dev_dbg(dev, "WQ device register: %s\n",
1728 dev_name(&wq->conf_dev));
1729 rc = device_register(&wq->conf_dev);
1730 if (rc < 0) {
1731 put_device(&wq->conf_dev);
1712 rc = device_add(&wq->conf_dev);
1713 if (rc < 0)
1732 goto cleanup;
1714 goto cleanup;
1733 }
1734 }
1735
1736 return 0;
1737
1738cleanup:
1715 }
1716
1717 return 0;
1718
1719cleanup:
1739 while (i--) {
1740 struct idxd_wq *wq = &idxd->wqs[i];
1720 j = i - 1;
1721 for (; i < idxd->max_wqs; i++)
1722 put_device(&idxd->wqs[i]->conf_dev);
1741
1723
1742 device_unregister(&wq->conf_dev);
1743 }
1724 while (j--)
1725 device_unregister(&idxd->wqs[j]->conf_dev);
1744 return rc;
1745}
1746
1747int idxd_register_devices(struct idxd_device *idxd)
1748{
1749 struct device *dev = &idxd->pdev->dev;
1726 return rc;
1727}
1728
1729int idxd_register_devices(struct idxd_device *idxd)
1730{
1731 struct device *dev = &idxd->pdev->dev;
1750 int rc;
1732 int rc, i;
1751
1752 rc = device_add(&idxd->conf_dev);
1753 if (rc < 0)
1754 return rc;
1755
1733
1734 rc = device_add(&idxd->conf_dev);
1735 if (rc < 0)
1736 return rc;
1737
1756 rc = idxd_setup_wq_sysfs(idxd);
1738 rc = idxd_register_wq_devices(idxd);
1757 if (rc < 0) {
1739 if (rc < 0) {
1758 /* unregister conf dev */
1759 dev_dbg(dev, "Work Queue sysfs registering failed: %d\n", rc);
1760 return rc;
1740 dev_dbg(dev, "WQ devices registering failed: %d\n", rc);
1741 goto err_wq;
1761 }
1762
1763 rc = idxd_setup_group_sysfs(idxd);
1764 if (rc < 0) {
1765 /* unregister conf dev */
1766 dev_dbg(dev, "Group sysfs registering failed: %d\n", rc);
1742 }
1743
1744 rc = idxd_setup_group_sysfs(idxd);
1745 if (rc < 0) {
1746 /* unregister conf dev */
1747 dev_dbg(dev, "Group sysfs registering failed: %d\n", rc);
1767 return rc;
1748 goto err;
1768 }
1769
1770 rc = idxd_setup_engine_sysfs(idxd);
1771 if (rc < 0) {
1772 /* unregister conf dev */
1773 dev_dbg(dev, "Engine sysfs registering failed: %d\n", rc);
1749 }
1750
1751 rc = idxd_setup_engine_sysfs(idxd);
1752 if (rc < 0) {
1753 /* unregister conf dev */
1754 dev_dbg(dev, "Engine sysfs registering failed: %d\n", rc);
1774 return rc;
1755 goto err;
1775 }
1776
1777 return 0;
1756 }
1757
1758 return 0;
1759
1760 err:
1761 for (i = 0; i < idxd->max_wqs; i++)
1762 device_unregister(&idxd->wqs[i]->conf_dev);
1763 err_wq:
1764 device_del(&idxd->conf_dev);
1765 return rc;
1778}
1779
1780void idxd_unregister_devices(struct idxd_device *idxd)
1781{
1782 int i;
1783
1784 for (i = 0; i < idxd->max_wqs; i++) {
1766}
1767
1768void idxd_unregister_devices(struct idxd_device *idxd)
1769{
1770 int i;
1771
1772 for (i = 0; i < idxd->max_wqs; i++) {
1785 struct idxd_wq *wq = &idxd->wqs[i];
1773 struct idxd_wq *wq = idxd->wqs[i];
1786
1787 device_unregister(&wq->conf_dev);
1788 }
1789
1790 for (i = 0; i < idxd->max_engines; i++) {
1791 struct idxd_engine *engine = &idxd->engines[i];
1792
1793 device_unregister(&engine->conf_dev);

--- 36 unchanged lines hidden ---
1774
1775 device_unregister(&wq->conf_dev);
1776 }
1777
1778 for (i = 0; i < idxd->max_engines; i++) {
1779 struct idxd_engine *engine = &idxd->engines[i];
1780
1781 device_unregister(&engine->conf_dev);

--- 36 unchanged lines hidden ---