Debian Codegraph @

ptl_am/scifrwu.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2013. Intel Corporation. All rights reserved.
3 * Copyright (c) 2010. QLogic Corporation. 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 <sys/types.h>
35 #include <stdint.h>
36 #include <fcntl.h>
37 #include <signal.h>
38
39 #include "psm_user.h"
40 #include "psm_mq_internal.h"
41 #include "psm_am_internal.h"
42 #include "scifrw.h"
43
44 #if defined(PSM_HAVE_SCIF)
45 int scif_register_region(scif_epd_t epd, void* addr, size_t len, off_t* offset)
46 {
47 /* SCIF requires registrations on page granularity. The address must be
48 rounded down to a page boundary, and the length must be rounded up. */
49 off_t addr_offset = (off_t)addr & 0xFFF;
50 uintptr_t reg_addr = (uintptr_t)addr & ~0xFFF;
51 size_t reg_len = len + addr_offset;
52
53 if(reg_len & 0xFFF) {
54 reg_len += 0x1000 - (reg_len & 0xFFF);
55 }
56
57 off_t reg = scif_register(epd, (void*)reg_addr, reg_len, 0,
58 SCIF_PROT_READ|SCIF_PROT_WRITE, 0);
59
60 if(reg == SCIF_REGISTER_FAILED) {
61 _IPATH_INFO("SCIF: Registering memory %p (%p) length %ld (%ld) epd %d failed: (%d) %s\n",
62 addr, (void*)reg_addr, len, reg_len, epd,
63 errno, strerror(errno));
64
65 *offset = SCIF_REGISTER_FAILED;
66 return PSM_INTERNAL_ERR;
67 }
68
69 /* Although the registration is rounded out to whole pages, return the
70 exact SCIF-space registration offset for the specified address. */
71 *offset = reg + addr_offset;
72 return PSM_OK;
73 }
74
75 int scif_unregister_region(scif_epd_t epd, off_t reg, size_t len)
76 {
77 /* SCIF requires registrations on page granularity. The address must be
78 rounded down to a page boundary, and the length must be rounded up. */
79 off_t reg_addr = reg & ~0xFFF;
80 size_t reg_len = len + ((size_t)reg & 0xFFF);
81
82 if(reg_len & 0xFFF) {
83 reg_len += 0x1000 - (reg_len & 0xFFF);
84 }
85
86 if(scif_unregister(epd, reg_addr, reg_len)) {
87 _IPATH_INFO("SCIF: Unregistering offset %lx (%lx) length %ld (%ld) epd %d failed: (%d) %s\n",
88 reg, reg_addr, len, reg_len, epd,
89 errno, strerror(errno));
90 return PSM_INTERNAL_ERR;
91 }
92
93 return PSM_OK;
94 }
95
96 #endif /* defined(PSM_USE_SCIF) */
97