treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / infiniband / hw / hfi1 / exp_rcv.h
blobf25362015095bbf319009220d3cd84195d837a28
1 #ifndef _HFI1_EXP_RCV_H
2 #define _HFI1_EXP_RCV_H
3 /*
4 * Copyright(c) 2017 Intel Corporation.
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.
9 * GPL LICENSE SUMMARY
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.
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.
20 * BSD LICENSE
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
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.
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.
50 #include "hfi.h"
52 #define EXP_TID_SET_EMPTY(set) (set.count == 0 && list_empty(&set.list))
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)
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); \
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)
76 * Define fields in the KDETH header so we can update the header
77 * template.
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
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)
110 #define KDETH_RESET(dw, field, val) ({ dw = 0; KDETH_SET(dw, field, val); })
112 /* KDETH OM multipliers and switch over point */
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))
119 struct tid_group {
120 struct list_head list;
121 u32 base;
122 u8 size;
123 u8 used;
124 u8 map;
128 * Write an "empty" RcvArray entry.
129 * This function exists so the TID registaration code can use it
130 * to write to unused/unneeded entries and still take advantage
131 * of the WC performance improvements. The HFI will ignore this
132 * write to the RcvArray entry.
134 static inline void rcv_array_wc_fill(struct hfi1_devdata *dd, u32 index)
137 * Doing the WC fill writes only makes sense if the device is
138 * present and the RcvArray has been mapped as WC memory.
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();
147 static inline void tid_group_add_tail(struct tid_group *grp,
148 struct exp_tid_set *set)
150 list_add_tail(&grp->list, &set->list);
151 set->count++;
154 static inline void tid_group_remove(struct tid_group *grp,
155 struct exp_tid_set *set)
157 list_del_init(&grp->list);
158 set->count--;
161 static inline void tid_group_move(struct tid_group *group,
162 struct exp_tid_set *s1,
163 struct exp_tid_set *s2)
165 tid_group_remove(group, s1);
166 tid_group_add_tail(group, s2);
169 static inline struct tid_group *tid_group_pop(struct exp_tid_set *set)
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;
178 static inline u32 rcventry2tidinfo(u32 rcventry)
180 u32 pair = rcventry & ~0x1;
182 return EXP_TID_SET(IDX, pair >> 1) |
183 EXP_TID_SET(CTRL, 1 << (rcventry - pair));
187 * hfi1_tid_group_to_idx - convert an index to a group
188 * @rcd - the receive context
189 * @grp - the group pointer
191 static inline u16
192 hfi1_tid_group_to_idx(struct hfi1_ctxtdata *rcd, struct tid_group *grp)
194 return grp - &rcd->groups[0];
198 * hfi1_idx_to_tid_group - convert a group to an index
199 * @rcd - the receive context
200 * @idx - the index
202 static inline struct tid_group *
203 hfi1_idx_to_tid_group(struct hfi1_ctxtdata *rcd, u16 idx)
205 return &rcd->groups[idx];
208 int hfi1_alloc_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
209 void hfi1_free_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
210 void hfi1_exp_tid_group_init(struct hfi1_ctxtdata *rcd);
212 #endif /* _HFI1_EXP_RCV_H */