exp_rcv.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #ifndef _HFI1_EXP_RCV_H
  2. #define _HFI1_EXP_RCV_H
  3. /*
  4. * Copyright(c) 2017 Intel Corporation.
  5. *
  6. * This file is provided under a dual BSD/GPLv2 license. When using or
  7. * redistributing this file, you may do so under either license.
  8. *
  9. * GPL LICENSE SUMMARY
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * BSD LICENSE
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. *
  26. * - Redistributions of source code must retain the above copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * - Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in
  30. * the documentation and/or other materials provided with the
  31. * distribution.
  32. * - Neither the name of Intel Corporation nor the names of its
  33. * contributors may be used to endorse or promote products derived
  34. * from this software without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  37. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  39. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  43. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  44. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  46. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. */
  49. #include "hfi.h"
  50. #define EXP_TID_SET_EMPTY(set) (set.count == 0 && list_empty(&set.list))
  51. #define EXP_TID_TIDLEN_MASK 0x7FFULL
  52. #define EXP_TID_TIDLEN_SHIFT 0
  53. #define EXP_TID_TIDCTRL_MASK 0x3ULL
  54. #define EXP_TID_TIDCTRL_SHIFT 20
  55. #define EXP_TID_TIDIDX_MASK 0x3FFULL
  56. #define EXP_TID_TIDIDX_SHIFT 22
  57. #define EXP_TID_GET(tid, field) \
  58. (((tid) >> EXP_TID_TID##field##_SHIFT) & EXP_TID_TID##field##_MASK)
  59. #define EXP_TID_SET(field, value) \
  60. (((value) & EXP_TID_TID##field##_MASK) << \
  61. EXP_TID_TID##field##_SHIFT)
  62. #define EXP_TID_CLEAR(tid, field) ({ \
  63. (tid) &= ~(EXP_TID_TID##field##_MASK << \
  64. EXP_TID_TID##field##_SHIFT); \
  65. })
  66. #define EXP_TID_RESET(tid, field, value) do { \
  67. EXP_TID_CLEAR(tid, field); \
  68. (tid) |= EXP_TID_SET(field, (value)); \
  69. } while (0)
  70. /*
  71. * Define fields in the KDETH header so we can update the header
  72. * template.
  73. */
  74. #define KDETH_OFFSET_SHIFT 0
  75. #define KDETH_OFFSET_MASK 0x7fff
  76. #define KDETH_OM_SHIFT 15
  77. #define KDETH_OM_MASK 0x1
  78. #define KDETH_TID_SHIFT 16
  79. #define KDETH_TID_MASK 0x3ff
  80. #define KDETH_TIDCTRL_SHIFT 26
  81. #define KDETH_TIDCTRL_MASK 0x3
  82. #define KDETH_INTR_SHIFT 28
  83. #define KDETH_INTR_MASK 0x1
  84. #define KDETH_SH_SHIFT 29
  85. #define KDETH_SH_MASK 0x1
  86. #define KDETH_KVER_SHIFT 30
  87. #define KDETH_KVER_MASK 0x3
  88. #define KDETH_JKEY_SHIFT 0x0
  89. #define KDETH_JKEY_MASK 0xff
  90. #define KDETH_HCRC_UPPER_SHIFT 16
  91. #define KDETH_HCRC_UPPER_MASK 0xff
  92. #define KDETH_HCRC_LOWER_SHIFT 24
  93. #define KDETH_HCRC_LOWER_MASK 0xff
  94. #define KDETH_GET(val, field) \
  95. (((le32_to_cpu((val))) >> KDETH_##field##_SHIFT) & KDETH_##field##_MASK)
  96. #define KDETH_SET(dw, field, val) do { \
  97. u32 dwval = le32_to_cpu(dw); \
  98. dwval &= ~(KDETH_##field##_MASK << KDETH_##field##_SHIFT); \
  99. dwval |= (((val) & KDETH_##field##_MASK) << \
  100. KDETH_##field##_SHIFT); \
  101. dw = cpu_to_le32(dwval); \
  102. } while (0)
  103. #define KDETH_RESET(dw, field, val) ({ dw = 0; KDETH_SET(dw, field, val); })
  104. /* KDETH OM multipliers and switch over point */
  105. #define KDETH_OM_SMALL 4
  106. #define KDETH_OM_SMALL_SHIFT 2
  107. #define KDETH_OM_LARGE 64
  108. #define KDETH_OM_LARGE_SHIFT 6
  109. #define KDETH_OM_MAX_SIZE (1 << ((KDETH_OM_LARGE / KDETH_OM_SMALL) + 1))
  110. struct tid_group {
  111. struct list_head list;
  112. u32 base;
  113. u8 size;
  114. u8 used;
  115. u8 map;
  116. };
  117. /*
  118. * Write an "empty" RcvArray entry.
  119. * This function exists so the TID registaration code can use it
  120. * to write to unused/unneeded entries and still take advantage
  121. * of the WC performance improvements. The HFI will ignore this
  122. * write to the RcvArray entry.
  123. */
  124. static inline void rcv_array_wc_fill(struct hfi1_devdata *dd, u32 index)
  125. {
  126. /*
  127. * Doing the WC fill writes only makes sense if the device is
  128. * present and the RcvArray has been mapped as WC memory.
  129. */
  130. if ((dd->flags & HFI1_PRESENT) && dd->rcvarray_wc) {
  131. writeq(0, dd->rcvarray_wc + (index * 8));
  132. if ((index & 3) == 3)
  133. flush_wc();
  134. }
  135. }
  136. static inline void tid_group_add_tail(struct tid_group *grp,
  137. struct exp_tid_set *set)
  138. {
  139. list_add_tail(&grp->list, &set->list);
  140. set->count++;
  141. }
  142. static inline void tid_group_remove(struct tid_group *grp,
  143. struct exp_tid_set *set)
  144. {
  145. list_del_init(&grp->list);
  146. set->count--;
  147. }
  148. static inline void tid_group_move(struct tid_group *group,
  149. struct exp_tid_set *s1,
  150. struct exp_tid_set *s2)
  151. {
  152. tid_group_remove(group, s1);
  153. tid_group_add_tail(group, s2);
  154. }
  155. static inline struct tid_group *tid_group_pop(struct exp_tid_set *set)
  156. {
  157. struct tid_group *grp =
  158. list_first_entry(&set->list, struct tid_group, list);
  159. list_del_init(&grp->list);
  160. set->count--;
  161. return grp;
  162. }
  163. static inline u32 rcventry2tidinfo(u32 rcventry)
  164. {
  165. u32 pair = rcventry & ~0x1;
  166. return EXP_TID_SET(IDX, pair >> 1) |
  167. EXP_TID_SET(CTRL, 1 << (rcventry - pair));
  168. }
  169. /**
  170. * hfi1_tid_group_to_idx - convert an index to a group
  171. * @rcd - the receive context
  172. * @grp - the group pointer
  173. */
  174. static inline u16
  175. hfi1_tid_group_to_idx(struct hfi1_ctxtdata *rcd, struct tid_group *grp)
  176. {
  177. return grp - &rcd->groups[0];
  178. }
  179. /**
  180. * hfi1_idx_to_tid_group - convert a group to an index
  181. * @rcd - the receive context
  182. * @idx - the index
  183. */
  184. static inline struct tid_group *
  185. hfi1_idx_to_tid_group(struct hfi1_ctxtdata *rcd, u16 idx)
  186. {
  187. return &rcd->groups[idx];
  188. }
  189. int hfi1_alloc_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
  190. void hfi1_free_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
  191. void hfi1_exp_tid_group_init(struct hfi1_ctxtdata *rcd);
  192. #endif /* _HFI1_EXP_RCV_H */