rdmavt_mr.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef DEF_RDMAVT_INCMR_H
  2. #define DEF_RDMAVT_INCMR_H
  3. /*
  4. * Copyright(c) 2016 Intel Corporation.
  5. *
  6. * This file is provided under a dual BSD/GPLv2 license. When using or
  7. * redistributing this file, you may do so under either license.
  8. *
  9. * GPL LICENSE SUMMARY
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * BSD LICENSE
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. *
  26. * - Redistributions of source code must retain the above copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * - Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in
  30. * the documentation and/or other materials provided with the
  31. * distribution.
  32. * - Neither the name of Intel Corporation nor the names of its
  33. * contributors may be used to endorse or promote products derived
  34. * from this software without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  37. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  39. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  43. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  44. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  46. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. */
  49. /*
  50. * For Memory Regions. This stuff should probably be moved into rdmavt/mr.h once
  51. * drivers no longer need access to the MR directly.
  52. */
  53. /*
  54. * A segment is a linear region of low physical memory.
  55. * Used by the verbs layer.
  56. */
  57. struct rvt_seg {
  58. void *vaddr;
  59. size_t length;
  60. };
  61. /* The number of rvt_segs that fit in a page. */
  62. #define RVT_SEGSZ (PAGE_SIZE / sizeof(struct rvt_seg))
  63. struct rvt_segarray {
  64. struct rvt_seg segs[RVT_SEGSZ];
  65. };
  66. struct rvt_mregion {
  67. struct ib_pd *pd; /* shares refcnt of ibmr.pd */
  68. u64 user_base; /* User's address for this region */
  69. u64 iova; /* IB start address of this region */
  70. size_t length;
  71. u32 lkey;
  72. u32 offset; /* offset (bytes) to start of region */
  73. int access_flags;
  74. u32 max_segs; /* number of rvt_segs in all the arrays */
  75. u32 mapsz; /* size of the map array */
  76. u8 page_shift; /* 0 - non unform/non powerof2 sizes */
  77. u8 lkey_published; /* in global table */
  78. atomic_t lkey_invalid; /* true if current lkey is invalid */
  79. struct completion comp; /* complete when refcount goes to zero */
  80. atomic_t refcount;
  81. struct rvt_segarray *map[0]; /* the segments */
  82. };
  83. #define RVT_MAX_LKEY_TABLE_BITS 23
  84. struct rvt_lkey_table {
  85. spinlock_t lock; /* protect changes in this struct */
  86. u32 next; /* next unused index (speeds search) */
  87. u32 gen; /* generation count */
  88. u32 max; /* size of the table */
  89. struct rvt_mregion __rcu **table;
  90. };
  91. /*
  92. * These keep track of the copy progress within a memory region.
  93. * Used by the verbs layer.
  94. */
  95. struct rvt_sge {
  96. struct rvt_mregion *mr;
  97. void *vaddr; /* kernel virtual address of segment */
  98. u32 sge_length; /* length of the SGE */
  99. u32 length; /* remaining length of the segment */
  100. u16 m; /* current index: mr->map[m] */
  101. u16 n; /* current index: mr->map[m]->segs[n] */
  102. };
  103. struct rvt_sge_state {
  104. struct rvt_sge *sg_list; /* next SGE to be used if any */
  105. struct rvt_sge sge; /* progress state for the current SGE */
  106. u32 total_len;
  107. u8 num_sge;
  108. };
  109. static inline void rvt_put_mr(struct rvt_mregion *mr)
  110. {
  111. if (unlikely(atomic_dec_and_test(&mr->refcount)))
  112. complete(&mr->comp);
  113. }
  114. static inline void rvt_get_mr(struct rvt_mregion *mr)
  115. {
  116. atomic_inc(&mr->refcount);
  117. }
  118. static inline void rvt_put_ss(struct rvt_sge_state *ss)
  119. {
  120. while (ss->num_sge) {
  121. rvt_put_mr(ss->sge.mr);
  122. if (--ss->num_sge)
  123. ss->sge = *ss->sg_list++;
  124. }
  125. }
  126. #endif /* DEF_RDMAVT_INCMRH */