xref: /kernel/linux/linux-6.6/include/rdma/rw.h (revision 62306a36)
162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2016 HGST, a Western Digital Company.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci#ifndef _RDMA_RW_H
662306a36Sopenharmony_ci#define _RDMA_RW_H
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/dma-mapping.h>
962306a36Sopenharmony_ci#include <linux/scatterlist.h>
1062306a36Sopenharmony_ci#include <rdma/ib_verbs.h>
1162306a36Sopenharmony_ci#include <rdma/rdma_cm.h>
1262306a36Sopenharmony_ci#include <rdma/mr_pool.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistruct rdma_rw_ctx {
1562306a36Sopenharmony_ci	/* number of RDMA READ/WRITE WRs (not counting MR WRs) */
1662306a36Sopenharmony_ci	u32			nr_ops;
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci	/* tag for the union below: */
1962306a36Sopenharmony_ci	u8			type;
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci	union {
2262306a36Sopenharmony_ci		/* for mapping a single SGE: */
2362306a36Sopenharmony_ci		struct {
2462306a36Sopenharmony_ci			struct ib_sge		sge;
2562306a36Sopenharmony_ci			struct ib_rdma_wr	wr;
2662306a36Sopenharmony_ci		} single;
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci		/* for mapping of multiple SGEs: */
2962306a36Sopenharmony_ci		struct {
3062306a36Sopenharmony_ci			struct ib_sge		*sges;
3162306a36Sopenharmony_ci			struct ib_rdma_wr	*wrs;
3262306a36Sopenharmony_ci		} map;
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci		/* for registering multiple WRs: */
3562306a36Sopenharmony_ci		struct rdma_rw_reg_ctx {
3662306a36Sopenharmony_ci			struct ib_sge		sge;
3762306a36Sopenharmony_ci			struct ib_rdma_wr	wr;
3862306a36Sopenharmony_ci			struct ib_reg_wr	reg_wr;
3962306a36Sopenharmony_ci			struct ib_send_wr	inv_wr;
4062306a36Sopenharmony_ci			struct ib_mr		*mr;
4162306a36Sopenharmony_ci		} *reg;
4262306a36Sopenharmony_ci	};
4362306a36Sopenharmony_ci};
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ciint rdma_rw_ctx_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u32 port_num,
4662306a36Sopenharmony_ci		struct scatterlist *sg, u32 sg_cnt, u32 sg_offset,
4762306a36Sopenharmony_ci		u64 remote_addr, u32 rkey, enum dma_data_direction dir);
4862306a36Sopenharmony_civoid rdma_rw_ctx_destroy(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
4962306a36Sopenharmony_ci			 u32 port_num, struct scatterlist *sg, u32 sg_cnt,
5062306a36Sopenharmony_ci			 enum dma_data_direction dir);
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciint rdma_rw_ctx_signature_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
5362306a36Sopenharmony_ci		u32 port_num, struct scatterlist *sg, u32 sg_cnt,
5462306a36Sopenharmony_ci		struct scatterlist *prot_sg, u32 prot_sg_cnt,
5562306a36Sopenharmony_ci		struct ib_sig_attrs *sig_attrs, u64 remote_addr, u32 rkey,
5662306a36Sopenharmony_ci		enum dma_data_direction dir);
5762306a36Sopenharmony_civoid rdma_rw_ctx_destroy_signature(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
5862306a36Sopenharmony_ci		u32 port_num, struct scatterlist *sg, u32 sg_cnt,
5962306a36Sopenharmony_ci		struct scatterlist *prot_sg, u32 prot_sg_cnt,
6062306a36Sopenharmony_ci		enum dma_data_direction dir);
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistruct ib_send_wr *rdma_rw_ctx_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
6362306a36Sopenharmony_ci		u32 port_num, struct ib_cqe *cqe, struct ib_send_wr *chain_wr);
6462306a36Sopenharmony_ciint rdma_rw_ctx_post(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u32 port_num,
6562306a36Sopenharmony_ci		struct ib_cqe *cqe, struct ib_send_wr *chain_wr);
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ciunsigned int rdma_rw_mr_factor(struct ib_device *device, u32 port_num,
6862306a36Sopenharmony_ci		unsigned int maxpages);
6962306a36Sopenharmony_civoid rdma_rw_init_qp(struct ib_device *dev, struct ib_qp_init_attr *attr);
7062306a36Sopenharmony_ciint rdma_rw_init_mrs(struct ib_qp *qp, struct ib_qp_init_attr *attr);
7162306a36Sopenharmony_civoid rdma_rw_cleanup_mrs(struct ib_qp *qp);
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#endif /* _RDMA_RW_H */
74