12025cf9eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2a060b562SChristoph Hellwig /* 3a060b562SChristoph Hellwig * Copyright (c) 2016 HGST, a Western Digital Company. 4a060b562SChristoph Hellwig */ 5a060b562SChristoph Hellwig #ifndef _RDMA_RW_H 6a060b562SChristoph Hellwig #define _RDMA_RW_H 7a060b562SChristoph Hellwig 8a060b562SChristoph Hellwig #include <linux/dma-mapping.h> 9a060b562SChristoph Hellwig #include <linux/scatterlist.h> 10a060b562SChristoph Hellwig #include <rdma/ib_verbs.h> 11a060b562SChristoph Hellwig #include <rdma/rdma_cm.h> 12a060b562SChristoph Hellwig #include <rdma/mr_pool.h> 13a060b562SChristoph Hellwig 14a060b562SChristoph Hellwig struct rdma_rw_ctx { 15a060b562SChristoph Hellwig /* number of RDMA READ/WRITE WRs (not counting MR WRs) */ 16a060b562SChristoph Hellwig u32 nr_ops; 17a060b562SChristoph Hellwig 18a060b562SChristoph Hellwig /* tag for the union below: */ 19a060b562SChristoph Hellwig u8 type; 20a060b562SChristoph Hellwig 21a060b562SChristoph Hellwig union { 22a060b562SChristoph Hellwig /* for mapping a single SGE: */ 23a060b562SChristoph Hellwig struct { 24a060b562SChristoph Hellwig struct ib_sge sge; 25a060b562SChristoph Hellwig struct ib_rdma_wr wr; 26a060b562SChristoph Hellwig } single; 27a060b562SChristoph Hellwig 28a060b562SChristoph Hellwig /* for mapping of multiple SGEs: */ 29a060b562SChristoph Hellwig struct { 30a060b562SChristoph Hellwig struct ib_sge *sges; 31a060b562SChristoph Hellwig struct ib_rdma_wr *wrs; 32a060b562SChristoph Hellwig } map; 33a060b562SChristoph Hellwig 34a060b562SChristoph Hellwig /* for registering multiple WRs: */ 35a060b562SChristoph Hellwig struct rdma_rw_reg_ctx { 36a060b562SChristoph Hellwig struct ib_sge sge; 37a060b562SChristoph Hellwig struct ib_rdma_wr wr; 38a060b562SChristoph Hellwig struct ib_reg_wr reg_wr; 39a060b562SChristoph Hellwig struct ib_send_wr inv_wr; 40a060b562SChristoph Hellwig struct ib_mr *mr; 41a060b562SChristoph Hellwig } *reg; 42a060b562SChristoph Hellwig }; 43a060b562SChristoph Hellwig }; 44a060b562SChristoph Hellwig 45*1fb7f897SMark Bloch int rdma_rw_ctx_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u32 port_num, 46a060b562SChristoph Hellwig struct scatterlist *sg, u32 sg_cnt, u32 sg_offset, 47a060b562SChristoph Hellwig u64 remote_addr, u32 rkey, enum dma_data_direction dir); 48*1fb7f897SMark Bloch void rdma_rw_ctx_destroy(struct rdma_rw_ctx *ctx, struct ib_qp *qp, 49*1fb7f897SMark Bloch u32 port_num, struct scatterlist *sg, u32 sg_cnt, 50a060b562SChristoph Hellwig enum dma_data_direction dir); 51a060b562SChristoph Hellwig 520e353e34SChristoph Hellwig int rdma_rw_ctx_signature_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, 53*1fb7f897SMark Bloch u32 port_num, struct scatterlist *sg, u32 sg_cnt, 540e353e34SChristoph Hellwig struct scatterlist *prot_sg, u32 prot_sg_cnt, 550e353e34SChristoph Hellwig struct ib_sig_attrs *sig_attrs, u64 remote_addr, u32 rkey, 560e353e34SChristoph Hellwig enum dma_data_direction dir); 570e353e34SChristoph Hellwig void rdma_rw_ctx_destroy_signature(struct rdma_rw_ctx *ctx, struct ib_qp *qp, 58*1fb7f897SMark Bloch u32 port_num, struct scatterlist *sg, u32 sg_cnt, 590e353e34SChristoph Hellwig struct scatterlist *prot_sg, u32 prot_sg_cnt, 600e353e34SChristoph Hellwig enum dma_data_direction dir); 610e353e34SChristoph Hellwig 62a060b562SChristoph Hellwig struct ib_send_wr *rdma_rw_ctx_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp, 63*1fb7f897SMark Bloch u32 port_num, struct ib_cqe *cqe, struct ib_send_wr *chain_wr); 64*1fb7f897SMark Bloch int rdma_rw_ctx_post(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u32 port_num, 65a060b562SChristoph Hellwig struct ib_cqe *cqe, struct ib_send_wr *chain_wr); 66a060b562SChristoph Hellwig 67*1fb7f897SMark Bloch unsigned int rdma_rw_mr_factor(struct ib_device *device, u32 port_num, 6800628182SChuck Lever unsigned int maxpages); 69a060b562SChristoph Hellwig void rdma_rw_init_qp(struct ib_device *dev, struct ib_qp_init_attr *attr); 70a060b562SChristoph Hellwig int rdma_rw_init_mrs(struct ib_qp *qp, struct ib_qp_init_attr *attr); 71a060b562SChristoph Hellwig void rdma_rw_cleanup_mrs(struct ib_qp *qp); 72a060b562SChristoph Hellwig 73a060b562SChristoph Hellwig #endif /* _RDMA_RW_H */ 74