rtrs-srv.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * RDMA Transport Layer
  4. *
  5. * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
  6. * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
  7. * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
  8. */
  9. #ifndef RTRS_SRV_H
  10. #define RTRS_SRV_H
  11. #include <linux/device.h>
  12. #include <linux/refcount.h>
  13. #include <linux/percpu.h>
  14. #include "rtrs-pri.h"
  15. /*
  16. * enum rtrs_srv_state - Server states.
  17. */
  18. enum rtrs_srv_state {
  19. RTRS_SRV_CONNECTING,
  20. RTRS_SRV_CONNECTED,
  21. RTRS_SRV_CLOSING,
  22. RTRS_SRV_CLOSED,
  23. };
  24. /* stats for Read and write operation.
  25. * see Documentation/ABI/testing/sysfs-class-rtrs-server for details
  26. */
  27. struct rtrs_srv_stats_rdma_stats {
  28. struct {
  29. u64 cnt;
  30. u64 size_total;
  31. } dir[2];
  32. };
  33. struct rtrs_srv_stats {
  34. struct kobject kobj_stats;
  35. struct rtrs_srv_stats_rdma_stats __percpu *rdma_stats;
  36. struct rtrs_srv_path *srv_path;
  37. };
  38. struct rtrs_srv_con {
  39. struct rtrs_con c;
  40. struct list_head rsp_wr_wait_list;
  41. spinlock_t rsp_wr_wait_lock;
  42. };
  43. /* IO context in rtrs_srv, each io has one */
  44. struct rtrs_srv_op {
  45. struct rtrs_srv_con *con;
  46. u32 msg_id;
  47. u8 dir;
  48. struct rtrs_msg_rdma_read *rd_msg;
  49. struct ib_rdma_wr tx_wr;
  50. struct ib_sge tx_sg;
  51. struct list_head wait_list;
  52. int status;
  53. };
  54. /*
  55. * server side memory region context, when always_invalidate=Y, we need
  56. * queue_depth of memory region to invalidate each memory region.
  57. */
  58. struct rtrs_srv_mr {
  59. struct ib_mr *mr;
  60. struct sg_table sgt;
  61. struct ib_cqe inv_cqe; /* only for always_invalidate=true */
  62. u32 msg_id; /* only for always_invalidate=true */
  63. u32 msg_off; /* only for always_invalidate=true */
  64. struct rtrs_iu *iu; /* send buffer for new rkey msg */
  65. };
  66. struct rtrs_srv_path {
  67. struct rtrs_path s;
  68. struct rtrs_srv_sess *srv;
  69. struct work_struct close_work;
  70. enum rtrs_srv_state state;
  71. spinlock_t state_lock;
  72. int cur_cq_vector;
  73. struct rtrs_srv_op **ops_ids;
  74. struct percpu_ref ids_inflight_ref;
  75. struct completion complete_done;
  76. struct rtrs_srv_mr *mrs;
  77. unsigned int mrs_num;
  78. dma_addr_t *dma_addr;
  79. bool established;
  80. unsigned int mem_bits;
  81. struct kobject kobj;
  82. struct rtrs_srv_stats *stats;
  83. };
  84. static inline struct rtrs_srv_path *to_srv_path(struct rtrs_path *s)
  85. {
  86. return container_of(s, struct rtrs_srv_path, s);
  87. }
  88. struct rtrs_srv_sess {
  89. struct list_head paths_list;
  90. int paths_up;
  91. struct mutex paths_ev_mutex;
  92. size_t paths_num;
  93. struct mutex paths_mutex;
  94. uuid_t paths_uuid;
  95. refcount_t refcount;
  96. struct rtrs_srv_ctx *ctx;
  97. struct list_head ctx_list;
  98. void *priv;
  99. size_t queue_depth;
  100. struct page **chunks;
  101. struct device dev;
  102. unsigned int dev_ref;
  103. struct kobject *kobj_paths;
  104. };
  105. struct rtrs_srv_ctx {
  106. struct rtrs_srv_ops ops;
  107. struct rdma_cm_id *cm_id_ip;
  108. struct rdma_cm_id *cm_id_ib;
  109. struct mutex srv_mutex;
  110. struct list_head srv_list;
  111. };
  112. struct rtrs_srv_ib_ctx {
  113. struct rtrs_srv_ctx *srv_ctx;
  114. u16 port;
  115. struct mutex ib_dev_mutex;
  116. int ib_dev_count;
  117. };
  118. extern struct class *rtrs_dev_class;
  119. void close_path(struct rtrs_srv_path *srv_path);
  120. static inline void rtrs_srv_update_rdma_stats(struct rtrs_srv_stats *s,
  121. size_t size, int d)
  122. {
  123. this_cpu_inc(s->rdma_stats->dir[d].cnt);
  124. this_cpu_add(s->rdma_stats->dir[d].size_total, size);
  125. }
  126. /* functions which are implemented in rtrs-srv-stats.c */
  127. int rtrs_srv_reset_rdma_stats(struct rtrs_srv_stats *stats, bool enable);
  128. ssize_t rtrs_srv_stats_rdma_to_str(struct rtrs_srv_stats *stats, char *page);
  129. int rtrs_srv_reset_all_stats(struct rtrs_srv_stats *stats, bool enable);
  130. ssize_t rtrs_srv_reset_all_help(struct rtrs_srv_stats *stats,
  131. char *page, size_t len);
  132. /* functions which are implemented in rtrs-srv-sysfs.c */
  133. int rtrs_srv_create_path_files(struct rtrs_srv_path *srv_path);
  134. void rtrs_srv_destroy_path_files(struct rtrs_srv_path *srv_path);
  135. #endif /* RTRS_SRV_H */