sysfs.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Intel I/OAT DMA Linux driver
  3. * Copyright(c) 2004 - 2015 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * The full GNU General Public License is included in this distribution in
  15. * the file called "COPYING".
  16. *
  17. */
  18. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <linux/dmaengine.h>
  21. #include <linux/pci.h>
  22. #include "dma.h"
  23. #include "registers.h"
  24. #include "hw.h"
  25. #include "../dmaengine.h"
  26. static ssize_t cap_show(struct dma_chan *c, char *page)
  27. {
  28. struct dma_device *dma = c->device;
  29. return sprintf(page, "copy%s%s%s%s%s\n",
  30. dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "",
  31. dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "",
  32. dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "",
  33. dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "",
  34. dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : "");
  35. }
  36. struct ioat_sysfs_entry ioat_cap_attr = __ATTR_RO(cap);
  37. static ssize_t version_show(struct dma_chan *c, char *page)
  38. {
  39. struct dma_device *dma = c->device;
  40. struct ioatdma_device *ioat_dma = to_ioatdma_device(dma);
  41. return sprintf(page, "%d.%d\n",
  42. ioat_dma->version >> 4, ioat_dma->version & 0xf);
  43. }
  44. struct ioat_sysfs_entry ioat_version_attr = __ATTR_RO(version);
  45. static ssize_t
  46. ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
  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->show)
  53. return -EIO;
  54. return entry->show(&ioat_chan->dma_chan, page);
  55. }
  56. static ssize_t
  57. ioat_attr_store(struct kobject *kobj, struct attribute *attr,
  58. const char *page, size_t count)
  59. {
  60. struct ioat_sysfs_entry *entry;
  61. struct ioatdma_chan *ioat_chan;
  62. entry = container_of(attr, struct ioat_sysfs_entry, attr);
  63. ioat_chan = container_of(kobj, struct ioatdma_chan, kobj);
  64. if (!entry->store)
  65. return -EIO;
  66. return entry->store(&ioat_chan->dma_chan, page, count);
  67. }
  68. const struct sysfs_ops ioat_sysfs_ops = {
  69. .show = ioat_attr_show,
  70. .store = ioat_attr_store,
  71. };
  72. void ioat_kobject_add(struct ioatdma_device *ioat_dma, struct kobj_type *type)
  73. {
  74. struct dma_device *dma = &ioat_dma->dma_dev;
  75. struct dma_chan *c;
  76. list_for_each_entry(c, &dma->channels, device_node) {
  77. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  78. struct kobject *parent = &c->dev->device.kobj;
  79. int err;
  80. err = kobject_init_and_add(&ioat_chan->kobj, type,
  81. parent, "quickdata");
  82. if (err) {
  83. dev_warn(to_dev(ioat_chan),
  84. "sysfs init error (%d), continuing...\n", err);
  85. kobject_put(&ioat_chan->kobj);
  86. set_bit(IOAT_KOBJ_INIT_FAIL, &ioat_chan->state);
  87. }
  88. }
  89. }
  90. void ioat_kobject_del(struct ioatdma_device *ioat_dma)
  91. {
  92. struct dma_device *dma = &ioat_dma->dma_dev;
  93. struct dma_chan *c;
  94. list_for_each_entry(c, &dma->channels, device_node) {
  95. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  96. if (!test_bit(IOAT_KOBJ_INIT_FAIL, &ioat_chan->state)) {
  97. kobject_del(&ioat_chan->kobj);
  98. kobject_put(&ioat_chan->kobj);
  99. }
  100. }
  101. }
  102. static ssize_t ring_size_show(struct dma_chan *c, char *page)
  103. {
  104. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  105. return sprintf(page, "%d\n", (1 << ioat_chan->alloc_order) & ~1);
  106. }
  107. static struct ioat_sysfs_entry ring_size_attr = __ATTR_RO(ring_size);
  108. static ssize_t ring_active_show(struct dma_chan *c, char *page)
  109. {
  110. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  111. /* ...taken outside the lock, no need to be precise */
  112. return sprintf(page, "%d\n", ioat_ring_active(ioat_chan));
  113. }
  114. static struct ioat_sysfs_entry ring_active_attr = __ATTR_RO(ring_active);
  115. static ssize_t intr_coalesce_show(struct dma_chan *c, char *page)
  116. {
  117. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  118. return sprintf(page, "%d\n", ioat_chan->intr_coalesce);
  119. }
  120. static ssize_t intr_coalesce_store(struct dma_chan *c, const char *page,
  121. size_t count)
  122. {
  123. int intr_coalesce = 0;
  124. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  125. if (sscanf(page, "%du", &intr_coalesce) != -1) {
  126. if ((intr_coalesce < 0) ||
  127. (intr_coalesce > IOAT_INTRDELAY_MASK))
  128. return -EINVAL;
  129. ioat_chan->intr_coalesce = intr_coalesce;
  130. }
  131. return count;
  132. }
  133. static struct ioat_sysfs_entry intr_coalesce_attr = __ATTR_RW(intr_coalesce);
  134. static struct attribute *ioat_attrs[] = {
  135. &ring_size_attr.attr,
  136. &ring_active_attr.attr,
  137. &ioat_cap_attr.attr,
  138. &ioat_version_attr.attr,
  139. &intr_coalesce_attr.attr,
  140. NULL,
  141. };
  142. struct kobj_type ioat_ktype = {
  143. .sysfs_ops = &ioat_sysfs_ops,
  144. .default_attrs = ioat_attrs,
  145. };