blob: 9afffccff9731c4a6aa2c6f12027ec993af09dc8 [file] [log] [blame]
Jack Wangcb803292020-05-11 15:51:11 +02001/* 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
10#ifndef RTRS_CLT_H
11#define RTRS_CLT_H
12
13#include <linux/device.h>
14#include "rtrs-pri.h"
15
16/**
17 * enum rtrs_clt_state - Client states.
18 */
19enum rtrs_clt_state {
20 RTRS_CLT_CONNECTING,
21 RTRS_CLT_CONNECTING_ERR,
22 RTRS_CLT_RECONNECTING,
23 RTRS_CLT_CONNECTED,
24 RTRS_CLT_CLOSING,
25 RTRS_CLT_CLOSED,
26 RTRS_CLT_DEAD,
27};
28
29enum rtrs_mp_policy {
30 MP_POLICY_RR,
31 MP_POLICY_MIN_INFLIGHT,
Gioh Kimdc3b66a2021-04-07 13:34:41 +020032 MP_POLICY_MIN_LATENCY,
Jack Wangcb803292020-05-11 15:51:11 +020033};
34
35/* see Documentation/ABI/testing/sysfs-class-rtrs-client for details */
36struct rtrs_clt_stats_reconnects {
37 int successful_cnt;
38 int fail_cnt;
39};
40
41/* see Documentation/ABI/testing/sysfs-class-rtrs-client for details */
42struct rtrs_clt_stats_cpu_migr {
43 atomic_t from;
44 int to;
45};
46
47/* stats for Read and write operation.
48 * see Documentation/ABI/testing/sysfs-class-rtrs-client for details
49 */
50struct rtrs_clt_stats_rdma {
51 struct {
52 u64 cnt;
53 u64 size_total;
54 } dir[2];
55
56 u64 failover_cnt;
57};
58
59struct rtrs_clt_stats_pcpu {
60 struct rtrs_clt_stats_cpu_migr cpu_migr;
61 struct rtrs_clt_stats_rdma rdma;
62};
63
64struct rtrs_clt_stats {
65 struct kobject kobj_stats;
66 struct rtrs_clt_stats_pcpu __percpu *pcpu_stats;
67 struct rtrs_clt_stats_reconnects reconnects;
68 atomic_t inflight;
69};
70
71struct rtrs_clt_con {
72 struct rtrs_con c;
73 struct rtrs_iu *rsp_ius;
Guoqing Jiang354462e2021-06-14 11:03:36 +020074 u32 queue_num;
Jack Wangcb803292020-05-11 15:51:11 +020075 unsigned int cpu;
Jack Wangfcf29592020-10-23 09:43:44 +020076 struct mutex con_mutex;
Jack Wangcb803292020-05-11 15:51:11 +020077 int cm_err;
78};
79
80/**
81 * rtrs_permit - permits the memory allocation for future RDMA operation.
82 * Combine with irq pinning to keep IO on same CPU.
83 */
84struct rtrs_permit {
85 enum rtrs_clt_con_type con_type;
86 unsigned int cpu_id;
87 unsigned int mem_id;
88 unsigned int mem_off;
89};
90
91/**
92 * rtrs_clt_io_req - describes one inflight IO request
93 */
94struct rtrs_clt_io_req {
95 struct list_head list;
96 struct rtrs_iu *iu;
97 struct scatterlist *sglist; /* list holding user data */
98 unsigned int sg_cnt;
99 unsigned int sg_size;
100 unsigned int data_len;
101 unsigned int usr_len;
102 void *priv;
103 bool in_use;
Gioh Kim0d8f2cfa2021-08-06 13:21:11 +0200104 enum rtrs_mp_policy mp_policy;
Jack Wangcb803292020-05-11 15:51:11 +0200105 struct rtrs_clt_con *con;
106 struct rtrs_sg_desc *desc;
107 struct ib_sge *sge;
108 struct rtrs_permit *permit;
109 enum dma_data_direction dir;
110 void (*conf)(void *priv, int errno);
111 unsigned long start_jiffies;
112
113 struct ib_mr *mr;
114 struct ib_cqe inv_cqe;
115 struct completion inv_comp;
116 int inv_errno;
117 bool need_inv_comp;
118 bool need_inv;
Jack Wang2ece9ec2021-06-21 07:53:37 +0200119 refcount_t ref;
Jack Wangcb803292020-05-11 15:51:11 +0200120};
121
122struct rtrs_rbuf {
123 u64 addr;
124 u32 rkey;
125};
126
127struct rtrs_clt_sess {
128 struct rtrs_sess s;
129 struct rtrs_clt *clt;
130 wait_queue_head_t state_wq;
131 enum rtrs_clt_state state;
132 atomic_t connected_cnt;
133 struct mutex init_mutex;
134 struct rtrs_clt_io_req *reqs;
135 struct delayed_work reconnect_dwork;
136 struct work_struct close_work;
137 unsigned int reconnect_attempts;
138 bool established;
139 struct rtrs_rbuf *rbufs;
140 size_t max_io_size;
141 u32 max_hdr_size;
142 u32 chunk_size;
143 size_t queue_depth;
144 u32 max_pages_per_mr;
Jack Wangcb803292020-05-11 15:51:11 +0200145 u32 flags;
146 struct kobject kobj;
Md Haris Iqbal03e9b332021-02-12 14:45:23 +0100147 u8 for_new_clt;
Jack Wangcb803292020-05-11 15:51:11 +0200148 struct rtrs_clt_stats *stats;
149 /* cache hca_port and hca_name to display in sysfs */
150 u8 hca_port;
151 char hca_name[IB_DEVICE_NAME_MAX];
152 struct list_head __percpu
153 *mp_skip_entry;
154};
155
156struct rtrs_clt {
157 struct list_head paths_list; /* rcu protected list */
158 size_t paths_num;
159 struct rtrs_clt_sess
160 __rcu * __percpu *pcpu_path;
161 uuid_t paths_uuid;
162 int paths_up;
163 struct mutex paths_mutex;
164 struct mutex paths_ev_mutex;
165 char sessname[NAME_MAX];
166 u16 port;
167 unsigned int max_reconnect_attempts;
168 unsigned int reconnect_delay_sec;
169 unsigned int max_segments;
Jack Wangcb803292020-05-11 15:51:11 +0200170 void *permits;
171 unsigned long *permits_map;
172 size_t queue_depth;
173 size_t max_io_size;
174 wait_queue_head_t permits_wait;
175 size_t pdu_sz;
176 void *priv;
177 void (*link_ev)(void *priv,
178 enum rtrs_clt_link_ev ev);
179 struct device dev;
180 struct kobject *kobj_paths;
181 enum rtrs_mp_policy mp_policy;
182};
183
184static inline struct rtrs_clt_con *to_clt_con(struct rtrs_con *c)
185{
186 return container_of(c, struct rtrs_clt_con, c);
187}
188
189static inline struct rtrs_clt_sess *to_clt_sess(struct rtrs_sess *s)
190{
191 return container_of(s, struct rtrs_clt_sess, s);
192}
193
194static inline int permit_size(struct rtrs_clt *clt)
195{
196 return sizeof(struct rtrs_permit) + clt->pdu_sz;
197}
198
199static inline struct rtrs_permit *get_permit(struct rtrs_clt *clt, int idx)
200{
201 return (struct rtrs_permit *)(clt->permits + permit_size(clt) * idx);
202}
203
204int rtrs_clt_reconnect_from_sysfs(struct rtrs_clt_sess *sess);
Guoqing Jiangb0c633c2021-05-28 13:30:07 +0200205void rtrs_clt_close_conns(struct rtrs_clt_sess *sess, bool wait);
Jack Wangcb803292020-05-11 15:51:11 +0200206int rtrs_clt_create_path_from_sysfs(struct rtrs_clt *clt,
207 struct rtrs_addr *addr);
208int rtrs_clt_remove_path_from_sysfs(struct rtrs_clt_sess *sess,
209 const struct attribute *sysfs_self);
210
211void rtrs_clt_set_max_reconnect_attempts(struct rtrs_clt *clt, int value);
212int rtrs_clt_get_max_reconnect_attempts(const struct rtrs_clt *clt);
213void free_sess(struct rtrs_clt_sess *sess);
214
215/* rtrs-clt-stats.c */
216
217int rtrs_clt_init_stats(struct rtrs_clt_stats *stats);
218
219void rtrs_clt_inc_failover_cnt(struct rtrs_clt_stats *s);
220
221void rtrs_clt_update_wc_stats(struct rtrs_clt_con *con);
222void rtrs_clt_update_all_stats(struct rtrs_clt_io_req *req, int dir);
223
224int rtrs_clt_reset_rdma_lat_distr_stats(struct rtrs_clt_stats *stats,
225 bool enable);
226ssize_t rtrs_clt_stats_rdma_lat_distr_to_str(struct rtrs_clt_stats *stats,
Md Haris Iqbal80ad07f2021-09-22 14:53:28 +0200227 char *page);
Jack Wangcb803292020-05-11 15:51:11 +0200228int rtrs_clt_reset_cpu_migr_stats(struct rtrs_clt_stats *stats, bool enable);
Md Haris Iqbal3f3fe682021-09-22 14:53:33 +0200229int rtrs_clt_stats_migration_from_cnt_to_str(struct rtrs_clt_stats *stats, char *buf);
230int rtrs_clt_stats_migration_to_cnt_to_str(struct rtrs_clt_stats *stats, char *buf);
Jack Wangcb803292020-05-11 15:51:11 +0200231int rtrs_clt_reset_reconnects_stat(struct rtrs_clt_stats *stats, bool enable);
Md Haris Iqbal80ad07f2021-09-22 14:53:28 +0200232int rtrs_clt_stats_reconnects_to_str(struct rtrs_clt_stats *stats, char *buf);
Jack Wangcb803292020-05-11 15:51:11 +0200233int rtrs_clt_reset_rdma_stats(struct rtrs_clt_stats *stats, bool enable);
234ssize_t rtrs_clt_stats_rdma_to_str(struct rtrs_clt_stats *stats,
Md Haris Iqbal80ad07f2021-09-22 14:53:28 +0200235 char *page);
Jack Wangcb803292020-05-11 15:51:11 +0200236int rtrs_clt_reset_all_stats(struct rtrs_clt_stats *stats, bool enable);
237ssize_t rtrs_clt_reset_all_help(struct rtrs_clt_stats *stats,
Md Haris Iqbal80ad07f2021-09-22 14:53:28 +0200238 char *page);
Jack Wangcb803292020-05-11 15:51:11 +0200239
240/* rtrs-clt-sysfs.c */
241
242int rtrs_clt_create_sysfs_root_files(struct rtrs_clt *clt);
Guoqing Jiang7b47b272020-12-17 15:19:04 +0100243void rtrs_clt_destroy_sysfs_root(struct rtrs_clt *clt);
Jack Wangcb803292020-05-11 15:51:11 +0200244
245int rtrs_clt_create_sess_files(struct rtrs_clt_sess *sess);
246void rtrs_clt_destroy_sess_files(struct rtrs_clt_sess *sess,
247 const struct attribute *sysfs_self);
248
249#endif /* RTRS_CLT_H */