Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / infiniband / ulp / rtrs / rtrs.h
blob8738e90e715a4de7153844423708ad2ee770b987
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * RDMA Transport Layer
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_H
10 #define RTRS_H
12 #include <linux/socket.h>
13 #include <linux/scatterlist.h>
15 struct rtrs_permit;
16 struct rtrs_clt;
17 struct rtrs_srv_ctx;
18 struct rtrs_srv;
19 struct rtrs_srv_op;
22 * RDMA transport (RTRS) client API
25 /**
26 * enum rtrs_clt_link_ev - Events about connectivity state of a client
27 * @RTRS_CLT_LINK_EV_RECONNECTED Client was reconnected.
28 * @RTRS_CLT_LINK_EV_DISCONNECTED Client was disconnected.
30 enum rtrs_clt_link_ev {
31 RTRS_CLT_LINK_EV_RECONNECTED,
32 RTRS_CLT_LINK_EV_DISCONNECTED,
35 /**
36 * Source and destination address of a path to be established
38 struct rtrs_addr {
39 struct sockaddr_storage *src;
40 struct sockaddr_storage *dst;
43 /**
44 * rtrs_clt_ops - it holds the link event callback and private pointer.
45 * @priv: User supplied private data.
46 * @link_ev: Event notification callback function for connection state changes
47 * @priv: User supplied data that was passed to rtrs_clt_open()
48 * @ev: Occurred event
50 struct rtrs_clt_ops {
51 void *priv;
52 void (*link_ev)(void *priv, enum rtrs_clt_link_ev ev);
55 struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,
56 const char *sessname,
57 const struct rtrs_addr *paths,
58 size_t path_cnt, u16 port,
59 size_t pdu_sz, u8 reconnect_delay_sec,
60 u16 max_segments,
61 size_t max_segment_size,
62 s16 max_reconnect_attempts);
64 void rtrs_clt_close(struct rtrs_clt *sess);
66 enum {
67 RTRS_PERMIT_NOWAIT = 0,
68 RTRS_PERMIT_WAIT = 1,
71 /**
72 * enum rtrs_clt_con_type() type of ib connection to use with a given
73 * rtrs_permit
74 * @ADMIN_CON - use connection reserved for "service" messages
75 * @IO_CON - use a connection reserved for IO
77 enum rtrs_clt_con_type {
78 RTRS_ADMIN_CON,
79 RTRS_IO_CON
82 struct rtrs_permit *rtrs_clt_get_permit(struct rtrs_clt *sess,
83 enum rtrs_clt_con_type con_type,
84 int wait);
86 void rtrs_clt_put_permit(struct rtrs_clt *sess, struct rtrs_permit *permit);
88 /**
89 * rtrs_clt_req_ops - it holds the request confirmation callback
90 * and a private pointer.
91 * @priv: User supplied private data.
92 * @conf_fn: callback function to be called as confirmation
93 * @priv: User provided data, passed back with corresponding
94 * @(conf) confirmation.
95 * @errno: error number.
97 struct rtrs_clt_req_ops {
98 void *priv;
99 void (*conf_fn)(void *priv, int errno);
102 int rtrs_clt_request(int dir, struct rtrs_clt_req_ops *ops,
103 struct rtrs_clt *sess, struct rtrs_permit *permit,
104 const struct kvec *vec, size_t nr, size_t len,
105 struct scatterlist *sg, unsigned int sg_cnt);
108 * rtrs_attrs - RTRS session attributes
110 struct rtrs_attrs {
111 u32 queue_depth;
112 u32 max_io_size;
113 u8 sessname[NAME_MAX];
114 struct kobject *sess_kobj;
117 int rtrs_clt_query(struct rtrs_clt *sess, struct rtrs_attrs *attr);
120 * Here goes RTRS server API
124 * enum rtrs_srv_link_ev - Server link events
125 * @RTRS_SRV_LINK_EV_CONNECTED: Connection from client established
126 * @RTRS_SRV_LINK_EV_DISCONNECTED: Connection was disconnected, all
127 * connection RTRS resources were freed.
129 enum rtrs_srv_link_ev {
130 RTRS_SRV_LINK_EV_CONNECTED,
131 RTRS_SRV_LINK_EV_DISCONNECTED,
134 struct rtrs_srv_ops {
136 * rdma_ev(): Event notification for RDMA operations
137 * If the callback returns a value != 0, an error
138 * message for the data transfer will be sent to
139 * the client.
141 * @sess: Session
142 * @priv: Private data set by rtrs_srv_set_sess_priv()
143 * @id: internal RTRS operation id
144 * @dir: READ/WRITE
145 * @data: Pointer to (bidirectional) rdma memory area:
146 * - in case of %RTRS_SRV_RDMA_EV_RECV contains
147 * data sent by the client
148 * - in case of %RTRS_SRV_RDMA_EV_WRITE_REQ points
149 * to the memory area where the response is to be
150 * written to
151 * @datalen: Size of the memory area in @data
152 * @usr: The extra user message sent by the client (%vec)
153 * @usrlen: Size of the user message
155 int (*rdma_ev)(struct rtrs_srv *sess, void *priv,
156 struct rtrs_srv_op *id, int dir,
157 void *data, size_t datalen, const void *usr,
158 size_t usrlen);
160 * link_ev(): Events about connectivity state changes
161 * If the callback returns != 0 and the event
162 * %RTRS_SRV_LINK_EV_CONNECTED the corresponding
163 * session will be destroyed.
164 * @sess: Session
165 * @ev: event
166 * @priv: Private data from user if previously set with
167 * rtrs_srv_set_sess_priv()
169 int (*link_ev)(struct rtrs_srv *sess, enum rtrs_srv_link_ev ev,
170 void *priv);
173 struct rtrs_srv_ctx *rtrs_srv_open(struct rtrs_srv_ops *ops, u16 port);
175 void rtrs_srv_close(struct rtrs_srv_ctx *ctx);
177 bool rtrs_srv_resp_rdma(struct rtrs_srv_op *id, int errno);
179 void rtrs_srv_set_sess_priv(struct rtrs_srv *sess, void *priv);
181 int rtrs_srv_get_sess_name(struct rtrs_srv *sess, char *sessname, size_t len);
183 int rtrs_srv_get_queue_depth(struct rtrs_srv *sess);
185 int rtrs_addr_to_sockaddr(const char *str, size_t len, u16 port,
186 struct rtrs_addr *addr);
188 int sockaddr_to_str(const struct sockaddr *addr, char *buf, size_t len);
189 #endif