Debian Codegraph @

ptl_am/knemrwu.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2010. QLogic Corporation. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33 #include <sys/types.h>
34 #include <stdint.h>
35 #include <fcntl.h>
36 #include <signal.h>
37
38 #include "psm_user.h"
39 #include "psm_mq_internal.h"
40 #include "psm_am_internal.h"
41 #include "knemrw.h"
42
43 int knem_open_device()
44 {
45 /* Process wide knem handle */
46 static int fd = -1;
47
48 #if defined(PSM_USE_KNEM)
49 if (fd >= 0)
50 return fd;
51
52 fd = open(KNEM_DEVICE_FILENAME, O_RDWR);
53 #endif
54 return fd;
55 }
56
57 int64_t knem_get(int fd, int64_t cookie, const void *src, int64_t n)
58 {
59
60 #if defined(PSM_USE_KNEM)
61 struct knem_cmd_inline_copy c;
62 struct knem_cmd_param_iovec iov;
63 int err;
64
65 iov.base = (uint64_t) (uintptr_t) src;
66 iov.len = n;
67
68 c.local_iovec_array = (uintptr_t) &iov;
69 c.local_iovec_nr = 1;
70 c.remote_cookie = cookie;
71 c.remote_offset = 0;
72 c.write = 0; /* Do a Read/Get from remote memory region */
73 c.flags = 0;
74 err = ioctl(fd, KNEM_CMD_INLINE_COPY, &c);
75
76 if (c.current_status != KNEM_STATUS_SUCCESS) {
77 _IPATH_INFO("KNEM: Get request of size 0x%"PRIx64" failed with error %d.\n",
78 n, c.current_status);
79 err = c.current_status;
80 }
81
82 return err;
83 #else
84 psmi_handle_error(PSMI_EP_NORETURN, PSM_INTERNAL_ERR,
85 "Attempt to use KNEM kassist (get), support for which has "
86 "not been compiled in.");
87
88 return PSM_INTERNAL_ERR;
89 #endif
90 }
91
92 int64_t knem_put(int fd, const void *src, int64_t n, int64_t cookie)
93 {
94
95 #if defined(PSM_USE_KNEM)
96 struct knem_cmd_inline_copy c;
97 struct knem_cmd_param_iovec iov;
98 int err;
99
100 iov.base = (uint64_t) (uintptr_t) src;
101 iov.len = n;
102
103 c.local_iovec_array = (uintptr_t) &iov;
104 c.local_iovec_nr = 1;
105 c.remote_cookie = cookie;
106 c.remote_offset = 0;
107 c.write = 1; /* Do a Write/Put to remote memory region */
108 c.flags = 0;
109 err = ioctl(fd, KNEM_CMD_INLINE_COPY, &c);
110
111 if (c.current_status != KNEM_STATUS_SUCCESS) {
112 _IPATH_INFO("KNEM: Put request of size 0x%"PRIx64" failed with error %d.\n",
113 n, c.current_status);
114 err = c.current_status;
115 }
116
117 return err;
118 #else
119
120 psmi_handle_error(PSMI_EP_NORETURN, PSM_INTERNAL_ERR,
121 "Attempt to use KNEM kassist (put), support for which has "
122 "not been compiled in.");
123
124 return PSM_INTERNAL_ERR;
125 #endif
126
127 }
128
129 int64_t knem_register_region(void *buffer, size_t len, int write)
130 {
131
132 #if defined(PSM_USE_KNEM)
133 struct knem_cmd_create_region create;
134 struct knem_cmd_param_iovec iov;
135
136 iov.base = (uint64_t) (uintptr_t) buffer;
137 iov.len = len;
138 create.iovec_array = (uintptr_t) &iov;
139 create.iovec_nr = 1;
140 create.flags = KNEM_FLAG_SINGLEUSE; /* Automatically destroy after put */
141 create.protection = write ? PROT_WRITE : PROT_READ;
142
143 /* AV: Handle failure in memory registration */
144 ioctl(psmi_kassist_fd, KNEM_CMD_CREATE_REGION, &create);
145 return create.cookie; /* Cookie for registered memory region */
146 #else
147
148 psmi_handle_error(PSMI_EP_NORETURN, PSM_INTERNAL_ERR,
149 "Attempt to use KNEM kassist (reg), support for which has "
150 "not been compiled in.");
151 return 0;
152 #endif
153
154 }