Debian Codegraph @

ptl_ips/ips_writehdrq.c

raw
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 #include "ips_writehdrq.h"
35
36 psm_error_t
37 ips_writehdrq_init(const psmi_context_t *context,
38 const struct ips_recvq_params *hdrq_params,
39 const struct ips_recvq_params *egrq_params,
40 struct ips_writehdrq *writeq,
41 struct ips_writehdrq_state *state,
42 uint32_t runtime_flags)
43 {
44 const struct ipath_base_info *base_info = &context->base_info;
45 memset(writeq, 0, sizeof(*writeq));
46 writeq->context = context;
47 writeq->state = state;
48 writeq->hdrq = *hdrq_params; /* deep copy */
49 writeq->hdrq_elemlast = ((writeq->hdrq.elemcnt - 1) * writeq->hdrq.elemsz);
50 writeq->egrq = *egrq_params; /* deep copy */
51 writeq->egrq_buftable =
52 ips_recvq_egrbuf_table_alloc(context->ep, writeq->egrq.base_addr,
53 base_info->spi_rcv_egrchunksize,
54 writeq->egrq.elemcnt,
55 writeq->egrq.elemsz);
56 writeq->runtime_flags = runtime_flags;
57 writeq->hdrq_rhf_off = base_info->spi_rhf_offset;
58 if (writeq->runtime_flags & IPATH_RUNTIME_NODMA_RTAIL) {
59 writeq->state->hdrq_rhf_seq = 1;
60 /*
61 * We don't allow readers to see the RHF until the writer can
62 * atomically write an updated RHF.
63 */
64 writeq->hdrq_hdr_copysz = (writeq->hdrq.elemsz - 2) * sizeof(uint32_t);
65 /*
66 * Ensure 8-byte alignment of the RHF by looking at RHF of the second
67 * header, which is required for atomic RHF updates.
68 */
69 psmi_assert_always(
70 !((uintptr_t)(writeq->hdrq.base_addr +
71 writeq->hdrq.elemsz + writeq->hdrq_rhf_off) & 0x7));
72 }
73 else {
74 writeq->hdrq_hdr_copysz = writeq->hdrq.elemsz * sizeof(uint32_t);
75 writeq->state->hdrq_rhf_seq = 0; /* _seq is ignored */
76 }
77 writeq->state->enabled = 1;
78 return PSM_OK;
79 }
80
81 psm_error_t
82 ips_writehdrq_fini(struct ips_writehdrq *writeq)
83 {
84 ips_recvq_egrbuf_table_free(writeq->egrq_buftable);
85 return PSM_OK;
86 }