sysfs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. const struct sysfs_ops ioat_sysfs_ops = {
  57. .show = ioat_attr_show,
  58. };
  59. void ioat_kobject_add(struct ioatdma_device *ioat_dma, struct kobj_type *type)
  60. {
  61. struct dma_device *dma = &ioat_dma->dma_dev;
  62. struct dma_chan *c;
  63. list_for_each_entry(c, &dma->channels, device_node) {
  64. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  65. struct kobject *parent = &c->dev->device.kobj;
  66. int err;
  67. err = kobject_init_and_add(&ioat_chan->kobj, type,
  68. parent, "quickdata");
  69. if (err) {
  70. dev_warn(to_dev(ioat_chan),
  71. "sysfs init error (%d), continuing...\n", err);
  72. kobject_put(&ioat_chan->kobj);
  73. set_bit(IOAT_KOBJ_INIT_FAIL, &ioat_chan->state);
  74. }
  75. }
  76. }
  77. void ioat_kobject_del(struct ioatdma_device *ioat_dma)
  78. {
  79. struct dma_device *dma = &ioat_dma->dma_dev;
  80. struct dma_chan *c;
  81. list_for_each_entry(c, &dma->channels, device_node) {
  82. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  83. if (!test_bit(IOAT_KOBJ_INIT_FAIL, &ioat_chan->state)) {
  84. kobject_del(&ioat_chan->kobj);
  85. kobject_put(&ioat_chan->kobj);
  86. }
  87. }
  88. }
  89. static ssize_t ring_size_show(struct dma_chan *c, char *page)
  90. {
  91. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  92. return sprintf(page, "%d\n", (1 << ioat_chan->alloc_order) & ~1);
  93. }
  94. static struct ioat_sysfs_entry ring_size_attr = __ATTR_RO(ring_size);
  95. static ssize_t ring_active_show(struct dma_chan *c, char *page)
  96. {
  97. struct ioatdma_chan *ioat_chan = to_ioat_chan(c);
  98. /* ...taken outside the lock, no need to be precise */
  99. return sprintf(page, "%d\n", ioat_ring_active(ioat_chan));
  100. }
  101. static struct ioat_sysfs_entry ring_active_attr = __ATTR_RO(ring_active);
  102. static struct attribute *ioat_attrs[] = {
  103. &ring_size_attr.attr,
  104. &ring_active_attr.attr,
  105. &ioat_cap_attr.attr,
  106. &ioat_version_attr.attr,
  107. NULL,
  108. };
  109. struct kobj_type ioat_ktype = {
  110. .sysfs_ops = &ioat_sysfs_ops,
  111. .default_attrs = ioat_attrs,
  112. };