1 #include <linux/socket.h>
4 #include <rdma/ib_verbs.h>
5 #include <rdma/rdma_cm.h>
9 #define DRV_NAME "isert"
10 #define PFX DRV_NAME ": "
12 #define isert_dbg(fmt, arg...) \
14 if (unlikely(isert_debug_level > 2)) \
15 printk(KERN_DEBUG PFX "%s: " fmt,\
19 #define isert_warn(fmt, arg...) \
21 if (unlikely(isert_debug_level > 0)) \
22 pr_warn(PFX "%s: " fmt, \
26 #define isert_info(fmt, arg...) \
28 if (unlikely(isert_debug_level > 1)) \
29 pr_info(PFX "%s: " fmt, \
33 #define isert_err(fmt, arg...) \
34 pr_err(PFX "%s: " fmt, __func__ , ## arg)
36 /* Constant PDU lengths calculations */
37 #define ISER_HEADERS_LEN (sizeof(struct iser_ctrl) + \
38 sizeof(struct iscsi_hdr))
39 #define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
42 /* Maximal bounds on received asynchronous PDUs */
43 #define ISERT_MAX_TX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */
45 #define ISERT_MAX_RX_MISC_PDUS 6 /*
46 * NOOP_OUT(2), TEXT(1),
47 * SCSI_TMFUNC(2), LOGOUT(1)
50 #define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */
52 #define ISERT_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX)
54 #define ISERT_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2)
56 #define ISERT_INFLIGHT_DATAOUTS 8
58 #define ISERT_QP_MAX_REQ_DTOS (ISCSI_DEF_XMIT_CMDS_MAX * \
59 (1 + ISERT_INFLIGHT_DATAOUTS) + \
60 ISERT_MAX_TX_MISC_PDUS + \
61 ISERT_MAX_RX_MISC_PDUS)
63 #define ISER_RX_PAD_SIZE (ISCSI_DEF_MAX_RECV_SEG_LEN + 4096 - \
64 (ISER_RX_PAYLOAD_SIZE + sizeof(u64) + sizeof(struct ib_sge) + \
65 sizeof(struct ib_cqe)))
67 #define ISCSI_ISER_SG_TABLESIZE 256
69 enum isert_desc_type
{
74 enum iser_ib_op_code
{
81 enum iser_conn_state
{
85 ISER_CONN_FULL_FEATURE
,
86 ISER_CONN_TERMINATING
,
91 struct iser_ctrl iser_header
;
92 struct iscsi_hdr iscsi_header
;
93 char data
[ISCSI_DEF_MAX_RECV_SEG_LEN
];
97 char pad
[ISER_RX_PAD_SIZE
];
100 static inline struct iser_rx_desc
*cqe_to_rx_desc(struct ib_cqe
*cqe
)
102 return container_of(cqe
, struct iser_rx_desc
, rx_cqe
);
105 struct iser_tx_desc
{
106 struct iser_ctrl iser_header
;
107 struct iscsi_hdr iscsi_header
;
108 enum isert_desc_type type
;
110 struct ib_sge tx_sg
[2];
111 struct ib_cqe tx_cqe
;
113 struct ib_send_wr send_wr
;
116 static inline struct iser_tx_desc
*cqe_to_tx_desc(struct ib_cqe
*cqe
)
118 return container_of(cqe
, struct iser_tx_desc
, tx_cqe
);
122 enum isert_indicator
{
123 ISERT_PROTECTED
= 1 << 0,
124 ISERT_DATA_KEY_VALID
= 1 << 1,
125 ISERT_PROT_KEY_VALID
= 1 << 2,
126 ISERT_SIG_KEY_VALID
= 1 << 3,
130 struct ib_mr
*prot_mr
;
131 struct ib_mr
*sig_mr
;
134 struct fast_reg_descriptor
{
135 struct list_head list
;
136 struct ib_mr
*data_mr
;
138 struct pi_context
*pi_ctx
;
141 struct isert_data_buf
{
142 struct scatterlist
*sg
;
145 u32 len
; /* cur_rdma_length */
147 unsigned int dma_nents
;
148 enum dma_data_direction dma_dir
;
165 struct isert_conn
*conn
;
166 struct iscsi_cmd
*iscsi_cmd
;
167 struct iser_tx_desc tx_desc
;
168 struct iser_rx_desc
*rx_desc
;
169 enum iser_ib_op_code iser_ib_op
;
170 struct ib_sge
*ib_sge
;
171 struct ib_sge s_ib_sge
;
173 struct ib_rdma_wr
*rdma_wr
;
174 struct ib_rdma_wr s_rdma_wr
;
175 struct ib_sge ib_sg
[3];
176 struct isert_data_buf data
;
177 struct isert_data_buf prot
;
178 struct fast_reg_descriptor
*fr_desc
;
179 struct work_struct comp_work
;
180 struct scatterlist sg
;
183 static inline struct isert_cmd
*tx_desc_to_cmd(struct iser_tx_desc
*desc
)
185 return container_of(desc
, struct isert_cmd
, tx_desc
);
191 enum iser_conn_state state
;
192 u32 responder_resources
;
196 struct iser_rx_desc
*login_req_buf
;
201 struct iser_rx_desc
*rx_descs
;
202 struct ib_recv_wr rx_wr
[ISERT_QP_MAX_RECV_DTOS
];
203 struct iscsi_conn
*conn
;
204 struct list_head node
;
205 struct completion login_comp
;
206 struct completion login_req_comp
;
207 struct iser_tx_desc login_tx_desc
;
208 struct rdma_cm_id
*cm_id
;
210 struct isert_device
*device
;
213 struct list_head fr_pool
;
215 /* lock to protect fastreg pool */
216 spinlock_t pool_lock
;
217 struct work_struct release_work
;
222 #define ISERT_MAX_CQ 64
225 * struct isert_comp - iSER completion context
227 * @device: pointer to device handle
228 * @cq: completion queue
229 * @active_qps: Number of active QPs attached
230 * to completion context
233 struct isert_device
*device
;
238 struct isert_device
{
242 struct ib_device
*ib_device
;
244 struct isert_comp
*comps
;
246 struct list_head dev_node
;
247 int (*reg_rdma_mem
)(struct isert_cmd
*isert_cmd
,
248 struct iscsi_conn
*conn
);
249 void (*unreg_rdma_mem
)(struct isert_cmd
*isert_cmd
,
250 struct isert_conn
*isert_conn
);
255 struct semaphore sem
;
256 struct rdma_cm_id
*cm_id
;
258 struct list_head accepted
;
259 struct list_head pending
;