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>
17 * enum rtrs_clt_state - Client states.
21 RTRS_CLT_CONNECTING_ERR
,
22 RTRS_CLT_RECONNECTING
,
31 MP_POLICY_MIN_INFLIGHT
,
32 MP_POLICY_MIN_LATENCY
,
35 /* see Documentation/ABI/testing/sysfs-class-rtrs-client for details */
36 struct rtrs_clt_stats_reconnects
{
41 /* see Documentation/ABI/testing/sysfs-class-rtrs-client for details */
42 struct rtrs_clt_stats_cpu_migr
{
47 /* stats for Read and write operation.
48 * see Documentation/ABI/testing/sysfs-class-rtrs-client for details
50 struct rtrs_clt_stats_rdma
{
59 struct rtrs_clt_stats_pcpu
{
60 struct rtrs_clt_stats_cpu_migr cpu_migr
;
61 struct rtrs_clt_stats_rdma rdma
;
64 struct rtrs_clt_stats
{
65 struct kobject kobj_stats
;
66 struct rtrs_clt_stats_pcpu __percpu
*pcpu_stats
;
67 struct rtrs_clt_stats_reconnects reconnects
;
73 struct rtrs_iu
*rsp_ius
;
76 struct mutex con_mutex
;
81 * rtrs_permit - permits the memory allocation for future RDMA operation.
82 * Combine with irq pinning to keep IO on same CPU.
85 enum rtrs_clt_con_type con_type
;
92 * rtrs_clt_io_req - describes one inflight IO request
94 struct rtrs_clt_io_req
{
95 struct list_head list
;
97 struct scatterlist
*sglist
; /* list holding user data */
100 unsigned int data_len
;
101 unsigned int usr_len
;
104 enum rtrs_mp_policy mp_policy
;
105 struct rtrs_clt_con
*con
;
106 struct rtrs_sg_desc
*desc
;
108 struct rtrs_permit
*permit
;
109 enum dma_data_direction dir
;
110 void (*conf
)(void *priv
, int errno
);
111 unsigned long start_jiffies
;
114 struct ib_cqe inv_cqe
;
115 struct completion inv_comp
;
126 struct rtrs_clt_path
{
128 struct rtrs_clt_sess
*clt
;
129 wait_queue_head_t state_wq
;
130 enum rtrs_clt_state state
;
131 atomic_t connected_cnt
;
132 struct mutex init_mutex
;
133 struct rtrs_clt_io_req
*reqs
;
134 struct delayed_work reconnect_dwork
;
135 struct work_struct close_work
;
136 struct work_struct err_recovery_work
;
137 unsigned int reconnect_attempts
;
139 struct rtrs_rbuf
*rbufs
;
144 u32 max_pages_per_mr
;
148 struct rtrs_clt_stats
*stats
;
149 /* cache hca_port and hca_name to display in sysfs */
151 char hca_name
[IB_DEVICE_NAME_MAX
];
152 struct list_head __percpu
156 struct rtrs_clt_sess
{
157 struct list_head paths_list
; /* rcu protected list */
160 __rcu
* __percpu
*pcpu_path
;
163 struct mutex paths_mutex
;
164 struct mutex paths_ev_mutex
;
165 char sessname
[NAME_MAX
];
167 unsigned int max_reconnect_attempts
;
168 unsigned int reconnect_delay_sec
;
169 unsigned int max_segments
;
171 unsigned long *permits_map
;
174 wait_queue_head_t permits_wait
;
177 void (*link_ev
)(void *priv
,
178 enum rtrs_clt_link_ev ev
);
180 struct kobject
*kobj_paths
;
181 enum rtrs_mp_policy mp_policy
;
184 static inline struct rtrs_clt_con
*to_clt_con(struct rtrs_con
*c
)
186 return container_of(c
, struct rtrs_clt_con
, c
);
189 static inline struct rtrs_clt_path
*to_clt_path(struct rtrs_path
*s
)
191 return container_of(s
, struct rtrs_clt_path
, s
);
194 static inline int permit_size(struct rtrs_clt_sess
*clt
)
196 return sizeof(struct rtrs_permit
) + clt
->pdu_sz
;
199 static inline struct rtrs_permit
*get_permit(struct rtrs_clt_sess
*clt
,
202 return (struct rtrs_permit
*)(clt
->permits
+ permit_size(clt
) * idx
);
205 int rtrs_clt_reconnect_from_sysfs(struct rtrs_clt_path
*path
);
206 void rtrs_clt_close_conns(struct rtrs_clt_path
*clt_path
, bool wait
);
207 int rtrs_clt_create_path_from_sysfs(struct rtrs_clt_sess
*clt
,
208 struct rtrs_addr
*addr
);
209 int rtrs_clt_remove_path_from_sysfs(struct rtrs_clt_path
*path
,
210 const struct attribute
*sysfs_self
);
212 void rtrs_clt_set_max_reconnect_attempts(struct rtrs_clt_sess
*clt
, int value
);
213 int rtrs_clt_get_max_reconnect_attempts(const struct rtrs_clt_sess
*clt
);
214 void free_path(struct rtrs_clt_path
*clt_path
);
215 void rtrs_clt_ib_event_handler(struct ib_event_handler
*handler
,
216 struct ib_event
*ibevent
);
218 /* rtrs-clt-stats.c */
220 int rtrs_clt_init_stats(struct rtrs_clt_stats
*stats
);
222 void rtrs_clt_inc_failover_cnt(struct rtrs_clt_stats
*s
);
224 void rtrs_clt_update_wc_stats(struct rtrs_clt_con
*con
);
225 void rtrs_clt_update_all_stats(struct rtrs_clt_io_req
*req
, int dir
);
227 int rtrs_clt_reset_rdma_lat_distr_stats(struct rtrs_clt_stats
*stats
,
229 ssize_t
rtrs_clt_stats_rdma_lat_distr_to_str(struct rtrs_clt_stats
*stats
,
231 int rtrs_clt_reset_cpu_migr_stats(struct rtrs_clt_stats
*stats
, bool enable
);
232 int rtrs_clt_stats_migration_from_cnt_to_str(struct rtrs_clt_stats
*stats
, char *buf
);
233 int rtrs_clt_stats_migration_to_cnt_to_str(struct rtrs_clt_stats
*stats
, char *buf
);
234 int rtrs_clt_reset_reconnects_stat(struct rtrs_clt_stats
*stats
, bool enable
);
235 int rtrs_clt_stats_reconnects_to_str(struct rtrs_clt_stats
*stats
, char *buf
);
236 int rtrs_clt_reset_rdma_stats(struct rtrs_clt_stats
*stats
, bool enable
);
237 ssize_t
rtrs_clt_stats_rdma_to_str(struct rtrs_clt_stats
*stats
,
239 int rtrs_clt_reset_all_stats(struct rtrs_clt_stats
*stats
, bool enable
);
240 ssize_t
rtrs_clt_reset_all_help(struct rtrs_clt_stats
*stats
,
243 /* rtrs-clt-sysfs.c */
245 int rtrs_clt_create_sysfs_root_files(struct rtrs_clt_sess
*clt
);
246 void rtrs_clt_destroy_sysfs_root(struct rtrs_clt_sess
*clt
);
248 int rtrs_clt_create_path_files(struct rtrs_clt_path
*clt_path
);
249 void rtrs_clt_destroy_path_files(struct rtrs_clt_path
*clt_path
,
250 const struct attribute
*sysfs_self
);
252 #endif /* RTRS_CLT_H */