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