^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef RTRS_PRI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define RTRS_PRI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/uuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <rdma/rdma_cm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <rdma/ib_verbs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <rdma/ib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "rtrs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define RTRS_PROTO_VER_MAJOR 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define RTRS_PROTO_VER_MINOR 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define RTRS_PROTO_VER_STRING __stringify(RTRS_PROTO_VER_MAJOR) "." \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) __stringify(RTRS_PROTO_VER_MINOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) enum rtrs_imm_const {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) MAX_IMM_TYPE_BITS = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) MAX_IMM_TYPE_MASK = ((1 << MAX_IMM_TYPE_BITS) - 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) MAX_IMM_PAYL_BITS = 28,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MAX_IMM_PAYL_MASK = ((1 << MAX_IMM_PAYL_BITS) - 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) enum rtrs_imm_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) RTRS_IO_REQ_IMM = 0, /* client to server */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) RTRS_IO_RSP_IMM = 1, /* server to client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) RTRS_IO_RSP_W_INV_IMM = 2, /* server to client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) RTRS_HB_MSG_IMM = 8, /* HB: HeartBeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) RTRS_HB_ACK_IMM = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) RTRS_LAST_IMM,
^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) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) SERVICE_CON_QUEUE_DEPTH = 512,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) MAX_PATHS_NUM = 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Max IB immediate data size is 2^28 (MAX_IMM_PAYL_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * and the minimum chunk size is 4096 (2^12).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * So the maximum sess_queue_depth is 65536 (2^16) in theory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * But mempool_create, create_qp and ib_post_send fail with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * "cannot allocate memory" error if sess_queue_depth is too big.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * Therefore the pratical max value of sess_queue_depth is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * somewhere between 1 and 65536 and it depends on the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) MAX_SESS_QUEUE_DEPTH = 65536,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) RTRS_HB_INTERVAL_MS = 5000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) RTRS_HB_MISSED_MAX = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) RTRS_MAGIC = 0x1BBD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) RTRS_PROTO_VER = (RTRS_PROTO_VER_MAJOR << 8) | RTRS_PROTO_VER_MINOR,
^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) struct rtrs_ib_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct rtrs_rdma_dev_pd_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct rtrs_ib_dev *(*alloc)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) void (*free)(struct rtrs_ib_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int (*init)(struct rtrs_ib_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) void (*deinit)(struct rtrs_ib_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct rtrs_rdma_dev_pd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) enum ib_pd_flags pd_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) const struct rtrs_rdma_dev_pd_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct rtrs_ib_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct ib_device *ib_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct ib_pd *ib_pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct kref ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct list_head entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct rtrs_rdma_dev_pd *pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct rtrs_con {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct rtrs_sess *sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct ib_qp *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct ib_cq *cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct rdma_cm_id *cm_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned int cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct rtrs_sess {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct list_head entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct sockaddr_storage dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct sockaddr_storage src_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) char sessname[NAME_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) uuid_t uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct rtrs_con **con;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned int con_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned int recon_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct rtrs_ib_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int dev_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct ib_cqe *hb_cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) void (*hb_err_handler)(struct rtrs_con *con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct workqueue_struct *hb_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct delayed_work hb_dwork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) unsigned int hb_interval_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) unsigned int hb_missed_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned int hb_missed_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* rtrs information unit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct rtrs_iu {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct ib_cqe cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) dma_addr_t dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) enum dma_data_direction direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * enum rtrs_msg_types - RTRS message types, see also rtrs/README
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * @RTRS_MSG_INFO_REQ: Client additional info request to the server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * @RTRS_MSG_INFO_RSP: Server additional info response to the client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * @RTRS_MSG_WRITE: Client writes data per RDMA to server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * @RTRS_MSG_READ: Client requests data transfer from server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * @RTRS_MSG_RKEY_RSP: Server refreshed rkey for rbuf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) enum rtrs_msg_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) RTRS_MSG_INFO_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) RTRS_MSG_INFO_RSP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) RTRS_MSG_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) RTRS_MSG_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) RTRS_MSG_RKEY_RSP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * enum rtrs_msg_flags - RTRS message flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * @RTRS_NEED_INVAL: Send invalidation in response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * @RTRS_MSG_NEW_RKEY_F: Send refreshed rkey in response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) enum rtrs_msg_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) RTRS_MSG_NEED_INVAL_F = 1 << 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) RTRS_MSG_NEW_RKEY_F = 1 << 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * struct rtrs_sg_desc - RDMA-Buffer entry description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @addr: Address of RDMA destination buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @key: Authorization rkey to write to the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * @len: Size of the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct rtrs_sg_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) __le64 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) __le32 key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) __le32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * struct rtrs_msg_conn_req - Client connection request to the server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * @magic: RTRS magic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * @version: RTRS protocol version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * @cid: Current connection id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * @cid_num: Number of connections per session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * @recon_cnt: Reconnections counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * @sess_uuid: UUID of a session (path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * @paths_uuid: UUID of a group of sessions (paths)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * NOTE: max size 56 bytes, see man rdma_connect().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct rtrs_msg_conn_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /* Is set to 0 by cma.c in case of AF_IB, do not touch that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * see https://www.spinics.net/lists/linux-rdma/msg22397.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) u8 __cma_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* On sender side that should be set to 0, or cma_save_ip_info()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * extract garbage and will fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) u8 __ip_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) __le16 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) __le16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) __le16 cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) __le16 cid_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) __le16 recon_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) uuid_t sess_uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) uuid_t paths_uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) u8 first_conn : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) u8 reserved_bits : 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) u8 reserved[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * struct rtrs_msg_conn_rsp - Server connection response to the client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * @magic: RTRS magic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * @version: RTRS protocol version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * @errno: If rdma_accept() then 0, if rdma_reject() indicates error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * @queue_depth: max inflight messages (queue-depth) in this session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * @max_io_size: max io size server supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * @max_hdr_size: max msg header size server supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * NOTE: size is 56 bytes, max possible is 136 bytes, see man rdma_accept().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct rtrs_msg_conn_rsp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) __le16 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) __le16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) __le16 errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) __le16 queue_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) __le32 max_io_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) __le32 max_hdr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) __le32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) u8 reserved[36];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * struct rtrs_msg_info_req
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * @type: @RTRS_MSG_INFO_REQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * @sessname: Session name chosen by client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct rtrs_msg_info_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) __le16 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) u8 sessname[NAME_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) u8 reserved[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * struct rtrs_msg_info_rsp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * @type: @RTRS_MSG_INFO_RSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * @sg_cnt: Number of @desc entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * @desc: RDMA buffers where the client can write to server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct rtrs_msg_info_rsp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) __le16 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) __le16 sg_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) u8 reserved[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct rtrs_sg_desc desc[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * struct rtrs_msg_rkey_rsp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * @type: @RTRS_MSG_RKEY_RSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * @buf_id: RDMA buf_id of the new rkey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * @rkey: new remote key for RDMA buffers id from server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct rtrs_msg_rkey_rsp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) __le16 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) __le16 buf_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) __le32 rkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * struct rtrs_msg_rdma_read - RDMA data transfer request from client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * @type: always @RTRS_MSG_READ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * @usr_len: length of user payload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * @sg_cnt: number of @desc entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * @desc: RDMA buffers where the server can write the result to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct rtrs_msg_rdma_read {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) __le16 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) __le16 usr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) __le16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) __le16 sg_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct rtrs_sg_desc desc[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * struct_msg_rdma_write - Message transferred to server with RDMA-Write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * @type: always @RTRS_MSG_WRITE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * @usr_len: length of user payload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct rtrs_msg_rdma_write {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) __le16 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) __le16 usr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * struct_msg_rdma_hdr - header for read or write request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * @type: @RTRS_MSG_WRITE | @RTRS_MSG_READ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct rtrs_msg_rdma_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) __le16 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* rtrs.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct rtrs_iu *rtrs_iu_alloc(u32 queue_size, size_t size, gfp_t t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct ib_device *dev, enum dma_data_direction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) void (*done)(struct ib_cq *cq, struct ib_wc *wc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) void rtrs_iu_free(struct rtrs_iu *iu, struct ib_device *dev, u32 queue_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int rtrs_iu_post_recv(struct rtrs_con *con, struct rtrs_iu *iu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int rtrs_iu_post_send(struct rtrs_con *con, struct rtrs_iu *iu, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct ib_send_wr *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int rtrs_iu_post_rdma_write_imm(struct rtrs_con *con, struct rtrs_iu *iu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct ib_sge *sge, unsigned int num_sge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) u32 rkey, u64 rdma_addr, u32 imm_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) enum ib_send_flags flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct ib_send_wr *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int rtrs_post_recv_empty(struct rtrs_con *con, struct ib_cqe *cqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int rtrs_post_rdma_write_imm_empty(struct rtrs_con *con, struct ib_cqe *cqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) u32 imm_data, enum ib_send_flags flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct ib_send_wr *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int rtrs_cq_qp_create(struct rtrs_sess *rtrs_sess, struct rtrs_con *con,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) u32 max_send_sge, int cq_vector, int cq_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) u32 max_send_wr, u32 max_recv_wr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) enum ib_poll_context poll_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) void rtrs_cq_qp_destroy(struct rtrs_con *con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) void rtrs_init_hb(struct rtrs_sess *sess, struct ib_cqe *cqe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) unsigned int interval_ms, unsigned int missed_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) void (*err_handler)(struct rtrs_con *con),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct workqueue_struct *wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) void rtrs_start_hb(struct rtrs_sess *sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) void rtrs_stop_hb(struct rtrs_sess *sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) void rtrs_send_hb_ack(struct rtrs_sess *sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) void rtrs_rdma_dev_pd_init(enum ib_pd_flags pd_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct rtrs_rdma_dev_pd *pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) void rtrs_rdma_dev_pd_deinit(struct rtrs_rdma_dev_pd *pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct rtrs_ib_dev *rtrs_ib_dev_find_or_add(struct ib_device *ib_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct rtrs_rdma_dev_pd *pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) int rtrs_ib_dev_put(struct rtrs_ib_dev *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static inline u32 rtrs_to_imm(u32 type, u32 payload)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) BUILD_BUG_ON(MAX_IMM_PAYL_BITS + MAX_IMM_TYPE_BITS != 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) BUILD_BUG_ON(RTRS_LAST_IMM > (1<<MAX_IMM_TYPE_BITS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return ((type & MAX_IMM_TYPE_MASK) << MAX_IMM_PAYL_BITS) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) (payload & MAX_IMM_PAYL_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static inline void rtrs_from_imm(u32 imm, u32 *type, u32 *payload)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) *payload = imm & MAX_IMM_PAYL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) *type = imm >> MAX_IMM_PAYL_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static inline u32 rtrs_to_io_req_imm(u32 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return rtrs_to_imm(RTRS_IO_REQ_IMM, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static inline u32 rtrs_to_io_rsp_imm(u32 msg_id, int errno, bool w_inval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) enum rtrs_imm_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) u32 payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /* 9 bits for errno, 19 bits for msg_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) payload = (abs(errno) & 0x1ff) << 19 | (msg_id & 0x7ffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) type = w_inval ? RTRS_IO_RSP_W_INV_IMM : RTRS_IO_RSP_IMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return rtrs_to_imm(type, payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static inline void rtrs_from_io_rsp_imm(u32 payload, u32 *msg_id, int *errno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* 9 bits for errno, 19 bits for msg_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) *msg_id = payload & 0x7ffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) *errno = -(int)((payload >> 19) & 0x1ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #define STAT_STORE_FUNC(type, set_value, reset) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static ssize_t set_value##_store(struct kobject *kobj, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct kobj_attribute *attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) const char *buf, size_t count) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) int ret = -EINVAL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) type *stats = container_of(kobj, type, kobj_stats); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (sysfs_streq(buf, "1")) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ret = reset(stats, true); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) else if (sysfs_streq(buf, "0")) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ret = reset(stats, false); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (ret) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return ret; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return count; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #define STAT_SHOW_FUNC(type, get_value, print) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static ssize_t get_value##_show(struct kobject *kobj, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct kobj_attribute *attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) char *page) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) type *stats = container_of(kobj, type, kobj_stats); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return print(stats, page, PAGE_SIZE); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) #define STAT_ATTR(type, stat, print, reset) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) STAT_STORE_FUNC(type, stat, reset) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) STAT_SHOW_FUNC(type, stat, print) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static struct kobj_attribute stat##_attr = __ATTR_RW(stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) #endif /* RTRS_PRI_H */