1 #include <linux/socket.h>
4 #include <rdma/ib_verbs.h>
5 #include <rdma/rdma_cm.h>
7 #define DRV_NAME "isert"
8 #define PFX DRV_NAME ": "
10 #define isert_dbg(fmt, arg...) \
12 if (unlikely(isert_debug_level > 2)) \
13 printk(KERN_DEBUG PFX "%s: " fmt,\
17 #define isert_warn(fmt, arg...) \
19 if (unlikely(isert_debug_level > 0)) \
20 pr_warn(PFX "%s: " fmt, \
24 #define isert_info(fmt, arg...) \
26 if (unlikely(isert_debug_level > 1)) \
27 pr_info(PFX "%s: " fmt, \
31 #define isert_err(fmt, arg...) \
32 pr_err(PFX "%s: " fmt, __func__ , ## arg)
34 #define ISERT_RDMA_LISTEN_BACKLOG 10
35 #define ISCSI_ISER_SG_TABLESIZE 256
36 #define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL
37 #define ISER_BEACON_WRID 0xfffffffffffffffeULL
39 enum isert_desc_type {
44 enum iser_ib_op_code {
51 enum iser_conn_state {
54 ISER_CONN_FULL_FEATURE,
55 ISER_CONN_TERMINATING,
60 struct iser_hdr iser_header;
61 struct iscsi_hdr iscsi_header;
62 char data[ISER_RECV_DATA_SEG_LEN];
65 char pad[ISER_RX_PAD_SIZE];
69 struct iser_hdr iser_header;
70 struct iscsi_hdr iscsi_header;
71 enum isert_desc_type type;
73 struct ib_sge tx_sg[2];
75 struct isert_cmd *isert_cmd;
76 struct ib_send_wr send_wr;
79 enum isert_indicator {
80 ISERT_PROTECTED = 1 << 0,
81 ISERT_DATA_KEY_VALID = 1 << 1,
82 ISERT_PROT_KEY_VALID = 1 << 2,
83 ISERT_SIG_KEY_VALID = 1 << 3,
87 struct ib_mr *prot_mr;
88 struct ib_fast_reg_page_list *prot_frpl;
92 struct fast_reg_descriptor {
93 struct list_head list;
94 struct ib_mr *data_mr;
95 struct ib_fast_reg_page_list *data_frpl;
97 struct pi_context *pi_ctx;
100 struct isert_data_buf {
101 struct scatterlist *sg;
104 u32 len; /* cur_rdma_length */
106 unsigned int dma_nents;
107 enum dma_data_direction dma_dir;
116 struct isert_rdma_wr {
117 struct list_head wr_list;
118 struct isert_cmd *isert_cmd;
119 enum iser_ib_op_code iser_ib_op;
120 struct ib_sge *ib_sge;
121 struct ib_sge s_ib_sge;
123 struct ib_send_wr *send_wr;
124 struct ib_send_wr s_send_wr;
125 struct ib_sge ib_sg[3];
126 struct isert_data_buf data;
127 struct isert_data_buf prot;
128 struct fast_reg_descriptor *fr_desc;
141 struct isert_conn *conn;
142 struct iscsi_cmd *iscsi_cmd;
143 struct iser_tx_desc tx_desc;
144 struct isert_rdma_wr rdma_wr;
145 struct work_struct comp_work;
151 enum iser_conn_state state;
152 int post_recv_buf_count;
153 u32 responder_resources;
163 unsigned int conn_rx_desc_head;
164 struct iser_rx_desc *conn_rx_descs;
165 struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX];
166 struct iscsi_conn *conn;
167 struct list_head conn_accept_node;
168 struct completion conn_login_comp;
169 struct completion login_req_comp;
170 struct iser_tx_desc conn_login_tx_desc;
171 struct rdma_cm_id *conn_cm_id;
172 struct ib_pd *conn_pd;
173 struct ib_mr *conn_mr;
174 struct ib_qp *conn_qp;
175 struct isert_device *conn_device;
176 struct mutex conn_mutex;
177 struct completion conn_wait;
178 struct completion conn_wait_comp_err;
179 struct kref conn_kref;
180 struct list_head conn_fr_pool;
181 int conn_fr_pool_size;
182 /* lock to protect fastreg pool */
183 spinlock_t conn_lock;
184 struct work_struct release_work;
185 struct ib_recv_wr beacon;
189 #define ISERT_MAX_CQ 64
192 * struct isert_comp - iSER completion context
194 * @device: pointer to device handle
195 * @cq: completion queue
196 * @wcs: work completion array
197 * @active_qps: Number of active QPs attached
198 * to completion context
199 * @work: completion work handle
202 struct isert_device *device;
204 struct ib_wc wcs[16];
206 struct work_struct work;
209 struct isert_device {
213 struct ib_device *ib_device;
214 struct isert_comp *comps;
216 struct list_head dev_node;
217 struct ib_device_attr dev_attr;
218 int (*reg_rdma_mem)(struct iscsi_conn *conn,
219 struct iscsi_cmd *cmd,
220 struct isert_rdma_wr *wr);
221 void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
222 struct isert_conn *isert_conn);
227 struct semaphore np_sem;
228 struct rdma_cm_id *np_cm_id;
229 struct mutex np_accept_mutex;
230 struct list_head np_accept_list;
231 struct completion np_login_comp;