rw.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2016 HGST, a Western Digital Company.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. */
  13. #ifndef _RDMA_RW_H
  14. #define _RDMA_RW_H
  15. #include <linux/dma-mapping.h>
  16. #include <linux/scatterlist.h>
  17. #include <rdma/ib_verbs.h>
  18. #include <rdma/rdma_cm.h>
  19. #include <rdma/mr_pool.h>
  20. struct rdma_rw_ctx {
  21. /* number of RDMA READ/WRITE WRs (not counting MR WRs) */
  22. u32 nr_ops;
  23. /* tag for the union below: */
  24. u8 type;
  25. union {
  26. /* for mapping a single SGE: */
  27. struct {
  28. struct ib_sge sge;
  29. struct ib_rdma_wr wr;
  30. } single;
  31. /* for mapping of multiple SGEs: */
  32. struct {
  33. struct ib_sge *sges;
  34. struct ib_rdma_wr *wrs;
  35. } map;
  36. /* for registering multiple WRs: */
  37. struct rdma_rw_reg_ctx {
  38. struct ib_sge sge;
  39. struct ib_rdma_wr wr;
  40. struct ib_reg_wr reg_wr;
  41. struct ib_send_wr inv_wr;
  42. struct ib_mr *mr;
  43. } *reg;
  44. struct {
  45. struct rdma_rw_reg_ctx data;
  46. struct rdma_rw_reg_ctx prot;
  47. struct ib_send_wr sig_inv_wr;
  48. struct ib_mr *sig_mr;
  49. struct ib_sge sig_sge;
  50. struct ib_sig_handover_wr sig_wr;
  51. } *sig;
  52. };
  53. };
  54. int rdma_rw_ctx_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
  55. struct scatterlist *sg, u32 sg_cnt, u32 sg_offset,
  56. u64 remote_addr, u32 rkey, enum dma_data_direction dir);
  57. void rdma_rw_ctx_destroy(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
  58. struct scatterlist *sg, u32 sg_cnt,
  59. enum dma_data_direction dir);
  60. int rdma_rw_ctx_signature_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
  61. u8 port_num, struct scatterlist *sg, u32 sg_cnt,
  62. struct scatterlist *prot_sg, u32 prot_sg_cnt,
  63. struct ib_sig_attrs *sig_attrs, u64 remote_addr, u32 rkey,
  64. enum dma_data_direction dir);
  65. void rdma_rw_ctx_destroy_signature(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
  66. u8 port_num, struct scatterlist *sg, u32 sg_cnt,
  67. struct scatterlist *prot_sg, u32 prot_sg_cnt,
  68. enum dma_data_direction dir);
  69. struct ib_send_wr *rdma_rw_ctx_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
  70. u8 port_num, struct ib_cqe *cqe, struct ib_send_wr *chain_wr);
  71. int rdma_rw_ctx_post(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
  72. struct ib_cqe *cqe, struct ib_send_wr *chain_wr);
  73. void rdma_rw_init_qp(struct ib_device *dev, struct ib_qp_init_attr *attr);
  74. int rdma_rw_init_mrs(struct ib_qp *qp, struct ib_qp_init_attr *attr);
  75. void rdma_rw_cleanup_mrs(struct ib_qp *qp);
  76. #endif /* _RDMA_RW_H */