Loading...
1/* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
2/*
3 * Copyright(c) 2017 Intel Corporation.
4 */
5
6#ifndef _HFI1_EXP_RCV_H
7#define _HFI1_EXP_RCV_H
8#include "hfi.h"
9
10#define EXP_TID_SET_EMPTY(set) (set.count == 0 && list_empty(&set.list))
11
12#define EXP_TID_TIDLEN_MASK 0x7FFULL
13#define EXP_TID_TIDLEN_SHIFT 0
14#define EXP_TID_TIDCTRL_MASK 0x3ULL
15#define EXP_TID_TIDCTRL_SHIFT 20
16#define EXP_TID_TIDIDX_MASK 0x3FFULL
17#define EXP_TID_TIDIDX_SHIFT 22
18#define EXP_TID_GET(tid, field) \
19 (((tid) >> EXP_TID_TID##field##_SHIFT) & EXP_TID_TID##field##_MASK)
20
21#define EXP_TID_SET(field, value) \
22 (((value) & EXP_TID_TID##field##_MASK) << \
23 EXP_TID_TID##field##_SHIFT)
24#define EXP_TID_CLEAR(tid, field) ({ \
25 (tid) &= ~(EXP_TID_TID##field##_MASK << \
26 EXP_TID_TID##field##_SHIFT); \
27 })
28#define EXP_TID_RESET(tid, field, value) do { \
29 EXP_TID_CLEAR(tid, field); \
30 (tid) |= EXP_TID_SET(field, (value)); \
31 } while (0)
32
33/*
34 * Define fields in the KDETH header so we can update the header
35 * template.
36 */
37#define KDETH_OFFSET_SHIFT 0
38#define KDETH_OFFSET_MASK 0x7fff
39#define KDETH_OM_SHIFT 15
40#define KDETH_OM_MASK 0x1
41#define KDETH_TID_SHIFT 16
42#define KDETH_TID_MASK 0x3ff
43#define KDETH_TIDCTRL_SHIFT 26
44#define KDETH_TIDCTRL_MASK 0x3
45#define KDETH_INTR_SHIFT 28
46#define KDETH_INTR_MASK 0x1
47#define KDETH_SH_SHIFT 29
48#define KDETH_SH_MASK 0x1
49#define KDETH_KVER_SHIFT 30
50#define KDETH_KVER_MASK 0x3
51#define KDETH_JKEY_SHIFT 0x0
52#define KDETH_JKEY_MASK 0xff
53#define KDETH_HCRC_UPPER_SHIFT 16
54#define KDETH_HCRC_UPPER_MASK 0xff
55#define KDETH_HCRC_LOWER_SHIFT 24
56#define KDETH_HCRC_LOWER_MASK 0xff
57
58#define KDETH_GET(val, field) \
59 (((le32_to_cpu((val))) >> KDETH_##field##_SHIFT) & KDETH_##field##_MASK)
60#define KDETH_SET(dw, field, val) do { \
61 u32 dwval = le32_to_cpu(dw); \
62 dwval &= ~(KDETH_##field##_MASK << KDETH_##field##_SHIFT); \
63 dwval |= (((val) & KDETH_##field##_MASK) << \
64 KDETH_##field##_SHIFT); \
65 dw = cpu_to_le32(dwval); \
66 } while (0)
67
68#define KDETH_RESET(dw, field, val) ({ dw = 0; KDETH_SET(dw, field, val); })
69
70/* KDETH OM multipliers and switch over point */
71#define KDETH_OM_SMALL 4
72#define KDETH_OM_SMALL_SHIFT 2
73#define KDETH_OM_LARGE 64
74#define KDETH_OM_LARGE_SHIFT 6
75#define KDETH_OM_MAX_SIZE (1 << ((KDETH_OM_LARGE / KDETH_OM_SMALL) + 1))
76
77struct tid_group {
78 struct list_head list;
79 u32 base;
80 u8 size;
81 u8 used;
82 u8 map;
83};
84
85/*
86 * Write an "empty" RcvArray entry.
87 * This function exists so the TID registaration code can use it
88 * to write to unused/unneeded entries and still take advantage
89 * of the WC performance improvements. The HFI will ignore this
90 * write to the RcvArray entry.
91 */
92static inline void rcv_array_wc_fill(struct hfi1_devdata *dd, u32 index)
93{
94 /*
95 * Doing the WC fill writes only makes sense if the device is
96 * present and the RcvArray has been mapped as WC memory.
97 */
98 if ((dd->flags & HFI1_PRESENT) && dd->rcvarray_wc) {
99 writeq(0, dd->rcvarray_wc + (index * 8));
100 if ((index & 3) == 3)
101 flush_wc();
102 }
103}
104
105static inline void tid_group_add_tail(struct tid_group *grp,
106 struct exp_tid_set *set)
107{
108 list_add_tail(&grp->list, &set->list);
109 set->count++;
110}
111
112static inline void tid_group_remove(struct tid_group *grp,
113 struct exp_tid_set *set)
114{
115 list_del_init(&grp->list);
116 set->count--;
117}
118
119static inline void tid_group_move(struct tid_group *group,
120 struct exp_tid_set *s1,
121 struct exp_tid_set *s2)
122{
123 tid_group_remove(group, s1);
124 tid_group_add_tail(group, s2);
125}
126
127static inline struct tid_group *tid_group_pop(struct exp_tid_set *set)
128{
129 struct tid_group *grp =
130 list_first_entry(&set->list, struct tid_group, list);
131 list_del_init(&grp->list);
132 set->count--;
133 return grp;
134}
135
136static inline u32 rcventry2tidinfo(u32 rcventry)
137{
138 u32 pair = rcventry & ~0x1;
139
140 return EXP_TID_SET(IDX, pair >> 1) |
141 EXP_TID_SET(CTRL, 1 << (rcventry - pair));
142}
143
144/**
145 * hfi1_tid_group_to_idx - convert an index to a group
146 * @rcd - the receive context
147 * @grp - the group pointer
148 */
149static inline u16
150hfi1_tid_group_to_idx(struct hfi1_ctxtdata *rcd, struct tid_group *grp)
151{
152 return grp - &rcd->groups[0];
153}
154
155/**
156 * hfi1_idx_to_tid_group - convert a group to an index
157 * @rcd - the receive context
158 * @idx - the index
159 */
160static inline struct tid_group *
161hfi1_idx_to_tid_group(struct hfi1_ctxtdata *rcd, u16 idx)
162{
163 return &rcd->groups[idx];
164}
165
166int hfi1_alloc_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
167void hfi1_free_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
168void hfi1_exp_tid_group_init(struct hfi1_ctxtdata *rcd);
169
170#endif /* _HFI1_EXP_RCV_H */
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
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 * Define fields in the KDETH header so we can update the header
77 * template.
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/* 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))
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 * 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.
133 */
134static inline void rcv_array_wc_fill(struct hfi1_devdata *dd, u32 index)
135{
136 /*
137 * Doing the WC fill writes only makes sense if the device is
138 * present and the RcvArray has been mapped as WC memory.
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
186int hfi1_alloc_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
187void hfi1_free_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd);
188void hfi1_exp_tid_group_init(struct exp_tid_set *set);
189
190#endif /* _HFI1_EXP_RCV_H */