ionic_regs.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) OR BSD-2-Clause */
  2. /* Copyright (c) 2018-2019 Pensando Systems, Inc. All rights reserved. */
  3. #ifndef IONIC_REGS_H
  4. #define IONIC_REGS_H
  5. #include <linux/io.h>
  6. /** struct ionic_intr - interrupt control register set.
  7. * @coal_init: coalesce timer initial value.
  8. * @mask: interrupt mask value.
  9. * @credits: interrupt credit count and return.
  10. * @mask_assert: interrupt mask value on assert.
  11. * @coal: coalesce timer time remaining.
  12. */
  13. struct ionic_intr {
  14. u32 coal_init;
  15. u32 mask;
  16. u32 credits;
  17. u32 mask_assert;
  18. u32 coal;
  19. u32 rsvd[3];
  20. };
  21. #define IONIC_INTR_CTRL_REGS_MAX 2048
  22. #define IONIC_INTR_CTRL_COAL_MAX 0x3F
  23. /** enum ionic_intr_mask_vals - valid values for mask and mask_assert.
  24. * @IONIC_INTR_MASK_CLEAR: unmask interrupt.
  25. * @IONIC_INTR_MASK_SET: mask interrupt.
  26. */
  27. enum ionic_intr_mask_vals {
  28. IONIC_INTR_MASK_CLEAR = 0,
  29. IONIC_INTR_MASK_SET = 1,
  30. };
  31. /** enum ionic_intr_credits_bits - bitwise composition of credits values.
  32. * @IONIC_INTR_CRED_COUNT: bit mask of credit count, no shift needed.
  33. * @IONIC_INTR_CRED_COUNT_SIGNED: bit mask of credit count, including sign bit.
  34. * @IONIC_INTR_CRED_UNMASK: unmask the interrupt.
  35. * @IONIC_INTR_CRED_RESET_COALESCE: reset the coalesce timer.
  36. * @IONIC_INTR_CRED_REARM: unmask the and reset the timer.
  37. */
  38. enum ionic_intr_credits_bits {
  39. IONIC_INTR_CRED_COUNT = 0x7fffu,
  40. IONIC_INTR_CRED_COUNT_SIGNED = 0xffffu,
  41. IONIC_INTR_CRED_UNMASK = 0x10000u,
  42. IONIC_INTR_CRED_RESET_COALESCE = 0x20000u,
  43. IONIC_INTR_CRED_REARM = (IONIC_INTR_CRED_UNMASK |
  44. IONIC_INTR_CRED_RESET_COALESCE),
  45. };
  46. static inline void ionic_intr_coal_init(struct ionic_intr __iomem *intr_ctrl,
  47. int intr_idx, u32 coal)
  48. {
  49. iowrite32(coal, &intr_ctrl[intr_idx].coal_init);
  50. }
  51. static inline void ionic_intr_mask(struct ionic_intr __iomem *intr_ctrl,
  52. int intr_idx, u32 mask)
  53. {
  54. iowrite32(mask, &intr_ctrl[intr_idx].mask);
  55. }
  56. static inline void ionic_intr_credits(struct ionic_intr __iomem *intr_ctrl,
  57. int intr_idx, u32 cred, u32 flags)
  58. {
  59. if (WARN_ON_ONCE(cred > IONIC_INTR_CRED_COUNT)) {
  60. cred = ioread32(&intr_ctrl[intr_idx].credits);
  61. cred &= IONIC_INTR_CRED_COUNT_SIGNED;
  62. }
  63. iowrite32(cred | flags, &intr_ctrl[intr_idx].credits);
  64. }
  65. static inline void ionic_intr_clean(struct ionic_intr __iomem *intr_ctrl,
  66. int intr_idx)
  67. {
  68. u32 cred;
  69. cred = ioread32(&intr_ctrl[intr_idx].credits);
  70. cred &= IONIC_INTR_CRED_COUNT_SIGNED;
  71. cred |= IONIC_INTR_CRED_RESET_COALESCE;
  72. iowrite32(cred, &intr_ctrl[intr_idx].credits);
  73. }
  74. static inline void ionic_intr_mask_assert(struct ionic_intr __iomem *intr_ctrl,
  75. int intr_idx, u32 mask)
  76. {
  77. iowrite32(mask, &intr_ctrl[intr_idx].mask_assert);
  78. }
  79. /** enum ionic_dbell_bits - bitwise composition of dbell values.
  80. *
  81. * @IONIC_DBELL_QID_MASK: unshifted mask of valid queue id bits.
  82. * @IONIC_DBELL_QID_SHIFT: queue id shift amount in dbell value.
  83. * @IONIC_DBELL_QID: macro to build QID component of dbell value.
  84. *
  85. * @IONIC_DBELL_RING_MASK: unshifted mask of valid ring bits.
  86. * @IONIC_DBELL_RING_SHIFT: ring shift amount in dbell value.
  87. * @IONIC_DBELL_RING: macro to build ring component of dbell value.
  88. *
  89. * @IONIC_DBELL_RING_0: ring zero dbell component value.
  90. * @IONIC_DBELL_RING_1: ring one dbell component value.
  91. * @IONIC_DBELL_RING_2: ring two dbell component value.
  92. * @IONIC_DBELL_RING_3: ring three dbell component value.
  93. *
  94. * @IONIC_DBELL_INDEX_MASK: bit mask of valid index bits, no shift needed.
  95. */
  96. enum ionic_dbell_bits {
  97. IONIC_DBELL_QID_MASK = 0xffffff,
  98. IONIC_DBELL_QID_SHIFT = 24,
  99. #define IONIC_DBELL_QID(n) \
  100. (((u64)(n) & IONIC_DBELL_QID_MASK) << IONIC_DBELL_QID_SHIFT)
  101. IONIC_DBELL_RING_MASK = 0x7,
  102. IONIC_DBELL_RING_SHIFT = 16,
  103. #define IONIC_DBELL_RING(n) \
  104. (((u64)(n) & IONIC_DBELL_RING_MASK) << IONIC_DBELL_RING_SHIFT)
  105. IONIC_DBELL_RING_0 = 0,
  106. IONIC_DBELL_RING_1 = IONIC_DBELL_RING(1),
  107. IONIC_DBELL_RING_2 = IONIC_DBELL_RING(2),
  108. IONIC_DBELL_RING_3 = IONIC_DBELL_RING(3),
  109. IONIC_DBELL_INDEX_MASK = 0xffff,
  110. };
  111. static inline void ionic_dbell_ring(u64 __iomem *db_page, int qtype, u64 val)
  112. {
  113. writeq(val, &db_page[qtype]);
  114. }
  115. #endif /* IONIC_REGS_H */