示例#1
0
文件: verbs.c 项目: kento/libpibverbs
struct ibv_comp_channel *ibv_create_comp_channel(struct ibv_context *context)
{
	struct ibv_comp_channel            *channel;
	struct ibv_create_comp_channel      cmd;
	struct ibv_create_comp_channel_resp resp;

	if (abi_ver <= 2)
		return ibv_create_comp_channel_v2(context);

	channel = malloc(sizeof *channel);
	if (!channel)
		return NULL;

	IBV_INIT_CMD_RESP(&cmd, sizeof cmd, CREATE_COMP_CHANNEL, &resp, sizeof resp);
	if (write(context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) {
		free(channel);
		return NULL;
	}

	VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp);

	channel->context = context;
	channel->fd      = resp.fd;
	channel->refcnt  = 0;

	return channel;
}
示例#2
0
文件: cmd_exp.c 项目: Cai900205/test
int ibv_exp_cmd_create_qp(struct ibv_context *context,
			  struct verbs_qp *qp, int vqp_sz,
			  struct ibv_exp_qp_init_attr *attr_exp,
			  void *cmd_buf, size_t lib_cmd_size, size_t drv_cmd_size,
			  void *resp_buf, size_t lib_resp_size, size_t drv_resp_size)
{
	struct verbs_xrcd *vxrcd = NULL;
	struct ibv_exp_create_qp	*cmd_exp = NULL;
	struct ibv_exp_create_qp_resp	*resp_exp = NULL;
	struct ibv_create_qp		*cmd;
	struct ibv_create_qp_resp	*resp;
	int wsize;

	if (attr_exp->comp_mask >= IBV_EXP_QP_INIT_ATTR_RESERVED)
		return ENOSYS;

	cmd = cmd_buf;
	resp = resp_buf;

	if (attr_exp->comp_mask >= IBV_EXP_QP_INIT_ATTR_CREATE_FLAGS) {

		cmd_exp = cmd_buf;
		resp_exp = resp_buf;
		wsize = lib_cmd_size + drv_cmd_size;

		/*
		 * Cast extended command to legacy command using a fact
		 * that legacy header size is equal 'comp_mask' field size
		 * and 'comp_mask' field position is on top of the valuable
		 * fields
		 */
		cmd = (struct ibv_create_qp *)((void *)&cmd_exp->comp_mask - sizeof(cmd->response));
		/*
		 * Cast extended response to legacy response using a fact
		 * that 'comp_mask' field is added on top of legacy response
		 */
		resp = (struct ibv_create_qp_resp *)
				((uint8_t *)resp_exp +
					sizeof(resp_exp->comp_mask));

		IBV_INIT_CMD_RESP_EXP(CREATE_QP, cmd_exp, lib_cmd_size, drv_cmd_size,
				      resp_exp, lib_resp_size, drv_resp_size);
	} else {
		wsize = lib_cmd_size;
		IBV_INIT_CMD_RESP(cmd, lib_cmd_size, CREATE_QP, resp, lib_resp_size);
	}

	cmd->user_handle     = (uintptr_t) qp;

	if (attr_exp->comp_mask & IBV_EXP_QP_INIT_ATTR_XRCD) {
		/* XRC reciever side */
		vxrcd = container_of(attr_exp->xrcd, struct verbs_xrcd, xrcd);
		cmd->pd_handle	= vxrcd->handle;
	} else {
示例#3
0
文件: init.c 项目: CJacky/virt-ib
static int vib_find_sysfs_devs(void)
{
    struct vib_find_sysfs_devs cmd;
    struct ibv_sysfs_dev *sysfs_list;
    struct ibv_sysfs_dev *sysfs_dev;
    int ret = 0;
    int cmd_fd = -1;
    int i;

    /*Assume there are at most 10 InfiniBand HCA in host*/
    sysfs_list = malloc(10*sizeof(struct ibv_sysfs_dev));

    for (i = 0; i < 10; i++)
        sysfs_list[i].have_driver = -1;

    IBV_INIT_CMD_RESP(&cmd, sizeof(cmd), FIND_SYSFS, sysfs_list, 10*sizeof(struct ibv_sysfs_dev));

    cmd_fd = open(uverbs0, O_RDWR);
    if (cmd_fd < 0) {
        printf("open uverbs0 failed\n");
        free(sysfs_list);
        return -1;
    }

    /*Write to virtib device to get sysfs of host InfiniBand*/
    ret = write(cmd_fd, &cmd, sizeof(cmd));
    close(cmd_fd);

    /*After getting results, put the results back to sysfs_dev_list*/
    if (!ret) {
        for(i = 0; i < 10; i++) {
            if (sysfs_list[i].have_driver > -1) {
                if (!sysfs_dev)
                    sysfs_dev = malloc(sizeof *sysfs_dev);
                memcpy(sysfs_dev, &sysfs_list[i], sizeof(struct ibv_sysfs_dev));
                sysfs_dev->next = sysfs_dev_list;
                sysfs_dev_list = sysfs_dev;
                sysfs_dev      = NULL;
            }
            else
                break;
        }
    }

    free(sysfs_list);
    return ret;
}