xref: /openbmc/linux/drivers/infiniband/ulp/rtrs/rtrs.h (revision 9dd7c463)
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 #ifndef RTRS_H
10 #define RTRS_H
11 
12 #include <linux/socket.h>
13 #include <linux/scatterlist.h>
14 
15 struct rtrs_permit;
16 struct rtrs_clt_sess;
17 struct rtrs_srv_ctx;
18 struct rtrs_srv_sess;
19 struct rtrs_srv_op;
20 
21 /*
22  * RDMA transport (RTRS) client API
23  */
24 
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.
29  */
30 enum rtrs_clt_link_ev {
31 	RTRS_CLT_LINK_EV_RECONNECTED,
32 	RTRS_CLT_LINK_EV_DISCONNECTED,
33 };
34 
35 /**
36  * Source and destination address of a path to be established
37  */
38 struct rtrs_addr {
39 	struct sockaddr_storage *src;
40 	struct sockaddr_storage *dst;
41 };
42 
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
49  */
50 struct rtrs_clt_ops {
51 	void	*priv;
52 	void	(*link_ev)(void *priv, enum rtrs_clt_link_ev ev);
53 };
54 
55 struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,
56 				 const char *pathname,
57 				 const struct rtrs_addr *paths,
58 				 size_t path_cnt, u16 port,
59 				 size_t pdu_sz, u8 reconnect_delay_sec,
60 				 s16 max_reconnect_attempts, u32 nr_poll_queues);
61 
62 void rtrs_clt_close(struct rtrs_clt_sess *clt);
63 
64 enum wait_type {
65 	RTRS_PERMIT_NOWAIT = 0,
66 	RTRS_PERMIT_WAIT   = 1
67 };
68 
69 /**
70  * enum rtrs_clt_con_type() type of ib connection to use with a given
71  * rtrs_permit
72  * @ADMIN_CON - use connection reserved for "service" messages
73  * @IO_CON - use a connection reserved for IO
74  */
75 enum rtrs_clt_con_type {
76 	RTRS_ADMIN_CON,
77 	RTRS_IO_CON
78 };
79 
80 struct rtrs_permit *rtrs_clt_get_permit(struct rtrs_clt_sess *sess,
81 					enum rtrs_clt_con_type con_type,
82 					enum wait_type wait);
83 
84 void rtrs_clt_put_permit(struct rtrs_clt_sess *sess,
85 			 struct rtrs_permit *permit);
86 
87 /**
88  * rtrs_clt_req_ops - it holds the request confirmation callback
89  * and a private pointer.
90  * @priv: User supplied private data.
91  * @conf_fn:	callback function to be called as confirmation
92  *	@priv:	User provided data, passed back with corresponding
93  *		@(conf) confirmation.
94  *	@errno: error number.
95  */
96 struct rtrs_clt_req_ops {
97 	void	*priv;
98 	void	(*conf_fn)(void *priv, int errno);
99 };
100 
101 int rtrs_clt_request(int dir, struct rtrs_clt_req_ops *ops,
102 		     struct rtrs_clt_sess *sess, struct rtrs_permit *permit,
103 		     const struct kvec *vec, size_t nr, size_t len,
104 		     struct scatterlist *sg, unsigned int sg_cnt);
105 int rtrs_clt_rdma_cq_direct(struct rtrs_clt_sess *clt, unsigned int index);
106 
107 /**
108  * rtrs_attrs - RTRS session attributes
109  */
110 struct rtrs_attrs {
111 	u32		queue_depth;
112 	u32		max_io_size;
113 	u32		max_segments;
114 };
115 
116 int rtrs_clt_query(struct rtrs_clt_sess *sess, struct rtrs_attrs *attr);
117 
118 /*
119  * Here goes RTRS server API
120  */
121 
122 /**
123  * enum rtrs_srv_link_ev - Server link events
124  * @RTRS_SRV_LINK_EV_CONNECTED:	Connection from client established
125  * @RTRS_SRV_LINK_EV_DISCONNECTED:	Connection was disconnected, all
126  *					connection RTRS resources were freed.
127  */
128 enum rtrs_srv_link_ev {
129 	RTRS_SRV_LINK_EV_CONNECTED,
130 	RTRS_SRV_LINK_EV_DISCONNECTED,
131 };
132 
133 struct rtrs_srv_ops {
134 	/**
135 	 * rdma_ev():		Event notification for RDMA operations
136 	 *			If the callback returns a value != 0, an error
137 	 *			message for the data transfer will be sent to
138 	 *			the client.
139 
140 	 *	@priv:		Private data set by rtrs_srv_set_sess_priv()
141 	 *	@id:		internal RTRS operation id
142 	 *	@dir:		READ/WRITE
143 	 *	@data:		Pointer to (bidirectional) rdma memory area:
144 	 *			- in case of %RTRS_SRV_RDMA_EV_RECV contains
145 	 *			data sent by the client
146 	 *			- in case of %RTRS_SRV_RDMA_EV_WRITE_REQ points
147 	 *			to the memory area where the response is to be
148 	 *			written to
149 	 *	@datalen:	Size of the memory area in @data
150 	 *	@usr:		The extra user message sent by the client (%vec)
151 	 *	@usrlen:	Size of the user message
152 	 */
153 	int (*rdma_ev)(void *priv,
154 		       struct rtrs_srv_op *id, int dir,
155 		       void *data, size_t datalen, const void *usr,
156 		       size_t usrlen);
157 	/**
158 	 * link_ev():		Events about connectivity state changes
159 	 *			If the callback returns != 0 and the event
160 	 *			%RTRS_SRV_LINK_EV_CONNECTED the corresponding
161 	 *			session will be destroyed.
162 	 *	@sess:		Session
163 	 *	@ev:		event
164 	 *	@priv:		Private data from user if previously set with
165 	 *			rtrs_srv_set_sess_priv()
166 	 */
167 	int (*link_ev)(struct rtrs_srv_sess *sess, enum rtrs_srv_link_ev ev,
168 		       void *priv);
169 };
170 
171 struct rtrs_srv_ctx *rtrs_srv_open(struct rtrs_srv_ops *ops, u16 port);
172 
173 void rtrs_srv_close(struct rtrs_srv_ctx *ctx);
174 
175 bool rtrs_srv_resp_rdma(struct rtrs_srv_op *id, int errno);
176 
177 void rtrs_srv_set_sess_priv(struct rtrs_srv_sess *sess, void *priv);
178 
179 int rtrs_srv_get_path_name(struct rtrs_srv_sess *sess, char *pathname,
180 			   size_t len);
181 
182 int rtrs_srv_get_queue_depth(struct rtrs_srv_sess *sess);
183 
184 int rtrs_addr_to_sockaddr(const char *str, size_t len, u16 port,
185 			  struct rtrs_addr *addr);
186 
187 int sockaddr_to_str(const struct sockaddr *addr, char *buf, size_t len);
188 int rtrs_addr_to_str(const struct rtrs_addr *addr, char *buf, size_t len);
189 #endif
190