Debian Codegraph @

ptl_ips/ips_tidflow.h

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 #ifndef _IPS_TIDFLOW_H
36 #define _IPS_TIDFLOW_H
37
38 #include "psm_user.h"
39
40 #define IPS_TF_MAX_GENERATION 256
41 #define IPS_TF_INVALID (~0U)
42 #define IPS_TF_INVALID_GENERATION 0
43
44 #define IPS_TF_PSN_PACK(flow,gen,seq) \
45 ( ((((uint64_t)flow)&0x1f)<<19) | \
46 ((((uint64_t)gen)&INFINIPATH_TF_GENVAL_MASK)<<INFINIPATH_TF_GENVAL_SHIFT)|\
47 ((((uint64_t)seq)&INFINIPATH_TF_SEQNUM_MASK)<<INFINIPATH_TF_SEQNUM_SHIFT))
48
49 #define IPS_TF_PSN_UNPACK(tfval,flow,gen,seq) do { \
50 (flow) = ((tfval)>>19) & 0x1f; \
51 (gen) = ((tfval)>>INFINIPATH_TF_GENVAL_SHIFT) & INFINIPATH_TF_GENVAL_MASK; \
52 (seq) = ((tfval)>>INFINIPATH_TF_SEQNUM_SHIFT) & INFINIPATH_TF_SEQNUM_MASK; \
53 } while (0)
54
55 #define IPS_TF_INC_SEQ(tfval) \
56 tfval = (tfval & ~INFINIPATH_TF_SEQNUM_MASK) | ((ipath_tidflow_get_seqnum(tfval) + 1) & INFINIPATH_TF_SEQNUM_MASK)
57
58 struct ips_tfctrl;
59
60 typedef void (*ips_tf_avail_cb_fn_t)(struct ips_tfctrl *,
61 void *context);
62 typedef enum {
63 TF_STATE_INVALID = 0,
64 TF_STATE_ALLOCATED = 1,
65 TF_STATE_DEALLOCATED = 2
66 } tf_state_t;
67
68 struct ips_tf {
69
70 SLIST_ENTRY(ips_tf) next;
71
72 tf_state_t state;
73
74 uint32_t tf_idx;
75
76 uint32_t next_gen:8;
77 uint32_t pad:24;
78 };
79
80 struct ips_tfctrl {
81 const psmi_context_t *context;
82
83 uint32_t tf_start_idx;
84 uint32_t tf_end_idx;
85
86 uint32_t tf_num_max;
87 uint32_t tf_num_avail;
88
89 uint32_t tf_num_total;
90
91 ips_tf_avail_cb_fn_t tf_avail_cb;
92 void *tf_avail_context;
93
94 SLIST_HEAD(tf_free, ips_tf) tf_avail;
95
96 struct ips_tf tf[INFINIPATH_TF_NFLOWS];
97 };
98
99 PSMI_ALWAYS_INLINE(
100 int
101 ips_tf_available(struct ips_tfctrl *tfctrl))
102 {
103 return tfctrl->tf_num_avail;
104 }
105
106 psm_error_t ips_tf_init(const psmi_context_t *context,
107 struct ips_tfctrl *tfctrl,
108 int start_flowidx,
109 int end_flowidx,
110 ips_tf_avail_cb_fn_t cb,
111 void *cb_context);
112 psm_error_t ips_tf_fini(struct ips_tfctrl *tfctrl);
113
114 /* Allocate a tidflow */
115 psm_error_t ips_tf_allocate(struct ips_tfctrl *tfctrl,
116 uint32_t *tf_idx,
117 uint32_t *tf_gen);
118
119 /* Deallocate a tidflow */
120 psm_error_t ips_tf_deallocate(struct ips_tfctrl *tfctrl, uint32_t tf_idx);
121
122 /* Allocate a generation for a flow */
123 psm_error_t ips_tfgen_allocate(struct ips_tfctrl *tfctrl,
124 uint32_t tf_idx,
125 uint32_t *tfgen);
126
127 #endif