1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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.
13 #include <linux/device.h>
14 #include <linux/refcount.h>
15 #include <linux/percpu.h>
19 * enum rtrs_srv_state - Server states.
28 /* stats for Read and write operation.
29 * see Documentation/ABI/testing/sysfs-class-rtrs-server for details
31 struct rtrs_srv_stats_rdma_stats
{
38 struct rtrs_srv_stats
{
39 struct kobject kobj_stats
;
40 struct rtrs_srv_stats_rdma_stats __percpu
*rdma_stats
;
41 struct rtrs_srv_path
*srv_path
;
46 struct list_head rsp_wr_wait_list
;
47 spinlock_t rsp_wr_wait_lock
;
50 /* IO context in rtrs_srv, each io has one */
52 struct rtrs_srv_con
*con
;
55 struct rtrs_msg_rdma_read
*rd_msg
;
56 struct ib_rdma_wr tx_wr
;
58 struct list_head wait_list
;
63 * server side memory region context, when always_invalidate=Y, we need
64 * queue_depth of memory region to invalidate each memory region.
69 struct ib_cqe inv_cqe
; /* only for always_invalidate=true */
70 u32 msg_id
; /* only for always_invalidate=true */
71 u32 msg_off
; /* only for always_invalidate=true */
72 struct rtrs_iu
*iu
; /* send buffer for new rkey msg */
75 struct rtrs_srv_path
{
77 struct rtrs_srv_sess
*srv
;
78 struct work_struct close_work
;
79 enum rtrs_srv_state state
;
80 spinlock_t state_lock
;
82 struct rtrs_srv_op
**ops_ids
;
83 struct percpu_ref ids_inflight_ref
;
84 struct completion complete_done
;
85 struct rtrs_srv_mr
*mrs
;
89 unsigned int mem_bits
;
91 struct rtrs_srv_stats
*stats
;
94 static inline struct rtrs_srv_path
*to_srv_path(struct rtrs_path
*s
)
96 return container_of(s
, struct rtrs_srv_path
, s
);
99 struct rtrs_srv_sess
{
100 struct list_head paths_list
;
102 struct mutex paths_ev_mutex
;
104 struct mutex paths_mutex
;
107 struct rtrs_srv_ctx
*ctx
;
108 struct list_head ctx_list
;
111 struct page
**chunks
;
113 unsigned int dev_ref
;
114 struct kobject
*kobj_paths
;
117 struct rtrs_srv_ctx
{
118 struct rtrs_srv_ops ops
;
119 struct rdma_cm_id
*cm_id_ip
;
120 struct rdma_cm_id
*cm_id_ib
;
121 struct mutex srv_mutex
;
122 struct list_head srv_list
;
125 struct rtrs_srv_ib_ctx
{
126 struct rtrs_srv_ctx
*srv_ctx
;
128 struct mutex ib_dev_mutex
;
132 extern const struct class rtrs_dev_class
;
134 void close_path(struct rtrs_srv_path
*srv_path
);
135 void rtrs_srv_ib_event_handler(struct ib_event_handler
*handler
,
136 struct ib_event
*ibevent
);
138 static inline void rtrs_srv_update_rdma_stats(struct rtrs_srv_stats
*s
,
141 this_cpu_inc(s
->rdma_stats
->dir
[d
].cnt
);
142 this_cpu_add(s
->rdma_stats
->dir
[d
].size_total
, size
);
145 /* functions which are implemented in rtrs-srv-stats.c */
146 int rtrs_srv_reset_rdma_stats(struct rtrs_srv_stats
*stats
, bool enable
);
147 ssize_t
rtrs_srv_stats_rdma_to_str(struct rtrs_srv_stats
*stats
, char *page
);
148 int rtrs_srv_reset_all_stats(struct rtrs_srv_stats
*stats
, bool enable
);
149 ssize_t
rtrs_srv_reset_all_help(struct rtrs_srv_stats
*stats
,
150 char *page
, size_t len
);
152 /* functions which are implemented in rtrs-srv-sysfs.c */
153 int rtrs_srv_create_path_files(struct rtrs_srv_path
*srv_path
);
154 void rtrs_srv_destroy_path_files(struct rtrs_srv_path
*srv_path
);
156 #endif /* RTRS_SRV_H */