1#ifndef _HFI1_EXP_RCV_H
2#define _HFI1_EXP_RCV_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50#include "hfi.h"
51
52#define EXP_TID_SET_EMPTY(set) (set.count == 0 && list_empty(&set.list))
53
54#define EXP_TID_TIDLEN_MASK 0x7FFULL
55#define EXP_TID_TIDLEN_SHIFT 0
56#define EXP_TID_TIDCTRL_MASK 0x3ULL
57#define EXP_TID_TIDCTRL_SHIFT 20
58#define EXP_TID_TIDIDX_MASK 0x3FFULL
59#define EXP_TID_TIDIDX_SHIFT 22
60#define EXP_TID_GET(tid, field) \
61 (((tid) >> EXP_TID_TID##field##_SHIFT) & EXP_TID_TID##field##_MASK)
62
63#define EXP_TID_SET(field, value) \
64 (((value) & EXP_TID_TID##field##_MASK) << \
65 EXP_TID_TID##field##_SHIFT)
66#define EXP_TID_CLEAR(tid, field) ({ \
67 (tid) &= ~(EXP_TID_TID##field##_MASK << \
68 EXP_TID_TID##field##_SHIFT); \
69 })
70#define EXP_TID_RESET(tid, field, value) do { \
71 EXP_TID_CLEAR(tid, field); \
72 (tid) |= EXP_TID_SET(field, (value)); \
73 } while (0)
74
75
76
77
78
79#define KDETH_OFFSET_SHIFT 0
80#define KDETH_OFFSET_MASK 0x7fff
81#define KDETH_OM_SHIFT 15
82#define KDETH_OM_MASK 0x1
83#define KDETH_TID_SHIFT 16
84#define KDETH_TID_MASK 0x3ff
85#define KDETH_TIDCTRL_SHIFT 26
86#define KDETH_TIDCTRL_MASK 0x3
87#define KDETH_INTR_SHIFT 28
88#define KDETH_INTR_MASK 0x1
89#define KDETH_SH_SHIFT 29
90#define KDETH_SH_MASK 0x1
91#define KDETH_KVER_SHIFT 30
92#define KDETH_KVER_MASK 0x3
93#define KDETH_JKEY_SHIFT 0x0
94#define KDETH_JKEY_MASK 0xff
95#define KDETH_HCRC_UPPER_SHIFT 16
96#define KDETH_HCRC_UPPER_MASK 0xff
97#define KDETH_HCRC_LOWER_SHIFT 24
98#define KDETH_HCRC_LOWER_MASK 0xff
99
100#define KDETH_GET(val, field) \
101 (((le32_to_cpu((val))) >> KDETH_##field##_SHIFT) & KDETH_##field##_MASK)
102#define KDETH_SET(dw, field, val) do { \
103 u32 dwval = le32_to_cpu(dw); \
104 dwval &= ~(KDETH_##field##_MASK << KDETH_##field##_SHIFT); \
105 dwval |= (((val) & KDETH_##field##_MASK) << \
106 KDETH_##field##_SHIFT); \
107 dw = cpu_to_le32(dwval); \
108 } while (0)
109
110#define KDETH_RESET(dw, field, val) ({ dw = 0; KDETH_SET(dw, field, val); })
111
112
113#define KDETH_OM_SMALL 4
114#define KDETH_OM_SMALL_SHIFT 2
115#define KDETH_OM_LARGE 64
116#define KDETH_OM_LARGE_SHIFT 6
117#define KDETH_OM_MAX_SIZE (1 << ((KDETH_OM_LARGE / KDETH_OM_SMALL) + 1))
118
119struct tid_group {
120 struct list_head list;
121 u32 base;
122 u8 size;
123 u8 used;
124 u8 map;
125};
126
127
128
129
130
131
132
133
134static inline void rcv_array_wc_fill(struct hfi1_devdata *dd, u32 index)
135{
136
137
138
139
140 if ((dd->flags & HFI1_PRESENT) && dd->rcvarray_wc) {
141 writeq(0, dd->rcvarray_wc + (index * 8));
142 if ((index & 3) == 3)
143 flush_wc();
144 }
145}
146
147static inline void tid_group_add_tail(struct tid_group *grp,
148 struct exp_tid_set *set)
149{
150 list_add_tail(&grp->list, &set->list);
151 set->count++;
152}
153
154static inline void tid_group_remove(struct tid_group *grp,
155 struct exp_tid_set *set)
156{
157 list_del_init(&grp->list);
158 set->count--;
159}
160
161static inline void tid_group_move(struct tid_group *group,
162 struct exp_tid_set *s1,
163 struct exp_tid_set *s2)
164{
165 tid_group_remove(group, s1);
166 tid_group_add_tail(group, s2);
167}
168
169static inline struct tid_group *tid_group_pop(struct exp_tid_set *set)
170{
171 struct tid_group *grp =
172 list_first_entry(&set->list, struct tid_group, list);
173 list_del_init(&grp->list);
174 set->count--;
175 return grp;
176}
177
178static inline u32 rcventry2tidinfo(u32 rcventry)
179{
180 u32 pair = rcventry & ~0x1;
181
182 return EXP_TID_SET(IDX, pair >> 1) |
183 EXP_TID_SET(CTRL, 1 << (rcventry - pair));
184}
185
186
187
188
189
190
191static inline u16
192hfi1_tid_group_to_idx(struct hfi1_ctxtdata *rcd, struct tid_group *grp)
193{
194 return grp - &rcd->groups[0];
195}
196
197
198
199
200
201
202static inline struct tid_group *
203hfi1_idx_to_tid_group(struct hfi1_ctxtdata *rcd, u16 idx)
204{
205 return &rcd->groups[idx];
206}
207
208int hfi1_alloc_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
209void hfi1_free_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
210void hfi1_exp_tid_group_init(struct hfi1_ctxtdata *rcd);
211
212#endif
213