dma_v2.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright(c) 2004 - 2009 Intel Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 2 of the License, or (at your option)
  7. * any later version.
  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. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc., 59
  16. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called COPYING.
  20. */
  21. #ifndef IOATDMA_V2_H
  22. #define IOATDMA_V2_H
  23. #include <linux/dmaengine.h>
  24. #include "dma.h"
  25. #include "hw.h"
  26. extern int ioat_pending_level;
  27. /*
  28. * workaround for IOAT ver.3.0 null descriptor issue
  29. * (channel returns error when size is 0)
  30. */
  31. #define NULL_DESC_BUFFER_SIZE 1
  32. #define IOAT_MAX_ORDER 16
  33. #define ioat_get_alloc_order() \
  34. (min(ioat_ring_alloc_order, IOAT_MAX_ORDER))
  35. /* struct ioat2_dma_chan - ioat v2 / v3 channel attributes
  36. * @base: common ioat channel parameters
  37. * @xfercap_log; log2 of channel max transfer length (for fast division)
  38. * @head: allocated index
  39. * @issued: hardware notification point
  40. * @tail: cleanup index
  41. * @pending: lock free indicator for issued != head
  42. * @dmacount: identical to 'head' except for occasionally resetting to zero
  43. * @alloc_order: log2 of the number of allocated descriptors
  44. * @ring: software ring buffer implementation of hardware ring
  45. * @ring_lock: protects ring attributes
  46. */
  47. struct ioat2_dma_chan {
  48. struct ioat_chan_common base;
  49. size_t xfercap_log;
  50. u16 head;
  51. u16 issued;
  52. u16 tail;
  53. u16 dmacount;
  54. u16 alloc_order;
  55. int pending;
  56. struct ioat_ring_ent **ring;
  57. spinlock_t ring_lock;
  58. };
  59. static inline struct ioat2_dma_chan *to_ioat2_chan(struct dma_chan *c)
  60. {
  61. struct ioat_chan_common *chan = to_chan_common(c);
  62. return container_of(chan, struct ioat2_dma_chan, base);
  63. }
  64. static inline u16 ioat2_ring_mask(struct ioat2_dma_chan *ioat)
  65. {
  66. return (1 << ioat->alloc_order) - 1;
  67. }
  68. /* count of descriptors in flight with the engine */
  69. static inline u16 ioat2_ring_active(struct ioat2_dma_chan *ioat)
  70. {
  71. return (ioat->head - ioat->tail) & ioat2_ring_mask(ioat);
  72. }
  73. /* count of descriptors pending submission to hardware */
  74. static inline u16 ioat2_ring_pending(struct ioat2_dma_chan *ioat)
  75. {
  76. return (ioat->head - ioat->issued) & ioat2_ring_mask(ioat);
  77. }
  78. static inline u16 ioat2_ring_space(struct ioat2_dma_chan *ioat)
  79. {
  80. u16 num_descs = ioat2_ring_mask(ioat) + 1;
  81. u16 active = ioat2_ring_active(ioat);
  82. BUG_ON(active > num_descs);
  83. return num_descs - active;
  84. }
  85. /* assumes caller already checked space */
  86. static inline u16 ioat2_desc_alloc(struct ioat2_dma_chan *ioat, u16 len)
  87. {
  88. ioat->head += len;
  89. return ioat->head - len;
  90. }
  91. static inline u16 ioat2_xferlen_to_descs(struct ioat2_dma_chan *ioat, size_t len)
  92. {
  93. u16 num_descs = len >> ioat->xfercap_log;
  94. num_descs += !!(len & ((1 << ioat->xfercap_log) - 1));
  95. return num_descs;
  96. }
  97. struct ioat_ring_ent {
  98. struct ioat_dma_descriptor *hw;
  99. struct dma_async_tx_descriptor txd;
  100. size_t len;
  101. #ifdef DEBUG
  102. int id;
  103. #endif
  104. };
  105. static inline struct ioat_ring_ent *
  106. ioat2_get_ring_ent(struct ioat2_dma_chan *ioat, u16 idx)
  107. {
  108. return ioat->ring[idx & ioat2_ring_mask(ioat)];
  109. }
  110. int __devinit ioat2_dma_probe(struct ioatdma_device *dev, int dca);
  111. int __devinit ioat3_dma_probe(struct ioatdma_device *dev, int dca);
  112. struct dca_provider * __devinit ioat2_dca_init(struct pci_dev *pdev, void __iomem *iobase);
  113. struct dca_provider * __devinit ioat3_dca_init(struct pci_dev *pdev, void __iomem *iobase);
  114. #endif /* IOATDMA_V2_H */