Debian Codegraph @

ipath/ipath_write_pio-x86_64.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2006-2012. QLogic Corporation. All rights reserved.
3 * Copyright (c) 2003-2006, PathScale, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34 // This file contains the initialization functions used by the low
35 // level infinipath protocol code.
36
37 #include <sys/poll.h>
38 #include <sys/types.h>
39 #include <stdint.h>
40 #include <stdlib.h>
41 #include <stddef.h>
42 #include <unistd.h>
43 #include <errno.h>
44 #include <string.h>
45 #include <stdio.h>
46 #include <fcntl.h>
47 #include <malloc.h>
48
49 #include "ipserror.h"
50 #include "ipath_user.h"
51
52 /*
53 * These pio copy routines are here so they can be used by test code, as well
54 * as by MPI, and can change independently of MPI
55 */
56
57 /*
58 * for processors that may not write store buffers in the order filled,
59 * and when the store buffer is not completely filled (partial at end, or
60 * interrupted and flushed) may write the partial buffer in
61 * "random" order. requires additional serialization
62 */
63 void ipath_write_pio_force_order(volatile uint32_t *piob, const struct ipath_pio_params *pioparm,
64 void *hdr, void *bdata)
65 {
66 union ipath_pbc buf = {.qword = 0};
67 uint32_t cksum_len = pioparm->cksum_is_valid ?
68 IPATH_CRC_SIZE_IN_BYTES : 0;
69
70 buf.length =
71 __cpu_to_le16(((IPATH_MESSAGE_HDR_SIZE + cksum_len + pioparm->length) >> 2) + 1);
72 if(pioparm->port > 1)
73 buf.pbcflags = __cpu_to_le32((pioparm->vl << __PBC_VLSHIFT) |
74 __PBC_IBPORT |
75 pioparm->rate);
76 else
77 buf.pbcflags = __cpu_to_le32(pioparm->vl << __PBC_VLSHIFT |
78 pioparm->rate);
79
80 *(volatile uint64_t *)piob = buf.qword;
81 ips_wmb(); // pbc must be forced to be first write to chip buffer
82 piob += 2;
83
84 if(!pioparm->length) {
85 uint32_t *dhdr, dcpywords;
86 dcpywords = (IPATH_MESSAGE_HDR_SIZE >> 2)-1;
87 ipath_dwordcpy_safe(piob, hdr, dcpywords);
88 ips_wmb();
89 dhdr = hdr;
90 piob += dcpywords;
91 dhdr += dcpywords;
92 *piob++ = *dhdr;
93 } else {
94 uint32_t *pay2 = bdata, j;
95 uint32_t len = pioparm->length;
96
97 ipath_dwordcpy_safe(piob, hdr,
98 IPATH_MESSAGE_HDR_SIZE >> 2);
99 piob += IPATH_MESSAGE_HDR_SIZE >> 2;
100
101 len >>= 2;
102 if(len>16) {
103 uint32_t pay_words = 16*((len-1)/16);
104 ipath_dwordcpy_safe(piob, pay2, pay_words);
105 piob += pay_words;
106 pay2 += pay_words;
107 len -= pay_words;
108 }
109 // now write the final chunk a word at a time, fence before trigger
110 for(j=0;j<(len-1);j++)
111 *piob++ = *pay2++;
112 ips_wmb(); // flush the buffer out now, so
113 *piob++ = *pay2;
114 }
115
116 /* If checksum is enabled insert CRC at end of packet */
117 if_pf (pioparm->cksum_is_valid){
118 int nCRCopies = IPATH_CRC_SIZE_IN_BYTES >> 2;
119 int nCRC = 0;
120
121 while (nCRC < (nCRCopies-1)) {
122 *piob = pioparm->cksum;
123 piob++;
124 nCRC++;
125 }
126
127 ips_wmb();
128 *piob = pioparm->cksum;
129 }
130
131 /* send it on it's way, now, rather than waiting for processor to
132 * get around to flushing it */
133 ips_wmb();
134 }
135
136
137 /*
138 * for processors that always write store buffers in the order filled,
139 * and if store buffer not completely filled (partial at end, or
140 * interrupted and flushed) always write the partial buffer in
141 * address order. Avoids serializing and flush instructions
142 * where possible.
143 */
144 #ifdef __MIC__
145 void ipath_write_pio_vector(volatile uint32_t *piob, const struct ipath_pio_params *pioparm,
146 void *hdr, void *bdata)
147 {
148 union ipath_pbc *pbc;
149 uint32_t cksum_len = pioparm->cksum_is_valid ?
150 IPATH_CRC_SIZE_IN_BYTES : 0;
151
152 pbc = (union ipath_pbc *)((char *)hdr - 8);
153 pbc->qword = 0;
154 pbc->length =
155 __cpu_to_le16(((IPATH_MESSAGE_HDR_SIZE + cksum_len + pioparm->length) >> 2) + 1);
156 if (pioparm->port > 1)
157 pbc->pbcflags = __cpu_to_le32((pioparm->vl << __PBC_VLSHIFT) |
158 __PBC_IBPORT |
159 pioparm->rate);
160 else
161 pbc->pbcflags = __cpu_to_le32(pioparm->vl << __PBC_VLSHIFT |
162 pioparm->rate);
163
164 #ifdef PSM_DEBUG
165 if (((uint64_t)piob) & 63) {
166 _IPATH_ERROR("ipath_write_pio_vector(): piob not 64byte aligned\n");
167 return;
168 }
169 if (((uint64_t)pbc) & 63) {
170 _IPATH_ERROR("ipath_write_pio_vector(): pbc not 64byte aligned\n");
171 return;
172 }
173 #endif
174 memcpy((uint32_t *)piob, pbc, IPATH_MESSAGE_HDR_SIZE+8);
175 piob += (IPATH_MESSAGE_HDR_SIZE >> 2) + 2;
176
177 if(pioparm->length)
178 memcpy((uint32_t *)piob, (uint32_t*)bdata, pioparm->length);
179
180 /* If checksum is enabled insert CRC at end of packet */
181 if_pf (pioparm->cksum_is_valid){
182 int nCRCopies = IPATH_CRC_SIZE_IN_BYTES >> 2;
183 int nCRC = 0;
184
185 piob += pioparm->length >> 2;
186
187 while (nCRC < (nCRCopies-1)) {
188 *piob = pioparm->cksum;
189 piob++;
190 nCRC++;
191 }
192
193 asm volatile("" : : : "memory"); // prevent compiler reorder
194 *piob = pioparm->cksum;
195 }
196
197 /* send it on it's way, now, rather than waiting for processor to
198 * get around to flushing it */
199 //ips_wmb();
200 }
201 #endif //__MIC__
202
203 void ipath_write_pio(volatile uint32_t *piob, const struct ipath_pio_params *pioparm,
204 void *hdr, void *bdata)
205 {
206 union ipath_pbc buf = {0};
207 uint32_t cksum_len = pioparm->cksum_is_valid ?
208 IPATH_CRC_SIZE_IN_BYTES : 0;
209
210 buf.length =
211 __cpu_to_le16(((IPATH_MESSAGE_HDR_SIZE + cksum_len + pioparm->length) >> 2) + 1);
212 if (pioparm->port > 1)
213 buf.pbcflags = __cpu_to_le32((pioparm->vl << __PBC_VLSHIFT) |
214 __PBC_IBPORT |
215 pioparm->rate);
216 else
217 buf.pbcflags = __cpu_to_le32(pioparm->vl << __PBC_VLSHIFT |
218 pioparm->rate);
219
220 *(volatile uint64_t *)piob = buf.qword;
221 piob += 2;
222 asm volatile("" : : : "memory"); // prevent compiler reordering
223
224 ipath_dwordcpy_safe(piob, hdr, IPATH_MESSAGE_HDR_SIZE >> 2);
225
226 asm volatile("" : : : "memory"); // prevent compiler reordering
227 piob += IPATH_MESSAGE_HDR_SIZE >> 2;
228
229 if(pioparm->length)
230 ipath_dwordcpy_safe(piob, (uint32_t*)bdata, pioparm->length>>2);
231
232 /* If checksum is enabled insert CRC at end of packet */
233 if_pf (pioparm->cksum_is_valid){
234 int nCRCopies = IPATH_CRC_SIZE_IN_BYTES >> 2;
235 int nCRC = 0;
236
237 piob += pioparm->length >> 2;
238
239 while (nCRC < (nCRCopies-1)) {
240 *piob = pioparm->cksum;
241 piob++;
242 nCRC++;
243 }
244
245 asm volatile("" : : : "memory"); // prevent compiler reorder
246 *piob = pioparm->cksum;
247 }
248
249 /* send it on it's way, now, rather than waiting for processor to
250 * get around to flushing it */
251 ips_wmb();
252 }
253
254 /*
255 * here we trigger on a "special" address, so just bang it out
256 * as fast as possible...
257 */
258 static inline void
259 ipath_write_pio_special_trigger(volatile uint32_t *piob,
260 const struct ipath_pio_params *pioparm,
261 void *hdr, void *bdata, unsigned offset)
262 {
263 union ipath_pbc buf = {0};
264 volatile uint32_t *piobs = piob;
265 uint32_t cksum_len = pioparm->cksum_is_valid ?
266 IPATH_CRC_SIZE_IN_BYTES : 0;
267
268 buf.length =
269 __cpu_to_le16(((IPATH_MESSAGE_HDR_SIZE + cksum_len + pioparm->length) >> 2) + 1);
270 if(pioparm->port > 1)
271 buf.pbcflags = __cpu_to_le32((pioparm->vl << __PBC_VLSHIFT) |
272 __PBC_IBPORT |
273 pioparm->rate);
274 else
275 buf.pbcflags = __cpu_to_le32(pioparm->vl << __PBC_VLSHIFT|
276 pioparm->rate);
277
278 *(volatile uint64_t *)piob = buf.qword;
279 piob += 2;
280 asm volatile("" : : : "memory"); // prevent compiler reordering
281
282 ipath_dwordcpy_safe(piob, hdr,
283 IPATH_MESSAGE_HDR_SIZE >> 2);
284 piob += IPATH_MESSAGE_HDR_SIZE >> 2;
285 asm volatile("" : : : "memory"); // prevent compiler reordering
286
287 if(pioparm->length)
288 ipath_dwordcpy_safe(piob, (uint32_t*)bdata, pioparm->length>>2);
289
290 /* If checksum is enabled insert CRC at end of packet */
291 if_pf (pioparm->cksum_is_valid){
292 int nCRCopies = IPATH_CRC_SIZE_IN_BYTES >> 2;
293 int nCRC = 0;
294
295 piob += pioparm->length >> 2;
296
297 while (nCRC < (nCRCopies-1)) {
298 *piob = pioparm->cksum;
299 piob++;
300 nCRC++;
301 }
302
303 asm volatile("" : : : "memory"); // prevent compiler reordering
304 *piob = pioparm->cksum;
305 }
306
307 /*
308 * flush then write "special" then flush...
309 */
310 ips_wmb();
311 *(piobs + offset) = IPATH_SPECIAL_TRIGGER_MAGIC;
312 ips_wmb();
313 }
314
315 void ipath_write_pio_special_trigger2k(volatile uint32_t *piob,
316 const struct ipath_pio_params *pioparm, void *hdr, void *bdata)
317 {
318 ipath_write_pio_special_trigger(piob, pioparm, hdr, bdata, 1023);
319 }
320
321 void ipath_write_pio_special_trigger4k(volatile uint32_t *piob,
322 const struct ipath_pio_params *pioparm, void *hdr, void *bdata)
323 {
324 ipath_write_pio_special_trigger(piob, pioparm, hdr, bdata, 2047);
325 }