Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#include <linux/socket.h>
  3#include <linux/in.h>
  4#include <linux/in6.h>
  5#include <rdma/ib_verbs.h>
  6#include <rdma/rdma_cm.h>
  7#include <rdma/rw.h>
  8#include <scsi/iser.h>
  9
 10
 11#define DRV_NAME	"isert"
 12#define PFX		DRV_NAME ": "
 13
 14#define isert_dbg(fmt, arg...)				 \
 15	do {						 \
 16		if (unlikely(isert_debug_level > 2))	 \
 17			printk(KERN_DEBUG PFX "%s: " fmt,\
 18				__func__ , ## arg);	 \
 19	} while (0)
 20
 21#define isert_warn(fmt, arg...)				\
 22	do {						\
 23		if (unlikely(isert_debug_level > 0))	\
 24			pr_warn(PFX "%s: " fmt,         \
 25				__func__ , ## arg);	\
 26	} while (0)
 27
 28#define isert_info(fmt, arg...)				\
 29	do {						\
 30		if (unlikely(isert_debug_level > 1))	\
 31			pr_info(PFX "%s: " fmt,         \
 32				__func__ , ## arg);	\
 33	} while (0)
 34
 35#define isert_err(fmt, arg...) \
 36	pr_err(PFX "%s: " fmt, __func__ , ## arg)
 37
 38/* Constant PDU lengths calculations */
 39#define ISER_HEADERS_LEN	(sizeof(struct iser_ctrl) + \
 40				 sizeof(struct iscsi_hdr))
 41#define ISER_RX_PAYLOAD_SIZE	(ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
 42
 43/* QP settings */
 44/* Maximal bounds on received asynchronous PDUs */
 45#define ISERT_MAX_TX_MISC_PDUS	4 /* NOOP_IN(2) , ASYNC_EVENT(2)   */
 46
 47#define ISERT_MAX_RX_MISC_PDUS	6 /*
 48				   * NOOP_OUT(2), TEXT(1),
 49				   * SCSI_TMFUNC(2), LOGOUT(1)
 50				   */
 51
 52#define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */
 53
 54#define ISERT_QP_MAX_RECV_DTOS	(ISCSI_DEF_XMIT_CMDS_MAX)
 55
 56#define ISERT_MIN_POSTED_RX	(ISCSI_DEF_XMIT_CMDS_MAX >> 2)
 57
 58#define ISERT_QP_MAX_REQ_DTOS	(ISCSI_DEF_XMIT_CMDS_MAX +    \
 59				ISERT_MAX_TX_MISC_PDUS	+ \
 60				ISERT_MAX_RX_MISC_PDUS)
 61
 62/*
 63 * RX size is default of 8k plus headers, but data needs to align to
 64 * 512 boundary, so use 1024 to have the extra space for alignment.
 65 */
 66#define ISER_RX_SIZE		(ISCSI_DEF_MAX_RECV_SEG_LEN + 1024)
 67
 68/* Minimum I/O size is 512KB */
 69#define ISCSI_ISER_MIN_SG_TABLESIZE 128
 70
 71/* Maximum support is 16MB I/O size */
 72#define ISCSI_ISER_MAX_SG_TABLESIZE	4096
 73
 74enum isert_desc_type {
 75	ISCSI_TX_CONTROL,
 76	ISCSI_TX_DATAIN
 77};
 78
 
 
 
 
 
 
 
 79enum iser_conn_state {
 80	ISER_CONN_INIT,
 81	ISER_CONN_UP,
 82	ISER_CONN_BOUND,
 83	ISER_CONN_FULL_FEATURE,
 84	ISER_CONN_TERMINATING,
 85	ISER_CONN_DOWN,
 86};
 87
 88struct iser_rx_desc {
 89	char		buf[ISER_RX_SIZE];
 
 
 90	u64		dma_addr;
 91	struct ib_sge	rx_sg;
 92	struct ib_cqe	rx_cqe;
 93	bool		in_use;
 94};
 95
 96static inline struct iser_rx_desc *cqe_to_rx_desc(struct ib_cqe *cqe)
 97{
 98	return container_of(cqe, struct iser_rx_desc, rx_cqe);
 99}
100
101static void *isert_get_iser_hdr(struct iser_rx_desc *desc)
102{
103	return PTR_ALIGN(desc->buf + ISER_HEADERS_LEN, 512) - ISER_HEADERS_LEN;
104}
105
106static size_t isert_get_hdr_offset(struct iser_rx_desc *desc)
107{
108	return isert_get_iser_hdr(desc) - (void *)desc->buf;
109}
110
111static void *isert_get_iscsi_hdr(struct iser_rx_desc *desc)
112{
113	return isert_get_iser_hdr(desc) + sizeof(struct iser_ctrl);
114}
115
116static void *isert_get_data(struct iser_rx_desc *desc)
117{
118	void *data = isert_get_iser_hdr(desc) + ISER_HEADERS_LEN;
119
120	WARN_ON((uintptr_t)data & 511);
121	return data;
122}
123
124struct iser_tx_desc {
125	struct iser_ctrl iser_header;
126	struct iscsi_hdr iscsi_header;
127	enum isert_desc_type type;
128	u64		dma_addr;
129	struct ib_sge	tx_sg[2];
130	struct ib_cqe	tx_cqe;
131	int		num_sge;
 
 
 
 
132	struct ib_send_wr send_wr;
133} __packed;
134
135static inline struct iser_tx_desc *cqe_to_tx_desc(struct ib_cqe *cqe)
136{
137	return container_of(cqe, struct iser_tx_desc, tx_cqe);
138}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
140struct isert_cmd {
141	uint32_t		read_stag;
142	uint32_t		write_stag;
143	uint64_t		read_va;
144	uint64_t		write_va;
145	uint32_t		inv_rkey;
146	u64			pdu_buf_dma;
147	u32			pdu_buf_len;
 
 
 
148	struct isert_conn	*conn;
149	struct iscsit_cmd	*iscsit_cmd;
150	struct iser_tx_desc	tx_desc;
151	struct iser_rx_desc	*rx_desc;
152	struct rdma_rw_ctx	rw;
153	struct work_struct	comp_work;
154	struct scatterlist	sg;
155	bool			ctx_init_done;
156};
157
158static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc)
159{
160	return container_of(desc, struct isert_cmd, tx_desc);
161}
162
163struct isert_device;
164
165struct isert_conn {
166	enum iser_conn_state	state;
 
 
 
167	u32			responder_resources;
168	u32			initiator_depth;
169	bool			pi_support;
170	struct iser_rx_desc	*login_desc;
 
171	char			*login_rsp_buf;
172	int			login_req_len;
173	u64			login_rsp_dma;
174	struct iser_rx_desc	*rx_descs;
175	struct ib_recv_wr	rx_wr[ISERT_QP_MAX_RECV_DTOS];
176	struct iscsit_conn	*conn;
177	struct list_head	node;
178	struct completion	login_comp;
179	struct completion	login_req_comp;
180	struct iser_tx_desc	login_tx_desc;
181	struct rdma_cm_id	*cm_id;
182	struct ib_qp		*qp;
183	struct ib_cq		*cq;
184	u32			cq_size;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185	struct isert_device	*device;
186	struct mutex		mutex;
187	struct kref		kref;
188	struct work_struct	release_work;
189	bool                    logout_posted;
190	bool                    snd_w_inv;
191	wait_queue_head_t	rem_wait;
192	bool			dev_removed;
193};
194
195struct isert_device {
 
196	bool			pi_capable;
 
197	int			refcount;
 
198	struct ib_device	*ib_device;
199	struct ib_pd		*pd;
200	struct isert_comp	*comps;
201	int                     comps_used;
202	struct list_head	dev_node;
 
 
 
 
 
 
203};
204
205struct isert_np {
206	struct iscsi_np         *np;
207	struct semaphore	sem;
208	struct rdma_cm_id	*cm_id;
209	struct mutex		mutex;
210	struct list_head	accepted;
211	struct list_head	pending;
212};
v3.15
 
  1#include <linux/socket.h>
  2#include <linux/in.h>
  3#include <linux/in6.h>
  4#include <rdma/ib_verbs.h>
  5#include <rdma/rdma_cm.h>
 
 
  6
  7#define ISERT_RDMA_LISTEN_BACKLOG	10
  8#define ISCSI_ISER_SG_TABLESIZE		256
  9#define ISER_FASTREG_LI_WRID		0xffffffffffffffffULL
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 10
 11enum isert_desc_type {
 12	ISCSI_TX_CONTROL,
 13	ISCSI_TX_DATAIN
 14};
 15
 16enum iser_ib_op_code {
 17	ISER_IB_RECV,
 18	ISER_IB_SEND,
 19	ISER_IB_RDMA_WRITE,
 20	ISER_IB_RDMA_READ,
 21};
 22
 23enum iser_conn_state {
 24	ISER_CONN_INIT,
 25	ISER_CONN_UP,
 
 
 26	ISER_CONN_TERMINATING,
 27	ISER_CONN_DOWN,
 28};
 29
 30struct iser_rx_desc {
 31	struct iser_hdr iser_header;
 32	struct iscsi_hdr iscsi_header;
 33	char		data[ISER_RECV_DATA_SEG_LEN];
 34	u64		dma_addr;
 35	struct ib_sge	rx_sg;
 36	char		pad[ISER_RX_PAD_SIZE];
 37} __packed;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 38
 39struct iser_tx_desc {
 40	struct iser_hdr iser_header;
 41	struct iscsi_hdr iscsi_header;
 42	enum isert_desc_type type;
 43	u64		dma_addr;
 44	struct ib_sge	tx_sg[2];
 
 45	int		num_sge;
 46	struct isert_cmd *isert_cmd;
 47	struct llist_node *comp_llnode_batch;
 48	struct llist_node comp_llnode;
 49	bool		llnode_active;
 50	struct ib_send_wr send_wr;
 51} __packed;
 52
 53enum isert_indicator {
 54	ISERT_PROTECTED		= 1 << 0,
 55	ISERT_DATA_KEY_VALID	= 1 << 1,
 56	ISERT_PROT_KEY_VALID	= 1 << 2,
 57	ISERT_SIG_KEY_VALID	= 1 << 3,
 58};
 59
 60struct pi_context {
 61	struct ib_mr		       *prot_mr;
 62	struct ib_fast_reg_page_list   *prot_frpl;
 63	struct ib_mr		       *sig_mr;
 64};
 65
 66struct fast_reg_descriptor {
 67	struct list_head		list;
 68	struct ib_mr		       *data_mr;
 69	struct ib_fast_reg_page_list   *data_frpl;
 70	u8				ind;
 71	struct pi_context	       *pi_ctx;
 72};
 73
 74struct isert_data_buf {
 75	struct scatterlist     *sg;
 76	int			nents;
 77	u32			sg_off;
 78	u32			len; /* cur_rdma_length */
 79	u32			offset;
 80	unsigned int		dma_nents;
 81	enum dma_data_direction dma_dir;
 82};
 83
 84struct isert_rdma_wr {
 85	struct list_head	wr_list;
 86	struct isert_cmd	*isert_cmd;
 87	enum iser_ib_op_code	iser_ib_op;
 88	struct ib_sge		*ib_sge;
 89	struct ib_sge		s_ib_sge;
 90	int			send_wr_num;
 91	struct ib_send_wr	*send_wr;
 92	struct ib_send_wr	s_send_wr;
 93	struct isert_data_buf	data;
 94	struct isert_data_buf	prot;
 95	struct fast_reg_descriptor *fr_desc;
 96};
 97
 98struct isert_cmd {
 99	uint32_t		read_stag;
100	uint32_t		write_stag;
101	uint64_t		read_va;
102	uint64_t		write_va;
 
103	u64			pdu_buf_dma;
104	u32			pdu_buf_len;
105	u32			read_va_off;
106	u32			write_va_off;
107	u32			rdma_wr_num;
108	struct isert_conn	*conn;
109	struct iscsi_cmd	*iscsi_cmd;
110	struct iser_tx_desc	tx_desc;
111	struct isert_rdma_wr	rdma_wr;
 
112	struct work_struct	comp_work;
 
 
113};
114
 
 
 
 
 
115struct isert_device;
116
117struct isert_conn {
118	enum iser_conn_state	state;
119	bool			logout_posted;
120	int			post_recv_buf_count;
121	atomic_t		post_send_buf_count;
122	u32			responder_resources;
123	u32			initiator_depth;
124	u32			max_sge;
125	char			*login_buf;
126	char			*login_req_buf;
127	char			*login_rsp_buf;
128	u64			login_req_dma;
129	u64			login_rsp_dma;
130	unsigned int		conn_rx_desc_head;
131	struct iser_rx_desc	*conn_rx_descs;
132	struct ib_recv_wr	conn_rx_wr[ISERT_MIN_POSTED_RX];
133	struct iscsi_conn	*conn;
134	struct list_head	conn_accept_node;
135	struct completion	conn_login_comp;
136	struct iser_tx_desc	conn_login_tx_desc;
137	struct rdma_cm_id	*conn_cm_id;
138	struct ib_pd		*conn_pd;
139	struct ib_mr		*conn_mr;
140	struct ib_qp		*conn_qp;
141	struct isert_device	*conn_device;
142	struct work_struct	conn_logout_work;
143	struct mutex		conn_mutex;
144	struct completion	conn_wait;
145	struct completion	conn_wait_comp_err;
146	struct kref		conn_kref;
147	struct list_head	conn_fr_pool;
148	int			conn_fr_pool_size;
149	/* lock to protect fastreg pool */
150	spinlock_t		conn_lock;
151#define ISERT_COMP_BATCH_COUNT	8
152	int			conn_comp_batch;
153	struct llist_head	conn_comp_llist;
154};
155
156#define ISERT_MAX_CQ 64
157
158struct isert_cq_desc {
159	struct isert_device	*device;
160	int			cq_index;
161	struct work_struct	cq_rx_work;
162	struct work_struct	cq_tx_work;
 
 
 
 
163};
164
165struct isert_device {
166	int			use_fastreg;
167	bool			pi_capable;
168	int			cqs_used;
169	int			refcount;
170	int			cq_active_qps[ISERT_MAX_CQ];
171	struct ib_device	*ib_device;
172	struct ib_cq		*dev_rx_cq[ISERT_MAX_CQ];
173	struct ib_cq		*dev_tx_cq[ISERT_MAX_CQ];
174	struct isert_cq_desc	*cq_desc;
175	struct list_head	dev_node;
176	struct ib_device_attr	dev_attr;
177	int			(*reg_rdma_mem)(struct iscsi_conn *conn,
178						    struct iscsi_cmd *cmd,
179						    struct isert_rdma_wr *wr);
180	void			(*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
181						  struct isert_conn *isert_conn);
182};
183
184struct isert_np {
185	struct semaphore	np_sem;
186	struct rdma_cm_id	*np_cm_id;
187	struct mutex		np_accept_mutex;
188	struct list_head	np_accept_list;
189	struct completion	np_login_comp;
 
190};