xref: /linux/include/rdma/rw.h (revision afcae7d7b8a278a6c29e064f99e5bafd4ac1fb37)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2016 HGST, a Western Digital Company.
4  */
5 #ifndef _RDMA_RW_H
6 #define _RDMA_RW_H
7 
8 #include <linux/bvec.h>
9 #include <linux/dma-mapping.h>
10 #include <linux/scatterlist.h>
11 #include <rdma/ib_verbs.h>
12 #include <rdma/rdma_cm.h>
13 #include <rdma/mr_pool.h>
14 
15 struct rdma_rw_ctx {
16 	/* number of RDMA READ/WRITE WRs (not counting MR WRs) */
17 	u32			nr_ops;
18 
19 	/* tag for the union below: */
20 	u8			type;
21 
22 	union {
23 		/* for mapping a single SGE: */
24 		struct {
25 			struct ib_sge		sge;
26 			struct ib_rdma_wr	wr;
27 		} single;
28 
29 		/* for mapping of multiple SGEs: */
30 		struct {
31 			struct ib_sge		*sges;
32 			struct ib_rdma_wr	*wrs;
33 		} map;
34 
35 		/* for IOVA-based mapping of bvecs into contiguous DMA range: */
36 		struct {
37 			struct dma_iova_state	state;
38 			struct ib_sge		sge;
39 			struct ib_rdma_wr	wr;
40 			size_t			mapped_len;
41 		} iova;
42 
43 		/* for registering multiple WRs: */
44 		struct rdma_rw_reg_ctx {
45 			struct ib_sge		sge;
46 			struct ib_rdma_wr	wr;
47 			struct ib_reg_wr	reg_wr;
48 			struct ib_send_wr	inv_wr;
49 			struct ib_mr		*mr;
50 			struct sg_table		sgt;
51 		} *reg;
52 	};
53 };
54 
55 int rdma_rw_ctx_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u32 port_num,
56 		struct scatterlist *sg, u32 sg_cnt, u32 sg_offset,
57 		u64 remote_addr, u32 rkey, enum dma_data_direction dir);
58 void rdma_rw_ctx_destroy(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
59 			 u32 port_num, struct scatterlist *sg, u32 sg_cnt,
60 			 enum dma_data_direction dir);
61 
62 struct bio_vec;
63 
64 int rdma_rw_ctx_init_bvec(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
65 		u32 port_num, const struct bio_vec *bvecs, u32 nr_bvec,
66 		struct bvec_iter iter, u64 remote_addr, u32 rkey,
67 		enum dma_data_direction dir);
68 void rdma_rw_ctx_destroy_bvec(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
69 		u32 port_num, const struct bio_vec *bvecs, u32 nr_bvec,
70 		enum dma_data_direction dir);
71 
72 int rdma_rw_ctx_signature_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
73 		u32 port_num, struct scatterlist *sg, u32 sg_cnt,
74 		struct scatterlist *prot_sg, u32 prot_sg_cnt,
75 		struct ib_sig_attrs *sig_attrs, u64 remote_addr, u32 rkey,
76 		enum dma_data_direction dir);
77 void rdma_rw_ctx_destroy_signature(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
78 		u32 port_num, struct scatterlist *sg, u32 sg_cnt,
79 		struct scatterlist *prot_sg, u32 prot_sg_cnt,
80 		enum dma_data_direction dir);
81 
82 struct ib_send_wr *rdma_rw_ctx_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
83 		u32 port_num, struct ib_cqe *cqe, struct ib_send_wr *chain_wr);
84 int rdma_rw_ctx_post(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u32 port_num,
85 		struct ib_cqe *cqe, struct ib_send_wr *chain_wr);
86 
87 unsigned int rdma_rw_mr_factor(struct ib_device *device, u32 port_num,
88 		unsigned int maxpages);
89 unsigned int rdma_rw_max_send_wr(struct ib_device *dev, u32 port_num,
90 		unsigned int max_rdma_ctxs, u32 create_flags);
91 void rdma_rw_init_qp(struct ib_device *dev, struct ib_qp_init_attr *attr);
92 int rdma_rw_init_mrs(struct ib_qp *qp, struct ib_qp_init_attr *attr);
93 void rdma_rw_cleanup_mrs(struct ib_qp *qp);
94 
95 #endif /* _RDMA_RW_H */
96