hns_roce_hem.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2016 Hisilicon Limited.
  3. * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #ifndef _HNS_ROCE_HEM_H
  34. #define _HNS_ROCE_HEM_H
  35. #define HW_SYNC_TIMEOUT_MSECS 500
  36. #define HW_SYNC_SLEEP_TIME_INTERVAL 20
  37. #define BT_CMD_SYNC_SHIFT 31
  38. enum {
  39. /* MAP HEM(Hardware Entry Memory) */
  40. HEM_TYPE_QPC = 0,
  41. HEM_TYPE_MTPT,
  42. HEM_TYPE_CQC,
  43. HEM_TYPE_SRQC,
  44. /* UNMAP HEM */
  45. HEM_TYPE_MTT,
  46. HEM_TYPE_IRRL,
  47. };
  48. #define HNS_ROCE_HEM_CHUNK_LEN \
  49. ((256 - sizeof(struct list_head) - 2 * sizeof(int)) / \
  50. (sizeof(struct scatterlist)))
  51. enum {
  52. HNS_ROCE_HEM_PAGE_SHIFT = 12,
  53. HNS_ROCE_HEM_PAGE_SIZE = 1 << HNS_ROCE_HEM_PAGE_SHIFT,
  54. };
  55. struct hns_roce_hem_chunk {
  56. struct list_head list;
  57. int npages;
  58. int nsg;
  59. struct scatterlist mem[HNS_ROCE_HEM_CHUNK_LEN];
  60. };
  61. struct hns_roce_hem {
  62. struct list_head chunk_list;
  63. int refcount;
  64. };
  65. struct hns_roce_hem_iter {
  66. struct hns_roce_hem *hem;
  67. struct hns_roce_hem_chunk *chunk;
  68. int page_idx;
  69. };
  70. void hns_roce_free_hem(struct hns_roce_dev *hr_dev, struct hns_roce_hem *hem);
  71. int hns_roce_table_get(struct hns_roce_dev *hr_dev,
  72. struct hns_roce_hem_table *table, unsigned long obj);
  73. void hns_roce_table_put(struct hns_roce_dev *hr_dev,
  74. struct hns_roce_hem_table *table, unsigned long obj);
  75. void *hns_roce_table_find(struct hns_roce_hem_table *table, unsigned long obj,
  76. dma_addr_t *dma_handle);
  77. int hns_roce_table_get_range(struct hns_roce_dev *hr_dev,
  78. struct hns_roce_hem_table *table,
  79. unsigned long start, unsigned long end);
  80. void hns_roce_table_put_range(struct hns_roce_dev *hr_dev,
  81. struct hns_roce_hem_table *table,
  82. unsigned long start, unsigned long end);
  83. int hns_roce_init_hem_table(struct hns_roce_dev *hr_dev,
  84. struct hns_roce_hem_table *table, u32 type,
  85. unsigned long obj_size, unsigned long nobj,
  86. int use_lowmem);
  87. void hns_roce_cleanup_hem_table(struct hns_roce_dev *hr_dev,
  88. struct hns_roce_hem_table *table);
  89. void hns_roce_cleanup_hem(struct hns_roce_dev *hr_dev);
  90. static inline void hns_roce_hem_first(struct hns_roce_hem *hem,
  91. struct hns_roce_hem_iter *iter)
  92. {
  93. iter->hem = hem;
  94. iter->chunk = list_empty(&hem->chunk_list) ? NULL :
  95. list_entry(hem->chunk_list.next,
  96. struct hns_roce_hem_chunk, list);
  97. iter->page_idx = 0;
  98. }
  99. static inline int hns_roce_hem_last(struct hns_roce_hem_iter *iter)
  100. {
  101. return !iter->chunk;
  102. }
  103. static inline void hns_roce_hem_next(struct hns_roce_hem_iter *iter)
  104. {
  105. if (++iter->page_idx >= iter->chunk->nsg) {
  106. if (iter->chunk->list.next == &iter->hem->chunk_list) {
  107. iter->chunk = NULL;
  108. return;
  109. }
  110. iter->chunk = list_entry(iter->chunk->list.next,
  111. struct hns_roce_hem_chunk, list);
  112. iter->page_idx = 0;
  113. }
  114. }
  115. static inline dma_addr_t hns_roce_hem_addr(struct hns_roce_hem_iter *iter)
  116. {
  117. return sg_dma_address(&iter->chunk->mem[iter->page_idx]);
  118. }
  119. #endif /*_HNS_ROCE_HEM_H*/