Ejemplo n.º 1
0
static int build_host_sge_array(RdmaDeviceResources *rdma_dev_res,
                                struct ibv_sge *dsge, struct ibv_sge *ssge,
                                uint8_t num_sge, uint64_t *total_length)
{
    RdmaRmMR *mr;
    int ssge_idx;

    for (ssge_idx = 0; ssge_idx < num_sge; ssge_idx++) {
        mr = rdma_rm_get_mr(rdma_dev_res, ssge[ssge_idx].lkey);
        if (unlikely(!mr)) {
            rdma_error_report("Invalid lkey 0x%x", ssge[ssge_idx].lkey);
            return VENDOR_ERR_INVLKEY | ssge[ssge_idx].lkey;
        }

        dsge->addr = (uintptr_t)mr->virt + ssge[ssge_idx].addr - mr->start;
        dsge->length = ssge[ssge_idx].length;
        dsge->lkey = rdma_backend_mr_lkey(&mr->backend_mr);

        *total_length += dsge->length;

        dsge++;
    }

    return 0;
}
Ejemplo n.º 2
0
int rdma_rm_alloc_mr(RdmaDeviceResources *dev_res, uint32_t pd_handle,
                     uint64_t guest_start, size_t guest_length, void *host_virt,
                     int access_flags, uint32_t *mr_handle, uint32_t *lkey,
                     uint32_t *rkey)
{
    RdmaRmMR *mr;
    int ret = 0;
    RdmaRmPD *pd;
    void *addr;
    size_t length;

    pd = rdma_rm_get_pd(dev_res, pd_handle);
    if (!pd) {
        pr_dbg("Invalid PD\n");
        return -EINVAL;
    }

    mr = res_tbl_alloc(&dev_res->mr_tbl, mr_handle);
    if (!mr) {
        pr_dbg("Failed to allocate obj in table\n");
        return -ENOMEM;
    }

    if (!host_virt) {
        /* TODO: This is my guess but not so sure that this needs to be
         * done */
        length = TARGET_PAGE_SIZE;
        addr = g_malloc(length);
    } else {
        mr->user_mr.host_virt = host_virt;
        pr_dbg("host_virt=0x%p\n", mr->user_mr.host_virt);
        mr->user_mr.length = guest_length;
        pr_dbg("length=%zu\n", guest_length);
        mr->user_mr.guest_start = guest_start;
        pr_dbg("guest_start=0x%" PRIx64 "\n", mr->user_mr.guest_start);

        length = mr->user_mr.length;
        addr = mr->user_mr.host_virt;
    }

    ret = rdma_backend_create_mr(&mr->backend_mr, &pd->backend_pd, addr, length,
                                 access_flags);
    if (ret) {
        pr_dbg("Fail in rdma_backend_create_mr, err=%d\n", ret);
        ret = -EIO;
        goto out_dealloc_mr;
    }

    if (!host_virt) {
        *lkey = mr->lkey = rdma_backend_mr_lkey(&mr->backend_mr);
        *rkey = mr->rkey = rdma_backend_mr_rkey(&mr->backend_mr);
    } else {
        /* We keep mr_handle in lkey so send and recv get get mr ptr */
        *lkey = *mr_handle;
        *rkey = -1;
    }

    mr->pd_handle = pd_handle;

    return 0;

out_dealloc_mr:
    res_tbl_dealloc(&dev_res->mr_tbl, *mr_handle);

    return ret;
}