sysfs.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Intel I/OAT DMA Linux driver
  4. * Copyright(c) 2004 - 2015 Intel Corporation.
  5. */
  6. #include <linux/init.h>
  7. #include <linux/module.h>
  8. #include <linux/dmaengine.h>
  9. #include <linux/pci.h>
  10. #include "dma.h"
  11. #include "registers.h"
  12. #include "hw.h"
  13. #include "../dmaengine.h"
  14. static ssize_t cap_show(struct dma_chan *c, char *page)
  15. {
  16. struct dma_device *dma = c->device;
  17. return sprintf(page, "copy%s%s%s%s%s\n",
  18. dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "",
  19. dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "",
  20. dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "",
  21. dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "",
  22. dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : "");
  23. }
  24. struct ioat_sysfs_entry ioat_cap_attr = __ATTR_RO(cap);
  25. static ssize_t version_show(struct dma_chan *c, char *page)
  26. {
  27. struct dma_device *dma = c->device;
  28. struct ioatdma_device *ioat_dma = to_ioatdma_device(dma);
  29. return sprintf(page, "%d.%d\n",
  30. ioat_dma->version >> 4, ioat_dma->version & 0xf);
  31. }
  32. struct ioat_sysfs_entry ioat_version_attr = __ATTR_RO(version);
  33. static ssize_t
  34. ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
  35. {
  36. struct ioat_sysfs_entry *entry;
  37. struct ioatdma_chan *ioat_chan;
  38. entry = container_of(attr, struct ioat_sysfs_entry, attr);
  39. ioat_chan = container_of(kobj, struct ioatdma_chan, kobj);
  40. if (!entry->show)
  41. return -EIO;
  42. return entry->show(&ioat_chan->dma_chan, page);
  43. }
  44. static ssize_t
  45. ioat_attr_store(struct kobject *kobj, struct attribute *attr,
  46. const char *page, size_t count)
  47. {
  48. struct ioat_sysfs_entry *entry;
  49. struct ioatdma_chan *ioat_chan;
  50. entry = container_of(attr, struct ioat_sysfs_entry, attr);
  51. ioat_chan = container_of(kobj, struct ioatdma_chan, kobj);
  52. if (!entry->store)
  53. return -EIO;
  54. return entry->store(&ioat_chan->dma_chan, page, count);
  55. }
  56. const struct sysfs_ops ioat_sysfs_ops = {
  57. .show = ioat_attr_show,
  58. .store = ioat_attr_store,
  59. };
  60. void ioat_kobject_add(struct ioatdma_device *ioat_dma, struct kobj_type *type)
  61. {
  62. struct dma_device *dma = &ioat_dma->dma_dev;
  63. struct dma_chan *c;
  64. list_for_each_entry(c, &dma->channels, device_node) {
  65. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  66. struct kobject *parent = &c->dev->device.kobj;
  67. int err;
  68. err = kobject_init_and_add(&ioat_chan->kobj, type,
  69. parent, "quickdata");
  70. if (err) {
  71. dev_warn(to_dev(ioat_chan),
  72. "sysfs init error (%d), continuing...\n", err);
  73. kobject_put(&ioat_chan->kobj);
  74. set_bit(IOAT_KOBJ_INIT_FAIL, &ioat_chan->state);
  75. }
  76. }
  77. }
  78. void ioat_kobject_del(struct ioatdma_device *ioat_dma)
  79. {
  80. struct dma_device *dma = &ioat_dma->dma_dev;
  81. struct dma_chan *c;
  82. list_for_each_entry(c, &dma->channels, device_node) {
  83. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  84. if (!test_bit(IOAT_KOBJ_INIT_FAIL, &ioat_chan->state)) {
  85. kobject_del(&ioat_chan->kobj);
  86. kobject_put(&ioat_chan->kobj);
  87. }
  88. }
  89. }
  90. static ssize_t ring_size_show(struct dma_chan *c, char *page)
  91. {
  92. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  93. return sprintf(page, "%d\n", (1 << ioat_chan->alloc_order) & ~1);
  94. }
  95. static struct ioat_sysfs_entry ring_size_attr = __ATTR_RO(ring_size);
  96. static ssize_t ring_active_show(struct dma_chan *c, char *page)
  97. {
  98. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  99. /* ...taken outside the lock, no need to be precise */
  100. return sprintf(page, "%d\n", ioat_ring_active(ioat_chan));
  101. }
  102. static struct ioat_sysfs_entry ring_active_attr = __ATTR_RO(ring_active);
  103. static ssize_t intr_coalesce_show(struct dma_chan *c, char *page)
  104. {
  105. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  106. return sprintf(page, "%d\n", ioat_chan->intr_coalesce);
  107. }
  108. static ssize_t intr_coalesce_store(struct dma_chan *c, const char *page,
  109. size_t count)
  110. {
  111. int intr_coalesce = 0;
  112. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  113. if (sscanf(page, "%du", &intr_coalesce) != -1) {
  114. if ((intr_coalesce < 0) ||
  115. (intr_coalesce > IOAT_INTRDELAY_MASK))
  116. return -EINVAL;
  117. ioat_chan->intr_coalesce = intr_coalesce;
  118. }
  119. return count;
  120. }
  121. static struct ioat_sysfs_entry intr_coalesce_attr = __ATTR_RW(intr_coalesce);
  122. static struct attribute *ioat_attrs[] = {
  123. &ring_size_attr.attr,
  124. &ring_active_attr.attr,
  125. &ioat_cap_attr.attr,
  126. &ioat_version_attr.attr,
  127. &intr_coalesce_attr.attr,
  128. NULL,
  129. };
  130. ATTRIBUTE_GROUPS(ioat);
  131. struct kobj_type ioat_ktype = {
  132. .sysfs_ops = &ioat_sysfs_ops,
  133. .default_groups = ioat_groups,
  134. };