rdma.c revision 8ddb3a46e1a09773609249d578c6decb530951c2
/*
*/
/*
* This file contains code imported from the OFED rds source file rdma.c
* Oracle elects to have and use the contents of rdma.c under and governed
* by the OpenIB.org BSD license (see below for full license text). However,
* the following notice accompanied the original version of this file:
*/
/*
* Copyright (c) 2007 Oracle. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#define DMA_TO_DEVICE 0
#define DMA_FROM_DEVICE 1
/*
* XXX
* - build with sparse
* - should we limit the size of a mr region? let transport return failure?
* - should we detect duplicate keys on a socket? hmm.
* - an rdma is an mlock, apply rlimit?
*/
/*
* get the number of pages by looking at the page indices that the start and
* end addresses fall in.
*
* Returns 0 if the vec is invalid. It is invalid if the number of bytes
* causes the address to wrap or overflows an unsigned int. This comes
* from being stored in the 'length' member of 'struct rdsv3_scatterlist'.
*/
static unsigned int
{
return (0);
}
}
static struct rdsv3_mr *
{
return (NULL);
}
return (mr);
}
/*
* Destroy the transport-specific part of a MR.
*/
static void
{
void *trans_private = NULL;
avl_node_t *np;
RDSV3_DPRINTF5("rdsv3_destroy_mr",
"RDS: destroy mr key is %x refcnt %u",
return;
if (trans_private)
}
void
{
}
/*
* By the time this is called we can't have any more ioctls called on
* the socket so we don't need to worry about racing with others.
*/
void
{
/* Release any MRs associated with this socket */
mr->r_invalidate = 0;
}
}
static int
{
void *trans_private;
unsigned int nents = 0;
int ret;
if (rs->rs_bound_addr == 0) {
goto out;
}
ret = -EOPNOTSUPP;
goto out;
}
if (!mr) {
goto out;
}
/*
* Obtain a transport specific MR. If this succeeds, the
* s/g list is now owned by the MR.
* Note that dma_map() implies that pending writes are
* flushed to RAM, so no dma_sync is needed here.
*/
if (IS_ERR(trans_private)) {
goto out;
}
/*
* The user may pass us an unaligned address, but we can only
* map page aligned regions. So we keep the offset, and build
* a 64bit cookie containing <R_Key, offset> and pass that
* around.
*/
if (cookie_ret)
*cookie_ret = cookie;
/*
* copy value of cookie to user address at args->cookie_addr
*/
if (args->cookie_addr) {
sizeof (rds_rdma_cookie_t), 0);
if (ret != 0) {
goto out;
}
}
RDSV3_DPRINTF5("__rdsv3_rdma_map",
"RDS: get_mr mr 0x%p addr 0x%llx key 0x%x",
/*
* Inserting the new MR into the rbtree bumps its
* reference count.
*/
if (mr_ret) {
}
ret = 0;
out:
if (mr)
return (ret);
}
int
{
struct rds_get_mr_args args;
if (optlen != sizeof (struct rds_get_mr_args))
return (-EINVAL);
#if 1
sizeof (struct rds_get_mr_args));
#else
return (-EFAULT);
#endif
}
int
int optlen)
{
struct rds_get_mr_for_dest_args args;
struct rds_get_mr_args new_args;
if (optlen != sizeof (struct rds_get_mr_for_dest_args))
return (-EINVAL);
#if 1
sizeof (struct rds_get_mr_for_dest_args));
#else
return (-EFAULT);
#endif
/*
* Initially, just behave like get_mr().
* TODO: Implement get_mr as wrapper around this
* and deprecate it.
*/
}
/*
* Free the MR indicated by the given R_Key
*/
int
{
struct rds_free_mr_args args;
if (optlen != sizeof (struct rds_free_mr_args))
return (-EINVAL);
#if 1
sizeof (struct rds_free_mr_args));
#else
sizeof (struct rds_free_mr_args), 0))
return (-EFAULT);
#endif
/* Special case - a null cookie means flush all unused MRs */
return (-EINVAL);
return (0);
}
/*
* Look up the MR given its R_key and remove it from the rbtree
* so nobody else finds it.
* This should also prevent races with rdsv3_rdma_unuse.
*/
if (mr) {
}
if (!mr)
return (-EINVAL);
/*
* call rdsv3_destroy_mr() ourselves so that we're sure it's done
* by time we return. If we let rdsv3_mr_put() do it it might not
* happen until someone else drops their ref.
*/
return (0);
}
/*
* This is called when we receive an extension header that
* tells us this MR was used. It allows us to implement
* use_once semantics
*/
void
{
int zot_me = 0;
if (!mr) {
RDSV3_DPRINTF4("rdsv3_rdma_unuse",
"rdsv3: trying to unuse MR with unknown r_key %u!", r_key);
return;
}
zot_me = 1;
} else {
}
/*
* May have to issue a dma_sync on this memory region.
* Note we could avoid this if the operation was a RDMA READ,
* but at this point we can't tell.
*/
/*
* If the MR was marked as invalidate, this will
* trigger an async flush.
*/
if (zot_me)
}
void
{
unsigned int i;
/* deallocate RDMA resources on rdsv3_message */
}
if (ro->r_notifier)
}
/*
* args is a pointer to an in-kernel copy in the sendmsg cmsg.
*/
static struct rdsv3_rdma_op *
{
unsigned int nr_bytes;
unsigned int nr;
unsigned int i;
int ret;
if (rs->rs_bound_addr == 0) {
goto out;
}
goto out;
}
goto out;
}
/*
* We allocate an uninitialized notifier here, because
* we don't want to do that in the completion handler. We
* would have to use GFP_ATOMIC there, and don't want to deal
* with failed allocations.
*/
if (!op->r_notifier) {
goto out;
}
}
/*
* The cookie contains the R_Key of the remote memory region, and
* optionally an offset into it. This is how we implement RDMA into
* unaligned memory.
* When setting up the RDMA, we need to add that offset to the
* destination address (which is really an offset into the MR)
* FIXME: We may want to move this into ib_rdma.c
*/
nr_bytes = 0;
RDSV3_DPRINTF5("rdsv3_rdma_prepare",
"RDS: rdma prepare nr_local %llu rva %llx rkey %x",
/* pin the scatter list of user buffers */
sizeof (struct rds_iovec), 0)) {
goto out;
}
if (nr == 0) {
RDSV3_DPRINTF2("rdsv3_rdma_prepare",
"rdsv3_pages_in_vec returned 0");
goto out;
}
/* pin user memory pages */
if (ret != 0) {
RDSV3_DPRINTF2("rdsv3_rdma_prepare",
"umem_lockmemory() returned %d", ret);
goto out;
}
RDSV3_DPRINTF5("rdsv3_rdma_prepare",
"RDS: nr_bytes %u nr %u vec.bytes %llu vec.addr %llx",
}
RDSV3_DPRINTF2("rdsv3_rdma_prepare",
"RDS nr_bytes %u remote_bytes %u do not match",
goto out;
}
ret = 0;
out:
if (ret) {
if (op)
}
return (op);
}
#define CEIL(x, y) (((x) + (y) - 1) / (y))
/*
* The application asks for a RDMA transfer.
* Extract all arguments and set up the rdma_op
*/
int
{
struct rdsv3_rdma_op *op;
/* uint64_t alignment on the buffer */
sizeof (uint64_t))];
return (-EINVAL);
return (0);
}
/*
* The application wants us to pass an RDMA destination (aka MR)
* to the remote
*/
int
{
int err = 0;
rm->m_rdma_cookie != 0)
return (-EINVAL);
sizeof (rm->m_rdma_cookie));
/*
* We are reusing a previously mapped MR here. Most likely, the
* application has written to the buffer, so we need to explicitly
* flush those writes to RAM. Otherwise the HCA may not see them
* when doing a DMA from that buffer.
*/
if (!mr)
else
if (mr) {
}
return (err);
}
/*
* The application passes us an address range it wants to enable RDMA
* in rm->m_rdma_cookie. This causes it to be sent along to the peer
* in an extension header.
*/
int
{
/* uint64_t alignment on the buffer */
sizeof (uint64_t))];
int status;
rm->m_rdma_cookie != 0)
return (-EINVAL);
return (status);
}