ib_mr.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (c) 2016 Oracle. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef _RDS_IB_MR_H
  33. #define _RDS_IB_MR_H
  34. #include <linux/kernel.h>
  35. #include "rds.h"
  36. #include "ib.h"
  37. #define RDS_MR_1M_POOL_SIZE (8192 / 2)
  38. #define RDS_MR_1M_MSG_SIZE 256
  39. #define RDS_MR_8K_MSG_SIZE 2
  40. #define RDS_MR_8K_SCALE (256 / (RDS_MR_8K_MSG_SIZE + 1))
  41. #define RDS_MR_8K_POOL_SIZE (RDS_MR_8K_SCALE * (8192 / 2))
  42. struct rds_ib_fmr {
  43. struct ib_fmr *fmr;
  44. };
  45. enum rds_ib_fr_state {
  46. FRMR_IS_FREE, /* mr invalidated & ready for use */
  47. FRMR_IS_INUSE, /* mr is in use or used & can be invalidated */
  48. FRMR_IS_STALE, /* Stale MR and needs to be dropped */
  49. };
  50. struct rds_ib_frmr {
  51. struct ib_mr *mr;
  52. enum rds_ib_fr_state fr_state;
  53. bool fr_inv;
  54. struct ib_send_wr fr_wr;
  55. unsigned int dma_npages;
  56. unsigned int sg_byte_len;
  57. };
  58. /* This is stored as mr->r_trans_private. */
  59. struct rds_ib_mr {
  60. struct rds_ib_device *device;
  61. struct rds_ib_mr_pool *pool;
  62. struct rds_ib_connection *ic;
  63. struct llist_node llnode;
  64. /* unmap_list is for freeing */
  65. struct list_head unmap_list;
  66. unsigned int remap_count;
  67. struct scatterlist *sg;
  68. unsigned int sg_len;
  69. int sg_dma_len;
  70. union {
  71. struct rds_ib_fmr fmr;
  72. struct rds_ib_frmr frmr;
  73. } u;
  74. };
  75. /* Our own little MR pool */
  76. struct rds_ib_mr_pool {
  77. unsigned int pool_type;
  78. struct mutex flush_lock; /* serialize fmr invalidate */
  79. struct delayed_work flush_worker; /* flush worker */
  80. atomic_t item_count; /* total # of MRs */
  81. atomic_t dirty_count; /* # dirty of MRs */
  82. struct llist_head drop_list; /* MRs not reached max_maps */
  83. struct llist_head free_list; /* unused MRs */
  84. struct llist_head clean_list; /* unused & unmapped MRs */
  85. wait_queue_head_t flush_wait;
  86. atomic_t free_pinned; /* memory pinned by free MRs */
  87. unsigned long max_items;
  88. unsigned long max_items_soft;
  89. unsigned long max_free_pinned;
  90. struct ib_fmr_attr fmr_attr;
  91. bool use_fastreg;
  92. };
  93. extern struct workqueue_struct *rds_ib_mr_wq;
  94. extern bool prefer_frmr;
  95. struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_dev,
  96. int npages);
  97. void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
  98. struct rds_info_rdma_connection *iinfo);
  99. void rds6_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
  100. struct rds6_info_rdma_connection *iinfo6);
  101. void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *);
  102. void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
  103. struct rds_sock *rs, u32 *key_ret,
  104. struct rds_connection *conn);
  105. void rds_ib_sync_mr(void *trans_private, int dir);
  106. void rds_ib_free_mr(void *trans_private, int invalidate);
  107. void rds_ib_flush_mrs(void);
  108. int rds_ib_mr_init(void);
  109. void rds_ib_mr_exit(void);
  110. void __rds_ib_teardown_mr(struct rds_ib_mr *);
  111. void rds_ib_teardown_mr(struct rds_ib_mr *);
  112. struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *, int);
  113. struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *);
  114. int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **);
  115. struct rds_ib_mr *rds_ib_reg_fmr(struct rds_ib_device *, struct scatterlist *,
  116. unsigned long, u32 *);
  117. struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *);
  118. void rds_ib_unreg_fmr(struct list_head *, unsigned int *,
  119. unsigned long *, unsigned int);
  120. void rds_ib_free_fmr_list(struct rds_ib_mr *);
  121. struct rds_ib_mr *rds_ib_reg_frmr(struct rds_ib_device *rds_ibdev,
  122. struct rds_ib_connection *ic,
  123. struct scatterlist *sg,
  124. unsigned long nents, u32 *key);
  125. void rds_ib_unreg_frmr(struct list_head *list, unsigned int *nfreed,
  126. unsigned long *unpinned, unsigned int goal);
  127. void rds_ib_free_frmr_list(struct rds_ib_mr *);
  128. #endif