2007-12-13 06:13:17 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005-2006 Network Appliance, Inc. 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 BSD-type
|
|
|
|
* 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
|
|
|
|
* disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
|
|
|
*
|
|
|
|
* Neither the name of the Network Appliance, Inc. nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Author: Tom Tucker <tom@opengridcomputing.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SVC_RDMA_H
|
|
|
|
#define SVC_RDMA_H
|
|
|
|
#include <linux/sunrpc/xdr.h>
|
|
|
|
#include <linux/sunrpc/svcsock.h>
|
|
|
|
#include <linux/sunrpc/rpc_rdma.h>
|
|
|
|
#include <rdma/ib_verbs.h>
|
|
|
|
#include <rdma/rdma_cm.h>
|
|
|
|
#define SVCRDMA_DEBUG
|
|
|
|
|
|
|
|
/* RPC/RDMA parameters and stats */
|
|
|
|
extern unsigned int svcrdma_ord;
|
|
|
|
extern unsigned int svcrdma_max_requests;
|
2016-01-08 03:50:02 +08:00
|
|
|
extern unsigned int svcrdma_max_bc_requests;
|
2007-12-13 06:13:17 +08:00
|
|
|
extern unsigned int svcrdma_max_req_size;
|
|
|
|
|
|
|
|
extern atomic_t rdma_stat_recv;
|
|
|
|
extern atomic_t rdma_stat_read;
|
|
|
|
extern atomic_t rdma_stat_write;
|
|
|
|
extern atomic_t rdma_stat_sq_starve;
|
|
|
|
extern atomic_t rdma_stat_rq_starve;
|
|
|
|
extern atomic_t rdma_stat_rq_poll;
|
|
|
|
extern atomic_t rdma_stat_rq_prod;
|
|
|
|
extern atomic_t rdma_stat_sq_poll;
|
|
|
|
extern atomic_t rdma_stat_sq_prod;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Contexts are built when an RDMA request is created and are a
|
|
|
|
* record of the resources that can be recovered when the request
|
|
|
|
* completes.
|
|
|
|
*/
|
|
|
|
struct svc_rdma_op_ctxt {
|
2017-02-08 00:58:56 +08:00
|
|
|
struct list_head list;
|
2008-05-01 08:50:56 +08:00
|
|
|
struct svc_rdma_op_ctxt *read_hdr;
|
2008-10-01 02:06:13 +08:00
|
|
|
struct svc_rdma_fastreg_mr *frmr;
|
2008-05-28 06:03:14 +08:00
|
|
|
int hdr_count;
|
2007-12-13 06:13:17 +08:00
|
|
|
struct xdr_buf arg;
|
2016-03-02 02:07:13 +08:00
|
|
|
struct ib_cqe cqe;
|
2016-03-02 02:07:22 +08:00
|
|
|
struct ib_cqe reg_cqe;
|
|
|
|
struct ib_cqe inv_cqe;
|
2007-12-13 06:13:17 +08:00
|
|
|
u32 byte_len;
|
2015-01-14 00:03:37 +08:00
|
|
|
u32 position;
|
2007-12-13 06:13:17 +08:00
|
|
|
struct svcxprt_rdma *xprt;
|
|
|
|
unsigned long flags;
|
|
|
|
enum dma_data_direction direction;
|
|
|
|
int count;
|
2016-09-13 22:52:50 +08:00
|
|
|
unsigned int mapped_sges;
|
2017-04-10 01:05:36 +08:00
|
|
|
struct ib_send_wr send_wr;
|
2007-12-13 06:13:17 +08:00
|
|
|
struct ib_sge sge[RPCSVC_MAXPAGES];
|
|
|
|
struct page *pages[RPCSVC_MAXPAGES];
|
|
|
|
};
|
|
|
|
|
2008-05-29 02:54:04 +08:00
|
|
|
/*
|
|
|
|
* NFS_ requests are mapped on the client side by the chunk lists in
|
|
|
|
* the RPCRDMA header. During the fetching of the RPC from the client
|
|
|
|
* and the writing of the reply to the client, the memory in the
|
|
|
|
* client and the memory in the server must be mapped as contiguous
|
|
|
|
* vaddr/len for access by the hardware. These data strucures keep
|
|
|
|
* these mappings.
|
|
|
|
*
|
|
|
|
* For an RDMA_WRITE, the 'sge' maps the RPC REPLY. For RDMA_READ, the
|
|
|
|
* 'sge' in the svc_rdma_req_map maps the server side RPC reply and the
|
|
|
|
* 'ch' field maps the read-list of the RPCRDMA header to the 'sge'
|
|
|
|
* mapping of the reply.
|
|
|
|
*/
|
|
|
|
struct svc_rdma_chunk_sge {
|
|
|
|
int start; /* sge no for this chunk */
|
|
|
|
int count; /* sge count for this chunk */
|
|
|
|
};
|
2008-10-01 02:06:13 +08:00
|
|
|
struct svc_rdma_fastreg_mr {
|
|
|
|
struct ib_mr *mr;
|
2015-10-14 00:11:36 +08:00
|
|
|
struct scatterlist *sg;
|
|
|
|
int sg_nents;
|
2008-10-01 02:06:13 +08:00
|
|
|
unsigned long access_flags;
|
|
|
|
enum dma_data_direction direction;
|
|
|
|
struct list_head frmr_list;
|
|
|
|
};
|
2008-05-29 02:54:04 +08:00
|
|
|
struct svc_rdma_req_map {
|
2016-01-08 03:49:20 +08:00
|
|
|
struct list_head free;
|
2008-05-29 02:54:04 +08:00
|
|
|
unsigned long count;
|
|
|
|
union {
|
|
|
|
struct kvec sge[RPCSVC_MAXPAGES];
|
|
|
|
struct svc_rdma_chunk_sge ch[RPCSVC_MAXPAGES];
|
2014-05-29 04:12:01 +08:00
|
|
|
unsigned long lkey[RPCSVC_MAXPAGES];
|
2008-05-29 02:54:04 +08:00
|
|
|
};
|
|
|
|
};
|
2007-12-13 06:13:17 +08:00
|
|
|
#define RDMACTXT_F_LAST_CTXT 2
|
|
|
|
|
2008-10-01 02:06:13 +08:00
|
|
|
#define SVCRDMA_DEVCAP_FAST_REG 1 /* fast mr registration */
|
|
|
|
#define SVCRDMA_DEVCAP_READ_W_INV 2 /* read w/ invalidate */
|
|
|
|
|
2007-12-13 06:13:17 +08:00
|
|
|
struct svcxprt_rdma {
|
|
|
|
struct svc_xprt sc_xprt; /* SVC transport structure */
|
|
|
|
struct rdma_cm_id *sc_cm_id; /* RDMA connection id */
|
|
|
|
struct list_head sc_accept_q; /* Conn. waiting accept */
|
|
|
|
int sc_ord; /* RDMA read limit */
|
|
|
|
int sc_max_sge;
|
2015-07-28 07:10:12 +08:00
|
|
|
int sc_max_sge_rd; /* max sge for read target */
|
2016-09-13 22:53:23 +08:00
|
|
|
bool sc_snd_w_inv; /* OK to use Send With Invalidate */
|
2007-12-13 06:13:17 +08:00
|
|
|
|
2016-11-30 00:04:50 +08:00
|
|
|
atomic_t sc_sq_avail; /* SQEs ready to be consumed */
|
2016-01-08 03:50:02 +08:00
|
|
|
unsigned int sc_sq_depth; /* Depth of SQ */
|
|
|
|
unsigned int sc_rq_depth; /* Depth of RQ */
|
2017-02-08 00:58:23 +08:00
|
|
|
__be32 sc_fc_credits; /* Forward credits */
|
|
|
|
u32 sc_max_requests; /* Max requests */
|
2016-01-08 03:50:02 +08:00
|
|
|
u32 sc_max_bc_requests;/* Backward credits */
|
2007-12-13 06:13:17 +08:00
|
|
|
int sc_max_req_size; /* Size of each RQ WR buf */
|
|
|
|
|
|
|
|
struct ib_pd *sc_pd;
|
|
|
|
|
2016-01-08 03:49:12 +08:00
|
|
|
spinlock_t sc_ctxt_lock;
|
|
|
|
struct list_head sc_ctxts;
|
|
|
|
int sc_ctxt_used;
|
2016-01-08 03:49:20 +08:00
|
|
|
spinlock_t sc_map_lock;
|
|
|
|
struct list_head sc_maps;
|
2016-01-08 03:49:12 +08:00
|
|
|
|
2007-12-13 06:13:17 +08:00
|
|
|
struct list_head sc_rq_dto_q;
|
|
|
|
spinlock_t sc_rq_dto_lock;
|
|
|
|
struct ib_qp *sc_qp;
|
|
|
|
struct ib_cq *sc_rq_cq;
|
|
|
|
struct ib_cq *sc_sq_cq;
|
2015-01-14 00:03:20 +08:00
|
|
|
int (*sc_reader)(struct svcxprt_rdma *,
|
|
|
|
struct svc_rqst *,
|
|
|
|
struct svc_rdma_op_ctxt *,
|
|
|
|
int *, u32 *, u32, u32, u64, bool);
|
2008-10-01 02:06:13 +08:00
|
|
|
u32 sc_dev_caps; /* distilled device caps */
|
|
|
|
unsigned int sc_frmr_pg_list_len;
|
|
|
|
struct list_head sc_frmr_q;
|
|
|
|
spinlock_t sc_frmr_q_lock;
|
2007-12-13 06:13:17 +08:00
|
|
|
|
|
|
|
spinlock_t sc_lock; /* transport lock */
|
|
|
|
|
|
|
|
wait_queue_head_t sc_send_wait; /* SQ exhaustion waitlist */
|
|
|
|
unsigned long sc_flags;
|
|
|
|
struct list_head sc_read_complete_q;
|
2008-05-01 11:00:46 +08:00
|
|
|
struct work_struct sc_work;
|
2007-12-13 06:13:17 +08:00
|
|
|
};
|
|
|
|
/* sc_flags */
|
|
|
|
#define RDMAXPRT_CONN_PENDING 3
|
|
|
|
|
|
|
|
#define RPCRDMA_LISTEN_BACKLOG 10
|
|
|
|
/* The default ORD value is based on two outstanding full-size writes with a
|
|
|
|
* page size of 4k, or 32k * 2 ops / 4k = 16 outstanding RDMA_READ. */
|
|
|
|
#define RPCRDMA_ORD (64/4)
|
|
|
|
#define RPCRDMA_SQ_DEPTH_MULT 8
|
2014-07-23 05:48:04 +08:00
|
|
|
#define RPCRDMA_MAX_REQUESTS 32
|
2007-12-13 06:13:17 +08:00
|
|
|
#define RPCRDMA_MAX_REQ_SIZE 4096
|
|
|
|
|
2016-01-08 03:50:02 +08:00
|
|
|
/* Typical ULP usage of BC requests is NFSv4.1 backchannel. Our
|
|
|
|
* current NFSv4.1 implementation supports one backchannel slot.
|
|
|
|
*/
|
|
|
|
#define RPCRDMA_MAX_BC_REQUESTS 2
|
|
|
|
|
2015-08-08 04:55:46 +08:00
|
|
|
#define RPCSVC_MAXPAYLOAD_RDMA RPCSVC_MAXPAYLOAD
|
|
|
|
|
2016-09-13 22:52:50 +08:00
|
|
|
/* Track DMA maps for this transport and context */
|
|
|
|
static inline void svc_rdma_count_mappings(struct svcxprt_rdma *rdma,
|
|
|
|
struct svc_rdma_op_ctxt *ctxt)
|
|
|
|
{
|
|
|
|
ctxt->mapped_sges++;
|
|
|
|
}
|
|
|
|
|
2016-01-08 03:50:10 +08:00
|
|
|
/* svc_rdma_backchannel.c */
|
|
|
|
extern int svc_rdma_handle_bc_reply(struct rpc_xprt *xprt,
|
|
|
|
struct rpcrdma_msg *rmsgp,
|
|
|
|
struct xdr_buf *rcvbuf);
|
|
|
|
|
2007-12-13 06:13:17 +08:00
|
|
|
/* svc_rdma_marshal.c */
|
2016-05-04 22:53:47 +08:00
|
|
|
extern int svc_rdma_xdr_decode_req(struct xdr_buf *);
|
2007-12-13 06:13:17 +08:00
|
|
|
extern int svc_rdma_xdr_encode_error(struct svcxprt_rdma *,
|
|
|
|
struct rpcrdma_msg *,
|
2015-06-04 23:21:10 +08:00
|
|
|
enum rpcrdma_errcode, __be32 *);
|
2007-12-13 06:13:17 +08:00
|
|
|
extern void svc_rdma_xdr_encode_write_list(struct rpcrdma_msg *, int);
|
|
|
|
extern void svc_rdma_xdr_encode_reply_array(struct rpcrdma_write_array *, int);
|
|
|
|
extern void svc_rdma_xdr_encode_array_chunk(struct rpcrdma_write_array *, int,
|
2012-02-21 15:28:04 +08:00
|
|
|
__be32, __be64, u32);
|
2017-02-08 00:58:15 +08:00
|
|
|
extern unsigned int svc_rdma_xdr_get_reply_hdr_len(__be32 *rdma_resp);
|
2007-12-13 06:13:17 +08:00
|
|
|
|
|
|
|
/* svc_rdma_recvfrom.c */
|
|
|
|
extern int svc_rdma_recvfrom(struct svc_rqst *);
|
2015-01-14 00:03:20 +08:00
|
|
|
extern int rdma_read_chunk_lcl(struct svcxprt_rdma *, struct svc_rqst *,
|
|
|
|
struct svc_rdma_op_ctxt *, int *, u32 *,
|
|
|
|
u32, u32, u64, bool);
|
|
|
|
extern int rdma_read_chunk_frmr(struct svcxprt_rdma *, struct svc_rqst *,
|
|
|
|
struct svc_rdma_op_ctxt *, int *, u32 *,
|
|
|
|
u32, u32, u64, bool);
|
2007-12-13 06:13:17 +08:00
|
|
|
|
|
|
|
/* svc_rdma_sendto.c */
|
2016-01-08 03:49:53 +08:00
|
|
|
extern int svc_rdma_map_xdr(struct svcxprt_rdma *, struct xdr_buf *,
|
2016-03-02 02:05:54 +08:00
|
|
|
struct svc_rdma_req_map *, bool);
|
2017-04-10 01:05:36 +08:00
|
|
|
extern int svc_rdma_post_send_wr(struct svcxprt_rdma *rdma,
|
|
|
|
struct svc_rdma_op_ctxt *ctxt,
|
|
|
|
int num_sge, u32 inv_rkey);
|
2007-12-13 06:13:17 +08:00
|
|
|
extern int svc_rdma_sendto(struct svc_rqst *);
|
2016-03-02 02:06:38 +08:00
|
|
|
extern void svc_rdma_send_error(struct svcxprt_rdma *, struct rpcrdma_msg *,
|
|
|
|
int);
|
2007-12-13 06:13:17 +08:00
|
|
|
|
|
|
|
/* svc_rdma_transport.c */
|
2016-03-02 02:07:22 +08:00
|
|
|
extern void svc_rdma_wc_send(struct ib_cq *, struct ib_wc *);
|
|
|
|
extern void svc_rdma_wc_write(struct ib_cq *, struct ib_wc *);
|
|
|
|
extern void svc_rdma_wc_reg(struct ib_cq *, struct ib_wc *);
|
|
|
|
extern void svc_rdma_wc_read(struct ib_cq *, struct ib_wc *);
|
|
|
|
extern void svc_rdma_wc_inv(struct ib_cq *, struct ib_wc *);
|
2007-12-13 06:13:17 +08:00
|
|
|
extern int svc_rdma_send(struct svcxprt_rdma *, struct ib_send_wr *);
|
2016-01-08 03:49:37 +08:00
|
|
|
extern int svc_rdma_post_recv(struct svcxprt_rdma *, gfp_t);
|
2016-03-02 02:06:20 +08:00
|
|
|
extern int svc_rdma_repost_recv(struct svcxprt_rdma *, gfp_t);
|
2007-12-13 06:13:17 +08:00
|
|
|
extern int svc_rdma_create_listen(struct svc_serv *, int, struct sockaddr *);
|
|
|
|
extern struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *);
|
|
|
|
extern void svc_rdma_put_context(struct svc_rdma_op_ctxt *, int);
|
2008-08-13 04:12:10 +08:00
|
|
|
extern void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt);
|
2016-01-08 03:49:20 +08:00
|
|
|
extern struct svc_rdma_req_map *svc_rdma_get_req_map(struct svcxprt_rdma *);
|
|
|
|
extern void svc_rdma_put_req_map(struct svcxprt_rdma *,
|
|
|
|
struct svc_rdma_req_map *);
|
2008-10-07 03:45:18 +08:00
|
|
|
extern struct svc_rdma_fastreg_mr *svc_rdma_get_frmr(struct svcxprt_rdma *);
|
|
|
|
extern void svc_rdma_put_frmr(struct svcxprt_rdma *,
|
|
|
|
struct svc_rdma_fastreg_mr *);
|
2007-12-13 06:13:17 +08:00
|
|
|
extern void svc_sq_reap(struct svcxprt_rdma *);
|
|
|
|
extern void svc_rq_reap(struct svcxprt_rdma *);
|
|
|
|
extern void svc_rdma_prep_reply_hdr(struct svc_rqst *);
|
|
|
|
|
2015-10-25 05:28:16 +08:00
|
|
|
extern struct svc_xprt_class svc_rdma_class;
|
|
|
|
#ifdef CONFIG_SUNRPC_BACKCHANNEL
|
|
|
|
extern struct svc_xprt_class svc_rdma_bc_class;
|
|
|
|
#endif
|
|
|
|
|
2007-12-13 06:13:17 +08:00
|
|
|
/* svc_rdma.c */
|
2016-01-08 03:49:28 +08:00
|
|
|
extern struct workqueue_struct *svc_rdma_wq;
|
2007-12-13 06:13:17 +08:00
|
|
|
extern int svc_rdma_init(void);
|
|
|
|
extern void svc_rdma_cleanup(void);
|
|
|
|
|
|
|
|
#endif
|