Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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_SRV_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define RTRS_SRV_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/refcount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "rtrs-pri.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * enum rtrs_srv_state - Server states.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) enum rtrs_srv_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	RTRS_SRV_CONNECTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	RTRS_SRV_CONNECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	RTRS_SRV_CLOSING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	RTRS_SRV_CLOSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* stats for Read and write operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * see Documentation/ABI/testing/sysfs-class-rtrs-server for details
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) struct rtrs_srv_stats_rdma_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		atomic64_t	cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		atomic64_t	size_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	} dir[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) struct rtrs_srv_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct kobject				kobj_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct rtrs_srv_stats_rdma_stats	rdma_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct rtrs_srv_sess			*sess;
^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) struct rtrs_srv_con {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct rtrs_con		c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	atomic_t		wr_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	atomic_t		sq_wr_avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct list_head	rsp_wr_wait_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	spinlock_t		rsp_wr_wait_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /* IO context in rtrs_srv, each io has one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) struct rtrs_srv_op {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct rtrs_srv_con		*con;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	u32				msg_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u8				dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct rtrs_msg_rdma_read	*rd_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct ib_rdma_wr		tx_wr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct ib_sge			tx_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct list_head		wait_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int				status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * server side memory region context, when always_invalidate=Y, we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * queue_depth of memory regrion to invalidate each memory region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) struct rtrs_srv_mr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct ib_mr	*mr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct sg_table	sgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct ib_cqe	inv_cqe;	/* only for always_invalidate=true */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u32		msg_id;		/* only for always_invalidate=true */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	u32		msg_off;	/* only for always_invalidate=true */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct rtrs_iu	*iu;		/* send buffer for new rkey msg */
^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_srv_sess {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct rtrs_sess	s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct rtrs_srv	*srv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct work_struct	close_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	enum rtrs_srv_state	state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	spinlock_t		state_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	int			cur_cq_vector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct rtrs_srv_op	**ops_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	atomic_t		ids_inflight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	wait_queue_head_t	ids_waitq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct rtrs_srv_mr	*mrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	unsigned int		mrs_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	dma_addr_t		*dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	bool			established;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned int		mem_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct kobject		kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct rtrs_srv_stats	*stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) struct rtrs_srv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct list_head	paths_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	int			paths_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct mutex		paths_ev_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	size_t			paths_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct mutex		paths_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	uuid_t			paths_uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	refcount_t		refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct rtrs_srv_ctx	*ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct list_head	ctx_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	void			*priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	size_t			queue_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct page		**chunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct device		dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	unsigned int		dev_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct kobject		*kobj_paths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct rtrs_srv_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct rtrs_srv_ops ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct rdma_cm_id *cm_id_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct rdma_cm_id *cm_id_ib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct mutex srv_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct list_head srv_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct rtrs_srv_ib_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct rtrs_srv_ctx	*srv_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	u16			port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct mutex            ib_dev_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	int			ib_dev_count;
^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) extern struct class *rtrs_dev_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void close_sess(struct rtrs_srv_sess *sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static inline void rtrs_srv_update_rdma_stats(struct rtrs_srv_stats *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 					      size_t size, int d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	atomic64_inc(&s->rdma_stats.dir[d].cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	atomic64_add(size, &s->rdma_stats.dir[d].size_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* functions which are implemented in rtrs-srv-stats.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int rtrs_srv_reset_rdma_stats(struct rtrs_srv_stats *stats, bool enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ssize_t rtrs_srv_stats_rdma_to_str(struct rtrs_srv_stats *stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				    char *page, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int rtrs_srv_reset_wc_completion_stats(struct rtrs_srv_stats *stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 					bool enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int rtrs_srv_stats_wc_completion_to_str(struct rtrs_srv_stats *stats, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 					 size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int rtrs_srv_reset_all_stats(struct rtrs_srv_stats *stats, bool enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ssize_t rtrs_srv_reset_all_help(struct rtrs_srv_stats *stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				 char *page, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* functions which are implemented in rtrs-srv-sysfs.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int rtrs_srv_create_sess_files(struct rtrs_srv_sess *sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) void rtrs_srv_destroy_sess_files(struct rtrs_srv_sess *sess);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #endif /* RTRS_SRV_H */