| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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 |
|
| 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; |
| 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; |
| 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; |
| 141 |
create.protection = write ? PROT_WRITE : PROT_READ; |
| 142 |
|
| 143 |
|
| 144 |
ioctl(psmi_kassist_fd, KNEM_CMD_CREATE_REGION, &create); |
| 145 |
return create.cookie; |
| 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 |
} |