rw.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include <linux/dma-mapping.h>
  8. #include <linux/scatterlist.h>
  9. #include <rdma/ib_verbs.h>
  10. #include <rdma/rdma_cm.h>
  11. #include <rdma/mr_pool.h>
  12. struct rdma_rw_ctx {
  13. /* number of RDMA READ/WRITE WRs (not counting MR WRs) */
  14. u32 nr_ops;
  15. /* tag for the union below: */
  16. u8 type;
  17. union {
  18. /* for mapping a single SGE: */
  19. struct {
  20. struct ib_sge sge;
  21. struct ib_rdma_wr wr;
  22. } single;
  23. /* for mapping of multiple SGEs: */
  24. struct {
  25. struct ib_sge *sges;
  26. struct ib_rdma_wr *wrs;
  27. } map;
  28. /* for registering multiple WRs: */
  29. struct rdma_rw_reg_ctx {
  30. struct ib_sge sge;
  31. struct ib_rdma_wr wr;
  32. struct ib_reg_wr reg_wr;
  33. struct ib_send_wr inv_wr;
  34. struct ib_mr *mr;
  35. } *reg;
  36. };
  37. };
  38. int rdma_rw_ctx_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
  39. struct scatterlist *sg, u32 sg_cnt, u32 sg_offset,
  40. u64 remote_addr, u32 rkey, enum dma_data_direction dir);
  41. void rdma_rw_ctx_destroy(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
  42. struct scatterlist *sg, u32 sg_cnt,
  43. enum dma_data_direction dir);
  44. int rdma_rw_ctx_signature_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
  45. u8 port_num, struct scatterlist *sg, u32 sg_cnt,
  46. struct scatterlist *prot_sg, u32 prot_sg_cnt,
  47. struct ib_sig_attrs *sig_attrs, u64 remote_addr, u32 rkey,
  48. enum dma_data_direction dir);
  49. void rdma_rw_ctx_destroy_signature(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
  50. u8 port_num, struct scatterlist *sg, u32 sg_cnt,
  51. struct scatterlist *prot_sg, u32 prot_sg_cnt,
  52. enum dma_data_direction dir);
  53. struct ib_send_wr *rdma_rw_ctx_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
  54. u8 port_num, struct ib_cqe *cqe, struct ib_send_wr *chain_wr);
  55. int rdma_rw_ctx_post(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
  56. struct ib_cqe *cqe, struct ib_send_wr *chain_wr);
  57. unsigned int rdma_rw_mr_factor(struct ib_device *device, u8 port_num,
  58. unsigned int maxpages);
  59. void rdma_rw_init_qp(struct ib_device *dev, struct ib_qp_init_attr *attr);
  60. int rdma_rw_init_mrs(struct ib_qp *qp, struct ib_qp_init_attr *attr);
  61. void rdma_rw_cleanup_mrs(struct ib_qp *qp);
  62. #endif /* _RDMA_RW_H */