qmgr.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License
  6. * as published by the Free Software Foundation.
  7. */
  8. #ifndef IXP4XX_QMGR_H
  9. #define IXP4XX_QMGR_H
  10. #include <linux/io.h>
  11. #include <linux/kernel.h>
  12. #define DEBUG_QMGR 0
  13. #define HALF_QUEUES 32
  14. #define QUEUES 64
  15. #define MAX_QUEUE_LENGTH 4 /* in dwords */
  16. #define QUEUE_STAT1_EMPTY 1 /* queue status bits */
  17. #define QUEUE_STAT1_NEARLY_EMPTY 2
  18. #define QUEUE_STAT1_NEARLY_FULL 4
  19. #define QUEUE_STAT1_FULL 8
  20. #define QUEUE_STAT2_UNDERFLOW 1
  21. #define QUEUE_STAT2_OVERFLOW 2
  22. #define QUEUE_WATERMARK_0_ENTRIES 0
  23. #define QUEUE_WATERMARK_1_ENTRY 1
  24. #define QUEUE_WATERMARK_2_ENTRIES 2
  25. #define QUEUE_WATERMARK_4_ENTRIES 3
  26. #define QUEUE_WATERMARK_8_ENTRIES 4
  27. #define QUEUE_WATERMARK_16_ENTRIES 5
  28. #define QUEUE_WATERMARK_32_ENTRIES 6
  29. #define QUEUE_WATERMARK_64_ENTRIES 7
  30. /* queue interrupt request conditions */
  31. #define QUEUE_IRQ_SRC_EMPTY 0
  32. #define QUEUE_IRQ_SRC_NEARLY_EMPTY 1
  33. #define QUEUE_IRQ_SRC_NEARLY_FULL 2
  34. #define QUEUE_IRQ_SRC_FULL 3
  35. #define QUEUE_IRQ_SRC_NOT_EMPTY 4
  36. #define QUEUE_IRQ_SRC_NOT_NEARLY_EMPTY 5
  37. #define QUEUE_IRQ_SRC_NOT_NEARLY_FULL 6
  38. #define QUEUE_IRQ_SRC_NOT_FULL 7
  39. struct qmgr_regs {
  40. u32 acc[QUEUES][MAX_QUEUE_LENGTH]; /* 0x000 - 0x3FF */
  41. u32 stat1[4]; /* 0x400 - 0x40F */
  42. u32 stat2[2]; /* 0x410 - 0x417 */
  43. u32 statne_h; /* 0x418 - queue nearly empty */
  44. u32 statf_h; /* 0x41C - queue full */
  45. u32 irqsrc[4]; /* 0x420 - 0x42F IRC source */
  46. u32 irqen[2]; /* 0x430 - 0x437 IRQ enabled */
  47. u32 irqstat[2]; /* 0x438 - 0x43F - IRQ access only */
  48. u32 reserved[1776];
  49. u32 sram[2048]; /* 0x2000 - 0x3FFF - config and buffer */
  50. };
  51. void qmgr_set_irq(unsigned int queue, int src,
  52. void (*handler)(void *pdev), void *pdev);
  53. void qmgr_enable_irq(unsigned int queue);
  54. void qmgr_disable_irq(unsigned int queue);
  55. /* request_ and release_queue() must be called from non-IRQ context */
  56. #if DEBUG_QMGR
  57. extern char qmgr_queue_descs[QUEUES][32];
  58. int qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */,
  59. unsigned int nearly_empty_watermark,
  60. unsigned int nearly_full_watermark,
  61. const char *desc_format, const char* name);
  62. #else
  63. int __qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */,
  64. unsigned int nearly_empty_watermark,
  65. unsigned int nearly_full_watermark);
  66. #define qmgr_request_queue(queue, len, nearly_empty_watermark, \
  67. nearly_full_watermark, desc_format, name) \
  68. __qmgr_request_queue(queue, len, nearly_empty_watermark, \
  69. nearly_full_watermark)
  70. #endif
  71. void qmgr_release_queue(unsigned int queue);
  72. static inline void qmgr_put_entry(unsigned int queue, u32 val)
  73. {
  74. struct qmgr_regs __iomem *qmgr_regs = IXP4XX_QMGR_BASE_VIRT;
  75. #if DEBUG_QMGR
  76. BUG_ON(!qmgr_queue_descs[queue]); /* not yet requested */
  77. printk(KERN_DEBUG "Queue %s(%i) put %X\n",
  78. qmgr_queue_descs[queue], queue, val);
  79. #endif
  80. __raw_writel(val, &qmgr_regs->acc[queue][0]);
  81. }
  82. static inline u32 qmgr_get_entry(unsigned int queue)
  83. {
  84. u32 val;
  85. const struct qmgr_regs __iomem *qmgr_regs = IXP4XX_QMGR_BASE_VIRT;
  86. val = __raw_readl(&qmgr_regs->acc[queue][0]);
  87. #if DEBUG_QMGR
  88. BUG_ON(!qmgr_queue_descs[queue]); /* not yet requested */
  89. printk(KERN_DEBUG "Queue %s(%i) get %X\n",
  90. qmgr_queue_descs[queue], queue, val);
  91. #endif
  92. return val;
  93. }
  94. static inline int __qmgr_get_stat1(unsigned int queue)
  95. {
  96. const struct qmgr_regs __iomem *qmgr_regs = IXP4XX_QMGR_BASE_VIRT;
  97. return (__raw_readl(&qmgr_regs->stat1[queue >> 3])
  98. >> ((queue & 7) << 2)) & 0xF;
  99. }
  100. static inline int __qmgr_get_stat2(unsigned int queue)
  101. {
  102. const struct qmgr_regs __iomem *qmgr_regs = IXP4XX_QMGR_BASE_VIRT;
  103. BUG_ON(queue >= HALF_QUEUES);
  104. return (__raw_readl(&qmgr_regs->stat2[queue >> 4])
  105. >> ((queue & 0xF) << 1)) & 0x3;
  106. }
  107. /**
  108. * qmgr_stat_empty() - checks if a hardware queue is empty
  109. * @queue: queue number
  110. *
  111. * Returns non-zero value if the queue is empty.
  112. */
  113. static inline int qmgr_stat_empty(unsigned int queue)
  114. {
  115. BUG_ON(queue >= HALF_QUEUES);
  116. return __qmgr_get_stat1(queue) & QUEUE_STAT1_EMPTY;
  117. }
  118. /**
  119. * qmgr_stat_below_low_watermark() - checks if a queue is below low watermark
  120. * @queue: queue number
  121. *
  122. * Returns non-zero value if the queue is below low watermark.
  123. */
  124. static inline int qmgr_stat_below_low_watermark(unsigned int queue)
  125. {
  126. const struct qmgr_regs __iomem *qmgr_regs = IXP4XX_QMGR_BASE_VIRT;
  127. if (queue >= HALF_QUEUES)
  128. return (__raw_readl(&qmgr_regs->statne_h) >>
  129. (queue - HALF_QUEUES)) & 0x01;
  130. return __qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_EMPTY;
  131. }
  132. /**
  133. * qmgr_stat_above_high_watermark() - checks if a queue is above high watermark
  134. * @queue: queue number
  135. *
  136. * Returns non-zero value if the queue is above high watermark
  137. */
  138. static inline int qmgr_stat_above_high_watermark(unsigned int queue)
  139. {
  140. BUG_ON(queue >= HALF_QUEUES);
  141. return __qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_FULL;
  142. }
  143. /**
  144. * qmgr_stat_full() - checks if a hardware queue is full
  145. * @queue: queue number
  146. *
  147. * Returns non-zero value if the queue is full.
  148. */
  149. static inline int qmgr_stat_full(unsigned int queue)
  150. {
  151. const struct qmgr_regs __iomem *qmgr_regs = IXP4XX_QMGR_BASE_VIRT;
  152. if (queue >= HALF_QUEUES)
  153. return (__raw_readl(&qmgr_regs->statf_h) >>
  154. (queue - HALF_QUEUES)) & 0x01;
  155. return __qmgr_get_stat1(queue) & QUEUE_STAT1_FULL;
  156. }
  157. /**
  158. * qmgr_stat_underflow() - checks if a hardware queue experienced underflow
  159. * @queue: queue number
  160. *
  161. * Returns non-zero value if the queue experienced underflow.
  162. */
  163. static inline int qmgr_stat_underflow(unsigned int queue)
  164. {
  165. return __qmgr_get_stat2(queue) & QUEUE_STAT2_UNDERFLOW;
  166. }
  167. /**
  168. * qmgr_stat_overflow() - checks if a hardware queue experienced overflow
  169. * @queue: queue number
  170. *
  171. * Returns non-zero value if the queue experienced overflow.
  172. */
  173. static inline int qmgr_stat_overflow(unsigned int queue)
  174. {
  175. return __qmgr_get_stat2(queue) & QUEUE_STAT2_OVERFLOW;
  176. }
  177. #endif