Debian Codegraph @

ptl_ips/ips_tidflow.c

raw
1 /*
2 * Copyright (c) 2013. Intel Corporation. All rights reserved.
3 * Copyright (c) 2006-2012. QLogic Corporation. All rights reserved.
4 * Copyright (c) 2003-2006, PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35 #include "ips_tidflow.h"
36
37 psm_error_t ips_tf_init(const psmi_context_t *context,
38 struct ips_tfctrl *tfctrl,
39 int start_flowidx,
40 int end_flowidx,
41 ips_tf_avail_cb_fn_t cb,
42 void *cb_context)
43 {
44 int tf_idx;
45 int num_flows = end_flowidx - start_flowidx;
46
47 #if TF_ADD
48 struct psmi_stats_entry entries[] = {
49 PSMI_STATS_DECL("tidflow update count", MPSPAWN_STATS_REDUCTION_ALL,
50 NULL, &tfctrl->tf_num_total),
51 };
52 #endif
53
54 psmi_assert_always(num_flows > 0);
55
56 tfctrl->context = context;
57 tfctrl->tf_start_idx = start_flowidx;
58 tfctrl->tf_end_idx = end_flowidx;
59 tfctrl->tf_num_max = num_flows;
60 tfctrl->tf_num_avail = num_flows;
61 tfctrl->tf_num_total = 0;
62 tfctrl->tf_avail_cb = cb;
63 tfctrl->tf_avail_context= cb_context;
64
65 SLIST_INIT(&tfctrl->tf_avail);
66
67 for (tf_idx = start_flowidx; tf_idx < end_flowidx; tf_idx++) {
68 /* Update flow state */
69 tfctrl->tf[tf_idx].state = TF_STATE_DEALLOCATED;
70 tfctrl->tf[tf_idx].tf_idx = tf_idx;
71 tfctrl->tf[tf_idx].next_gen = IPS_TF_INVALID_GENERATION + 1;
72
73 SLIST_NEXT(&tfctrl->tf[tf_idx], next) = NULL;
74 SLIST_INSERT_HEAD(&tfctrl->tf_avail, &tfctrl->tf[tf_idx], next);
75
76 /* Use tidflow reset as we may want to emulate hardware suppression on
77 * QLE73XX and tidflow_set_entry enables the header suppression engine while
78 * reset does not.
79 */
80 ipath_tidflow_reset(context->ctrl, tf_idx);
81 }
82
83 #if TF_ADD
84 /* TF_ADD: Add a new stats type for tid flows in psm_stats.h */
85 return psmi_stats_register_type(PSMI_STATS_NO_HEADING,
86 PSMI_STATSTYPE_TIDS,
87 entries,
88 PSMI_STATS_HOWMANY(entries),
89 tidc);
90 #else
91 return PSM_OK;
92 #endif
93 }
94
95 psm_error_t ips_tf_fini(struct ips_tfctrl *tfctrl)
96 {
97 return PSM_OK;
98 }
99
100 /* Allocate a tidflow */
101 psm_error_t ips_tf_allocate(struct ips_tfctrl *tfctrl,
102 uint32_t *tf_idx,
103 uint32_t *tf_gen)
104 {
105 struct ips_tf *tf;
106
107 if (!tfctrl->tf_num_avail){
108 *tf_idx = IPS_TF_INVALID;
109 *tf_gen = IPS_TF_INVALID_GENERATION;
110 return PSM_EP_NO_RESOURCES;
111 }
112
113 psmi_assert(!SLIST_EMPTY(&tfctrl->tf_avail));
114
115 tf = SLIST_FIRST(&tfctrl->tf_avail);
116 SLIST_REMOVE_HEAD(&tfctrl->tf_avail, next);
117
118 psmi_assert(tf->state == TF_STATE_DEALLOCATED);
119
120 tf->state = TF_STATE_ALLOCATED;
121
122 tfctrl->tf_num_avail--;
123 tfctrl->tf_num_total++;
124
125 *tf_idx = tf->tf_idx;
126 *tf_gen = tf->next_gen;
127
128 tf->next_gen++;
129 if (tf->next_gen == IPS_TF_INVALID_GENERATION)
130 tf->next_gen++;
131
132 psmi_assert(*tf_gen != IPS_TF_INVALID_GENERATION);
133 psmi_assert_always(*tf_gen <= IPS_TF_MAX_GENERATION);
134
135 return PSM_OK;
136 }
137
138 /* Deallocate a tidflow */
139 psm_error_t ips_tf_deallocate(struct ips_tfctrl *tfctrl, uint32_t tf_idx)
140 {
141 struct ips_tf *tf;
142
143 psmi_assert_always(tf_idx < tfctrl->tf_end_idx);
144
145 tf = &tfctrl->tf[tf_idx];
146 psmi_assert(tf->state == TF_STATE_ALLOCATED);
147 tf->state = TF_STATE_DEALLOCATED;
148
149 /* Mark invalid generation for flow (stale packets will be dropped) */
150 ipath_tidflow_set_entry(tfctrl->context->ctrl,
151 tf_idx, IPS_TF_INVALID_GENERATION, 0);
152
153 SLIST_NEXT(tf, next) = NULL;
154 SLIST_INSERT_HEAD(&tfctrl->tf_avail, tf, next);
155
156 /* If an available callback is registered invoke it */
157 if ((tfctrl->tf_num_avail++ == 0) && tfctrl->tf_avail_cb)
158 tfctrl->tf_avail_cb(tfctrl, tfctrl->tf_avail_context);
159
160 return PSM_OK;
161 }
162
163 /* Allocate a generation for a flow */
164 psm_error_t ips_tfgen_allocate(struct ips_tfctrl *tfctrl,
165 uint32_t tf_idx,
166 uint32_t *tfgen)
167 {
168 struct ips_tf *tf;
169 int ret = PSM_OK;
170
171 psmi_assert_always(tf_idx < tfctrl->tf_end_idx);
172
173 tf = &tfctrl->tf[tf_idx];
174 psmi_assert(tf->state == TF_STATE_ALLOCATED);
175
176 *tfgen = tf->next_gen;
177
178 tf->next_gen++;
179 if (tf->next_gen == IPS_TF_INVALID_GENERATION)
180 tf->next_gen++;
181
182 return ret;
183 }
184