1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/socket.h>
5 #include <rdma/ib_verbs.h>
6 #include <rdma/rdma_cm.h>
11 #define DRV_NAME "isert"
12 #define PFX DRV_NAME ": "
14 #define isert_dbg(fmt, arg...) \
16 if (unlikely(isert_debug_level > 2)) \
17 printk(KERN_DEBUG PFX "%s: " fmt,\
21 #define isert_warn(fmt, arg...) \
23 if (unlikely(isert_debug_level > 0)) \
24 pr_warn(PFX "%s: " fmt, \
28 #define isert_info(fmt, arg...) \
30 if (unlikely(isert_debug_level > 1)) \
31 pr_info(PFX "%s: " fmt, \
35 #define isert_err(fmt, arg...) \
36 pr_err(PFX "%s: " fmt, __func__ , ## arg)
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)
44 /* Maximal bounds on received asynchronous PDUs */
45 #define ISERT_MAX_TX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */
47 #define ISERT_MAX_RX_MISC_PDUS 6 /*
48 * NOOP_OUT(2), TEXT(1),
49 * SCSI_TMFUNC(2), LOGOUT(1)
52 #define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */
54 #define ISERT_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX)
56 #define ISERT_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2)
58 #define ISERT_QP_MAX_REQ_DTOS (ISCSI_DEF_XMIT_CMDS_MAX + \
59 ISERT_MAX_TX_MISC_PDUS + \
60 ISERT_MAX_RX_MISC_PDUS)
62 #define ISER_RX_PAD_SIZE (ISCSI_DEF_MAX_RECV_SEG_LEN + 4096 - \
63 (ISER_RX_PAYLOAD_SIZE + sizeof(u64) + sizeof(struct ib_sge) + \
64 sizeof(struct ib_cqe) + sizeof(bool)))
66 #define ISCSI_ISER_SG_TABLESIZE 256
68 enum isert_desc_type {
73 enum iser_conn_state {
77 ISER_CONN_FULL_FEATURE,
78 ISER_CONN_TERMINATING,
83 struct iser_ctrl iser_header;
84 struct iscsi_hdr iscsi_header;
85 char data[ISCSI_DEF_MAX_RECV_SEG_LEN];
90 char pad[ISER_RX_PAD_SIZE];
93 static inline struct iser_rx_desc *cqe_to_rx_desc(struct ib_cqe *cqe)
95 return container_of(cqe, struct iser_rx_desc, rx_cqe);
99 struct iser_ctrl iser_header;
100 struct iscsi_hdr iscsi_header;
101 enum isert_desc_type type;
103 struct ib_sge tx_sg[2];
104 struct ib_cqe tx_cqe;
106 struct ib_send_wr send_wr;
109 static inline struct iser_tx_desc *cqe_to_tx_desc(struct ib_cqe *cqe)
111 return container_of(cqe, struct iser_tx_desc, tx_cqe);
122 struct isert_conn *conn;
123 struct iscsi_cmd *iscsi_cmd;
124 struct iser_tx_desc tx_desc;
125 struct iser_rx_desc *rx_desc;
126 struct rdma_rw_ctx rw;
127 struct work_struct comp_work;
128 struct scatterlist sg;
132 static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc)
134 return container_of(desc, struct isert_cmd, tx_desc);
140 enum iser_conn_state state;
141 u32 responder_resources;
144 struct iser_rx_desc *login_req_buf;
149 struct iser_rx_desc *rx_descs;
150 struct ib_recv_wr rx_wr[ISERT_QP_MAX_RECV_DTOS];
151 struct iscsi_conn *conn;
152 struct list_head node;
153 struct completion login_comp;
154 struct completion login_req_comp;
155 struct iser_tx_desc login_tx_desc;
156 struct rdma_cm_id *cm_id;
158 struct isert_device *device;
161 struct work_struct release_work;
164 wait_queue_head_t rem_wait;
168 #define ISERT_MAX_CQ 64
171 * struct isert_comp - iSER completion context
173 * @device: pointer to device handle
174 * @cq: completion queue
175 * @active_qps: Number of active QPs attached
176 * to completion context
179 struct isert_device *device;
184 struct isert_device {
187 struct ib_device *ib_device;
189 struct isert_comp *comps;
191 struct list_head dev_node;
196 struct semaphore sem;
197 struct rdma_cm_id *cm_id;
199 struct list_head accepted;
200 struct list_head pending;