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)
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.
66 #define ISER_RX_SIZE (ISCSI_DEF_MAX_RECV_SEG_LEN + 1024)
68 /* Default I/O size is 1MB */
69 #define ISCSI_ISER_DEF_SG_TABLESIZE 256
71 /* Minimum I/O size is 512KB */
72 #define ISCSI_ISER_MIN_SG_TABLESIZE 128
74 /* Maximum support is 16MB I/O size */
75 #define ISCSI_ISER_MAX_SG_TABLESIZE 4096
77 enum isert_desc_type
{
82 enum iser_conn_state
{
86 ISER_CONN_FULL_FEATURE
,
87 ISER_CONN_TERMINATING
,
92 char buf
[ISER_RX_SIZE
];
99 static inline struct iser_rx_desc
*cqe_to_rx_desc(struct ib_cqe
*cqe
)
101 return container_of(cqe
, struct iser_rx_desc
, rx_cqe
);
104 static void *isert_get_iser_hdr(struct iser_rx_desc
*desc
)
106 return PTR_ALIGN(desc
->buf
+ ISER_HEADERS_LEN
, 512) - ISER_HEADERS_LEN
;
109 static size_t isert_get_hdr_offset(struct iser_rx_desc
*desc
)
111 return isert_get_iser_hdr(desc
) - (void *)desc
->buf
;
114 static void *isert_get_iscsi_hdr(struct iser_rx_desc
*desc
)
116 return isert_get_iser_hdr(desc
) + sizeof(struct iser_ctrl
);
119 static void *isert_get_data(struct iser_rx_desc
*desc
)
121 void *data
= isert_get_iser_hdr(desc
) + ISER_HEADERS_LEN
;
123 WARN_ON((uintptr_t)data
& 511);
127 struct iser_tx_desc
{
128 struct iser_ctrl iser_header
;
129 struct iscsi_hdr iscsi_header
;
130 enum isert_desc_type type
;
132 struct ib_sge tx_sg
[2];
133 struct ib_cqe tx_cqe
;
135 struct ib_send_wr send_wr
;
138 static inline struct iser_tx_desc
*cqe_to_tx_desc(struct ib_cqe
*cqe
)
140 return container_of(cqe
, struct iser_tx_desc
, tx_cqe
);
151 struct isert_conn
*conn
;
152 struct iscsi_cmd
*iscsi_cmd
;
153 struct iser_tx_desc tx_desc
;
154 struct iser_rx_desc
*rx_desc
;
155 struct rdma_rw_ctx rw
;
156 struct work_struct comp_work
;
157 struct scatterlist sg
;
161 static inline struct isert_cmd
*tx_desc_to_cmd(struct iser_tx_desc
*desc
)
163 return container_of(desc
, struct isert_cmd
, tx_desc
);
169 enum iser_conn_state state
;
170 u32 responder_resources
;
173 struct iser_rx_desc
*login_desc
;
177 struct iser_rx_desc
*rx_descs
;
178 struct ib_recv_wr rx_wr
[ISERT_QP_MAX_RECV_DTOS
];
179 struct iscsi_conn
*conn
;
180 struct list_head node
;
181 struct completion login_comp
;
182 struct completion login_req_comp
;
183 struct iser_tx_desc login_tx_desc
;
184 struct rdma_cm_id
*cm_id
;
188 struct isert_device
*device
;
191 struct work_struct release_work
;
194 wait_queue_head_t rem_wait
;
198 struct isert_device
{
201 struct ib_device
*ib_device
;
203 struct isert_comp
*comps
;
205 struct list_head dev_node
;
210 struct semaphore sem
;
211 struct rdma_cm_id
*cm_id
;
213 struct list_head accepted
;
214 struct list_head pending
;