| 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 |
|
| 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 |
*/ |
| 19 |
enum 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 |
|
| 29 |
enum rtrs_mp_policy { |
| 30 |
MP_POLICY_RR, |
| 31 |
MP_POLICY_MIN_INFLIGHT, |
| 32 |
MP_POLICY_MIN_LATENCY, |
| 33 |
}; |
| 34 |
|
| 35 |
/* see Documentation/ABI/testing/sysfs-class-rtrs-client for details */ |
| 36 |
struct 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 */ |
| 42 |
struct 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 |
*/ |
| 50 |
struct rtrs_clt_stats_rdma { |
| 51 |
struct { |
| 52 |
u64 cnt; |
| 53 |
u64 size_total; |
| 54 |
} dir[2]; |
| 55 |
|
| 56 |
u64 failover_cnt; |
| 57 |
}; |
| 58 |
|
| 59 |
struct rtrs_clt_stats_pcpu { |
| 60 |
struct rtrs_clt_stats_cpu_migr cpu_migr; |
| 61 |
struct rtrs_clt_stats_rdma rdma; |
| 62 |
}; |
| 63 |
|
| 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; |
| 68 |
atomic_t inflight; |
| 69 |
}; |
| 70 |
|
| 71 |
struct rtrs_clt_con { |
| 72 |
struct rtrs_con c; |
| 73 |
struct rtrs_iu *rsp_ius; |
| 74 |
u32 queue_num; |
| 75 |
unsigned int cpu; |
| 76 |
struct mutex con_mutex; |
| 77 |
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 |
*/ |
| 84 |
struct 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 |
*/ |
| 94 |
struct rtrs_clt_io_req { |
| 95 |
struct rtrs_iu *iu; |
| 96 |
struct scatterlist *sglist; /* list holding user data */ |
| 97 |
unsigned int sg_cnt; |
| 98 |
unsigned int sg_size; |
| 99 |
unsigned int data_len; |
| 100 |
unsigned int usr_len; |
| 101 |
void *priv; |
| 102 |
bool in_use; |
| 103 |
enum rtrs_mp_policy mp_policy; |
| 104 |
struct rtrs_clt_con *con; |
| 105 |
struct ib_sge *sge; |
| 106 |
struct rtrs_permit *permit; |
| 107 |
enum dma_data_direction dir; |
| 108 |
void (*conf)(void *priv, int errno); |
| 109 |
|
| 110 |
struct ib_mr *mr; |
| 111 |
struct ib_cqe inv_cqe; |
| 112 |
struct completion inv_comp; |
| 113 |
int inv_errno; |
| 114 |
bool need_inv_comp; |
| 115 |
refcount_t ref; |
| 116 |
}; |
| 117 |
|
| 118 |
struct rtrs_rbuf { |
| 119 |
u64 addr; |
| 120 |
u32 rkey; |
| 121 |
}; |
| 122 |
|
| 123 |
struct rtrs_clt_path { |
| 124 |
struct rtrs_path s; |
| 125 |
struct rtrs_clt_sess *clt; |
| 126 |
wait_queue_head_t state_wq; |
| 127 |
enum rtrs_clt_state state; |
| 128 |
atomic_t connected_cnt; |
| 129 |
struct mutex init_mutex; |
| 130 |
struct rtrs_clt_io_req *reqs; |
| 131 |
struct delayed_work reconnect_dwork; |
| 132 |
struct work_struct close_work; |
| 133 |
struct work_struct err_recovery_work; |
| 134 |
unsigned int reconnect_attempts; |
| 135 |
bool established; |
| 136 |
struct rtrs_rbuf *rbufs; |
| 137 |
size_t max_io_size; |
| 138 |
u32 max_hdr_size; |
| 139 |
u32 chunk_size; |
| 140 |
size_t queue_depth; |
| 141 |
u32 max_pages_per_mr; |
| 142 |
u32 flags; |
| 143 |
struct kobject kobj; |
| 144 |
u8 for_new_clt; |
| 145 |
struct rtrs_clt_stats *stats; |
| 146 |
/* cache hca_port and hca_name to display in sysfs */ |
| 147 |
u8 hca_port; |
| 148 |
char hca_name[IB_DEVICE_NAME_MAX]; |
| 149 |
struct list_head __percpu |
| 150 |
*mp_skip_entry; |
| 151 |
}; |
| 152 |
|
| 153 |
struct rtrs_clt_sess { |
| 154 |
struct list_head paths_list; /* rcu protected list */ |
| 155 |
size_t paths_num; |
| 156 |
struct rtrs_clt_path |
| 157 |
__rcu * __percpu *pcpu_path; |
| 158 |
uuid_t paths_uuid; |
| 159 |
int paths_up; |
| 160 |
struct mutex paths_mutex; |
| 161 |
struct mutex paths_ev_mutex; |
| 162 |
char sessname[NAME_MAX]; |
| 163 |
u16 port; |
| 164 |
unsigned int max_reconnect_attempts; |
| 165 |
unsigned int reconnect_delay_sec; |
| 166 |
unsigned int max_segments; |
| 167 |
void *permits; |
| 168 |
unsigned long *permits_map; |
| 169 |
size_t queue_depth; |
| 170 |
size_t max_io_size; |
| 171 |
wait_queue_head_t permits_wait; |
| 172 |
size_t pdu_sz; |
| 173 |
void *priv; |
| 174 |
void (*link_ev)(void *priv, |
| 175 |
enum rtrs_clt_link_ev ev); |
| 176 |
struct device dev; |
| 177 |
struct kobject *kobj_paths; |
| 178 |
enum rtrs_mp_policy mp_policy; |
| 179 |
}; |
| 180 |
|
| 181 |
static inline struct rtrs_clt_con *to_clt_con(struct rtrs_con *c) |
| 182 |
{ |
| 183 |
return container_of(c, struct rtrs_clt_con, c); |
| 184 |
} |
| 185 |
|
| 186 |
static inline struct rtrs_clt_path *to_clt_path(struct rtrs_path *s) |
| 187 |
{ |
| 188 |
return container_of(s, struct rtrs_clt_path, s); |
| 189 |
} |
| 190 |
|
| 191 |
static inline int permit_size(struct rtrs_clt_sess *clt) |
| 192 |
{ |
| 193 |
return sizeof(struct rtrs_permit) + clt->pdu_sz; |
| 194 |
} |
| 195 |
|
| 196 |
static inline struct rtrs_permit *get_permit(struct rtrs_clt_sess *clt, |
| 197 |
int idx) |
| 198 |
{ |
| 199 |
return (struct rtrs_permit *)(clt->permits + permit_size(clt) * idx); |
| 200 |
} |
| 201 |
|
| 202 |
int rtrs_clt_reconnect_from_sysfs(struct rtrs_clt_path *path); |
| 203 |
void rtrs_clt_close_conns(struct rtrs_clt_path *clt_path, bool wait); |
| 204 |
int rtrs_clt_create_path_from_sysfs(struct rtrs_clt_sess *clt, |
| 205 |
struct rtrs_addr *addr); |
| 206 |
int rtrs_clt_remove_path_from_sysfs(struct rtrs_clt_path *path, |
| 207 |
const struct attribute *sysfs_self); |
| 208 |
|
| 209 |
void rtrs_clt_set_max_reconnect_attempts(struct rtrs_clt_sess *clt, int value); |
| 210 |
int rtrs_clt_get_max_reconnect_attempts(const struct rtrs_clt_sess *clt); |
| 211 |
void free_path(struct rtrs_clt_path *clt_path); |
| 212 |
void rtrs_clt_ib_event_handler(struct ib_event_handler *handler, |
| 213 |
struct ib_event *ibevent); |
| 214 |
|
| 215 |
/* rtrs-clt-stats.c */ |
| 216 |
|
| 217 |
int rtrs_clt_init_stats(struct rtrs_clt_stats *stats); |
| 218 |
|
| 219 |
void rtrs_clt_inc_failover_cnt(struct rtrs_clt_stats *s); |
| 220 |
|
| 221 |
void rtrs_clt_update_wc_stats(struct rtrs_clt_con *con); |
| 222 |
void rtrs_clt_update_all_stats(struct rtrs_clt_io_req *req, int dir); |
| 223 |
|
| 224 |
int rtrs_clt_reset_rdma_lat_distr_stats(struct rtrs_clt_stats *stats, |
| 225 |
bool enable); |
| 226 |
ssize_t rtrs_clt_stats_rdma_lat_distr_to_str(struct rtrs_clt_stats *stats, |
| 227 |
char *page); |
| 228 |
int rtrs_clt_reset_cpu_migr_stats(struct rtrs_clt_stats *stats, bool enable); |
| 229 |
int rtrs_clt_stats_migration_from_cnt_to_str(struct rtrs_clt_stats *stats, char *buf); |
| 230 |
int rtrs_clt_stats_migration_to_cnt_to_str(struct rtrs_clt_stats *stats, char *buf); |
| 231 |
int rtrs_clt_reset_reconnects_stat(struct rtrs_clt_stats *stats, bool enable); |
| 232 |
int rtrs_clt_stats_reconnects_to_str(struct rtrs_clt_stats *stats, char *buf); |
| 233 |
int rtrs_clt_reset_rdma_stats(struct rtrs_clt_stats *stats, bool enable); |
| 234 |
ssize_t rtrs_clt_stats_rdma_to_str(struct rtrs_clt_stats *stats, |
| 235 |
char *page); |
| 236 |
int rtrs_clt_reset_all_stats(struct rtrs_clt_stats *stats, bool enable); |
| 237 |
ssize_t rtrs_clt_reset_all_help(struct rtrs_clt_stats *stats, |
| 238 |
char *page); |
| 239 |
|
| 240 |
/* rtrs-clt-sysfs.c */ |
| 241 |
|
| 242 |
int rtrs_clt_create_sysfs_root_files(struct rtrs_clt_sess *clt); |
| 243 |
void rtrs_clt_destroy_sysfs_root(struct rtrs_clt_sess *clt); |
| 244 |
|
| 245 |
int rtrs_clt_create_path_files(struct rtrs_clt_path *clt_path); |
| 246 |
void rtrs_clt_destroy_path_files(struct rtrs_clt_path *clt_path, |
| 247 |
const struct attribute *sysfs_self); |
| 248 |
|
| 249 |
#endif /* RTRS_CLT_H */ |