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, 60b5c27cdbSJack Wang u16 max_segments, 61d6ea3950SDanil Kipnis size_t max_segment_size, 62b5c27cdbSJack Wang s16 max_reconnect_attempts); 63b5c27cdbSJack Wang 64b5c27cdbSJack Wang void rtrs_clt_close(struct rtrs_clt *sess); 65b5c27cdbSJack Wang 66*9f455eeaSGioh Kim enum wait_type { 67b5c27cdbSJack Wang RTRS_PERMIT_NOWAIT = 0, 68*9f455eeaSGioh Kim RTRS_PERMIT_WAIT = 1 69b5c27cdbSJack Wang }; 70b5c27cdbSJack Wang 71b5c27cdbSJack Wang /** 72b5c27cdbSJack Wang * enum rtrs_clt_con_type() type of ib connection to use with a given 73b5c27cdbSJack Wang * rtrs_permit 74b5c27cdbSJack Wang * @ADMIN_CON - use connection reserved for "service" messages 75b5c27cdbSJack Wang * @IO_CON - use a connection reserved for IO 76b5c27cdbSJack Wang */ 77b5c27cdbSJack Wang enum rtrs_clt_con_type { 78b5c27cdbSJack Wang RTRS_ADMIN_CON, 79b5c27cdbSJack Wang RTRS_IO_CON 80b5c27cdbSJack Wang }; 81b5c27cdbSJack Wang 82b5c27cdbSJack Wang struct rtrs_permit *rtrs_clt_get_permit(struct rtrs_clt *sess, 83b5c27cdbSJack Wang enum rtrs_clt_con_type con_type, 84*9f455eeaSGioh Kim enum wait_type wait); 85b5c27cdbSJack Wang 86b5c27cdbSJack Wang void rtrs_clt_put_permit(struct rtrs_clt *sess, struct rtrs_permit *permit); 87b5c27cdbSJack Wang 88b5c27cdbSJack Wang /** 89b5c27cdbSJack Wang * rtrs_clt_req_ops - it holds the request confirmation callback 90b5c27cdbSJack Wang * and a private pointer. 91b5c27cdbSJack Wang * @priv: User supplied private data. 92b5c27cdbSJack Wang * @conf_fn: callback function to be called as confirmation 93b5c27cdbSJack Wang * @priv: User provided data, passed back with corresponding 94b5c27cdbSJack Wang * @(conf) confirmation. 95b5c27cdbSJack Wang * @errno: error number. 96b5c27cdbSJack Wang */ 97b5c27cdbSJack Wang struct rtrs_clt_req_ops { 98b5c27cdbSJack Wang void *priv; 99b5c27cdbSJack Wang void (*conf_fn)(void *priv, int errno); 100b5c27cdbSJack Wang }; 101b5c27cdbSJack Wang 102b5c27cdbSJack Wang int rtrs_clt_request(int dir, struct rtrs_clt_req_ops *ops, 103b5c27cdbSJack Wang struct rtrs_clt *sess, struct rtrs_permit *permit, 104b5c27cdbSJack Wang const struct kvec *vec, size_t nr, size_t len, 105b5c27cdbSJack Wang struct scatterlist *sg, unsigned int sg_cnt); 106b5c27cdbSJack Wang 107b5c27cdbSJack Wang /** 108b5c27cdbSJack Wang * rtrs_attrs - RTRS session attributes 109b5c27cdbSJack Wang */ 110b5c27cdbSJack Wang struct rtrs_attrs { 111b5c27cdbSJack Wang u32 queue_depth; 112b5c27cdbSJack Wang u32 max_io_size; 113b5c27cdbSJack Wang u8 sessname[NAME_MAX]; 114b5c27cdbSJack Wang struct kobject *sess_kobj; 115b5c27cdbSJack Wang }; 116b5c27cdbSJack Wang 117b5c27cdbSJack Wang int rtrs_clt_query(struct rtrs_clt *sess, struct rtrs_attrs *attr); 118b5c27cdbSJack Wang 119b5c27cdbSJack Wang /* 120b5c27cdbSJack Wang * Here goes RTRS server API 121b5c27cdbSJack Wang */ 122b5c27cdbSJack Wang 123b5c27cdbSJack Wang /** 124b5c27cdbSJack Wang * enum rtrs_srv_link_ev - Server link events 125b5c27cdbSJack Wang * @RTRS_SRV_LINK_EV_CONNECTED: Connection from client established 126b5c27cdbSJack Wang * @RTRS_SRV_LINK_EV_DISCONNECTED: Connection was disconnected, all 127b5c27cdbSJack Wang * connection RTRS resources were freed. 128b5c27cdbSJack Wang */ 129b5c27cdbSJack Wang enum rtrs_srv_link_ev { 130b5c27cdbSJack Wang RTRS_SRV_LINK_EV_CONNECTED, 131b5c27cdbSJack Wang RTRS_SRV_LINK_EV_DISCONNECTED, 132b5c27cdbSJack Wang }; 133b5c27cdbSJack Wang 134b5c27cdbSJack Wang struct rtrs_srv_ops { 135b5c27cdbSJack Wang /** 136b5c27cdbSJack Wang * rdma_ev(): Event notification for RDMA operations 137b5c27cdbSJack Wang * If the callback returns a value != 0, an error 138b5c27cdbSJack Wang * message for the data transfer will be sent to 139b5c27cdbSJack Wang * the client. 140b5c27cdbSJack Wang 141b5c27cdbSJack Wang * @sess: Session 142b5c27cdbSJack Wang * @priv: Private data set by rtrs_srv_set_sess_priv() 143b5c27cdbSJack Wang * @id: internal RTRS operation id 144b5c27cdbSJack Wang * @dir: READ/WRITE 145b5c27cdbSJack Wang * @data: Pointer to (bidirectional) rdma memory area: 146b5c27cdbSJack Wang * - in case of %RTRS_SRV_RDMA_EV_RECV contains 147b5c27cdbSJack Wang * data sent by the client 148b5c27cdbSJack Wang * - in case of %RTRS_SRV_RDMA_EV_WRITE_REQ points 149b5c27cdbSJack Wang * to the memory area where the response is to be 150b5c27cdbSJack Wang * written to 151b5c27cdbSJack Wang * @datalen: Size of the memory area in @data 152b5c27cdbSJack Wang * @usr: The extra user message sent by the client (%vec) 153b5c27cdbSJack Wang * @usrlen: Size of the user message 154b5c27cdbSJack Wang */ 155b5c27cdbSJack Wang int (*rdma_ev)(struct rtrs_srv *sess, void *priv, 156b5c27cdbSJack Wang struct rtrs_srv_op *id, int dir, 157b5c27cdbSJack Wang void *data, size_t datalen, const void *usr, 158b5c27cdbSJack Wang size_t usrlen); 159b5c27cdbSJack Wang /** 160b5c27cdbSJack Wang * link_ev(): Events about connectivity state changes 161b5c27cdbSJack Wang * If the callback returns != 0 and the event 162b5c27cdbSJack Wang * %RTRS_SRV_LINK_EV_CONNECTED the corresponding 163b5c27cdbSJack Wang * session will be destroyed. 164b5c27cdbSJack Wang * @sess: Session 165b5c27cdbSJack Wang * @ev: event 166b5c27cdbSJack Wang * @priv: Private data from user if previously set with 167b5c27cdbSJack Wang * rtrs_srv_set_sess_priv() 168b5c27cdbSJack Wang */ 169b5c27cdbSJack Wang int (*link_ev)(struct rtrs_srv *sess, enum rtrs_srv_link_ev ev, 170b5c27cdbSJack Wang void *priv); 171b5c27cdbSJack Wang }; 172b5c27cdbSJack Wang 173b5c27cdbSJack Wang struct rtrs_srv_ctx *rtrs_srv_open(struct rtrs_srv_ops *ops, u16 port); 174b5c27cdbSJack Wang 175b5c27cdbSJack Wang void rtrs_srv_close(struct rtrs_srv_ctx *ctx); 176b5c27cdbSJack Wang 177b5c27cdbSJack Wang bool rtrs_srv_resp_rdma(struct rtrs_srv_op *id, int errno); 178b5c27cdbSJack Wang 179b5c27cdbSJack Wang void rtrs_srv_set_sess_priv(struct rtrs_srv *sess, void *priv); 180b5c27cdbSJack Wang 181b5c27cdbSJack Wang int rtrs_srv_get_sess_name(struct rtrs_srv *sess, char *sessname, size_t len); 182b5c27cdbSJack Wang 183b5c27cdbSJack Wang int rtrs_srv_get_queue_depth(struct rtrs_srv *sess); 184b5c27cdbSJack Wang 185b5c27cdbSJack Wang int rtrs_addr_to_sockaddr(const char *str, size_t len, u16 port, 186b5c27cdbSJack Wang struct rtrs_addr *addr); 187b5c27cdbSJack Wang 188b5c27cdbSJack Wang int sockaddr_to_str(const struct sockaddr *addr, char *buf, size_t len); 189b5c27cdbSJack Wang #endif 190