IB_UCM_MAX_DEVICES = 32
};
+static inline int ERR(int err)
+{
+ errno = err;
+ return -1;
+}
+
+
#define CM_CREATE_MSG_CMD_RESP(msg, cmd, resp, type, size) \
do { \
struct cm_abi_cmd_hdr *hdr; \
size = sizeof(*hdr) + sizeof(*cmd); \
msg = alloca(size); \
if (!msg) \
- return -ENOMEM; \
+ return ERR(ENOMEM); \
hdr = msg; \
cmd = msg + sizeof(*hdr); \
hdr->cmd = type; \
memset(cmd, 0, sizeof(*cmd)); \
resp = alloca(sizeof(*resp)); \
if (!resp) \
- return -ENOMEM; \
+ return ERR(ENOMEM); \
cmd->response = (uintptr_t)resp;\
} while (0)
size = sizeof(*hdr) + sizeof(*cmd); \
msg = alloca(size); \
if (!msg) \
- return -ENOMEM; \
+ return ERR(ENOMEM); \
hdr = msg; \
cmd = msg + sizeof(*hdr); \
hdr->cmd = type; \
cm_id_priv = ib_cm_alloc_id(device, context);
if (!cm_id_priv)
- return -ENOMEM;
+ return ERR(ENOMEM);
CM_CREATE_MSG_CMD_RESP(msg, cmd, resp, IB_USER_CM_CMD_CREATE_ID, size);
cmd->uid = (uintptr_t) cm_id_priv;
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
int size;
if (!param)
- return -EINVAL;
+ return ERR(EINVAL);
CM_CREATE_MSG_CMD_RESP(msg, cmd, resp, IB_USER_CM_CMD_ATTR_ID, size);
cmd->id = cm_id->handle;
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
int size;
if (!qp_attr || !qp_attr_mask)
- return -EINVAL;
+ return ERR(EINVAL);
CM_CREATE_MSG_CMD_RESP(msg, cmd, resp, IB_USER_CM_CMD_INIT_QP_ATTR, size);
cmd->id = cm_id->handle;
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : result;
VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
return 0;
}
int size;
if (!param)
- return -EINVAL;
+ return ERR(EINVAL);
CM_CREATE_MSG_CMD(msg, cmd, IB_USER_CM_CMD_SEND_REQ, size);
cmd->id = cm_id->handle;
if (param->primary_path) {
p_path = alloca(sizeof(*p_path));
if (!p_path)
- return -ENOMEM;
+ return ERR(ENOMEM);
ibv_copy_path_rec_to_kern(p_path, param->primary_path);
cmd->primary_path = (uintptr_t) p_path;
if (param->alternate_path) {
a_path = alloca(sizeof(*a_path));
if (!a_path)
- return -ENOMEM;
+ return ERR(ENOMEM);
ibv_copy_path_rec_to_kern(a_path, param->alternate_path);
cmd->alternate_path = (uintptr_t) a_path;
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
return 0;
}
int size;
if (!param)
- return -EINVAL;
+ return ERR(EINVAL);
CM_CREATE_MSG_CMD(msg, cmd, IB_USER_CM_CMD_SEND_REP, size);
cmd->uid = (uintptr_t) container_of(cm_id, struct cm_id_private, id);
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
return 0;
}
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
return 0;
}
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
return 0;
}
if (event == IBV_EVENT_COMM_EST)
return cm_establish(cm_id);
else
- return -EINVAL;
+ return ERR(EINVAL);
}
CM_CREATE_MSG_CMD(msg, cmd, IB_USER_CM_CMD_NOTIFY, size);
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
return 0;
}
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
return 0;
}
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : result;
return 0;
}
if (alternate_path) {
abi_path = alloca(sizeof(*abi_path));
if (!abi_path)
- return -ENOMEM;
+ return ERR(ENOMEM);
ibv_copy_path_rec_to_kern(abi_path, alternate_path);
cmd->path = (uintptr_t) abi_path;
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
return 0;
}
int size;
if (!param)
- return -EINVAL;
+ return ERR(EINVAL);
CM_CREATE_MSG_CMD(msg, cmd, IB_USER_CM_CMD_SEND_SIDR_REQ, size);
cmd->id = cm_id->handle;
if (param->path) {
abi_path = alloca(sizeof(*abi_path));
if (!abi_path)
- return -ENOMEM;
+ return ERR(ENOMEM);
ibv_copy_path_rec_to_kern(abi_path, param->path);
cmd->path = (uintptr_t) abi_path;
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : result;
return 0;
}
int size;
if (!param)
- return -EINVAL;
+ return ERR(EINVAL);
CM_CREATE_MSG_CMD(msg, cmd, IB_USER_CM_CMD_SEND_SIDR_REP, size);
cmd->id = cm_id->handle;
result = write(cm_id->device->fd, msg, size);
if (result != size)
- return (result > 0) ? -ENODATA : result;
+ return (result >= 0) ? ERR(ENODATA) : -1;
return 0;
}
int size;
if (!event)
- return -EINVAL;
+ return ERR(EINVAL);
size = sizeof(*hdr) + sizeof(*cmd);
msg = alloca(size);
if (!msg)
- return -ENOMEM;
+ return ERR(ENOMEM);
hdr = msg;
cmd = msg + sizeof(*hdr);
resp = alloca(sizeof(*resp));
if (!resp)
- return -ENOMEM;
+ return ERR(ENOMEM);
cmd->response = (uintptr_t) resp;
cmd->data_len = (uint8_t)(~0U);
data = malloc(cmd->data_len);
if (!data) {
- result = -ENOMEM;
+ result = ERR(ENOMEM);
goto done;
}
info = malloc(cmd->info_len);
if (!info) {
- result = -ENOMEM;
+ result = ERR(ENOMEM);
goto done;
}
result = write(device->fd, msg, size);
if (result != size) {
- result = (result > 0) ? -ENODATA : result;
+ result = (result >= 0) ? ERR(ENODATA) : -1;
goto done;
}
*/
evt = malloc(sizeof(*evt));
if (!evt) {
- result = -ENOMEM;
+ result = ERR(ENOMEM);
goto done;
}
memset(evt, 0, sizeof(*evt));
if (resp->present & CM_ABI_PRES_PRIMARY) {
path_a = malloc(sizeof(*path_a));
if (!path_a) {
- result = -ENOMEM;
+ result = ERR(ENOMEM);
goto done;
}
}
if (resp->present & CM_ABI_PRES_ALTERNATE) {
path_b = malloc(sizeof(*path_b));
if (!path_b) {
- result = -ENOMEM;
+ result = ERR(ENOMEM);
goto done;
}
}
cm_id_priv = ib_cm_alloc_id(evt->cm_id->device,
evt->cm_id->context);
if (!cm_id_priv) {
- result = -ENOMEM;
+ result = ERR(ENOMEM);
goto done;
}
cm_id_priv->id.handle = resp->id;
cm_id_priv = ib_cm_alloc_id(evt->cm_id->device,
evt->cm_id->context);
if (!cm_id_priv) {
- result = -ENOMEM;
+ result = ERR(ENOMEM);
goto done;
}
cm_id_priv->id.handle = resp->id;
struct cm_id_private *cm_id_priv;
if (!event)
- return -EINVAL;
+ return ERR(EINVAL);
if (event->private_data)
free(event->private_data);