ib_isert.h 4.5 KB
Newer Older
1 2 3 4 5 6 7
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/in6.h>
#include <rdma/ib_verbs.h>
#include <rdma/rdma_cm.h>

#define ISERT_RDMA_LISTEN_BACKLOG	10
8
#define ISCSI_ISER_SG_TABLESIZE		256
9
#define ISER_FASTREG_LI_WRID		0xffffffffffffffffULL
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

enum isert_desc_type {
	ISCSI_TX_CONTROL,
	ISCSI_TX_DATAIN
};

enum iser_ib_op_code {
	ISER_IB_RECV,
	ISER_IB_SEND,
	ISER_IB_RDMA_WRITE,
	ISER_IB_RDMA_READ,
};

enum iser_conn_state {
	ISER_CONN_INIT,
	ISER_CONN_UP,
26
	ISER_CONN_FULL_FEATURE,
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
	ISER_CONN_TERMINATING,
	ISER_CONN_DOWN,
};

struct iser_rx_desc {
	struct iser_hdr iser_header;
	struct iscsi_hdr iscsi_header;
	char		data[ISER_RECV_DATA_SEG_LEN];
	u64		dma_addr;
	struct ib_sge	rx_sg;
	char		pad[ISER_RX_PAD_SIZE];
} __packed;

struct iser_tx_desc {
	struct iser_hdr iser_header;
	struct iscsi_hdr iscsi_header;
	enum isert_desc_type type;
	u64		dma_addr;
	struct ib_sge	tx_sg[2];
	int		num_sge;
	struct isert_cmd *isert_cmd;
	struct ib_send_wr send_wr;
} __packed;

51 52 53 54 55 56 57 58 59 60 61 62 63
enum isert_indicator {
	ISERT_PROTECTED		= 1 << 0,
	ISERT_DATA_KEY_VALID	= 1 << 1,
	ISERT_PROT_KEY_VALID	= 1 << 2,
	ISERT_SIG_KEY_VALID	= 1 << 3,
};

struct pi_context {
	struct ib_mr		       *prot_mr;
	struct ib_fast_reg_page_list   *prot_frpl;
	struct ib_mr		       *sig_mr;
};

64
struct fast_reg_descriptor {
65 66 67 68 69
	struct list_head		list;
	struct ib_mr		       *data_mr;
	struct ib_fast_reg_page_list   *data_frpl;
	u8				ind;
	struct pi_context	       *pi_ctx;
70 71
};

72 73 74 75 76 77 78 79 80 81
struct isert_data_buf {
	struct scatterlist     *sg;
	int			nents;
	u32			sg_off;
	u32			len; /* cur_rdma_length */
	u32			offset;
	unsigned int		dma_nents;
	enum dma_data_direction dma_dir;
};

82 83 84 85 86 87
enum {
	DATA = 0,
	PROT = 1,
	SIG = 2,
};

88 89 90 91 92
struct isert_rdma_wr {
	struct list_head	wr_list;
	struct isert_cmd	*isert_cmd;
	enum iser_ib_op_code	iser_ib_op;
	struct ib_sge		*ib_sge;
93
	struct ib_sge		s_ib_sge;
94 95
	int			send_wr_num;
	struct ib_send_wr	*send_wr;
96
	struct ib_send_wr	s_send_wr;
97
	struct ib_sge		ib_sg[3];
98
	struct isert_data_buf	data;
99
	struct isert_data_buf	prot;
100
	struct fast_reg_descriptor *fr_desc;
101 102 103 104 105 106 107
};

struct isert_cmd {
	uint32_t		read_stag;
	uint32_t		write_stag;
	uint64_t		read_va;
	uint64_t		write_va;
108 109
	u64			pdu_buf_dma;
	u32			pdu_buf_len;
110 111 112 113
	u32			read_va_off;
	u32			write_va_off;
	u32			rdma_wr_num;
	struct isert_conn	*conn;
114
	struct iscsi_cmd	*iscsi_cmd;
115 116 117 118 119 120 121 122 123 124 125 126 127
	struct iser_tx_desc	tx_desc;
	struct isert_rdma_wr	rdma_wr;
	struct work_struct	comp_work;
};

struct isert_device;

struct isert_conn {
	enum iser_conn_state	state;
	int			post_recv_buf_count;
	atomic_t		post_send_buf_count;
	u32			responder_resources;
	u32			initiator_depth;
128
	bool			pi_support;
129 130 131 132 133
	u32			max_sge;
	char			*login_buf;
	char			*login_req_buf;
	char			*login_rsp_buf;
	u64			login_req_dma;
134
	int			login_req_len;
135 136 137 138 139 140 141
	u64			login_rsp_dma;
	unsigned int		conn_rx_desc_head;
	struct iser_rx_desc	*conn_rx_descs;
	struct ib_recv_wr	conn_rx_wr[ISERT_MIN_POSTED_RX];
	struct iscsi_conn	*conn;
	struct list_head	conn_accept_node;
	struct completion	conn_login_comp;
142
	struct completion	login_req_comp;
143 144 145 146 147 148
	struct iser_tx_desc	conn_login_tx_desc;
	struct rdma_cm_id	*conn_cm_id;
	struct ib_pd		*conn_pd;
	struct ib_mr		*conn_mr;
	struct ib_qp		*conn_qp;
	struct isert_device	*conn_device;
149
	struct mutex		conn_mutex;
150 151
	struct completion	conn_wait;
	struct completion	conn_wait_comp_err;
152
	struct kref		conn_kref;
153 154 155
	struct list_head	conn_fr_pool;
	int			conn_fr_pool_size;
	/* lock to protect fastreg pool */
156
	spinlock_t		conn_lock;
157
	struct work_struct	release_work;
158 159 160 161
};

#define ISERT_MAX_CQ 64

162 163 164 165
/**
 * struct isert_comp - iSER completion context
 *
 * @device:     pointer to device handle
166
 * @cq:         completion queue
167 168
 * @active_qps: Number of active QPs attached
 *              to completion context
169
 * @work:       completion work handle
170 171
 */
struct isert_comp {
172 173
	struct isert_device     *device;
	struct ib_cq		*cq;
174
	int                      active_qps;
175
	struct work_struct	 work;
176 177 178
};

struct isert_device {
179
	int			use_fastreg;
180
	bool			pi_capable;
181 182
	int			refcount;
	struct ib_device	*ib_device;
183 184
	struct isert_comp	*comps;
	int                     comps_used;
185
	struct list_head	dev_node;
186
	struct ib_device_attr	dev_attr;
187 188 189 190 191
	int			(*reg_rdma_mem)(struct iscsi_conn *conn,
						    struct iscsi_cmd *cmd,
						    struct isert_rdma_wr *wr);
	void			(*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
						  struct isert_conn *isert_conn);
192 193 194
};

struct isert_np {
195
	struct iscsi_np         *np;
196
	struct semaphore	np_sem;
197 198 199 200 201
	struct rdma_cm_id	*np_cm_id;
	struct mutex		np_accept_mutex;
	struct list_head	np_accept_list;
	struct completion	np_login_comp;
};