linux/drivers/infiniband/ulp/rtrs/rtrs-pri.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * RDMA Transport Layer
 *
 * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
 * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
 * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
 */

#ifndef RTRS_PRI_H
#define RTRS_PRI_H

#include <linux/uuid.h>
#include <rdma/rdma_cm.h>
#include <rdma/ib_verbs.h>
#include <rdma/ib.h>

#include "rtrs.h"

#define RTRS_PROTO_VER_MAJOR
#define RTRS_PROTO_VER_MINOR

#define RTRS_PROTO_VER_STRING

/*
 * Max IB immediate data size is 2^28 (MAX_IMM_PAYL_BITS)
 * and the minimum chunk size is 4096 (2^12).
 * So the maximum sess_queue_depth is 65535 (2^16 - 1) in theory
 * since queue_depth in rtrs_msg_conn_rsp is defined as le16.
 * Therefore the pratical max value of sess_queue_depth is
 * somewhere between 1 and 65535 and it depends on the system.
 */
#define MAX_SESS_QUEUE_DEPTH

enum rtrs_imm_const {};

enum rtrs_imm_type {};

enum {};

struct rtrs_ib_dev;

struct rtrs_rdma_dev_pd_ops {};

struct rtrs_rdma_dev_pd {};

struct rtrs_ib_dev {};

struct rtrs_con {};

struct rtrs_path {};

/* rtrs information unit */
struct rtrs_iu {};

/**
 * enum rtrs_msg_types - RTRS message types, see also rtrs/README
 * @RTRS_MSG_INFO_REQ:		Client additional info request to the server
 * @RTRS_MSG_INFO_RSP:		Server additional info response to the client
 * @RTRS_MSG_WRITE:		Client writes data per RDMA to server
 * @RTRS_MSG_READ:		Client requests data transfer from server
 * @RTRS_MSG_RKEY_RSP:		Server refreshed rkey for rbuf
 */
enum rtrs_msg_types {};

/**
 * enum rtrs_msg_flags - RTRS message flags.
 * @RTRS_NEED_INVAL:	Send invalidation in response.
 * @RTRS_MSG_NEW_RKEY_F: Send refreshed rkey in response.
 */
enum rtrs_msg_flags {};

/**
 * struct rtrs_sg_desc - RDMA-Buffer entry description
 * @addr:	Address of RDMA destination buffer
 * @key:	Authorization rkey to write to the buffer
 * @len:	Size of the buffer
 */
struct rtrs_sg_desc {};

/**
 * struct rtrs_msg_conn_req - Client connection request to the server
 * @magic:	   RTRS magic
 * @version:	   RTRS protocol version
 * @cid:	   Current connection id
 * @cid_num:	   Number of connections per session
 * @recon_cnt:	   Reconnections counter
 * @sess_uuid:	   UUID of a session (path)
 * @paths_uuid:	   UUID of a group of sessions (paths)
 *
 * NOTE: max size 56 bytes, see man rdma_connect().
 */
struct rtrs_msg_conn_req {};

/**
 * struct rtrs_msg_conn_rsp - Server connection response to the client
 * @magic:	   RTRS magic
 * @version:	   RTRS protocol version
 * @errno:	   If rdma_accept() then 0, if rdma_reject() indicates error
 * @queue_depth:   max inflight messages (queue-depth) in this session
 * @max_io_size:   max io size server supports
 * @max_hdr_size:  max msg header size server supports
 *
 * NOTE: size is 56 bytes, max possible is 136 bytes, see man rdma_accept().
 */
struct rtrs_msg_conn_rsp {};

/**
 * struct rtrs_msg_info_req
 * @type:		@RTRS_MSG_INFO_REQ
 * @pathname:		Path name chosen by client
 */
struct rtrs_msg_info_req {};

/**
 * struct rtrs_msg_info_rsp
 * @type:		@RTRS_MSG_INFO_RSP
 * @sg_cnt:		Number of @desc entries
 * @desc:		RDMA buffers where the client can write to server
 */
struct rtrs_msg_info_rsp {};

/**
 * struct rtrs_msg_rkey_rsp
 * @type:		@RTRS_MSG_RKEY_RSP
 * @buf_id:		RDMA buf_id of the new rkey
 * @rkey:		new remote key for RDMA buffers id from server
 */
struct rtrs_msg_rkey_rsp {};

/**
 * struct rtrs_msg_rdma_read - RDMA data transfer request from client
 * @type:		always @RTRS_MSG_READ
 * @usr_len:		length of user payload
 * @sg_cnt:		number of @desc entries
 * @desc:		RDMA buffers where the server can write the result to
 */
struct rtrs_msg_rdma_read {};

/**
 * struct_msg_rdma_write - Message transferred to server with RDMA-Write
 * @type:		always @RTRS_MSG_WRITE
 * @usr_len:		length of user payload
 */
struct rtrs_msg_rdma_write {};

/**
 * struct_msg_rdma_hdr - header for read or write request
 * @type:		@RTRS_MSG_WRITE | @RTRS_MSG_READ
 */
struct rtrs_msg_rdma_hdr {};

/* rtrs.c */

struct rtrs_iu *rtrs_iu_alloc(u32 queue_num, size_t size, gfp_t t,
			      struct ib_device *dev, enum dma_data_direction,
			      void (*done)(struct ib_cq *cq, struct ib_wc *wc));
void rtrs_iu_free(struct rtrs_iu *iu, struct ib_device *dev, u32 queue_num);
int rtrs_iu_post_recv(struct rtrs_con *con, struct rtrs_iu *iu);
int rtrs_iu_post_send(struct rtrs_con *con, struct rtrs_iu *iu, size_t size,
		      struct ib_send_wr *head);
int rtrs_iu_post_rdma_write_imm(struct rtrs_con *con, struct rtrs_iu *iu,
				struct ib_sge *sge, unsigned int num_sge,
				u32 rkey, u64 rdma_addr, u32 imm_data,
				enum ib_send_flags flags,
				struct ib_send_wr *head,
				struct ib_send_wr *tail);

int rtrs_post_recv_empty(struct rtrs_con *con, struct ib_cqe *cqe);

int rtrs_cq_qp_create(struct rtrs_path *path, struct rtrs_con *con,
		      u32 max_send_sge, int cq_vector, int nr_cqe,
		      u32 max_send_wr, u32 max_recv_wr,
		      enum ib_poll_context poll_ctx);
void rtrs_cq_qp_destroy(struct rtrs_con *con);

void rtrs_init_hb(struct rtrs_path *path, struct ib_cqe *cqe,
		  unsigned int interval_ms, unsigned int missed_max,
		  void (*err_handler)(struct rtrs_con *con),
		  struct workqueue_struct *wq);
void rtrs_start_hb(struct rtrs_path *path);
void rtrs_stop_hb(struct rtrs_path *path);
void rtrs_send_hb_ack(struct rtrs_path *path);

void rtrs_rdma_dev_pd_init(enum ib_pd_flags pd_flags,
			   struct rtrs_rdma_dev_pd *pool);
void rtrs_rdma_dev_pd_deinit(struct rtrs_rdma_dev_pd *pool);

struct rtrs_ib_dev *rtrs_ib_dev_find_or_add(struct ib_device *ib_dev,
					    struct rtrs_rdma_dev_pd *pool);
int rtrs_ib_dev_put(struct rtrs_ib_dev *dev);

static inline u32 rtrs_to_imm(u32 type, u32 payload)
{}

static inline void rtrs_from_imm(u32 imm, u32 *type, u32 *payload)
{}

static inline u32 rtrs_to_io_req_imm(u32 addr)
{}

static inline u32 rtrs_to_io_rsp_imm(u32 msg_id, int errno, bool w_inval)
{}

static inline void rtrs_from_io_rsp_imm(u32 payload, u32 *msg_id, int *errno)
{}

#define STAT_STORE_FUNC(type, set_value, reset)

#define STAT_SHOW_FUNC(type, get_value, print)

#define STAT_ATTR(type, stat, print, reset)

#endif /* RTRS_PRI_H */