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

8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#define DRV_NAME	"isert"
#define PFX		DRV_NAME ": "

#define isert_dbg(fmt, arg...)				 \
	do {						 \
		if (unlikely(isert_debug_level > 2))	 \
			printk(KERN_DEBUG PFX "%s: " fmt,\
				__func__ , ## arg);	 \
	} while (0)

#define isert_warn(fmt, arg...)				\
	do {						\
		if (unlikely(isert_debug_level > 0))	\
			pr_warn(PFX "%s: " fmt,         \
				__func__ , ## arg);	\
	} while (0)

#define isert_info(fmt, arg...)				\
	do {						\
		if (unlikely(isert_debug_level > 1))	\
			pr_info(PFX "%s: " fmt,         \
				__func__ , ## arg);	\
	} while (0)

#define isert_err(fmt, arg...) \
	pr_err(PFX "%s: " fmt, __func__ , ## arg)

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
/* Constant PDU lengths calculations */
#define ISER_HEADERS_LEN	(sizeof(struct iser_ctrl) + \
				 sizeof(struct iscsi_hdr))
#define ISER_RECV_DATA_SEG_LEN	8192
#define ISER_RX_PAYLOAD_SIZE	(ISER_HEADERS_LEN + ISER_RECV_DATA_SEG_LEN)
#define ISER_RX_LOGIN_SIZE	(ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)

/* QP settings */
/* Maximal bounds on received asynchronous PDUs */
#define ISERT_MAX_TX_MISC_PDUS	4 /* NOOP_IN(2) , ASYNC_EVENT(2)   */

#define ISERT_MAX_RX_MISC_PDUS	6 /*
				   * NOOP_OUT(2), TEXT(1),
				   * SCSI_TMFUNC(2), LOGOUT(1)
				   */

#define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */

#define ISERT_QP_MAX_RECV_DTOS	(ISCSI_DEF_XMIT_CMDS_MAX)

#define ISERT_MIN_POSTED_RX	(ISCSI_DEF_XMIT_CMDS_MAX >> 2)

#define ISERT_INFLIGHT_DATAOUTS	8

#define ISERT_QP_MAX_REQ_DTOS	(ISCSI_DEF_XMIT_CMDS_MAX *    \
				(1 + ISERT_INFLIGHT_DATAOUTS) + \
				ISERT_MAX_TX_MISC_PDUS	+ \
				ISERT_MAX_RX_MISC_PDUS)

#define ISER_RX_PAD_SIZE	(ISER_RECV_DATA_SEG_LEN + 4096 - \
		(ISER_RX_PAYLOAD_SIZE + sizeof(u64) + sizeof(struct ib_sge)))

68
#define ISCSI_ISER_SG_TABLESIZE		256
69
#define ISER_FASTREG_LI_WRID		0xffffffffffffffffULL
70
#define ISER_BEACON_WRID               0xfffffffffffffffeULL
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

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,
87
	ISER_CONN_FULL_FEATURE,
88 89 90 91 92
	ISER_CONN_TERMINATING,
	ISER_CONN_DOWN,
};

struct iser_rx_desc {
93
	struct iser_ctrl iser_header;
94 95 96 97 98 99 100 101
	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 {
102
	struct iser_ctrl iser_header;
103 104 105 106 107 108 109 110 111
	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;

112 113 114 115 116 117 118 119 120 121 122 123
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_mr		       *sig_mr;
};

124
struct fast_reg_descriptor {
125 126 127 128
	struct list_head		list;
	struct ib_mr		       *data_mr;
	u8				ind;
	struct pi_context	       *pi_ctx;
129 130
};

131 132 133 134 135 136 137 138 139 140
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;
};

141 142 143 144 145 146
enum {
	DATA = 0,
	PROT = 1,
	SIG = 2,
};

147 148 149 150
struct isert_rdma_wr {
	struct isert_cmd	*isert_cmd;
	enum iser_ib_op_code	iser_ib_op;
	struct ib_sge		*ib_sge;
151
	struct ib_sge		s_ib_sge;
C
Christoph Hellwig 已提交
152 153 154
	int			rdma_wr_num;
	struct ib_rdma_wr	*rdma_wr;
	struct ib_rdma_wr	s_rdma_wr;
155
	struct ib_sge		ib_sg[3];
156
	struct isert_data_buf	data;
157
	struct isert_data_buf	prot;
158
	struct fast_reg_descriptor *fr_desc;
159 160 161 162 163 164 165
};

struct isert_cmd {
	uint32_t		read_stag;
	uint32_t		write_stag;
	uint64_t		read_va;
	uint64_t		write_va;
166 167
	u64			pdu_buf_dma;
	u32			pdu_buf_len;
168
	struct isert_conn	*conn;
169
	struct iscsi_cmd	*iscsi_cmd;
170
	struct iser_tx_desc	tx_desc;
171
	struct iser_rx_desc	*rx_desc;
172 173
	struct isert_rdma_wr	rdma_wr;
	struct work_struct	comp_work;
174
	struct scatterlist	sg;
175 176 177 178 179 180 181 182 183
};

struct isert_device;

struct isert_conn {
	enum iser_conn_state	state;
	int			post_recv_buf_count;
	u32			responder_resources;
	u32			initiator_depth;
184
	bool			pi_support;
185 186 187 188 189
	u32			max_sge;
	char			*login_buf;
	char			*login_req_buf;
	char			*login_rsp_buf;
	u64			login_req_dma;
190
	int			login_req_len;
191
	u64			login_rsp_dma;
192
	struct iser_rx_desc	*rx_descs;
193
	struct ib_recv_wr	rx_wr[ISERT_QP_MAX_RECV_DTOS];
194
	struct iscsi_conn	*conn;
195
	struct list_head	node;
196
	struct completion	login_comp;
197
	struct completion	login_req_comp;
198 199 200 201 202 203 204 205 206 207
	struct iser_tx_desc	login_tx_desc;
	struct rdma_cm_id	*cm_id;
	struct ib_qp		*qp;
	struct isert_device	*device;
	struct mutex		mutex;
	struct completion	wait;
	struct completion	wait_comp_err;
	struct kref		kref;
	struct list_head	fr_pool;
	int			fr_pool_size;
208
	/* lock to protect fastreg pool */
209
	spinlock_t		pool_lock;
210
	struct work_struct	release_work;
211
	struct ib_recv_wr       beacon;
S
Sagi Grimberg 已提交
212
	bool                    logout_posted;
213 214 215 216
};

#define ISERT_MAX_CQ 64

217 218 219 220
/**
 * struct isert_comp - iSER completion context
 *
 * @device:     pointer to device handle
221
 * @cq:         completion queue
222
 * @wcs:        work completion array
223 224
 * @active_qps: Number of active QPs attached
 *              to completion context
225
 * @work:       completion work handle
226 227
 */
struct isert_comp {
228 229
	struct isert_device     *device;
	struct ib_cq		*cq;
230
	struct ib_wc		 wcs[16];
231
	int                      active_qps;
232
	struct work_struct	 work;
233 234 235
};

struct isert_device {
236
	int			use_fastreg;
237
	bool			pi_capable;
238 239
	int			refcount;
	struct ib_device	*ib_device;
240
	struct ib_pd		*pd;
241 242
	struct isert_comp	*comps;
	int                     comps_used;
243
	struct list_head	dev_node;
244 245 246 247 248
	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);
249 250 251
};

struct isert_np {
252
	struct iscsi_np         *np;
253 254 255
	struct semaphore	sem;
	struct rdma_cm_id	*cm_id;
	struct mutex		mutex;
256 257
	struct list_head	accepted;
	struct list_head	pending;
258
};