qmgr.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 HALF_QUEUES 32
  13. #define QUEUES 64 /* only 32 lower queues currently supported */
  14. #define MAX_QUEUE_LENGTH 4 /* in dwords */
  15. #define QUEUE_STAT1_EMPTY 1 /* queue status bits */
  16. #define QUEUE_STAT1_NEARLY_EMPTY 2
  17. #define QUEUE_STAT1_NEARLY_FULL 4
  18. #define QUEUE_STAT1_FULL 8
  19. #define QUEUE_STAT2_UNDERFLOW 1
  20. #define QUEUE_STAT2_OVERFLOW 2
  21. #define QUEUE_WATERMARK_0_ENTRIES 0
  22. #define QUEUE_WATERMARK_1_ENTRY 1
  23. #define QUEUE_WATERMARK_2_ENTRIES 2
  24. #define QUEUE_WATERMARK_4_ENTRIES 3
  25. #define QUEUE_WATERMARK_8_ENTRIES 4
  26. #define QUEUE_WATERMARK_16_ENTRIES 5
  27. #define QUEUE_WATERMARK_32_ENTRIES 6
  28. #define QUEUE_WATERMARK_64_ENTRIES 7
  29. /* queue interrupt request conditions */
  30. #define QUEUE_IRQ_SRC_EMPTY 0
  31. #define QUEUE_IRQ_SRC_NEARLY_EMPTY 1
  32. #define QUEUE_IRQ_SRC_NEARLY_FULL 2
  33. #define QUEUE_IRQ_SRC_FULL 3
  34. #define QUEUE_IRQ_SRC_NOT_EMPTY 4
  35. #define QUEUE_IRQ_SRC_NOT_NEARLY_EMPTY 5
  36. #define QUEUE_IRQ_SRC_NOT_NEARLY_FULL 6
  37. #define QUEUE_IRQ_SRC_NOT_FULL 7
  38. struct qmgr_regs {
  39. u32 acc[QUEUES][MAX_QUEUE_LENGTH]; /* 0x000 - 0x3FF */
  40. u32 stat1[4]; /* 0x400 - 0x40F */
  41. u32 stat2[2]; /* 0x410 - 0x417 */
  42. u32 statne_h; /* 0x418 - queue nearly empty */
  43. u32 statf_h; /* 0x41C - queue full */
  44. u32 irqsrc[4]; /* 0x420 - 0x42F IRC source */
  45. u32 irqen[2]; /* 0x430 - 0x437 IRQ enabled */
  46. u32 irqstat[2]; /* 0x438 - 0x43F - IRQ access only */
  47. u32 reserved[1776];
  48. u32 sram[2048]; /* 0x2000 - 0x3FFF - config and buffer */
  49. };
  50. void qmgr_set_irq(unsigned int queue, int src,
  51. void (*handler)(void *pdev), void *pdev);
  52. void qmgr_enable_irq(unsigned int queue);
  53. void qmgr_disable_irq(unsigned int queue);
  54. /* request_ and release_queue() must be called from non-IRQ context */
  55. int qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */,
  56. unsigned int nearly_empty_watermark,
  57. unsigned int nearly_full_watermark);
  58. void qmgr_release_queue(unsigned int queue);
  59. static inline void qmgr_put_entry(unsigned int queue, u32 val)
  60. {
  61. extern struct qmgr_regs __iomem *qmgr_regs;
  62. __raw_writel(val, &qmgr_regs->acc[queue][0]);
  63. }
  64. static inline u32 qmgr_get_entry(unsigned int queue)
  65. {
  66. extern struct qmgr_regs __iomem *qmgr_regs;
  67. return __raw_readl(&qmgr_regs->acc[queue][0]);
  68. }
  69. static inline int qmgr_get_stat1(unsigned int queue)
  70. {
  71. extern struct qmgr_regs __iomem *qmgr_regs;
  72. return (__raw_readl(&qmgr_regs->stat1[queue >> 3])
  73. >> ((queue & 7) << 2)) & 0xF;
  74. }
  75. static inline int qmgr_get_stat2(unsigned int queue)
  76. {
  77. extern struct qmgr_regs __iomem *qmgr_regs;
  78. return (__raw_readl(&qmgr_regs->stat2[queue >> 4])
  79. >> ((queue & 0xF) << 1)) & 0x3;
  80. }
  81. static inline int qmgr_stat_empty(unsigned int queue)
  82. {
  83. return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_EMPTY);
  84. }
  85. static inline int qmgr_stat_nearly_empty(unsigned int queue)
  86. {
  87. return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_EMPTY);
  88. }
  89. static inline int qmgr_stat_nearly_full(unsigned int queue)
  90. {
  91. return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_FULL);
  92. }
  93. static inline int qmgr_stat_full(unsigned int queue)
  94. {
  95. return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_FULL);
  96. }
  97. static inline int qmgr_stat_underflow(unsigned int queue)
  98. {
  99. return !!(qmgr_get_stat2(queue) & QUEUE_STAT2_UNDERFLOW);
  100. }
  101. static inline int qmgr_stat_overflow(unsigned int queue)
  102. {
  103. return !!(qmgr_get_stat2(queue) & QUEUE_STAT2_OVERFLOW);
  104. }
  105. #endif