Debian Codegraph @

ptl_ips/ips_recvhdrq.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 #include "psm_user.h"
36 #include "ips_proto.h"
37 #include "ips_proto_header.h"
38 #include "ips_proto_params.h"
39 #include "ips_recvq.h"
40
41 #ifndef _IPS_RECVHDRQ_H
42 #define _IPS_RECVHDRQ_H
43
44 struct ips_recvhdrq;
45 struct ips_recvhdrq_state;
46 struct ips_epstate;
47
48 #define IPS_RECVHDRQ_CONTINUE 0
49 #define IPS_RECVHDRQ_BREAK 1
50 #define IPS_RECVHDRQ_OOO 2 /* out of order */
51 #define IPS_RECVHDRQ_ELEMSZ_MAX 32 /* 128 bytes */
52 #define LAST_RHF_SEQNO 13
53
54 /* CCA related receive events */
55 #define IPS_RECV_EVENT_FECN 0x1
56 #define IPS_RECV_EVENT_BECN 0x2
57
58 struct ips_recvhdrq_event {
59 struct ips_proto *proto;
60 const struct ips_recvhdrq *recvq; /* where message received */
61 const uint32_t *rcv_hdr; /* rcv_hdr ptr */
62 const __le32 *rhf; /* receive header flags */
63 struct ips_message_header *p_hdr; /* protocol header in rcv_hdr */
64 struct ptl_epaddr *ipsaddr; /* peer ipsaddr, if available */
65 psm_epid_t epid; /* peer epid */
66 uint32_t error_flags; /* error flags */
67 uint8_t has_cksum; /* payload has cksum */
68 uint8_t is_congested;/* Packet faced congestion */
69 uint16_t ptype; /* packet type */
70 };
71
72 struct ips_recvhdrq_callbacks {
73 int (*callback_packet_unknown)(const struct ips_recvhdrq_event *);
74 int (*callback_subcontext)(const struct ips_recvhdrq_event *, uint32_t subcontext);
75 int (*callback_error)(struct ips_recvhdrq_event *);
76 };
77
78 psm_error_t
79 ips_recvhdrq_init(const psmi_context_t *context,
80 const struct ips_epstate *epstate,
81 const struct ips_proto *proto,
82 const struct ips_recvq_params *hdrq_params,
83 const struct ips_recvq_params *egrq_params,
84 const struct ips_recvhdrq_callbacks *callbacks,
85 uint32_t flags,
86 uint32_t subcontext,
87 struct ips_recvhdrq *recvq,
88 struct ips_recvhdrq_state *recvq_state);
89
90 psm_error_t
91 ips_recvhdrq_progress(struct ips_recvhdrq *recvq);
92
93 psm_error_t
94 ips_recvhdrq_fini(struct ips_recvhdrq *recvq);
95
96 /*
97 * Structure containing state for recvhdrq reading. This is logically
98 * part of ips_recvhdrq but needs to be separated out for context
99 * sharing so that it can be put in a shared memory page and hence
100 * be available to all processes sharing the context. Generally, do not
101 * put pointers in here since the address map of each process can be
102 * different.
103 */
104 #define NO_EAGER_UPDATE ~0U
105 struct ips_recvhdrq_state
106 {
107 uint32_t hdrq_head; /* software copy of head */
108 uint32_t rcv_egr_index_head; /* software copy of eager index head*/
109 uint32_t hdrq_rhf_seq; /* QLE73XX/QLE72XX last seq */
110 uint32_t head_update_interval; /* Header update interval */
111 uint32_t num_hdrq_done; /* Num header queue done */
112 uint32_t hdr_countdown; /* for false-egr-full tracing */
113 };
114
115 /*
116 * Structure to read from recvhdrq
117 */
118 typedef psm_error_t (*ips_recvhdrq_progress_fn_t)(struct ips_recvhdrq *recvq);
119
120 struct ips_recvhdrq
121 {
122 struct ips_proto *proto;
123 const psmi_context_t *context; /* error handling, epid id, etc. */
124 ips_recvhdrq_progress_fn_t progress_fn;
125 struct ips_recvhdrq_state *state;
126 uint32_t context_flags; /* derived from base_info.spi_runtime_flags */
127 uint32_t subcontext; /* messages that don't match subcontext call
128 * recv_callback_subcontext */
129
130 /* Header queue handling */
131 pthread_spinlock_t hdrq_lock; /* Lock for thread-safe polling */
132 uint32_t hdrq_rhf_off; /* QLE73XX/QLE72XX rhf offset */
133 int hdrq_rhf_notail; /* rhf notail enabled */
134 uint32_t hdrq_elemlast; /* last element precomputed */
135 struct ips_recvq_params hdrq;
136
137 /* Eager queue handling */
138 void **egrq_buftable; /* table of eager idx-to-ptr */
139 struct ips_recvq_params egrq;
140
141 /* Lookup endpoints epid -> ptladdr (rank)) */
142 const struct ips_epstate *epstate;
143
144 /* Callbacks to handle recvq events */
145 struct ips_recvhdrq_callbacks recvq_callbacks;
146
147 /* List of flows with pending acks for receive queue */
148 SLIST_HEAD(pending_flows, ips_flow) pending_acks;
149
150 uint32_t runtime_flags;
151 volatile __u64 *spi_status;
152 };
153
154 PSMI_INLINE(
155 int ips_recvhdrq_isempty(const struct ips_recvhdrq *recvq))
156 {
157 if (recvq->hdrq_rhf_notail) /* use rhf-based reads */
158 return recvq->state->hdrq_rhf_seq !=
159 ipath_hdrget_seq(
160 recvq->hdrq.base_addr + recvq->state->hdrq_head +
161 recvq->hdrq_rhf_off);
162 else
163 return ips_recvq_tail_get(&recvq->hdrq) == recvq->state->hdrq_head;
164 }
165
166 PSMI_INLINE(
167 void *ips_recvhdrq_event_payload(const struct ips_recvhdrq_event *rcv_ev))
168 {
169 /* XXX return NULL if no eager buffer allocated */
170 return ips_recvq_egr_index_2_ptr(rcv_ev->recvq->egrq_buftable,
171 ipath_hdrget_index(rcv_ev->rhf));
172 }
173
174 PSMI_INLINE(
175 int ips_recvhdrq_trylock(struct ips_recvhdrq *recvq))
176 {
177 int ret = pthread_spin_trylock(&recvq->hdrq_lock);
178 return !ret;
179 }
180
181 PSMI_INLINE(
182 int ips_recvhdrq_lock(struct ips_recvhdrq *recvq))
183 {
184 int ret = pthread_spin_lock(&recvq->hdrq_lock);
185 return !ret;
186 }
187
188 PSMI_INLINE(
189 int ips_recvhdrq_unlock(struct ips_recvhdrq *recvq))
190 {
191 int ret = pthread_spin_unlock(&recvq->hdrq_lock);
192 return !ret;
193 }
194
195 PSMI_INLINE(
196 uint32_t ips_recvhdrq_event_paylen(const struct ips_recvhdrq_event *rcv_ev))
197 {
198 uint32_t cksum_len = rcv_ev->has_cksum ? PSM_CRC_SIZE_IN_BYTES : 0;
199
200 return ipath_hdrget_length_in_bytes(rcv_ev->rhf) -
201 (sizeof(struct ips_message_header) + CRC_SIZE_IN_BYTES + cksum_len +
202 ((__be32_to_cpu(rcv_ev->p_hdr->bth[0]) >> 20) & 3)); /* padding */
203 }
204
205 #endif /* _IPS_RECVHDRQ_H */
206