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